#! /bin/sh
### BEGIN INIT INFO
# Provides:          mountkernfs
# Required-Start:
# Required-Stop:
# Default-Start:     S
# Default-Stop:
# Short-Description: Mount kernel virtual file systems.
# Description:       Mount initial set of virtual filesystems the kernel
#                    provides and that are required by everything.
### END INIT INFO

PATH=/lib/init:/sbin:/bin

. /lib/lsb/init-functions
. /lib/init/mount-functions.sh

do_start () {
	#
	# Mount proc filesystem on /proc
	#
	domount proc "" /proc -onodev,noexec,nosuid

	#
	# Mount sysfs on /sys
	#
	# Only mount sysfs if it is supported (kernel >= 2.6)
	if grep -E -qs "sysfs\$" /proc/filesystems
	then
		domount sysfs "" /sys -onodev,noexec,nosuid
	fi

	#
	# Mount usbfs/usbdevfs if /proc/bus/usb is present.
	#
	# Usbfs/usbdevfs is used for USB related binaries/libraries.
	# "usbfs" and "usbdevfs" are the exact same filesystem.
	# "usbdevfs" was renamed to "usbfs" by linux usb developers,
	# because people sometimes mistook it as a part of devfs. Usbfs
	# will be superseded by other filesystems (e.g. sysfs), and when
	# it becomes obsolete the mount action below should be removed.
	#
	if [ -d /proc/bus/usb ]
	then
		domount usbfs usbdevfs /proc/bus/usb -onodev,noexec,nosuid
	fi
}

case "$1" in
  "")
	echo "Warning: mountkernfs should be called with the 'start' argument." >&2
	do_start
	;;
  start)
	do_start
	;;
  restart|reload|force-reload)
	echo "Error: argument '$1' not supported" >&2
	exit 3
	;;
  stop)
	# No-op
	;;
  *)
	echo "Usage: mountkernfs [start|stop]" >&2
	exit 3
	;;
esac
