chiark / gitweb /
Change the gentoo rules to use cdrom_id instead of cdsymlink.sh
[elogind.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}", GROUP="%c{3}"
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         num=0
19         DRIVE="${1%%[0-9]*}"
20
21         for x in /proc/ide/*/media; do
22                 if [ -e "${x}" ]; then
23                         lMEDIA=`cat ${x}`
24                         if [ "${lMEDIA}" = "$2" ]; then
25                                 num=$((${num} + 1))
26                         fi
27                         if [ "${x}" = "/proc/ide/${DRIVE}/media" ]; then
28                                 break
29                         fi
30                 fi
31         done
32         
33         echo $((${num} - 1))
34 }
35
36 if [ -z "$3" ] && [ -f /proc/ide/${1}/media ]; then
37         MEDIA=`cat /proc/ide/${1}/media`
38         if [ "${MEDIA}" = "cdrom" ]; then
39                 echo ide/host${HOST}/bus${BUS}/target${TARGET}/lun0/cd cdroms/cdrom`get_dev_number $1 cdrom` ${MEDIA}
40         elif [ "${MEDIA}" = "floppy" ]; then
41                 echo ide/host${HOST}/bus${BUS}/target${TARGET}/lun0/disc floppies/floppy`get_dev_number $1 floppy`/disc ${MEDIA}
42         elif [ "${MEDIA}" = "disk" ]; then
43                 echo ide/host${HOST}/bus${BUS}/target${TARGET}/lun0/disc discs/disc`get_dev_number $1 disk`/disc ${MEDIA}
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