-
Notifications
You must be signed in to change notification settings - Fork 0
/
device-helper
executable file
·55 lines (45 loc) · 1.23 KB
/
device-helper
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
50
51
52
53
54
55
#!/bin/sh -f
# See COPYING and COPYRIGHT files for corresponding information.
# Create /dev/disk/by-* and /dev/mapper/* symlinks.
create_symlink() {
_typ="$1"
_sym="$2"
_sym="${_sym%\"}"
_sym="${_sym#\"}"
_sym="/dev/disk/by-${_typ}/${_sym}"
mkdir -p "${_sym%/*}"
ln -s "../../${dev_name}" "${_sym}"
}
# DEVPATH is part of uevent which is exported to environment by device
# manager.
if [ ! -b "/dev/${dev_name=${DEVPATH##*/}}" ]; then
exit 1
fi
exec >/dev/null 2>&1
if read -r dm_name < "/sys/block/${dev_name}/dm/name"; then
mkdir -p /dev/mapper
ln -sf "../${dev_name}" "/dev/mapper/${dm_name:?}"
fi
if ! command -v blkid; then
exit 0
fi
# Race condition may occur if uevent arrives faster (isn't that a
# kernel bug!?) than the kernel initializes device. This prevents
# blkid to fetch data from device. To fix this, we simply waiting
# until blkid is succeeded.
while ! _blkid=$(blkid "/dev/${dev_name}"); do
if [ "$((count += 1))" = 10 ]; then
exit 1
else
sleep 1
fi
done
for line in $_blkid; do
case "${line%%=*}" in
UUID) create_symlink uuid "${line##*=}" ;;
LABEL) create_symlink label "${line##*=}" ;;
PARTUUID) create_symlink partuuid "${line##*=}" ;;
esac
done
# vim: cc=72 tw=70
# End of file.