]> git.ipfire.org Git - thirdparty/systemd.git/blob - extras/ide-devfs.sh
8648f6c0c06d7c97678cef10f9bc7993394a693f
[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="%1c %2c"
6
7 HOST="${2%\.[0-9]}"
8 TARGET="${2#[0-9]\.}"
9
10 if [ -z "${HOST#[13579]}" ]; then
11 HOST=`expr ${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=`expr ${num} + 1`
28 fi
29 if [ "${x}" = "/proc/ide/${DRIVE}/media" ]; then
30 break
31 fi
32 fi
33 done
34
35 echo `expr ${num} - 1`
36 }
37
38 if [ -z "$3" ]; 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}" = "disk" ]; then
43 echo ide/host${HOST}/bus${BUS}/target${TARGET}/lun0/disc discs/disc`get_dev_number $1 disk`/disc
44 fi
45 else
46 echo ide/host${HOST}/bus${BUS}/target${TARGET}/lun0/part$3 discs/disc`get_dev_number $1 disk`/part$3
47 fi