Debian Codegraph @

list-devices-kfreebsd

raw symbols SCIP
1 #! /bin/sh
2 set -e
3 TYPE="$1"
4
5 case $TYPE in
6 maybe-floppy)
7 logger -t list-devices "deprecated parameter maybe-floppy"
8 TYPE=floppy
9 ;;
10 maybe-usb-floppy)
11 # Linux specific option, ignore it
12 exit 0
13 ;;
14 cd|disk|partition|floppy)
15 ;;
16 usb-partition)
17 TYPE=usb_partition
18 ;;
19 *)
20 echo "Usage: $0 cd|disk|partition|floppy|maybe-usb-floppy|usb-partition" >&2
21 exit 2
22 ;;
23 esac
24
25 #
26 # We are using the entries present in /dev to detect the different kind
27 # of devices. Some heuristics are then used to refine the result.
28 #
29
30 is_cd() {
31 echo "$1" | egrep -q '^/dev/cd[0-9]+$' || return 1
32
33 return 0
34 }
35
36 is_disk() {
37 echo "$1" | egrep -q '^/dev/(ad|da)[0-9]+$' || return 1
38
39 return 0
40 }
41
42 is_partition() {
43 echo "$1" | egrep -q '^/dev/((ad|da)[0-9]+[ps][0-9]+[a-z]?$|md[0-9])+$' || return 1
44
45 return 0
46 }
47
48 is_floppy() {
49 echo "$1" | egrep -q '^/dev/fd[0-9]+$' || return 1
50
51 return 0
52 }
53
54 is_usb_partition() {
55 echo "$1" | egrep -q '^/dev/(ad|da)[0-9]+[ps][0-9]+$' || return 1
56 drive="$(echo "$1" | sed -e 's,^/dev/,,' -e 's,[ps][0-9]\+,,')"
57 grep -q "kernel: $drive at umass" /var/log/syslog || return 1
58
59 return 0
60 }
61
62 # Loop through all /dev/ entries and test all the character ones
63 for x in /dev/* ; do
64 [ -c "$x" ] || continue
65
66 if is_$TYPE "$x" ; then
67 echo $x
68 fi
69 done
70
71 exit 0