Systemd/extras/ide-devfs.sh
tao@kernel.org b9e3301c3b [PATCH] Minor POSIX-fixes for udev
The attached patch contains a few patches against udev, to remove
use of various XSI:isms and bash:isms, and to change two scripts form
/bin/bash to /bin/sh.  None of the bash-scripts in test/ uses any
bash-specific functions as far as I know, but I didn't touch them since
they aren't used runtime.

Rationale:
* Both of the /bin/bash-scripts are totally free from bashisms, hence they
  don't need to be /bin/bash; using /bin/sh instead helps (mainly)
  embedded-people

* local and source are bash:isms (well, they exist in several other
  shells as well, but they aren't part of POSIX or any of its extensions)

* -a in tests is an XSI-extension, not part of strict POSIX, and is
  easily replaced by &&
  | http://www.opengroup.org/onlinepubs/009695399/utilities/test.html

* Use of fgrep is deprecated in POSIX in favour of grep -F (though fgrep
  will remain in use for a long time...)
  | http://www.opengroup.org/onlinepubs/009695399/utilities/grep.html

The fgrep-change isn't really necessary, since fgrep can always be
implemented as a shell-script, but the rest of the changes would really
be appreciated.
2005-04-26 21:36:59 -07:00

48 lines
1.2 KiB
Bash

#!/bin/sh
# udev external PROGRAM script
# return devfs-names for ide-devices
# BUS="ide", KERNEL="hd*", PROGRAM="/etc/udev/ide-devfs.sh %k %b %n", NAME="%k", SYMLINK="%c{1} %c{2}"
HOST="${2%\.[0-9]}"
TARGET="${2#[0-9]\.}"
if [ -z "${HOST#[13579]}" ]; then
HOST=$((${HOST} - 1))
BUS="1"
else
BUS="0"
fi
get_dev_number() {
num=0
DRIVE="${1%%[0-9]*}"
for x in /proc/ide/*/media; do
if [ -e "${x}" ]; then
lMEDIA=`cat ${x}`
if [ "${lMEDIA}" = "$2" ]; then
num=$((${num} + 1))
fi
if [ "${x}" = "/proc/ide/${DRIVE}/media" ]; then
break
fi
fi
done
echo $((${num} - 1))
}
if [ -z "$3" ] && [ -f /proc/ide/${1}/media ]; then
MEDIA=`cat /proc/ide/${1}/media`
if [ "${MEDIA}" = "cdrom" ]; then
echo ide/host${HOST}/bus${BUS}/target${TARGET}/lun0/cd cdroms/cdrom`get_dev_number $1 cdrom`
elif [ "${MEDIA}" = "floppy" ]; then
echo ide/host${HOST}/bus${BUS}/target${TARGET}/lun0/disc floppies/floppy`get_dev_number $1 floppy`/disc
elif [ "${MEDIA}" = "disk" ]; then
echo ide/host${HOST}/bus${BUS}/target${TARGET}/lun0/disc discs/disc`get_dev_number $1 disk`/disc
fi
else
echo ide/host${HOST}/bus${BUS}/target${TARGET}/lun0/part$3 discs/disc`get_dev_number $1 disk`/part$3
fi