6 # =====================================================================
8 # Copyright (C) 2006, 2007 by Keith Marshall
9 # mailto:keithmarshall@users.sourceforge.net
11 # This file is part of MSYS
12 # http://www.mingw.org/msys.shtml
14 # MSYS is free software. It is provided "as is", in the hope that it
15 # may be useful; there is NO WARRANTY OF ANY KIND, not even an implied
16 # warranty of MERCHANTABILITY or FITNESS FOR ANY PARTICULAR PURPOSE.
17 # At no time will the author accept liability for damages, however
18 # caused, resulting from the use of this software.
20 # Permission is granted to copy and redistribute this software, either
21 # as is, or in modified form, provided that:--
23 # 1) All such copies are distributed with the same rights
26 # 2) The preceding disclaimer of warranty and liabality is
27 # retained verbatim, in all copies.
29 # 3) Accreditation of the original author remains in place.
31 # 4) Modified copies are clearly identified as such, with
32 # additional accreditation given to the authors of each
35 # =====================================================================
38 # Ensure the the `fstab' mount registry exists, and is writeable.
40 >> ${MNTTAB="/etc/fstab"}
42 # Select the operation to be performed, based on number of argumemnts.
47 # No arguments specified...
48 # Simply report the current state of the mount table.
54 # One argument specified...
55 # Check for any pre-existing mount which may conflict; if none,
56 # try to match it to a default mount specification from the `fstab'
57 # configuration file, and mount the specified directory, if any,
58 # on its associated mount point.
60 FSTAB=${FSTAB-"$MNTTAB.conf"}
61 MNTPATH=`echo "$1" | tr '\\\\' /`
63 if cat $MNTTAB | tr '\\' / | awk '
65 # Check for pre-existing mount of specified argument;
66 # set exit status to:--
67 # 0: if no such mount exists;
68 # 1: if argument is an already mounted directory;
69 # 2: if argument is a mount point already in use.
73 $1 == "'$MNTPATH'" { status = 1 }
74 $2 == "'$MNTPATH'" { status = 2 }
78 # No pre-existing mount conflicts...
80 if WINPATH=`cat 2>/dev/null $FSTAB | tr '\\' / | awk '
82 # Look up the default mount point specification;
83 # set exit status, (assigned to "errno"), to:--
84 # 0: if found; (it is assigned to WINPATH);
85 # 1: if found, but multiply and ambiguously defined;
88 BEGIN { status = 0; mount = "" }
91 if( mount == "" ) mount = $0
92 else if( mount != $0 ) status = 1
95 if( mount == "" ) mount = $0
96 else if( mount != $0 ) status = 1
99 if( mount == "" ) exit 2
105 # Found a default mount specification; activate it.
107 echo $WINPATH >> $MNTTAB
109 elif test -f $FSTAB && test -r $FSTAB
112 # Read the configuration file, but could not find
113 # a mount specification matching the argument.
116 1) echo >&2 "$0: $FSTAB: ambiguous reference for $MNTPATH" ;;
117 2) echo >&2 "$0: $FSTAB: no mount specification for $MNTPATH" ;;
123 # Found the configuration file, but could not read it.
125 echo >&2 "$0: $FSTAB: cannot read configuration file"
129 # Could not find the configuration file.
131 echo >&2 "$0: $FSTAB: configuration file not found"
136 # Found a conflicting active mount...
137 # Display an appropriate diagnostic message, depending on
138 # whether the argument represented a directory path name,
139 # or a mount point, and bail out.
142 1) echo >&2 "$0: '$MNTPATH' is already mounted" ;;
143 2) echo >&2 "$0: mount point '$MNTPATH' is already in use" ;;
150 # Two arguments specified...
151 # First is directory path name, second is mount point.
153 WINPATH=`echo "$1" | tr '\\\\' /`
154 MNTPATH=`echo "$2" | tr '\\\\' /`
156 if cat $MNTTAB | tr '\\' / | awk '
158 # Check that the mount point is not already in use;
159 # set exit status to:--
160 # 0: if no existing mount table entry matches;
161 # 1: if mount point already in mount table.
165 $2 == "'$MNTPATH'" { status = 1 }
169 # Mount point not yet assigned...
170 # Update the mount table, to include the new specification.
172 echo -e "$WINPATH\t$MNTPATH" >> "$MNTTAB"
176 # Specified mount point is already in use...
177 # Diagnose, and bail out.
179 echo >&2 "$0: mount point '$MNTPATH' is already in use"
185 # More than two arguments specified...
186 # Complain, and bail out.
188 echo >&2 "$0: incorrect number of arguments"
189 echo >&2 "usage: mount [<win32path> <msyspath>]"
193 # On successful completion, ensure we set the exit status appropriately.
197 # $RCSfile$: end of file