xref: /illumos-gate/usr/src/cmd/initpkg/mountall.sh (revision bd93c05d)
17c478bd9Sstevel@tonic-gate#!/sbin/sh
27c478bd9Sstevel@tonic-gate#
37c478bd9Sstevel@tonic-gate# CDDL HEADER START
47c478bd9Sstevel@tonic-gate#
57c478bd9Sstevel@tonic-gate# The contents of this file are subject to the terms of the
67c478bd9Sstevel@tonic-gate# Common Development and Distribution License, Version 1.0 only
77c478bd9Sstevel@tonic-gate# (the "License").  You may not use this file except in compliance
87c478bd9Sstevel@tonic-gate# with the License.
97c478bd9Sstevel@tonic-gate#
107c478bd9Sstevel@tonic-gate# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
117c478bd9Sstevel@tonic-gate# or http://www.opensolaris.org/os/licensing.
127c478bd9Sstevel@tonic-gate# See the License for the specific language governing permissions
137c478bd9Sstevel@tonic-gate# and limitations under the License.
147c478bd9Sstevel@tonic-gate#
157c478bd9Sstevel@tonic-gate# When distributing Covered Code, include this CDDL HEADER in each
167c478bd9Sstevel@tonic-gate# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
177c478bd9Sstevel@tonic-gate# If applicable, add the following below this CDDL HEADER, with the
187c478bd9Sstevel@tonic-gate# fields enclosed by brackets "[]" replaced with your own identifying
197c478bd9Sstevel@tonic-gate# information: Portions Copyright [yyyy] [name of copyright owner]
207c478bd9Sstevel@tonic-gate#
217c478bd9Sstevel@tonic-gate# CDDL HEADER END
227c478bd9Sstevel@tonic-gate#
23812e8c05SGordon Ross
247c478bd9Sstevel@tonic-gate#
25812e8c05SGordon Ross# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
267c478bd9Sstevel@tonic-gate# Use is subject to license terms.
27*bd93c05dSAlexander Eremin# Copyright 2015 Nexenta Systems, Inc. All rights reserved.
287c478bd9Sstevel@tonic-gate#
297c478bd9Sstevel@tonic-gate#	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T
307c478bd9Sstevel@tonic-gate#	  All Rights Reserved
317c478bd9Sstevel@tonic-gate#
327c478bd9Sstevel@tonic-gate
33812e8c05SGordon Rossusage () {
34812e8c05SGordon Ross	if [ -n "$1" ]; then
35812e8c05SGordon Ross		echo "mountall: $1" 1>&2
36812e8c05SGordon Ross	fi
37812e8c05SGordon Ross	echo "Usage:\nmountall [-F FSType] [-l|-r|-g] [file_system_table]" 1>&2
38812e8c05SGordon Ross	exit 2
39812e8c05SGordon Ross}
40812e8c05SGordon Ross
41812e8c05SGordon RossPATH=/usr/sbin:/usr/bin
42812e8c05SGordon RossTYPES=all
43812e8c05SGordon RossFSTAB=/etc/vfstab
44812e8c05SGordon Rosserr=0
45812e8c05SGordon Ross
46812e8c05SGordon Ross# Clear these in case they were already set in our environment.
47812e8c05SGordon RossFSType=
48812e8c05SGordon RossGFLAG=
49812e8c05SGordon RossRFLAG=
50812e8c05SGordon RossLFLAG=
51812e8c05SGordon RossSFLAG=
52812e8c05SGordon RossRemoteFSTypes=
53812e8c05SGordon Ross
547c478bd9Sstevel@tonic-gate#	checkmessage "fsck_device | mount_point"
557c478bd9Sstevel@tonic-gate#
567c478bd9Sstevel@tonic-gate# Simple auxilary routine to the shell function checkfs. Prints out
577c478bd9Sstevel@tonic-gate# instructions for a manual file system check before entering the shell.
587c478bd9Sstevel@tonic-gate#
597c478bd9Sstevel@tonic-gatecheckmessage() {
607c478bd9Sstevel@tonic-gate	echo "" > /dev/console
617c478bd9Sstevel@tonic-gate	if [ "$1" != "" ] ; then
627c478bd9Sstevel@tonic-gate		echo "WARNING - Unable to repair one or more \c" > /dev/console
637c478bd9Sstevel@tonic-gate		echo "of the following filesystem(s):" > /dev/console
647c478bd9Sstevel@tonic-gate		echo "\t$1" > /dev/console
657c478bd9Sstevel@tonic-gate	else
667c478bd9Sstevel@tonic-gate		echo "WARNING - Unable to repair one or more filesystems." \
677c478bd9Sstevel@tonic-gate			> /dev/console
687c478bd9Sstevel@tonic-gate	fi
697c478bd9Sstevel@tonic-gate	echo "Run fsck manually (fsck filesystem...)." > /dev/console
707c478bd9Sstevel@tonic-gate	echo "" > /dev/console
717c478bd9Sstevel@tonic-gate}
727c478bd9Sstevel@tonic-gate
737c478bd9Sstevel@tonic-gate#
747c478bd9Sstevel@tonic-gate#	checkfs raw_device fstype mountpoint
757c478bd9Sstevel@tonic-gate#
767c478bd9Sstevel@tonic-gate# Check the file system specified. The return codes from fsck have the
777c478bd9Sstevel@tonic-gate# following meanings.
787c478bd9Sstevel@tonic-gate#	 0 - file system is unmounted and okay
797c478bd9Sstevel@tonic-gate#	32 - file system is unmounted and needs checking (fsck -m only)
807c478bd9Sstevel@tonic-gate#	33 - file system is already mounted
817c478bd9Sstevel@tonic-gate#	34 - cannot stat device
827c478bd9Sstevel@tonic-gate#	36 - uncorrectable errors detected - terminate normally (4.1 code 8)
837c478bd9Sstevel@tonic-gate#	37 - a signal was caught during processing (4.1 exit 12)
847c478bd9Sstevel@tonic-gate#	39 - uncorrectable errors detected - terminate rightaway (4.1 code 8)
857c478bd9Sstevel@tonic-gate#	40 - for root, same as 0 (used by rcS to remount root)
867c478bd9Sstevel@tonic-gate#
877c478bd9Sstevel@tonic-gatecheckfs() {
887c478bd9Sstevel@tonic-gate	/usr/sbin/fsck -F $2 -m $1  >/dev/null 2>&1
897c478bd9Sstevel@tonic-gate
907c478bd9Sstevel@tonic-gate	if [ $? -ne 0 ]
917c478bd9Sstevel@tonic-gate	then
927c478bd9Sstevel@tonic-gate		# Determine fsck options by file system type
937c478bd9Sstevel@tonic-gate		case "$2" in
947c478bd9Sstevel@tonic-gate		ufs)	foptions="-o p"
957c478bd9Sstevel@tonic-gate			;;
967c478bd9Sstevel@tonic-gate		*)	foptions="-y"
977c478bd9Sstevel@tonic-gate			;;
987c478bd9Sstevel@tonic-gate		esac
997c478bd9Sstevel@tonic-gate
1007c478bd9Sstevel@tonic-gate		echo "The "$3" file system ("$1") is being checked."
1017c478bd9Sstevel@tonic-gate		/usr/sbin/fsck -F $2 ${foptions} $1
1027c478bd9Sstevel@tonic-gate
1037c478bd9Sstevel@tonic-gate		case $? in
1047c478bd9Sstevel@tonic-gate		0|40)	# file system OK
1057c478bd9Sstevel@tonic-gate			;;
1067c478bd9Sstevel@tonic-gate
1077c478bd9Sstevel@tonic-gate		*)	# couldn't fix the file system
1087c478bd9Sstevel@tonic-gate			echo "/usr/sbin/fsck failed with exit code "$?"."
1097c478bd9Sstevel@tonic-gate			checkmessage "$1"
1107c478bd9Sstevel@tonic-gate			;;
1117c478bd9Sstevel@tonic-gate		esac
1127c478bd9Sstevel@tonic-gate	fi
1137c478bd9Sstevel@tonic-gate}
1147c478bd9Sstevel@tonic-gate
1157c478bd9Sstevel@tonic-gate#
1167c478bd9Sstevel@tonic-gate# Used to save an entry that we will want to mount either in
1177c478bd9Sstevel@tonic-gate# a command file or as a mount point list.
1187c478bd9Sstevel@tonic-gate#
1197c478bd9Sstevel@tonic-gate# saveentry fstype options special mountp
1207c478bd9Sstevel@tonic-gate#
1217c478bd9Sstevel@tonic-gatesaveentry() {
1227c478bd9Sstevel@tonic-gate	if [ "$ALTM" ]; then
1237c478bd9Sstevel@tonic-gate		echo "/sbin/mount -F $1 $2 $3 $4" >> $ALTM
1247c478bd9Sstevel@tonic-gate	else
1257c478bd9Sstevel@tonic-gate		mntlist="$mntlist $4"
1267c478bd9Sstevel@tonic-gate	fi
1277c478bd9Sstevel@tonic-gate}
1287c478bd9Sstevel@tonic-gate
129812e8c05SGordon Ross# Do the passed mount options include "global"?
130812e8c05SGordon Rossisglobal() {
131812e8c05SGordon Ross	case ",${1}," in
132812e8c05SGordon Ross	*,global,*)
133812e8c05SGordon Ross		return 0
134812e8c05SGordon Ross		;;
135812e8c05SGordon Ross	esac
136812e8c05SGordon Ross	return 1
137812e8c05SGordon Ross}
138812e8c05SGordon Ross
139812e8c05SGordon Ross# Is the passed fstype a "remote" one?
140812e8c05SGordon Ross# Essentially: /usr/bin/grep "^$1" /etc/dfs/fstypes
141812e8c05SGordon Rossisremote() {
142812e8c05SGordon Ross	for t in $RemoteFSTypes
143812e8c05SGordon Ross	do
144812e8c05SGordon Ross		[ "$t" = "$1" ] && return 0
145812e8c05SGordon Ross	done
146812e8c05SGordon Ross	return 1
147812e8c05SGordon Ross}
148812e8c05SGordon Ross
149812e8c05SGordon Ross# Get list of remote FS types (just once)
150812e8c05SGordon RossRemoteFSTypes=`while read t junk; do echo $t; done < /etc/dfs/fstypes`
1517c478bd9Sstevel@tonic-gate
1527c478bd9Sstevel@tonic-gate
1537c478bd9Sstevel@tonic-gate#
1547c478bd9Sstevel@tonic-gate# Process command line args
1557c478bd9Sstevel@tonic-gate#
1567c478bd9Sstevel@tonic-gatewhile getopts ?grlsF: c
1577c478bd9Sstevel@tonic-gatedo
1587c478bd9Sstevel@tonic-gate	case $c in
1597c478bd9Sstevel@tonic-gate	g)	GFLAG="g";;
1607c478bd9Sstevel@tonic-gate	r)	RFLAG="r";;
1617c478bd9Sstevel@tonic-gate	l)	LFLAG="l";;
1627c478bd9Sstevel@tonic-gate	s)	SFLAG="s";;
1637c478bd9Sstevel@tonic-gate	F)	FSType="$OPTARG";
1647c478bd9Sstevel@tonic-gate		if [ "$TYPES" = "one" ]
1657c478bd9Sstevel@tonic-gate		then
1667c478bd9Sstevel@tonic-gate			echo "mountall: more than one FSType specified"
1677c478bd9Sstevel@tonic-gate			exit 2
1687c478bd9Sstevel@tonic-gate		fi
1697c478bd9Sstevel@tonic-gate		TYPES="one";
1707c478bd9Sstevel@tonic-gate
1717c478bd9Sstevel@tonic-gate		case $FSType in
1727c478bd9Sstevel@tonic-gate		?????????*)
1737c478bd9Sstevel@tonic-gate			echo "mountall: FSType $FSType exceeds 8 characters"
1747c478bd9Sstevel@tonic-gate			exit 2
1757c478bd9Sstevel@tonic-gate		esac
1767c478bd9Sstevel@tonic-gate		;;
177812e8c05SGordon Ross	\?)	usage "";;
1787c478bd9Sstevel@tonic-gate	esac
1797c478bd9Sstevel@tonic-gatedone
1807c478bd9Sstevel@tonic-gate
1817c478bd9Sstevel@tonic-gateshift `/usr/bin/expr $OPTIND - 1`	# get past the processed args
1827c478bd9Sstevel@tonic-gate
1837c478bd9Sstevel@tonic-gateif [ $# -gt 1 ]; then
184812e8c05SGordon Ross	usage "multiple arguments not supported"
1857c478bd9Sstevel@tonic-gatefi
1867c478bd9Sstevel@tonic-gate
1877c478bd9Sstevel@tonic-gate# get file system table name and make sure file exists
1887c478bd9Sstevel@tonic-gateif [ $# = 1 ]; then
1897c478bd9Sstevel@tonic-gate	case $1 in
1907c478bd9Sstevel@tonic-gate	"-")	FSTAB=""
1917c478bd9Sstevel@tonic-gate		;;
1927c478bd9Sstevel@tonic-gate	*)	FSTAB=$1
1937c478bd9Sstevel@tonic-gate		;;
1947c478bd9Sstevel@tonic-gate	esac
1957c478bd9Sstevel@tonic-gatefi
1967c478bd9Sstevel@tonic-gate#
1977c478bd9Sstevel@tonic-gate# if an alternate vfstab file is used or serial mode is specified, then
1987c478bd9Sstevel@tonic-gate# use a mount command file
1997c478bd9Sstevel@tonic-gate#
2007c478bd9Sstevel@tonic-gateif [ $# = 1 -o "$SFLAG" ]; then
2017c478bd9Sstevel@tonic-gate	ALTM=/var/tmp/mount$$
2027c478bd9Sstevel@tonic-gate	rm -f $ALTM
2037c478bd9Sstevel@tonic-gatefi
2047c478bd9Sstevel@tonic-gate
2057c478bd9Sstevel@tonic-gateif [ "$FSTAB" != ""  -a  ! -s "$FSTAB" ]
2067c478bd9Sstevel@tonic-gatethen
2077c478bd9Sstevel@tonic-gate	echo "mountall: file system table ($FSTAB) not found"
2087c478bd9Sstevel@tonic-gate	exit 1
2097c478bd9Sstevel@tonic-gatefi
2107c478bd9Sstevel@tonic-gate
2117c478bd9Sstevel@tonic-gate#
2127c478bd9Sstevel@tonic-gate# Check for incompatible args
2137c478bd9Sstevel@tonic-gate#
2147c478bd9Sstevel@tonic-gateif [ "$GFLAG" = "g" -a "$RFLAG$LFLAG" != "" -o \
2157c478bd9Sstevel@tonic-gate     "$RFLAG" = "r" -a "$GFLAG$LFLAG" != "" -o \
2167c478bd9Sstevel@tonic-gate     "$LFLAG" = "l" -a "$RFLAG$GFLAG" != "" ]
2177c478bd9Sstevel@tonic-gatethen
218812e8c05SGordon Ross	usage "options -g, -r and -l are mutually exclusive"
2197c478bd9Sstevel@tonic-gatefi
2207c478bd9Sstevel@tonic-gate
221812e8c05SGordon Rossif [ "$LFLAG" = "l" -a -n "$FSType" ]; then
222812e8c05SGordon Ross	# remote FSType not allowed
223812e8c05SGordon Ross	isremote "$FSType" &&
224812e8c05SGordon Ross	usage "option -l and FSType are incompatible"
2257c478bd9Sstevel@tonic-gatefi
226812e8c05SGordon Ross
227812e8c05SGordon Rossif [ "$RFLAG" = "r" -a -n "$FSType" ]; then
228812e8c05SGordon Ross	# remote FSType required
229812e8c05SGordon Ross	isremote "$FSType" ||
230812e8c05SGordon Ross	usage "option -r and FSType are incompatible"
2317c478bd9Sstevel@tonic-gatefi
2327c478bd9Sstevel@tonic-gate
2337c478bd9Sstevel@tonic-gate#	file-system-table format:
2347c478bd9Sstevel@tonic-gate#
2357c478bd9Sstevel@tonic-gate#	column 1:	special- block special device or resource name
2367c478bd9Sstevel@tonic-gate#	column 2: 	fsckdev- char special device for fsck
2377c478bd9Sstevel@tonic-gate#	column 3:	mountp- mount point
2387c478bd9Sstevel@tonic-gate#	column 4:	fstype- File system type
2397c478bd9Sstevel@tonic-gate#	column 5:	fsckpass- number if to be checked automatically
2407c478bd9Sstevel@tonic-gate#	column 6:	automnt-	yes/no for automatic mount
2417c478bd9Sstevel@tonic-gate#	column 7:	mntopts- -o specific mount options
2427c478bd9Sstevel@tonic-gate
2437c478bd9Sstevel@tonic-gate#	White-space separates columns.
2447c478bd9Sstevel@tonic-gate#	Lines beginning with \"#\" are comments.  Empty lines are ignored.
2457c478bd9Sstevel@tonic-gate#	a '-' in any field is a no-op.
2467c478bd9Sstevel@tonic-gate
2477c478bd9Sstevel@tonic-gate#
2487c478bd9Sstevel@tonic-gate# Read FSTAB, fsck'ing appropriate filesystems:
2497c478bd9Sstevel@tonic-gate#
2507c478bd9Sstevel@tonic-gateexec < $FSTAB
2517c478bd9Sstevel@tonic-gatewhile  read special fsckdev mountp fstype fsckpass automnt mntopts
2527c478bd9Sstevel@tonic-gatedo
2537c478bd9Sstevel@tonic-gate	case $special in
2547c478bd9Sstevel@tonic-gate	'#'* | '')	#  Ignore comments, empty lines
2557c478bd9Sstevel@tonic-gate			continue ;;
2567c478bd9Sstevel@tonic-gate	'-')		#  Ignore no-action lines
2577c478bd9Sstevel@tonic-gate			continue
2587c478bd9Sstevel@tonic-gate	esac
2597c478bd9Sstevel@tonic-gate
2607c478bd9Sstevel@tonic-gate	if [ "$automnt" != "yes" ]; then
2617c478bd9Sstevel@tonic-gate		continue
2627c478bd9Sstevel@tonic-gate	fi
2637c478bd9Sstevel@tonic-gate	if [ "$FSType" -a "$FSType" != "$fstype" ]; then
2647c478bd9Sstevel@tonic-gate		# ignore different fstypes
2657c478bd9Sstevel@tonic-gate		continue
2667c478bd9Sstevel@tonic-gate	fi
2677c478bd9Sstevel@tonic-gate
268812e8c05SGordon Ross	# The -g option is not in the man page, but according to
269812e8c05SGordon Ross	# PSARC/1998/255 it's used by Sun Cluster (via contract) to
270812e8c05SGordon Ross	# mount disk-based filesystems with the "global" option.
271812e8c05SGordon Ross	# Also, the -l option now skips those "global" mounts.
272812e8c05SGordon Ross	#
273812e8c05SGordon Ross	# Note: options -g -l -r are mutually exclusive
274812e8c05SGordon Ross	#
275812e8c05SGordon Ross	if [ -n "$GFLAG" ]; then
276812e8c05SGordon Ross		# Mount "local" filesystems that have
277812e8c05SGordon Ross		# the "global" option in mntopts.
278812e8c05SGordon Ross		isremote "$fstype" && continue
279812e8c05SGordon Ross		isglobal "$mntopts" || continue
280812e8c05SGordon Ross	fi
281812e8c05SGordon Ross	if [ -n "$LFLAG" ]; then
282812e8c05SGordon Ross		# Mount "local" filesystems, excluding
283812e8c05SGordon Ross		# those marked "global".
284812e8c05SGordon Ross		isremote "$fstype" && continue
285812e8c05SGordon Ross		isglobal "$mntopts" && continue
286812e8c05SGordon Ross	fi
287812e8c05SGordon Ross	if [ -n "$RFLAG" ]; then
288812e8c05SGordon Ross		# Mount "remote" filesystems.
289812e8c05SGordon Ross		isremote "$fstype" || continue
2907c478bd9Sstevel@tonic-gate	fi
2917c478bd9Sstevel@tonic-gate
2927c478bd9Sstevel@tonic-gate	if [ "$fstype" = "-" ]; then
2937c478bd9Sstevel@tonic-gate		echo "mountall: FSType of $special cannot be identified" 1>&2
2947c478bd9Sstevel@tonic-gate		continue
2957c478bd9Sstevel@tonic-gate	fi
2967c478bd9Sstevel@tonic-gate
2977c478bd9Sstevel@tonic-gate	if [ "$ALTM" -a "$mntopts" != "-" ]; then
2987c478bd9Sstevel@tonic-gate		OPTIONS="-o $mntopts"		# Use mount options if any
2997c478bd9Sstevel@tonic-gate	else
3007c478bd9Sstevel@tonic-gate		OPTIONS=""
3017c478bd9Sstevel@tonic-gate	fi
3027c478bd9Sstevel@tonic-gate
3037c478bd9Sstevel@tonic-gate	#
3047c478bd9Sstevel@tonic-gate	# Ignore entries already mounted
3057c478bd9Sstevel@tonic-gate	#
3067c478bd9Sstevel@tonic-gate	/usr/bin/grep "	$mountp	" /etc/mnttab >/dev/null 2>&1 && continue
3077c478bd9Sstevel@tonic-gate
3087c478bd9Sstevel@tonic-gate	#
3097c478bd9Sstevel@tonic-gate	# Can't fsck if no fsckdev is specified
3107c478bd9Sstevel@tonic-gate	#
3117c478bd9Sstevel@tonic-gate	if [ "$fsckdev" = "-" ]; then
3127c478bd9Sstevel@tonic-gate		saveentry $fstype "$OPTIONS" $special $mountp
3137c478bd9Sstevel@tonic-gate		continue
3147c478bd9Sstevel@tonic-gate	fi
3157c478bd9Sstevel@tonic-gate	#
3167c478bd9Sstevel@tonic-gate	# For fsck purposes, we make a distinction between file systems
3177c478bd9Sstevel@tonic-gate	# that have a /usr/lib/fs/<fstyp>/fsckall script and those
3187c478bd9Sstevel@tonic-gate	# that don't.  For those that do, just keep a list of them
3197c478bd9Sstevel@tonic-gate	# and pass the list to the fsckall script for that file
3207c478bd9Sstevel@tonic-gate	# file system type.
3217c478bd9Sstevel@tonic-gate	#
3227c478bd9Sstevel@tonic-gate	if [ -x /usr/lib/fs/$fstype/fsckall ]; then
3237c478bd9Sstevel@tonic-gate
3247c478bd9Sstevel@tonic-gate		#
3257c478bd9Sstevel@tonic-gate		# add fstype to the list of fstypes for which
3267c478bd9Sstevel@tonic-gate		# fsckall should be called, if it's not already
3277c478bd9Sstevel@tonic-gate		# in the list.
3287c478bd9Sstevel@tonic-gate		#
3297c478bd9Sstevel@tonic-gate		found=no
3307c478bd9Sstevel@tonic-gate		if [ "$fsckall_fstypes" != "" ] ; then
3317c478bd9Sstevel@tonic-gate			for fst in $fsckall_fstypes; do
3327c478bd9Sstevel@tonic-gate				if [ "$fst" = "$fstype" ] ; then
3337c478bd9Sstevel@tonic-gate					found=yes
3347c478bd9Sstevel@tonic-gate					break
3357c478bd9Sstevel@tonic-gate				fi
3367c478bd9Sstevel@tonic-gate			done
3377c478bd9Sstevel@tonic-gate		fi
3387c478bd9Sstevel@tonic-gate		if [ $found = no ] ; then
3397c478bd9Sstevel@tonic-gate			fsckall_fstypes="$fsckall_fstypes ${fstype}"
3407c478bd9Sstevel@tonic-gate		fi
3417c478bd9Sstevel@tonic-gate
3427c478bd9Sstevel@tonic-gate		#
3437c478bd9Sstevel@tonic-gate		# add the device to the name of devices to be passed
3447c478bd9Sstevel@tonic-gate		# to the fsckall program for this file system type
3457c478bd9Sstevel@tonic-gate		#
3467c478bd9Sstevel@tonic-gate		cmd="${fstype}_fscklist=\"\$${fstype}_fscklist $fsckdev\""
3477c478bd9Sstevel@tonic-gate		eval $cmd
3487c478bd9Sstevel@tonic-gate		saveentry $fstype "$OPTIONS" $special $mountp
3497c478bd9Sstevel@tonic-gate		continue
3507c478bd9Sstevel@tonic-gate	fi
3517c478bd9Sstevel@tonic-gate	#
3527c478bd9Sstevel@tonic-gate	# fsck everything else:
3537c478bd9Sstevel@tonic-gate 	#
3547c478bd9Sstevel@tonic-gate 	# fsck -m simply returns true if the filesystem is suitable for
3557c478bd9Sstevel@tonic-gate 	# mounting.
3567c478bd9Sstevel@tonic-gate 	#
3577c478bd9Sstevel@tonic-gate	/usr/sbin/fsck -m -F $fstype $fsckdev >/dev/null 2>&1
3587c478bd9Sstevel@tonic-gate	case $? in
3597c478bd9Sstevel@tonic-gate	0|40)	saveentry $fstype "$OPTIONS" $special $mountp
3607c478bd9Sstevel@tonic-gate		continue
3617c478bd9Sstevel@tonic-gate		;;
3627c478bd9Sstevel@tonic-gate	32)	checkfs $fsckdev $fstype $mountp
3637c478bd9Sstevel@tonic-gate		saveentry $fstype "$OPTIONS" $special $mountp
3647c478bd9Sstevel@tonic-gate		continue
3657c478bd9Sstevel@tonic-gate		;;
3667c478bd9Sstevel@tonic-gate	33)	# already mounted
3677c478bd9Sstevel@tonic-gate		echo "$special already mounted"
3687c478bd9Sstevel@tonic-gate		;;
3697c478bd9Sstevel@tonic-gate	34)	# bogus special device
3707c478bd9Sstevel@tonic-gate		echo "Cannot stat $fsckdev - ignoring"
3717c478bd9Sstevel@tonic-gate		err=1
3727c478bd9Sstevel@tonic-gate		;;
3737c478bd9Sstevel@tonic-gate	*)	# uncorrectable errors
3747c478bd9Sstevel@tonic-gate		echo "$fsckdev uncorrectable error"
3757c478bd9Sstevel@tonic-gate		err=1
3767c478bd9Sstevel@tonic-gate		;;
3777c478bd9Sstevel@tonic-gate	esac
3787c478bd9Sstevel@tonic-gatedone
3797c478bd9Sstevel@tonic-gate
3807c478bd9Sstevel@tonic-gate#
3817c478bd9Sstevel@tonic-gate# Call the fsckall programs
3827c478bd9Sstevel@tonic-gate#
3837c478bd9Sstevel@tonic-gatefor fst in $fsckall_fstypes
3847c478bd9Sstevel@tonic-gatedo
3857c478bd9Sstevel@tonic-gate	cmd="/usr/lib/fs/$fst/fsckall \$${fst}_fscklist"
3867c478bd9Sstevel@tonic-gate	eval $cmd
3877c478bd9Sstevel@tonic-gate
3887c478bd9Sstevel@tonic-gate	case $? in
3897c478bd9Sstevel@tonic-gate	0)	# file systems OK
3907c478bd9Sstevel@tonic-gate			;;
3917c478bd9Sstevel@tonic-gate
3927c478bd9Sstevel@tonic-gate	*)	# couldn't fix some of the filesystems
3937c478bd9Sstevel@tonic-gate		echo "fsckall failed with exit code "$?"."
3947c478bd9Sstevel@tonic-gate		checkmessage
3957c478bd9Sstevel@tonic-gate		;;
3967c478bd9Sstevel@tonic-gate	esac
3977c478bd9Sstevel@tonic-gatedone
3987c478bd9Sstevel@tonic-gate
3997c478bd9Sstevel@tonic-gateif [ "$ALTM" ]; then
4007c478bd9Sstevel@tonic-gate	if [ ! -f "$ALTM" ]; then
4017c478bd9Sstevel@tonic-gate		exit
4027c478bd9Sstevel@tonic-gate	fi
4037c478bd9Sstevel@tonic-gate	/sbin/sh $ALTM		# run the saved mount commands
4047c478bd9Sstevel@tonic-gate	/usr/bin/rm -f $ALTM
4057c478bd9Sstevel@tonic-gate	exit
4067c478bd9Sstevel@tonic-gatefi
4077c478bd9Sstevel@tonic-gate
4087c478bd9Sstevel@tonic-gateif [ -n "$FSType" ]; then
4097c478bd9Sstevel@tonic-gate	/sbin/mount -a -F $FSType
4107c478bd9Sstevel@tonic-gate	exit
4117c478bd9Sstevel@tonic-gatefi
4127c478bd9Sstevel@tonic-gate
413*bd93c05dSAlexander Eremin# Some remote filesystems (e.g. autofs) shouldn't be mounted
414812e8c05SGordon Ross# with mountall, so the list here is explicit (not from /etc/dfs/fstypes)
4157c478bd9Sstevel@tonic-gateif [ "$RFLAG" ]; then
4167c478bd9Sstevel@tonic-gate	/sbin/mount -a -F nfs
417812e8c05SGordon Ross	/sbin/mount -a -F smbfs
4187c478bd9Sstevel@tonic-gate	exit
4197c478bd9Sstevel@tonic-gatefi
4207c478bd9Sstevel@tonic-gate
4217c478bd9Sstevel@tonic-gateif [ "$LFLAG" -o "$GFLAG" -o $err != 0 ]; then
4227c478bd9Sstevel@tonic-gate	[ -z "$mntlist" ] || /sbin/mount -a $mntlist
4237c478bd9Sstevel@tonic-gate	exit
4247c478bd9Sstevel@tonic-gatefi
4257c478bd9Sstevel@tonic-gate
4267c478bd9Sstevel@tonic-gate# else mount them all
4277c478bd9Sstevel@tonic-gate
4287c478bd9Sstevel@tonic-gate/sbin/mount -a
429