xref: /titanic_51/usr/src/cmd/initpkg/umountall.sh (revision 812e8c05270efb3334ff7b081079ed4b71c712c8)
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
6ef4c14d2Ssetje# Common Development and Distribution License (the "License").
7ef4c14d2Ssetje# You may not use this file except in compliance with the License.
87c478bd9Sstevel@tonic-gate#
97c478bd9Sstevel@tonic-gate# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate# or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate# See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate# and limitations under the License.
137c478bd9Sstevel@tonic-gate#
147c478bd9Sstevel@tonic-gate# When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate# If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate# fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate# information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate#
207c478bd9Sstevel@tonic-gate# CDDL HEADER END
217c478bd9Sstevel@tonic-gate#
227c478bd9Sstevel@tonic-gate#
234e49521aSDan Price# Copyright (c) 1988, 2010, Oracle and/or its affiliates. All rights reserved.
247c478bd9Sstevel@tonic-gate#
257c478bd9Sstevel@tonic-gate#	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T
267c478bd9Sstevel@tonic-gate#	  All Rights Reserved
277c478bd9Sstevel@tonic-gate#
287c478bd9Sstevel@tonic-gate#
297c478bd9Sstevel@tonic-gate
307c478bd9Sstevel@tonic-gateusage () {
317c478bd9Sstevel@tonic-gate	if [ -n "$1" ]; then
327c478bd9Sstevel@tonic-gate		echo "umountall: $1" 1>&2
337c478bd9Sstevel@tonic-gate	fi
345fad3adeSPavel Filipensky	echo "Usage:\n\tumountall [-k] [-s] [-F FSType] [-l|-r] [-Z] [-n]" 1>&2
355fad3adeSPavel Filipensky	echo "\tumountall [-k] [-s] [-h host] [-Z] [-n]" 1>&2
367c478bd9Sstevel@tonic-gate	exit 2
377c478bd9Sstevel@tonic-gate}
387c478bd9Sstevel@tonic-gate
397c478bd9Sstevel@tonic-gateMNTTAB=/etc/mnttab
407c478bd9Sstevel@tonic-gate
417c478bd9Sstevel@tonic-gate# This script is installed as both /sbin/umountall (as used in some
427c478bd9Sstevel@tonic-gate# /sbin/rc? and /etc/init.d scripts) _and_ as /usr/sbin/umountall (typically
437c478bd9Sstevel@tonic-gate# PATHed from the command line).  As such it should not depend on /usr
447c478bd9Sstevel@tonic-gate# being mounted (if /usr is a separate filesystem).
457c478bd9Sstevel@tonic-gate#
467c478bd9Sstevel@tonic-gate# /sbin/sh Bourne shell builtins we use:
477c478bd9Sstevel@tonic-gate#	echo
487c478bd9Sstevel@tonic-gate#	exit
497c478bd9Sstevel@tonic-gate#	getopts
507c478bd9Sstevel@tonic-gate#	test, [ ]
517c478bd9Sstevel@tonic-gate#	exec
527c478bd9Sstevel@tonic-gate#	read
537c478bd9Sstevel@tonic-gate#
547c478bd9Sstevel@tonic-gate# /sbin commands we use:
557c478bd9Sstevel@tonic-gate#	/sbin/uname
567c478bd9Sstevel@tonic-gate#	/sbin/umount
577c478bd9Sstevel@tonic-gate#
587c478bd9Sstevel@tonic-gate# The following /usr based commands may be used by this script (depending on
597c478bd9Sstevel@tonic-gate# command line options).  We will set our PATH to find them, but where they
607c478bd9Sstevel@tonic-gate# are not present (eg, if /usr is not mounted) we will catch references to
617c478bd9Sstevel@tonic-gate# them via shell functions conditionally defined after option processing
627c478bd9Sstevel@tonic-gate# (don't use any of these commands before then).
637c478bd9Sstevel@tonic-gate#
647c478bd9Sstevel@tonic-gate#	Command		Command line option and use
657c478bd9Sstevel@tonic-gate# /usr/bin/sleep	-k, to sleep after an fuser -c -k on the mountpoint
667c478bd9Sstevel@tonic-gate# /usr/sbin/fuser	-k, to kill processes keeping a mount point busy
677c478bd9Sstevel@tonic-gate#
687c478bd9Sstevel@tonic-gate# In addition, we use /usr/bin/tail if it is available; if not we use
697c478bd9Sstevel@tonic-gate# slower shell constructs to reverse a file.
707c478bd9Sstevel@tonic-gate
717c478bd9Sstevel@tonic-gatePATH=/sbin:/usr/sbin:/usr/bin
727c478bd9Sstevel@tonic-gate
737c478bd9Sstevel@tonic-gate# Clear these in case they were already set in our inherited environment.
747c478bd9Sstevel@tonic-gateFSType=
757c478bd9Sstevel@tonic-gateFFLAG=
767c478bd9Sstevel@tonic-gateHOST=
777c478bd9Sstevel@tonic-gateHFLAG=
787c478bd9Sstevel@tonic-gateRFLAG=
797c478bd9Sstevel@tonic-gateLFLAG=
807c478bd9Sstevel@tonic-gateSFLAG=
817c478bd9Sstevel@tonic-gateKFLAG=
825fad3adeSPavel FilipenskyZFLAG=
837c478bd9Sstevel@tonic-gateNFLAG=
847c478bd9Sstevel@tonic-gateLOCALNAME=
857c478bd9Sstevel@tonic-gateUMOUNTFLAG=
86*812e8c05SGordon RossRemoteFSTypes=
87*812e8c05SGordon Ross
88*812e8c05SGordon Ross# Is the passed fstype a "remote" one?
89*812e8c05SGordon Ross# Essentially: /usr/bin/grep "^$1" /etc/dfs/fstypes
90*812e8c05SGordon Rossisremote() {
91*812e8c05SGordon Ross	for t in $RemoteFSTypes
92*812e8c05SGordon Ross	do
93*812e8c05SGordon Ross		[ "$t" = "$1" ] && return 0
94*812e8c05SGordon Ross	done
95*812e8c05SGordon Ross	return 1
96*812e8c05SGordon Ross}
97*812e8c05SGordon Ross
98*812e8c05SGordon Ross# Get list of remote FS types (just once)
99*812e8c05SGordon RossRemoteFSTypes=`while read t junk; do echo $t; done < /etc/dfs/fstypes`
1007c478bd9Sstevel@tonic-gate
1017c478bd9Sstevel@tonic-gate
102*812e8c05SGordon Ross#
103*812e8c05SGordon Ross# Process command line args
104*812e8c05SGordon Ross#
1055fad3adeSPavel Filipenskywhile getopts ?rslkF:h:Zn c
1067c478bd9Sstevel@tonic-gatedo
1077c478bd9Sstevel@tonic-gate	case $c in
1087c478bd9Sstevel@tonic-gate	r)	RFLAG="r";;
1097c478bd9Sstevel@tonic-gate	l)	LFLAG="l";;
1107c478bd9Sstevel@tonic-gate	s)	SFLAG="s";;
1117c478bd9Sstevel@tonic-gate	k)	KFLAG="k";;
1127c478bd9Sstevel@tonic-gate	h)	if [ -n "$HFLAG" ]; then
1137c478bd9Sstevel@tonic-gate			usage "more than one host specified"
1147c478bd9Sstevel@tonic-gate		fi
1157c478bd9Sstevel@tonic-gate		HOST=$OPTARG
1167c478bd9Sstevel@tonic-gate		HFLAG="h"
1177c478bd9Sstevel@tonic-gate		LOCALNAME=`uname -n`
1187c478bd9Sstevel@tonic-gate		;;
1197c478bd9Sstevel@tonic-gate	F)	if [ -n "$FFLAG" ]; then
1207c478bd9Sstevel@tonic-gate			usage "more than one FStype specified"
1217c478bd9Sstevel@tonic-gate		fi
1227c478bd9Sstevel@tonic-gate		FSType=$OPTARG
1237c478bd9Sstevel@tonic-gate		FFLAG="f"
1247c478bd9Sstevel@tonic-gate		case $FSType in
1257c478bd9Sstevel@tonic-gate		?????????*)
1267c478bd9Sstevel@tonic-gate			usage "FSType ${FSType} exceeds 8 characters"
1277c478bd9Sstevel@tonic-gate		esac;
1287c478bd9Sstevel@tonic-gate		;;
1295fad3adeSPavel Filipensky	Z)	ZFLAG="z";;
1307c478bd9Sstevel@tonic-gate	n)	NFLAG="n"
1317c478bd9Sstevel@tonic-gate		# Alias any commands that would perform real actions to
1327c478bd9Sstevel@tonic-gate		# something that tells what action would have been performed
1337c478bd9Sstevel@tonic-gate		UMOUNTFLAG="-V"
1347c478bd9Sstevel@tonic-gate		fuser () {
1357c478bd9Sstevel@tonic-gate			echo "fuser $*" 1>&2
1367c478bd9Sstevel@tonic-gate		}
1377c478bd9Sstevel@tonic-gate		sleep () {
1387c478bd9Sstevel@tonic-gate			: # No need to show where we'd sleep
1397c478bd9Sstevel@tonic-gate		}
1407c478bd9Sstevel@tonic-gate		;;
1417c478bd9Sstevel@tonic-gate	\?)	usage ""
1427c478bd9Sstevel@tonic-gate		;;
1437c478bd9Sstevel@tonic-gate	esac
1447c478bd9Sstevel@tonic-gatedone
1457c478bd9Sstevel@tonic-gate
1467c478bd9Sstevel@tonic-gate# Sanity checking:
1477c478bd9Sstevel@tonic-gate#	1) arguments beyond those supported
1487c478bd9Sstevel@tonic-gate#	2) can't specify both remote and local
1497c478bd9Sstevel@tonic-gate#	3) can't specify a host with -r or -l
1507c478bd9Sstevel@tonic-gate#	4) can't specify a fstype with -h
1517c478bd9Sstevel@tonic-gate#	5) can't specify this host with -h (checks only uname -n)
1527c478bd9Sstevel@tonic-gate#	6) can't be fstype nfs and local
1537c478bd9Sstevel@tonic-gate#	7) only fstype nfs is remote
1547c478bd9Sstevel@tonic-gate
1557c478bd9Sstevel@tonic-gateif [ $# -ge $OPTIND ]; then						# 1
1567c478bd9Sstevel@tonic-gate	usage "additional arguments not supported"
1577c478bd9Sstevel@tonic-gatefi
1587c478bd9Sstevel@tonic-gate
1597c478bd9Sstevel@tonic-gateif [ -n "$RFLAG" -a -n "$LFLAG" ]; then					# 2
1607c478bd9Sstevel@tonic-gate	usage "options -r and -l are incompatible"
1617c478bd9Sstevel@tonic-gatefi
1627c478bd9Sstevel@tonic-gate
1637c478bd9Sstevel@tonic-gateif [ \( -n "$RFLAG" -o -n "$LFLAG" \) -a "$HFLAG" = "h" ]; then		# 3
1647c478bd9Sstevel@tonic-gate	usage "option -${RFLAG}${LFLAG} incompatible with -h option"
1657c478bd9Sstevel@tonic-gatefi
1667c478bd9Sstevel@tonic-gate
1677c478bd9Sstevel@tonic-gateif [ -n "$FFLAG" -a "$HFLAG" = "h" ]; then				# 4
1687c478bd9Sstevel@tonic-gate	usage "Specifying FStype incompatible with -h option"
1697c478bd9Sstevel@tonic-gatefi
1707c478bd9Sstevel@tonic-gate
1717c478bd9Sstevel@tonic-gateif [ -n "$HFLAG" -a "$HOST" = "$LOCALNAME" ]; then			# 5
1727c478bd9Sstevel@tonic-gate	usage "Specifying local host illegal for -h option"
1737c478bd9Sstevel@tonic-gatefi
1747c478bd9Sstevel@tonic-gate
175*812e8c05SGordon Rossif [ "$LFLAG" = "l" -a -n "$FSType" ]; then				# 6
176*812e8c05SGordon Ross	# remote FSType not allowed
177*812e8c05SGordon Ross	isremote "$FSType" &&
178*812e8c05SGordon Ross	usage "option -l and FSType ${FSType} are incompatible"
1797c478bd9Sstevel@tonic-gatefi
1807c478bd9Sstevel@tonic-gate
181*812e8c05SGordon Rossif [ "$RFLAG" = "r" -a -n "$FSType" ]; then				# 7
182*812e8c05SGordon Ross	# remote FSType required
183*812e8c05SGordon Ross	isremote "$FSType" ||
1847c478bd9Sstevel@tonic-gate	usage "option -r and FSType ${FSType} are incompatible"
1857c478bd9Sstevel@tonic-gatefi
1867c478bd9Sstevel@tonic-gate
1877c478bd9Sstevel@tonic-gateZONENAME=`zonename`
1887c478bd9Sstevel@tonic-gate
18976bc4030Snadkarni#
1907c478bd9Sstevel@tonic-gate# Take advantage of parallel unmounting at this point if we have no
1917c478bd9Sstevel@tonic-gate# criteria to match and we are in the global zone
1927c478bd9Sstevel@tonic-gate#
1935fad3adeSPavel Filipenskyif [ -z "${SFLAG}${LFLAG}${RFLAG}${HFLAG}${KFLAG}${FFLAG}${ZFLAG}" -a \
1947c478bd9Sstevel@tonic-gate    "$ZONENAME" = "global" ]; then
1957c478bd9Sstevel@tonic-gate	umount -a ${UMOUNTFLAG}
1967c478bd9Sstevel@tonic-gate	exit			# with return code of the umount -a
1977c478bd9Sstevel@tonic-gatefi
1987c478bd9Sstevel@tonic-gate
1997c478bd9Sstevel@tonic-gate#
2007c478bd9Sstevel@tonic-gate# Catch uses of /usr commands when /usr is not mounted
2017c478bd9Sstevel@tonic-gateif [ -n "$KFLAG" -a -z "$NFLAG" ]; then
2027c478bd9Sstevel@tonic-gate	if [ ! -x /usr/sbin/fuser ]; then
2037c478bd9Sstevel@tonic-gate		fuser () {
2047c478bd9Sstevel@tonic-gate			echo "umountall: fuser -k skipped (no /usr)" 1>&2
2057c478bd9Sstevel@tonic-gate			# continue - not fatal
2067c478bd9Sstevel@tonic-gate		}
2077c478bd9Sstevel@tonic-gate		sleep () {
2087c478bd9Sstevel@tonic-gate			: # no point in sleeping if fuser is doing nothing
2097c478bd9Sstevel@tonic-gate		}
2107c478bd9Sstevel@tonic-gate	else
2117c478bd9Sstevel@tonic-gate		if [ ! -x /usr/bin/sleep ]; then
2127c478bd9Sstevel@tonic-gate			sleep () {
2137c478bd9Sstevel@tonic-gate		echo "umountall: sleep after fuser -k skipped (no /usr)" 1>&2
2147c478bd9Sstevel@tonic-gate				# continue - not fatal
2157c478bd9Sstevel@tonic-gate			}
2167c478bd9Sstevel@tonic-gate		fi
2177c478bd9Sstevel@tonic-gate	fi
2187c478bd9Sstevel@tonic-gatefi
2197c478bd9Sstevel@tonic-gate
2207c478bd9Sstevel@tonic-gate#
2217c478bd9Sstevel@tonic-gate# Shell function to avoid using /usr/bin/cut.  Given a dev from a
2227c478bd9Sstevel@tonic-gate# fstype=nfs line in mnttab (eg, "host:/export) extract the host
223*812e8c05SGordon Ross# component.  The dev string looks like: "host:/path"
224*812e8c05SGordon Rossprint_nfs_host () {
2257c478bd9Sstevel@tonic-gate	OIFS=$IFS
2267c478bd9Sstevel@tonic-gate	IFS=":"
2277c478bd9Sstevel@tonic-gate	set -- $*
2287c478bd9Sstevel@tonic-gate	echo $1
2297c478bd9Sstevel@tonic-gate	IFS=$OIFS
2307c478bd9Sstevel@tonic-gate}
231*812e8c05SGordon Ross#
232*812e8c05SGordon Ross# Similar for smbfs, but tricky due to the optional parts
233*812e8c05SGordon Ross# of the "device" syntax.  The dev strings look like:
234*812e8c05SGordon Ross# "//server/share" or "//user@server/share"
235*812e8c05SGordon Rossprint_smbfs_host () {
236*812e8c05SGordon Ross	OIFS=$IFS
237*812e8c05SGordon Ross	IFS="/@"
238*812e8c05SGordon Ross	set -- $*
239*812e8c05SGordon Ross	case $# in
240*812e8c05SGordon Ross	3) echo "$2";;
241*812e8c05SGordon Ross	2) echo "$1";;
242*812e8c05SGordon Ross	esac
243*812e8c05SGordon Ross	IFS=$OIFS
244*812e8c05SGordon Ross}
2457c478bd9Sstevel@tonic-gate
2467c478bd9Sstevel@tonic-gate#
2477c478bd9Sstevel@tonic-gate# doumounts echos its return code to stdout, so commands used within
2487c478bd9Sstevel@tonic-gate# this function should take care to produce no other output to stdout.
2497c478bd9Sstevel@tonic-gatedoumounts () {
2507c478bd9Sstevel@tonic-gate	(
2517c478bd9Sstevel@tonic-gate	rc=0
2527c478bd9Sstevel@tonic-gate	fslist=""
2537c478bd9Sstevel@tonic-gate	while read dev mountp fstype mode dummy
2547c478bd9Sstevel@tonic-gate	do
2557c478bd9Sstevel@tonic-gate		case "${mountp}" in
2567c478bd9Sstevel@tonic-gate		/			| \
2577c478bd9Sstevel@tonic-gate		/dev			| \
2587c478bd9Sstevel@tonic-gate		/dev/fd			| \
2597c478bd9Sstevel@tonic-gate		/devices		| \
2607c478bd9Sstevel@tonic-gate		/etc/mnttab		| \
2617c478bd9Sstevel@tonic-gate		/etc/svc/volatile	| \
2627c478bd9Sstevel@tonic-gate		/lib			| \
2637c478bd9Sstevel@tonic-gate		/proc			| \
2647c478bd9Sstevel@tonic-gate		/sbin			| \
2657c478bd9Sstevel@tonic-gate		/system/contract	| \
2667c478bd9Sstevel@tonic-gate		/system/object		| \
2677c478bd9Sstevel@tonic-gate		/tmp			| \
268753a6d45SSherry Moore		/tmp/.libgrubmgmt*	| \
2697c478bd9Sstevel@tonic-gate		/usr			| \
2707c478bd9Sstevel@tonic-gate		/var			| \
2717c478bd9Sstevel@tonic-gate		/var/adm		| \
2727c478bd9Sstevel@tonic-gate		/var/run		| \
2737c478bd9Sstevel@tonic-gate		'' )
2747c478bd9Sstevel@tonic-gate			#
2757c478bd9Sstevel@tonic-gate			# file systems possibly mounted in the kernel or
2767c478bd9Sstevel@tonic-gate			# in the methods of some of the file system
2777c478bd9Sstevel@tonic-gate			# services
2787c478bd9Sstevel@tonic-gate			#
2797c478bd9Sstevel@tonic-gate			continue
2807c478bd9Sstevel@tonic-gate			;;
2817c478bd9Sstevel@tonic-gate		* )
2827c478bd9Sstevel@tonic-gate			if [ -n "$HFLAG" ]; then
283*812e8c05SGordon Ross				thishost='-'
2847c478bd9Sstevel@tonic-gate				if [ "$fstype" = "nfs" ]; then
285*812e8c05SGordon Ross					thishost=`print_nfs_host $dev`
2867c478bd9Sstevel@tonic-gate				fi
287*812e8c05SGordon Ross				if [ "$fstype" = "smbfs" ]; then
288*812e8c05SGordon Ross					thishost=`print_smbfs_host $dev`
289*812e8c05SGordon Ross				fi
290*812e8c05SGordon Ross				if [ "$HOST" != "$thishost" ]; then
2917c478bd9Sstevel@tonic-gate					continue
2927c478bd9Sstevel@tonic-gate				fi
2937c478bd9Sstevel@tonic-gate			fi
2947c478bd9Sstevel@tonic-gate			if [ -n "$FFLAG" -a "$FSType" != "$fstype" ]; then
2957c478bd9Sstevel@tonic-gate				continue
2967c478bd9Sstevel@tonic-gate			fi
297*812e8c05SGordon Ross
298*812e8c05SGordon Ross			if [ -n "$LFLAG" ]; then
299*812e8c05SGordon Ross				# umount local filesystems
300*812e8c05SGordon Ross				isremote "$fstype" && continue
3017c478bd9Sstevel@tonic-gate			fi
302*812e8c05SGordon Ross
303*812e8c05SGordon Ross			# Note: isremote is true for both nfs & autofs, so
304*812e8c05SGordon Ross			# this will filter out autofs mounts with nfs file
30529937fd1SPavel Filipensky			# system mounted on the top of it.
30629937fd1SPavel Filipensky			#
30729937fd1SPavel Filipensky			# WARNING: use of any syscall on a NFS file system has
30829937fd1SPavel Filipensky			# the danger to go over-the-wire and could cause nfs
30929937fd1SPavel Filipensky			# clients to hang on shutdown, if the nfs server is
31029937fd1SPavel Filipensky			# down beforehand.
31129937fd1SPavel Filipensky			# For the reason described above, a simple test like
31229937fd1SPavel Filipensky			# "df -F nfs $mountp" can't be used to filter out
313*812e8c05SGordon Ross			# nfs-over-autofs mounts.  (isremote works OK)
31429937fd1SPavel Filipensky			#
315*812e8c05SGordon Ross			if [ -n "$RFLAG" ]; then
316*812e8c05SGordon Ross				# umount remote filesystems
317*812e8c05SGordon Ross				isremote "$fstype" || continue
3187c478bd9Sstevel@tonic-gate			fi
3197c478bd9Sstevel@tonic-gate			if [ "$ZONENAME" != "global" ]; then
3207c478bd9Sstevel@tonic-gate				for option in `echo $mode | tr , '\012'`; do
3217c478bd9Sstevel@tonic-gate					#
3227c478bd9Sstevel@tonic-gate					# should not see any zone options
3237c478bd9Sstevel@tonic-gate					# but our own
3247c478bd9Sstevel@tonic-gate					#
3257c478bd9Sstevel@tonic-gate					if [ "$option" = "zone=$ZONENAME" ]; then
3267c478bd9Sstevel@tonic-gate						break
3277c478bd9Sstevel@tonic-gate					fi
3287c478bd9Sstevel@tonic-gate				done
3297c478bd9Sstevel@tonic-gate				if [ "$option" != "zone=$ZONENAME" ]; then
3307c478bd9Sstevel@tonic-gate					continue
3317c478bd9Sstevel@tonic-gate				fi
3325fad3adeSPavel Filipensky			# we are called from the global zone
3335fad3adeSPavel Filipensky			else
3345fad3adeSPavel Filipensky				for option in `echo $mode | tr , '\012'`; do
3355fad3adeSPavel Filipensky					case "$option" in
3365fad3adeSPavel Filipensky					zone=*)
3375fad3adeSPavel Filipensky						option="zone="
3385fad3adeSPavel Filipensky						break
3395fad3adeSPavel Filipensky					;;
3405fad3adeSPavel Filipensky					esac
3415fad3adeSPavel Filipensky				done
3425fad3adeSPavel Filipensky				# skip mounts from non-global zones if ZFLAG is not set
3435fad3adeSPavel Filipensky				if [ "$option" = "zone=" -a -z "$ZFLAG" ]; then
3445fad3adeSPavel Filipensky					continue
3455fad3adeSPavel Filipensky				fi
3465fad3adeSPavel Filipensky				# skip mounts from the global zone if ZFLAG is set
3475fad3adeSPavel Filipensky				if [ "$option" != "zone=" -a -n "$ZFLAG" ]; then
3485fad3adeSPavel Filipensky					continue
3495fad3adeSPavel Filipensky				fi
3507c478bd9Sstevel@tonic-gate			fi
3517c478bd9Sstevel@tonic-gate			if [ -n "${KFLAG}" ]; then
3527c478bd9Sstevel@tonic-gate				fuser -c -k $mountp 1>&2
3537c478bd9Sstevel@tonic-gate				sleep 2
3547c478bd9Sstevel@tonic-gate			fi
3557c478bd9Sstevel@tonic-gate			if [ -n "$SFLAG" ]; then
3567c478bd9Sstevel@tonic-gate				umount ${UMOUNTFLAG} ${mountp} 1>&2
3577c478bd9Sstevel@tonic-gate				trc=$?
3587c478bd9Sstevel@tonic-gate				if [ $trc -ne 0 ]; then
3597c478bd9Sstevel@tonic-gate					rc=$trc
3607c478bd9Sstevel@tonic-gate				fi
3617c478bd9Sstevel@tonic-gate			else
3627c478bd9Sstevel@tonic-gate				# We want to umount in parallel
3637c478bd9Sstevel@tonic-gate				fslist="$fslist $mountp"
3647c478bd9Sstevel@tonic-gate			fi
3657c478bd9Sstevel@tonic-gate		esac
3667c478bd9Sstevel@tonic-gate	done
3677c478bd9Sstevel@tonic-gate
3687c478bd9Sstevel@tonic-gate	if [ -n "$fslist" ]; then
3697c478bd9Sstevel@tonic-gate		umount -a ${UMOUNTFLAG} $fslist 1>&2
3707c478bd9Sstevel@tonic-gate		trc=$?
3717c478bd9Sstevel@tonic-gate		if [ $trc -ne 0 ]; then
3727c478bd9Sstevel@tonic-gate			rc=$trc
3737c478bd9Sstevel@tonic-gate		fi
3747c478bd9Sstevel@tonic-gate	fi
3757c478bd9Sstevel@tonic-gate
3767c478bd9Sstevel@tonic-gate	echo $rc
3777c478bd9Sstevel@tonic-gate	)
3787c478bd9Sstevel@tonic-gate}
3797c478bd9Sstevel@tonic-gate
3807c478bd9Sstevel@tonic-gate#
3817c478bd9Sstevel@tonic-gate# /etc/mnttab has the most recent mounts last.  Reverse it so that we
3827c478bd9Sstevel@tonic-gate# may umount in opposite order to the original mounts.
3837c478bd9Sstevel@tonic-gate#
3847c478bd9Sstevel@tonic-gate
3857c478bd9Sstevel@tonic-gateif [ ! -x /usr/bin/tail ]; then
3867c478bd9Sstevel@tonic-gate	exec < $MNTTAB
3877c478bd9Sstevel@tonic-gate	REVERSED=
3887c478bd9Sstevel@tonic-gate	while read line; do
3897c478bd9Sstevel@tonic-gate		if [ -n "$REVERSED" ]; then
3907c478bd9Sstevel@tonic-gate        		REVERSED="$line\n$REVERSED"
3917c478bd9Sstevel@tonic-gate		else
3927c478bd9Sstevel@tonic-gate			REVERSED="$line"
3937c478bd9Sstevel@tonic-gate		fi
3947c478bd9Sstevel@tonic-gate	done
3957c478bd9Sstevel@tonic-gate
3967c478bd9Sstevel@tonic-gate	error=`echo $REVERSED | doumounts`
3977c478bd9Sstevel@tonic-gateelse
3987c478bd9Sstevel@tonic-gate	error=`tail -r $MNTTAB | doumounts`
3997c478bd9Sstevel@tonic-gatefi
4007c478bd9Sstevel@tonic-gate
4017c478bd9Sstevel@tonic-gateexit $error
402