5 # The contents of this file are subject to the terms of the
6 # Common Development and Distribution License (the "License").
7 # You may not use this file except in compliance with the License.
9 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 # or http://www.opensolaris.org/os/licensing.
11 # See the License for the specific language governing permissions
12 # and limitations under the License.
14 # When distributing Covered Code, include this CDDL HEADER in each
15 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 # If applicable, add the following below this CDDL HEADER, with the
17 # fields enclosed by brackets "[]" replaced with your own identifying
18 # information: Portions Copyright [yyyy] [name of copyright owner]
23 # Copyright 2008 Sun Microsystems, Inc. All rights reserved.
24 # Use is subject to license terms.
26 # Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T.
27 # All rights reserved.
30 #ident "%Z%%M% %I% %E% SMI"
32 vfstab
=${vfstab:=/etc/vfstab}
35 # readvfstab mount_point
36 # -> (special, fsckdev, mountp, fstype, fsckpass, automnt, mntopts)
38 # A vfstab-like input stream is scanned for the mount point specified
39 # as $1. Returns the fields of vfstab in the following shell
42 # special block device
44 # mountp mount point (must match $1, if found)
45 # fstype file system type
46 # fsckpass fsck(1M) pass number
47 # automnt automount flag (yes or no)
48 # mntopts file system-specific mount options.
50 # If the mount point can not be found in the standard input stream,
51 # then all fields are set to empty values. This function assumes that
52 # stdin is already set /etc/vfstab (or other appropriate input
56 while read special fsckdev mountp fstype fsckpass automnt mntopts
; do
58 '' ) # Ignore empty lines.
62 '#'* ) # Ignore comment lines.
66 '-') # Ignore "no-action" lines.
71 [ "x$mountp" = "x$1" ] && break
76 while read special fsckdev mountp fstype fsckpass automnt mntopts
; do
77 # Ignore comments, empty lines, and no-action lines
79 '#'* |
'' |
'-') continue;;
82 [ "$fstype" != swap
] && continue
84 [ "x$special" = "x$1" ] && break
89 # readmnttab mount_point
90 # -> (special, mountp, fstype, mntopts, mnttime)
92 # A mnttab-like input stream is scanned for the mount point specified
93 # as $1. Returns the fields of mnttab in the following shell
96 # special block device
97 # mountp mount point (must match $1, if found)
98 # fstype file system type
99 # mntopts file system-specific mount options.
100 # mnttime time at which file system was mounted
102 # If the mount point can not be found in the standard input stream,
103 # then all fields are set to empty values. This function assumes that
104 # stdin is already set to /etc/mnttab (or other appropriate input
108 while read special mountp fstype mntopts mnttime
; do
109 [ "x$mountp" = "x$1" ] && break
119 # checkmessage raw_device fstype mountpoint
120 # checkmessage2 raw_device fstype mountpoint
122 # Two simple auxilary routines to the shell function checkfs. Both
123 # display instructions for a manual file system check.
127 cecho
"WARNING - Unable to repair the $3 filesystem. Run fsck"
128 cecho
"manually (fsck -F $2 $1)."
134 cecho
"WARNING - fatal error from fsck - error $4"
135 cecho
"Unable to repair the $3 filesystem. Run fsck manually"
136 cecho
"(fsck -F $2 $1)."
141 # checkfs raw_device fstype mountpoint
143 # Check the file system specified. The return codes from fsck have the
144 # following meanings.
146 # 0 file system is unmounted and okay
147 # 32 file system is unmounted and needs checking (fsck -m only)
148 # 33 file system is already mounted
149 # 34 cannot stat device
150 # 35 modified root or something equally dangerous
151 # 36 uncorrectable errors detected - terminate normally (4.1 code 8)
152 # 37 a signal was caught during processing (4.1 exit 12)
153 # 39 uncorrectable errors detected - terminate rightaway (4.1 code 8)
154 # 40 for root, same as 0 (used here to remount root)
157 # skip checking if the fsckdev is "-"
158 [ "x$1" = x-
] && return
160 # if fsck isn't present, it is probably because either the mount of
161 # /usr failed or the /usr filesystem is badly damanged. In either
162 # case, there is not much to be done automatically. Fail with
163 # a message to the user.
164 if [ ! -x /usr
/sbin
/fsck
]; then
166 cecho
"WARNING - /usr/sbin/fsck not found. Most likely the"
167 cecho
"mount of /usr failed or the /usr filesystem is badly"
173 # If a filesystem-specific fsck binary is unavailable, then no
174 # fsck pass is required.
175 [ ! -x /usr
/lib
/fs
/$2/fsck
] && [ ! -x /etc
/fs
/$2/fsck
] && return
177 /usr
/sbin
/fsck
-F $2 -m $1 >/dev
/null
2>&1
179 if [ $?
-ne 0 ]; then
180 # Determine fsck options by file system type
188 cecho
"The $3 file system ($1) is being checked."
189 /usr
/sbin
/fsck
-F $2 $foptions $1
192 0|
40) # File system OK
195 1|
34|
36|
37|
39) # couldn't fix the file system - fail
196 checkmessage
"$1" "$2" "$3"
199 33) # already mounted
203 *) # fsck child process killed (+ error code 35)
204 checkmessage2
"$1" "$2" "$3" "$?"
214 # checkopt option option-string
215 # -> ($option, $otherops)
217 # Check to see if a given mount option is present in the comma
218 # separated list gotten from vfstab.
221 # ${option} : the option if found the empty string if not found
222 # ${otherops} : the option string with the found option deleted
228 [ "x$2" = x-
] && return
231 set -- `IFS=, ; echo $2`
233 while [ $# -gt 0 ]; do
234 if [ "x$1" = "x$searchop" ]; then
237 if [ -z "$otherops" ]; then
240 otherops
="${otherops},$1"
248 # hasopts $opts $allopts
250 # Check if all options from the list $opts are present in $allopts.
251 # Both $opts and $allopts should be in comma separated format.
253 # Return 0 on success, and 1 otherwise.
259 set -- `IFS=, ; echo $opts`
260 while [ $# -gt 0 ]; do
261 if [ "$1" != "remount" ]; then
264 # Don't report errors if the filesystem is already
265 # read-write when mounting it as read-only.
267 [ -z "$option" ] && [ "$1" = "ro" ] && \
269 [ -z "$option" ] && return 1
277 # mounted $path $fsopts $fstype
279 # Check whether the specified file system of the given type is currently
280 # mounted with all required filesystem options by going through /etc/mnttab
281 # in our standard input.
285 # 1 The filesystem is not currently mounted, or mounted without required
286 # options, or a filesystem of a different type is mounted instead.
293 while read mntspec mntpath mnttype mntopts on
; do
294 [ "$mntpath" = "$path" ] ||
continue
295 [ "$fstype" != "-" ] && [ "$mnttype" != "$fstype" ] && return 1
296 [ "$fsopts" = "-" ] && return 0
297 hasopts
$fsopts $mntopts && return 0
303 # mountfs $opts $path $type $fsopts $special
305 # Try to mount a filesystem. If failed, display our standard error
306 # message on the console and print more details about what happened
307 # to our service log.
310 # $opts - options for mount(1M) [optional]
311 # $path - mount point
312 # $type - file system type [optional]
313 # $fsopts - file system specific options (-o) [optional]
314 # $special - device on which the file system resides [optional]
318 # otherwise - error code returned by mount(1M).
326 # Take care of optional arguments
328 [ "$opts" = "-" ] && opts
=""
329 [ "$special" = "-" ] && special
=""
330 [ "$3" = "-" ] && type=""
331 [ "$3" != "-" ] && type="-F $3"
332 [ "$4" = "-" ] && fsopts
=""
333 [ "$4" != "-" ] && fsopts
="-o $4"
335 cmd
="/sbin/mount $opts $type $fsopts $special $path"
339 [ $err = 0 ] && return 0
342 # If the specified file system is already mounted with all
343 # required options, and has the same filesystem type
344 # then ignore errors and return success
346 mounted
$path $4 $3 < /etc
/mnttab
&& return 0
348 echo "ERROR: $SMF_FMRI failed to mount $path "\
349 "(see 'svcs -x' for details)" > /dev
/msglog
350 echo "ERROR: $cmd failed, err=$err"