~ubuntu-branches/ubuntu/natty/debian-installer-utils/natty-updates

« back to all changes in this revision

Viewing changes to list-devices-linux

  • Committer: Bazaar Package Importer
  • Author(s): Colin Watson
  • Date: 2010-08-23 14:21:53 UTC
  • Revision ID: james.westby@ubuntu.com-20100823142153-efk4peksh54sjpxr
Tags: 1.79ubuntu1
* Resynchronise with Debian.  Remaining changes:
  - user-params: Don't propagate vga=*, break=*, *-ubiquity, or
    noninteractive to installed system.
  - Use /proc/self/fd/4 rather than /dev/fd/4 in fetch-url-methods/http;
    the latter doesn't seem to exist in d-i.
  - list-devices: new "mmc-partition" type for detecting partitions on MMC
    devices.
  - Don't include the battery subsystem on calls to udevadm trigger.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#! /bin/sh -e
 
2
TYPE="$1"
 
3
 
 
4
case $TYPE in
 
5
    maybe-floppy)
 
6
        logger -t list-devices "deprecated parameter maybe-floppy"
 
7
        TYPE=floppy
 
8
        ;;
 
9
    cd|disk|partition|floppy|maybe-usb-floppy|usb-partition|mmc-partition) ;;
 
10
    *)
 
11
        echo "Usage: $0 cd|disk|partition|floppy|maybe-usb-floppy|usb-partition|mmc-partition" >&2
 
12
        exit 2
 
13
        ;;
 
14
esac
 
15
 
 
16
if [ ! -d /sys/block ]; then
 
17
        exit 0
 
18
fi
 
19
if type udevadm >/dev/null 2>&1; then
 
20
        device_info () {
 
21
                udevadm info -q "$1" -p "$2" 2>/dev/null
 
22
        }
 
23
elif type udevinfo >/dev/null 2>&1; then
 
24
        device_info () {
 
25
                udevinfo -q "$1" -p "$2" 2>/dev/null
 
26
        }
 
27
else
 
28
        exit 0
 
29
fi
 
30
 
 
31
device_name () {
 
32
        local name
 
33
        if ! name="$(device_info name "$1")"; then
 
34
                name="$(printf %s "${1##*/}" | \
 
35
                        sed 's,!,/,g')"
 
36
        fi
 
37
        echo "/dev/$name"
 
38
}
 
39
 
 
40
is_sataraid () {
 
41
        grep -qs ^DMRAID- "$1/dm/uuid"
 
42
}
 
43
 
 
44
is_sataraid_partition () {
 
45
        # dmraid partitions are always slaved to another dm device
 
46
        for slave in "$1"/slaves/dm-*; do
 
47
                if [ -e "$slave" ]; then
 
48
                        return 0
 
49
                fi
 
50
        done
 
51
        return 1
 
52
}
 
53
 
 
54
if type dmraid >/dev/null 2>&1; then
 
55
        raiddevs="$(dmraid -r -c || true)"
 
56
else
 
57
        raiddevs=
 
58
fi
 
59
 
 
60
# cloned-and-hacked from partman-base/init.d/parted
 
61
part_of_sataraid () {
 
62
        local raiddev
 
63
        for raiddev in $raiddevs; do
 
64
                if [ "$(readlink -f "$raiddev")" = "$1" ]; then
 
65
                        return 0
 
66
                fi
 
67
        done
 
68
        return 1
 
69
}
 
70
 
 
71
syspaths=
 
72
scan_partition=false
 
73
case $TYPE in
 
74
    partition)
 
75
        for x in /sys/block/*/*[0-9]; do
 
76
                [ -d "$x" ] || continue
 
77
                syspaths="${syspaths:+$syspaths }$x"
 
78
        done
 
79
        for x in /sys/block/dm-*; do
 
80
                [ -d "$x" ] || continue
 
81
                (is_sataraid "$x" && is_sataraid_partition "$x") || continue
 
82
                syspaths="${syspaths:+$syspaths }$x"
 
83
        done
 
84
        TYPE=disk
 
85
        # Also allow misdetected USB devices
 
86
        scan_partition=:
 
87
        ;;
 
88
    usb-partition|mmc-partition)
 
89
        for x in /sys/block/*/*; do
 
90
                [ -d "$x" ] || continue
 
91
                syspaths="${syspaths:+$syspaths }$x"
 
92
        done
 
93
        ;;
 
94
    *)
 
95
        for x in /sys/block/*; do
 
96
                [ -d "$x" ] || continue
 
97
                case $x in
 
98
                    /sys/block/dm-*)
 
99
                        if is_sataraid "$x" && is_sataraid_partition "$x"; then
 
100
                                continue
 
101
                        fi
 
102
                        ;;
 
103
                    *)
 
104
                        name="$(device_name "$x")"
 
105
                        if part_of_sataraid "$name"; then
 
106
                                continue
 
107
                        fi
 
108
                        ;;
 
109
                esac
 
110
                syspaths="${syspaths:+$syspaths }$x"
 
111
        done
 
112
        ;;
 
113
esac
 
114
for x in $syspaths; do
 
115
        devpath="${x#/sys}"
 
116
        match=false
 
117
        case $TYPE in
 
118
            floppy)
 
119
                # TODO ugly special case for non-IDE floppies
 
120
                case $devpath in
 
121
                    /block/fd[0-9]*)
 
122
                        match=:
 
123
                        ;;
 
124
                esac
 
125
                ;;
 
126
        esac
 
127
        if ! $match && [ "$TYPE" = cd ]; then
 
128
                if device_info env "$devpath" | grep -q '^ID_CDROM='; then
 
129
                        match=:
 
130
                fi
 
131
        fi
 
132
        if ! $match; then
 
133
                if device_info env "$devpath" | grep -q "^ID_TYPE=$TYPE"; then
 
134
                        match=:
 
135
                fi
 
136
        fi
 
137
        if ! $match && [ "$TYPE" = disk ]; then
 
138
                case $devpath in
 
139
                    /block/cciss\!*|/block/ida\!*|/block/rd\!*|/block/mmcblk*|/block/vd[a-z]*|/block/xvd[a-z]*)
 
140
                        match=:
 
141
                        ;;
 
142
                    /block/dm-*)
 
143
                        # for now, we only understand dmraid
 
144
                        if is_sataraid "/sys$devpath"; then
 
145
                                match=:
 
146
                        fi
 
147
                        ;;
 
148
                esac
 
149
        fi
 
150
        # Some USB sticks and CD drives are misdetected as floppy
 
151
        # This allows to scan for those
 
152
        if ! $match && ( $scan_partition || [ "$TYPE" = maybe-usb-floppy ] ); then
 
153
                if device_info env "$devpath" | grep -q '^ID_BUS=usb' && \
 
154
                   device_info env "$devpath" | grep -q '^ID_TYPE=floppy'; then
 
155
                        match=:
 
156
                fi
 
157
        fi
 
158
        # Disk partitions, but only on USB drives
 
159
        if ! $match && [ "$TYPE" = usb-partition ]; then
 
160
                if device_info env "$devpath" | grep -q '^ID_BUS=usb' && \
 
161
                   device_info env "$devpath" | grep -q '^ID_TYPE=disk'; then
 
162
                        match=:
 
163
                fi
 
164
        fi
 
165
        # Disk partitions, but only on (non-USB) MMC devices
 
166
        if ! $match && [ "$TYPE" = mmc-partition ]; then
 
167
                if device_info env "$devpath" | egrep -q '^ID_PATH=(platform-mmc|platform-orion-ehci|platform-mxsdhci)'; then
 
168
                        match=:
 
169
                fi
 
170
        fi
 
171
        if $match; then
 
172
                device_name "/sys$devpath"
 
173
        fi
 
174
done