#!/sbin/sh
#
# Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
# Use is subject to license terms.
#
# ident	"@(#)svc-volfs	1.1	06/01/20 SMI"

FMRI=svc:/system/filesystem/volfs:default

# For modifying parameters passed to vold, do not edit
# this script. Instead use svccfg(1m) to modify the SMF
# repository. For example:
#
# # svccfg
# svc:> select system/filesystem/volfs
# svc:/system/filesystem/volfs> setprop vold/never_writeback_label= "true"
# svc:/system/filesystem/volfs> exit
#
# refer to vold(1M) man page for additional examples

. /lib/svc/share/smf_include.sh

getpropstring() {
        val=`svcprop -c -p $2 $FMRI`
        [ -n "$val" ] && [ "$val" != '""' ] && echo $1 $val
}

config_file=/etc/vold.conf

val=`svcprop -c -p vold/config_file $FMRI`
[ -n "$val" ] && [ "$val" != '""' ] && config_file="$val"

if [ ! -f $config_file ]; then
	echo "\"$config_file\" does not exist"
	exit $SMF_EXIT_ERR_CONFIG
fi

case "$1" in
'start')
        # volume management is not supported in a local zone
        if [ `/sbin/zonename` != "global" ] ; then
                /usr/sbin/svcadm disable -t svc:/system/filesystem/volfs
                echo "Volume management is not supported in a local zone"
                sleep 5 &
                exit $SMF_EXIT_OK
        fi

	if [ ! -x /usr/sbin/vold ]; then
		echo "/usr/sbin/vold is not executable"
		exit $SMF_EXIT_ERR_CONFIG
	fi

	if [ ! -f /dev/volctl ]; then
		devfsadm -i vol
	fi

	args="$args `getpropstring -d vold/root_dir`"
	args="$args `getpropstring -l vold/log_file`"

	val=`svcprop -c -p vold/log_debuglevel $FMRI`
	[ -n "$val" ] && [ "$val" != '0' ] && args="$args -L $val"

	[ `svcprop -c -p vold/never_writeback_label $FMRI` = "true" ] && args="$args -n"

	[ `svcprop -c -p vold/log_nfs_trace $FMRI` = "true" ] && args="$args -t"

	[ `svcprop -c -p vold/log_verbose $FMRI` = "true" ] && args="$args -v"

	# note that vold is not self-daemonizing and that any service depending
	# on vold may need its own mechanism for figuring out whether vold is
	# actually fully operational

	/usr/sbin/vold $args -f $config_file &
	;;

'refresh')
	touch $config_file
	/usr/bin/pkill -HUP -z global -x vold
	;;

*)
        echo "Usage: $0 { start | refresh }"
	exit $SMF_EXIT_ERR_FATAL 
        ;;


esac

exit $SMF_EXIT_OK
