aboutsummaryrefslogtreecommitdiffstats
path: root/main/busybox-initscripts/usbdisk_link
blob: 750242bb5cfca97db1faae7c87b467184b1a1a9f (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
#!/bin/sh

# NOTE: since mdev -s only provide $MDEV, don't depend on any hotplug vars.

current=$(readlink usbdisk)

if [ "$current" = "$MDEV" ] && [ "$ACTION" = "remove" ]; then
	rm -f usbdisk usba1 
fi
[ -n "$current" ] && exit

if [ -e /sys/block/$MDEV ]; then
	SYSDEV=$(readlink -f /sys/block/$MDEV/device)
	# if /sys device path contains '/usb[0-9]' then we assume its usb
	# also, if its an usb without partitions we require FAT
	if [ "${SYSDEV##*/usb[0-9]}" != "$SYSDEV" ]; then
		# do not create link if there is not FAT
		dd if=/dev/$MDEV bs=512 count=1 2>/dev/null | strings | grep FAT >/dev/null || exit 0

		ln -sf $MDEV usbdisk
		# keep this for compat. people have it in fstab
		ln -sf $MDEV usba1
	fi

elif [ -e /sys/block/*/$MDEV ] ; then
	PARENT=$(dirname /sys/block/*/$MDEV)
	SYSDEV=$(readlink -f $PARENT/device)
	if [ "${SYSDEV##*/usb[0-9]}" != "$SYSDEV" ]; then
		ln -sf $MDEV usbdisk
		# keep this for compat. people have it in fstab
		ln -sf $MDEV usba1
	fi
fi