#!/bin/sh
# Begin /etc/init.d/mountfs

#
# Include the functions declared in the /etc/init.d/functions file
#

source $INIT_D/functions

case "$1" in
    start)
	
	need $checked_filesystems
	
        #
        # Remount the root partition in read-write mode. -n tells mount
        # not to
        # write to the /etc/mtab file (because it can't do this. The
        # root
        # partition is most likely still mounted in read-only mode
        #

        echo -n "Remounting root file system in read-write mode..."
        mount -n -o remount,rw /
        evaluate_retval || exit_if_any_error

        #
        # First empty the /etc/mtab file. Then remount root partition
        # in read-write
        # mode again but pass -f to mount. This way mount does
        # everything
        # except the mount itself. This is needed for it to write to the
        # mtab
        # file which contains a list of currently mounted file systems.
        #

        echo > $INIT_ROOT/etc/mtab
        mount -f -o remount,rw /

        #
        # Remove the possible /fastboot and /forcefsck files. they are
        # only
        # supposed to be used during the next reboot's checkfs which just
        # happened. If you want to fastboot or forcefsck again you'll
        # have to
        # recreate the files
        #

        rm -f /fastboot /forcefsck

        #
        # Walk through /etc/fstab and mount all file systems that don't
        # have the noauto option set in the fs_mntops field (the 4th
        # field.
        # See man fstab for more info)
        #

        echo -n "Mounting other file systems..."
        mount -a
        evaluate_retval || exit_if_any_error
        ;;

    stop)

        #
        # Deactivate all the swap partitions
        #

        echo -n "Deactivating swap..."
        swapoff -a
        evaluate_retval

        #
        # And unmount all the file systems, mounting the root file
        # system
        # read-only (all are unmounted but because root can't be
        # unmounted
        # at this point mount will automatically mount it read-only
        # which
        # is what supposed to happen. This way no data can be written
        # anymore from disk)
        #

        echo -n "Unmounting file systems..."
        umount -a -r
        evaluate_retval || exit_if_any_error
        ;;

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

exit 0

# End /etc/init.d/mountfs
