]> git.ipfire.org Git - thirdparty/systemd.git/blob - extras/ide-devfs.sh
[PATCH] udev callout for reading filesystem labels
[thirdparty/systemd.git] / extras / ide-devfs.sh
1 #!/bin/sh
2
3 # udev external PROGRAM script
4 # return devfs-names for ide-devices
5 # BUS="ide", KERNEL="hd*", PROGRAM="/etc/udev/ide-devfs.sh %k %b %n", NAME="%k", SYMLINK="%c{1} %c{2}"
6
7 HOST="${2%\.[0-9]}"
8 TARGET="${2#[0-9]\.}"
9
10 if [ -z "${HOST#[13579]}" ]; then
11 HOST=$((${HOST} - 1))
12 BUS="1"
13 else
14 BUS="0"
15 fi
16
17 get_dev_number() {
18 local x=
19 local num=0
20 local MEDIA=
21 local DRIVE="${1%%[0-9]*}"
22
23 for x in /proc/ide/*/media; do
24 if [ -e "${x}" ]; then
25 MEDIA=`cat ${x}`
26 if [ "${MEDIA}" = "$2" ]; then
27 num=$((${num} + 1))
28 fi
29 if [ "${x}" = "/proc/ide/${DRIVE}/media" ]; then
30 break
31 fi
32 fi
33 done
34
35 echo $((${num} - 1))
36 }
37
38 if [ -z "$3" -a -f /proc/ide/${1}/media ]; then
39 MEDIA=`cat /proc/ide/${1}/media`
40 if [ "${MEDIA}" = "cdrom" ]; then
41 echo ide/host${HOST}/bus${BUS}/target${TARGET}/lun0/cd cdroms/cdrom`get_dev_number $1 cdrom`
42 elif [ "${MEDIA}" = "floppy" ]; then
43 echo ide/host${HOST}/bus${BUS}/target${TARGET}/lun0/disc floppies/floppy`get_dev_number $1 floppy`/disc
44 elif [ "${MEDIA}" = "disk" ]; then
45 echo ide/host${HOST}/bus${BUS}/target${TARGET}/lun0/disc discs/disc`get_dev_number $1 disk`/disc
46 fi
47 else
48 echo ide/host${HOST}/bus${BUS}/target${TARGET}/lun0/part$3 discs/disc`get_dev_number $1 disk`/part$3
49 fi