1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
|
#! /bin/sh
set -e
TYPE="$1"
case $TYPE in
maybe-floppy)
logger -t list-devices "deprecated parameter maybe-floppy"
TYPE=floppy
;;
cd|disk|partition|floppy)
;;
usb-partition|maybe-usb-floppy)
# USB is not supported on hurd
exit 0
;;
*)
echo "Usage: $0 cd|disk|partition|floppy|maybe-usb-floppy|usb-partition" >&2
exit 2
;;
esac
#
# We are using the entries present in /dev to detect the different kind
# of devices. Some heuristics are then used to refine the result.
#
is_cd_kernel() {
dev="${1#/dev/}"
grep -q "kernel: $dev: .* CDROM drive" /var/log/syslog || \
grep -q "kernel: $dev at .*> cdrom " /var/log/syslog
}
is_cd() {
echo "$1" | egrep -q '^/dev/cd[0-9]+$' && return 0
echo "$1" | egrep -q '^/dev/ucd[0-9]+$' && return 0
# FIXME: this also detect hard drives, but anyway the mount will
# later fail
echo "$1" | egrep -q '^/dev/[shwu]d[0-9]+$' || return 1
is_cd_kernel "$1"
}
is_disk() {
echo "$1" | egrep -q '^/dev/[shwu]d[0-9]+$' || return 1
! is_cd_kernel "$1"
}
is_partition() {
echo "$1" | egrep -q '^/dev/[shwu]d[0-9]+s[0-9]+$' || return 1
return 0
}
is_floppy() {
echo "$1" | egrep -q '^/dev/fd[0-9]+$' || return 1
return 0
}
# Loop through some /dev/ entries and test all the character ones
for x in /dev/fd* /dev/hd* /dev/sd* /dev/wd* /dev/ud* /dev/cd* /dev/ucd* ; do
[ -b "$x" -a -s "$x" ] || continue
if is_$TYPE "$x" ; then
echo $x
fi
done
exit 0
|