chiark / gitweb /
[PATCH] experimental CALLOUT script for devfs ide node creation with cd, disc, part
authorkay.sievers@vrfy.org <kay.sievers@vrfy.org>
Tue, 23 Dec 2003 04:34:53 +0000 (20:34 -0800)
committerGreg KH <gregkh@suse.de>
Wed, 27 Apr 2005 04:13:09 +0000 (21:13 -0700)
Here is a experimental CALLOUT script for udev to create devfs nodes
for IDE-devices. Not that I need these, I just wanted to see if it works :)

The script is really stupid, no error handling, nothing more than
absolutely needed. The rule uses the 'k' format char of the previous
patch. The %D is not used, so the user can have disc or disk :)

this single line:
  CALLOUT, BUS="ide", PROGRAM="/etc/udev/ide-devfs.sh %k %b %n", ID="hd*", NAME="%1c", SYMLINK="%2c"

creates the following on my machine with two hard disks, one DVD and a PCMCIA-compact-flash inserted:
  /udev
  |-- hda
  |-- hda1
  |-- hda2
  |-- hda4
  |-- hdb
  |-- hdb1
  |-- hdc
  |-- hde
  |-- hde1
  `-- ide
      |-- host0
      |   |-- bus0
      |   |   |-- target0
      |   |   |   `-- lun0
      |   |   |       |-- disc -> ../../../../../hda
      |   |   |       |-- part1 -> ../../../../../hda1
      |   |   |       |-- part2 -> ../../../../../hda2
      |   |   |       `-- part4 -> ../../../../../hda4
      |   |   `-- target1
      |   |       `-- lun0
      |   |           |-- disc -> ../../../../../hdb
      |   |           `-- part1 -> ../../../../../hdb1
      |   `-- bus1
      |       `-- target0
      |           `-- lun0
      |               `-- cd -> ../../../../../hdc
      `-- host2
          `-- bus0
              `-- target0
                  `-- lun0
                      |-- disc -> ../../../../../hde
                      `-- part1 -> ../../../../../hde1

extras/ide-devfs.sh [new file with mode: 0644]

diff --git a/extras/ide-devfs.sh b/extras/ide-devfs.sh
new file mode 100644 (file)
index 0000000..3409c40
--- /dev/null
@@ -0,0 +1,27 @@
+#!/bin/sh
+
+# udev CALLOUT script
+# return devfs-names for ide-devices
+# CALLOUT, BUS="ide", PROGRAM="/etc/udev/ide-devfs.sh %k %b %n", ID="hd*", NAME="%1c", SYMLINK="%2c"
+
+HOST=${2%\.[0-9]}
+TARGET=${2#[0-9]\.}
+
+if [ -z ${HOST#[13579]} ]; then
+       HOST=`expr $HOST - 1`
+       BUS="1"
+else
+       BUS="0"
+fi
+
+if [ -z "$3" ]; then
+       MEDIA=`cat /proc/ide/$1/media`
+       if [ "$MEDIA" = "cdrom" ]; then
+               echo $1 ide/host$HOST/bus$BUS/target$TARGET/lun0/cd
+       elif [ "$MEDIA" = "disk" ]; then
+               echo $1 ide/host$HOST/bus$BUS/target$TARGET/lun0/disc
+       fi
+else
+       echo $1 ide/host$HOST/bus$BUS/target$TARGET/lun0/part$3
+fi
+