#!/bin/sh -e
#
# Name: udev-mtab 
# Date: 2006-07-25 14:40
# Author: MontaVista Software, Inc. <source@mvista.com>
# Copyright: Copyright 1999-2003 MontaVista Software, Inc.
# License: 2003 (c) MontaVista Software, Inc. This file is licensed
#          under the terms of the GNU General Public License version 2.
#          This program is licensed "as is" without any warranty of any
#          kind, whether express or implied.
#
# Copyright 2002, 2003, 2004 Sony Corporation
# Copyright 2002, 2003, 2004 Matsushita Electric Industrial Co., Ltd.
#
### BEGIN INIT INFO
# Required-Start:    udev checkroot
# Required-Stop:
# Should-Start:
# Should-Stop:
# Default-Start: S
# Default-Stop: 0 1 2 3 4 5 6
# Short-Description: fix mtab entries for udev
# Description: Add to mtab the entries for /dev and /dev/.static/dev.
### END INIT INFO 
# chkconfig: S 36 99

PATH="/sbin:/bin"

# copy the rules generated before / was mounted read-write
for file in /dev/.udev/tmp-rules--*; do
  dest=${file##*tmp-rules--}
  [ "$dest" = '*' ] && break
  cat $file >> /etc/udev/rules.d/$dest
  rm -f $file
done


# if it's not, it's probably a symlink to /proc/mounts
###[ -w /etc/mtab ] || exit 0

# defaults
tmpfs_size="10M"
udev_root="/dev/"

. /etc/udev/udev.conf

# strip the trailing slash
udev_root=${udev_root%/}

if mountpoint -q $udev_root; then
  grep -E -q -s "^[^ ]+ +$udev_root +" /etc/mtab || \
    mount -f -o size=$tmpfs_size,mode=0755 -t tmpfs tmpfs $udev_root
fi

# /dev/.static/dev/ is not added to mtab because /dev/.static/ is not
# world readable and some users are annoyed by the resulting error
# message from df.
if grep -E -q -s "^[^ ]+ +/dev/\.static/dev +" /etc/mtab; then
    umount /dev/.static/dev
fi
exit 0

# mountpoint(1) does not report bind mounts
if [ -e /dev/.static/dev/null ]; then
  grep -E -q -s "^[^ ]+ +/dev/\.static/dev +" /etc/mtab || \
    mount -f --bind /dev /dev/.static/dev
fi

exit 0

