File: list-devices

package info (click to toggle)
debian-installer-utils 1.45etch1
  • links: PTS
  • area: main
  • in suites: etch
  • size: 516 kB
  • ctags: 18
  • sloc: sh: 581; ansic: 106; makefile: 72
file content (122 lines) | stat: -rwxr-xr-x 2,564 bytes parent folder | download
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#! /bin/sh -e
TYPE="$1"

case $TYPE in
	cd|disk|partition|floppy|maybe-floppy|maybe-usb-floppy)	;;
	*)
		echo "Usage: $0 cd|disk|partition|floppy|maybe-floppy|maybe-usb-floppy" >&2
		exit 2
		;;
esac

if [ -d /sys/block ] && type udevinfo >/dev/null 2>&1; then
	syspaths=
	case $TYPE in
		partition)
			for x in /sys/block/*/*; do
				[ -d "$x" ] || continue
				syspaths="${syspaths:+$syspaths }$x"
			done
			TYPE=disk
			;;
		*)
			for x in /sys/block/*; do
				[ -d "$x" ] || continue
				syspaths="${syspaths:+$syspaths }$x"
			done
			;;
	esac
	for x in $syspaths; do
		devpath="${x#/sys}"
		match=false
		case $TYPE in
			maybe-floppy)
				TYPE=floppy
				;;
		esac
		case $TYPE in
			floppy)
				# TODO ugly special case for non-IDE floppies
				case $devpath in
					/block/fd[0-9]*)
						match=:
						;;
				esac
				;;
		esac
		# Some USB sticks and CD drives are misdetected as floppy
		# This allows to scan for those
		if ! $match && [ "$TYPE" = maybe-usb-floppy ]; then
			if udevinfo -q env -p "$devpath" 2>/dev/null | \
			   grep -q '^ID_BUS=usb' && \
			   udevinfo -q env -p "$devpath" 2>/dev/null | \
			   grep -q '^ID_TYPE=floppy'; then
				match=:
			fi
		fi
		if ! $match && [ "$TYPE" = cd ]; then
			if udevinfo -q env -p "$devpath" 2>/dev/null | \
			   grep -q '^ID_CDROM='; then
				match=:
			fi
		fi
		if ! $match; then
			if udevinfo -q env -p "$devpath" 2>/dev/null | \
			   grep -q "^ID_TYPE=$TYPE"; then
				match=:
			fi
		fi
		if ! $match && [ "$TYPE" = disk ]; then
			case $devpath in
				/block/cciss\!*|/block/ida\!*|/block/rd\!*)
					match=:
					;;
			esac
		fi
		if $match; then
			if ! name="$(udevinfo -q name -p "$devpath" \
					2>/dev/null)"; then
				name="$(printf %s "${devpath##*/}" | \
					sed 's,!,/,g')"
			fi
			echo "/dev/$name"
		fi
	done
else
	case $TYPE in
		cd)
			if [ -d /dev/cdroms ]; then
				find /dev/cdroms -type b
			fi
			;;
		disk)
			if [ -d /dev/discs ]; then
				# busybox find has no -maxdepth
				find /dev/discs -type b | \
					grep -v '/.*/.*/.*/' || true
			fi
			;;
		partition)
			if [ -d /dev/discs ]; then
				# busybox find has no -mindepth
				find /dev/discs -type b | \
					grep '/.*/.*/.*/' || true
			fi
			;;
		floppy)
			if [ -d /dev/floppy ]; then
				find /dev/floppy -type b
			fi
			;;
		maybe-floppy)
			# Without udev, we can't necessarily tell floppies
			# from other kinds of disks, so we have to offer
			# everything.
			for x in /dev/floppy /dev/scsi /dev/ide /dev/discs; do
				if [ -d "$x" ]; then
					find "$x" -type b
				fi
			done
			;;
	esac
fi