summaryrefslogtreecommitdiffstats
path: root/openwrt/package/base-files/default/etc/hotplug.d/usb/01-mount
blob: c28ada204ec01b0eab05bc328bb868e86585bc85 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
mount_storage() {
	cd /dev/discs
	for dev in disc*; do
		[ -f /tmp/.${dev}_id ] || {
			echo ${INTERFACE}${PRODUCT} > /tmp/.${dev}_id
			mount | grep /mnt/${dev} || (
				[ -d /mnt/. ] || {
					mkdir -p /tmp/mnt
					ln -s /tmp/mnt /
				}
				cd $dev
				for part in part*; do
					path=/mnt/${dev}_${part##*part}
					mkdir -p ${path}
					mount ${part} ${path}
				done
			)
		}
	done
}

umount_storage() {
	for tmp in /tmp/.*_id; do
		id=$(cat $tmp 2>&-)
		[ "${INTERFACE}${PRODUCT}" = "$id" ] && {
			rm -f $tmp
			disc=${tmp##*disc}
			disc=${disc%%_id}
			for disc in /mnt/disc${disc}*; do
				umount -f $disc || umount -l $disc
			done
		}
	done
}

[ -f /proc/bus/usb/devices ] || mount -t usbfs none /proc/bus/usb

case "$ACTION" in
	add)
		case "${INTERFACE%%/*}" in
			8) mount_storage ;;
		esac
	;;
	remove)
		case "${INTERFACE%%/*}" in
			8) umount_storage ;;
		esac
	;;
esac