#!/bin/sh
#########################################
# USB Port on FH7200
#
# REAR : ehci-brcm.0 -> BUSNUM=001
# INNER : ehci-brcm.1 -> BUSNUM=002
# FRONT : ehci-brcm.2 -> BUSNUM=003
#########################################
# set to '1' to enable USB thumbdrive automount
AUTOMOUNT=1
AUTOMOUNT_REAR_POINT="/mnt/usbrear"
AUTOMOUNT_RSS_POINT="/mnt/rss"
AUTOMOUNT_FRONT_POINT="/mnt/usb"
SAVED_REAR_DEVPATH="/tmp/saved-usbrear-devpath"
SAVED_RSS_DEVPATH="/tmp/saved-rss-devpath"
SAVED_FRONT_DEVPATH="/tmp/saved-usb-devpath"
AUTOMOUNT_FS="vfat"
HOTPLUG_FW_DIR=/lib/firmware
# on boot (option : -s)
if [ "$1" = "-s" ]; then
for i in /sys/block/sd*/*/dev
do
if [ -f $i ]; then
DEV=$(echo $i | sed -e 's@/dev@@' -e 's@.*/@@')
BLKDEV=$(echo $DEV | cut -c1-3)
BLKDEVPATH=`readlink /sys/block/$BLKDEV/device`
DEVPATH="/block/$BLKDEV/$DEV"
if [[ "$BLKDEVPATH" == *usb1* ]]; then
echo $DEVPATH > $SAVED_REAR_DEVPATH
exec mount /dev/${DEV} ${AUTOMOUNT_REAR_POINT} -o iocharset=utf8
if [ $? -ne 0 ]; then
exec mount /dev/${DEV} ${AUTOMOUNT_REAR_POINT}
fi
elif [[ "$BLKDEVPATH" == *usb2* ]]; then
echo $DEVPATH > $SAVED_RSS_DEVPATH
exec mount /dev/${DEV} ${AUTOMOUNT_RSS_POINT} -o data=journal
elif [[ "$BLKDEVPATH" == *usb3* ]]; then
echo $DEVPATH > $SAVED_FRONT_DEVPATH
exec mount /dev/${DEV} ${AUTOMOUNT_FRONT_POINT} -o iocharset=utf8
if [ $? -ne 0 ]; then
exec mount /dev/${DEV} ${AUTOMOUNT_FRONT_POINT}
fi
fi
fi
done
fi
# userspace firmware loader
if [ "$1" = "firmware" ]; then
if [ "$ACTION" = "add" ]; then
echo 1 > /sys/$DEVPATH/loading
cat $HOTPLUG_FW_DIR/$FIRMWARE > /sys/$DEVPATH/data
echo 0 > /sys/$DEVPATH/loading
fi
fi
# network hotplug
# NOTE: this only operates on real NICs (ethN), not lo/br0/sit0/etc.
if [ "$1" = "net" -a -e /sys/class/net/$INTERFACE/device ]; then
if [ "$ACTION" = "add" ]; then
/sbin/ifup $INTERFACE
elif [ "$ACTION" = "remove" ]; then
/sbin/ifdown $INTERFACE
fi
fi
# USB automount (only works with bash)
if [[ "$ACTION" = "remove" && "$1" = "block" ]]; then
if [[ -e $SAVED_REAR_DEVPATH ]]; then
USB_DEVPATH=`cat $SAVED_REAR_DEVPATH`
if [[ "$DEVPATH" = "$USB_DEVPATH" ]]; then
rm -f $SAVED_REAR_DEVPATH
exec umount -l ${AUTOMOUNT_REAR_POINT}
fi
fi
if [[ -e $SAVED_RSS_DEVPATH ]]; then
USB_DEVPATH=`cat $SAVED_RSS_DEVPATH`
if [[ "$DEVPATH" = "$USB_DEVPATH" ]]; then
rm -f $SAVED_RSS_DEVPATH
exec umount -l ${AUTOMOUNT_RSS_POINT}
fi
fi
if [[ -e $SAVED_FRONT_DEVPATH ]]; then
USB_DEVPATH=`cat $SAVED_FRONT_DEVPATH`
if [[ "$DEVPATH" = "$USB_DEVPATH" ]]; then
rm -f $SAVED_FRONT_DEVPATH
exec umount -l ${AUTOMOUNT_FRONT_POINT}
fi
fi
fi
# PHYSDEV* vars were removed in 2.6.37
if [ -z "$PHYSDEVPATH" ]; then
# for DEVPATH = /block/sda/sda1
PHYSDEVPATH=`readlink /sys/$DEVPATH/../device`
PHYSDEVDRIVER=`readlink /sys/$DEVPATH/../device/driver`
fi
if [[ "$AUTOMOUNT" = "1" && "$1" = "block" && "$ACTION" = "add" ]]; then
if [[ "$PHYSDEVPATH" == *usb1* ]]; then
if [[ ! -e $SAVED_REAR_DEVPATH && "$PHYSDEVDRIVER" = *sd && $[ ($MINOR % 16) == 1 ] ]]; then
DEV=${DEVPATH##*/}
echo $DEVPATH > $SAVED_REAR_DEVPATH
exec mount /dev/${DEV} ${AUTOMOUNT_REAR_POINT} -o iocharset=utf8
if [ $? -ne 0 ]; then
exec mount /dev/${DEV} ${AUTOMOUNT_REAR_POINT}
fi
fi
elif [[ "$PHYSDEVPATH" == *usb2* ]]; then
if [[ ! -e $SAVED_RSS_DEVPATH && "$PHYSDEVDRIVER" = *sd && $[ ($MINOR % 16) == 1 ] ]]; then
DEV=${DEVPATH##*/}
echo $DEVPATH > $SAVED_RSS_DEVPATH
exec mount /dev/${DEV} ${AUTOMOUNT_RSS_POINT} -o data=journal
fi
elif [[ "$PHYSDEVPATH" == *usb3* ]]; then
if [[ ! -e $SAVED_FRONT_DEVPATH && "$PHYSDEVDRIVER" = *sd && $[ ($MINOR % 16) == 1 ] ]]; then
DEV=${DEVPATH##*/}
echo $DEVPATH > $SAVED_FRONT_DEVPATH
exec mount /dev/${DEV} ${AUTOMOUNT_FRONT_POINT} -o iocharset=utf8
if [ $? -ne 0 ]; then
exec mount /dev/${DEV} ${AUTOMOUNT_FRONT_POINT}
fi
fi
fi
fi
Here's a C program to print hotplug nelink events to stdout:
참조 :
http://lwn.net/Articles/242046/
https://www.kernel.org/doc/pending/hotplug.txt
[Fedora17] When yum, segmentation fault (0) | 2013.10.21 |
---|---|
[Linux] Fedora 8 Newtork 설치 (0) | 2013.09.30 |
Fedora 17 NFS 설정 (0) | 2012.12.10 |
Fedora17 SAMBA 설정 (0) | 2012.12.07 |
[Linux] .vimrc & mkcscope.sh (1) | 2012.11.23 |