#!/bin/sh
#
# $NetBSD: mountall,v 1.8 2009/10/18 21:58:37 haad Exp $
#

# REQUIRE: mountcritremote named ypbind
# PROVIDE: mountall

$_rc_subr_loaded . /etc/rc.subr

name="mountall"
start_cmd="mountall_start"
stop_cmd="mountall_stop"

mountall_start()
{
	echo 'Mounting all filesystems...'
	if [ -f /etc/zfs/zpool.cache ]; then
		# Get ZFS module loaded (and thereby, zvols created).
		zfs list > /dev/null 2>&1
		# Initialize zvols so they can be mounted 
		zfs volinit
		# Mount file systems noted in fstab.
		mount -a
		# Mount ZFS file systems.
		zfs mount -a
	else
		# Mount file systems noted in fstab.
		mount -a
	fi
}

mountall_stop()
{
	echo 'Unmounting all filesystems...'
	if [ -f /etc/zfs/zpool.cache ]; then
		# Unmount ZFS file systems.
		zfs unmount -a
		# Unmount file systems noted in fstab.
		umount -a
		# Unload ZFS module, so disk devices are closed.
		modunload zfs
	else
		# Otherwise, just deal with fstab.
		umount -a
	fi
}

load_rc_config $name
run_rc_command "$1"
