view usr/src/cmd/initpkg/arm/mountfs @ 0:c9caec207d52 b86

Initial porting based on b86
author Koji Uno <koji.uno@sun.com>
date Tue, 02 Jun 2009 18:56:50 +0900
parents
children
line wrap: on
line source

#!/sbin/sh
#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License (the "License").
# You may not use this file except in compliance with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# or http://www.opensolaris.org/os/licensing.
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#

#
# Copyright (c) 2006-2008 NEC Corporation
# All rights reserved.
#

PATH=/sbin:$PATH

USRVAR="mountfsusrvar"
DATA="mountfsdata"
VFSTAB="/etc/vfstab"
ZPOOLNAME="ZPOOL"

#
# Read from /etc/vfstab
#
# /etc/vfstab
# device to mount : devmnt
# device to fsck  : devfsck
# mount point     : mntpoint
# FS type         : FStype
# fsck pass       : fsckps
# mount at boot   : mntboot
# mount options   : mntopt
#
rdvfstab()
{
	while read devmnt devfsck mntpoint FStype fsckps mntboot mntopt
	do
		case "$devmnt" in
		''|'#'*|'-' ) continue
			;;
		esac
		if [ "fs$mntpoint" = "fs$1" ]
		then
			break
		fi
	done
}

#
# Check and mount the file system
#
mountfs()
{
	rdvfstab $1 < $VFSTAB
	if [ "fs$mntpoint" != "fs$1" ]
	then
		return 1
	fi

	cmd="mount -F $FStype $devmnt $mntpoint"
	$cmd > /dev/null 2>&1
	if [ $? -ne 0 ]
	then
		echo "ERROR: $cmd failed" >& 2
		return 3
	fi
	return 0
}

#
# Deliver portions of path names
#
bname()
{
	pathname="fs$1"
	SAVEIFS=$IFS
	IFS="/"
	for cnt in $pathname
	do
		fname=$cnt
	done
	IFS=$SAVEIFS
}

case "$1" in
'start')
	bname $0
	case "$fname" in
	S*$USRVAR)
		if [ -x /usr/sbin/czfs -o -x /sbin/czfs ]
		then
			czfs mount $ZPOOLNAME/usr > /dev/null 2>&1
			czfs mount $ZPOOLNAME/var > /dev/null 2>&1
			if [ $? -eq 0 ]
			then
				mountfs /var/run
			fi
		fi
		;;
	S*$DATA)
		if [ -x /usr/sbin/czfs -o -x /sbin/czfs ]
		then
			# Mount all CZFS filesystems.
			czfs mount -a > /dev/null 2>&1
			if [ $? -ne 0 ]
			then
				echo "ERROR: czfs mount -a failed" >& 2
				exit 1
			fi
		fi
		;;
	esac
	;;

'stop')
	bname $0
	case "$fname" in
	K*$DATA)
		if [ -x /usr/sbin/czfs -o -x /sbin/czfs ]
		then
			czfs unmount -a > /dev/null 2>&1
		fi
		;;
	K*$USRVAR)
		if [ -x /usr/sbin/czfs -o -x /sbin/czfs ]
		then
			umount /var/run > /dev/null 2>&1
			czfs unmount  $ZPOOLNAME/var > /dev/null 2>&1
			czfs unmount  $ZPOOLNAME/usr > /dev/null 2>&1
		fi
		;;
	esac
	;;

*)
	echo "Usage: $0 { start | stop }"
	exit 1
	;;
esac
exit 0