Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 57633
Collapse All | Expand All

(-)/etc/conf.d/usb (+1 lines)
Lines 5-7 Link Here
5
5
6
# Put any modules here that you want to be loaded by the USB hotplug system
6
# Put any modules here that you want to be loaded by the USB hotplug system
7
#STATIC_MODULE_LIST=
7
#STATIC_MODULE_LIST=
8
STATIC_MODULE_LIST=usb-storage
(-)/etc/hotplug/usb.usermap (+9 lines)
Line 1 Link Here
1
# usb module         match_flags idVendor idProduct bcdDevice_lo bcdDevice_hi bDeviceClass bDeviceSubClass bDeviceProtocol bInterfaceClass bInterfaceSubClass bInterfaceProtocol driver_info
1
# usb module         match_flags idVendor idProduct bcdDevice_lo bcdDevice_hi bDeviceClass bDeviceSubClass bDeviceProtocol bInterfaceClass bInterfaceSubClass bInterfaceProtocol driver_info
2
#
3
# The entry below has two effects:
4
#   It causes /etc/hotplug/usb/usb-storage to be invoked, 
5
#      as usual per its flags and matches (Interface class 8=USB mass storage)
6
#   It has the special side effect of invoking /usr/sbin/updfstab,
7
#      if that file exists
8
# See hotplug.functions, around line 169
9
#
10
usb-storage           0x0080      0x0000    0x0000   0x0000       0x0000         0x00          0x00               0x00            0x08            0x00            0x00           0x00000000
(-) (+223 lines)
Added Link Here
1
#!/bin/sh
2
#
3
# Automount hotplugged USB block devices, by Scott Marks (smarks@mobile-mind.com)
4
# Based on automount.hotplug by Wout Mertens (wmertens@gentoo.org)
5
#
6
# Linux v2.6 version
7
# This script is released under version 2 of the GPL.
8
9
# To install this, either make it /etc/hotplug/usb/usb-storage.
10
# It needs to be executable. 
11
#
12
# The devices will be mounted for the console user if applicable.
13
#
14
# To work, this needs:
15
# - v2.6 kernel support:
16
#   - hotplugging, /proc mounted, /sys mounted
17
#   - filesystems that will be mounted, like vfat
18
# - sh, echo, sed, stat or ls, getent or grep passwd,
19
#   mount, umount, mkdir, rmdir. logger is used if there.
20
#
21
# Possible improvements:
22
# - Create a desktop entry for the device.
23
# - Mount as supermount if available. This will improve behaviour for
24
#   synchronous writes and hanging mounts, although umount -lf already
25
#   does a good job. UPDATE: added, but untested. Let me know if it works.
26
# - Detect filesystem on device, so filesystems that don't need a mounting
27
#   user can skip user detection.
28
29
# Debugging
30
# set -xv
31
# exec > /tmp/hotplug.$$ 2>&1 
32
33
PATH="/bin:/sbin:/usr/bin:/usr/sbin"
34
export PATH
35
36
# Proclaim stuff to the world
37
mesg () {
38
	logger -t $0 "$*"
39
}
40
41
# Is path already mounted?
42
is_path_mounted () {
43
	while read dev path rest
44
	do
45
		if [ "$path" = "$1" ]
46
		then
47
			return 0
48
		fi
49
	done < /proc/self/mounts
50
	return 1
51
}
52
53
54
# Remove strange characters from a filename
55
clean_filename () {
56
	# Note the lack of quotes around $1, this strips off spaces.
57
	echo $1 | sed 's/[ /?*\"<>]/_/g'
58
}
59
60
61
SYSFS=/sys
62
63
: DEVPATH=$DEVPATH
64
65
# Wait for a file matching host* to appear in $SYSFS$DEVPATH
66
67
local count
68
for count in 1 2 3 4 5 6 7 8 9 10
69
do
70
    count is $count
71
    HOST=`ls -1 $SYSFS$DEVPATH | grep -m 1 '^host[1-9][0-9]*$'`
72
    [ -z "$HOST" ] || break
73
    sleep 1
74
done
75
76
[ -z "$HOST" ] && mesg No host in $SYSFS$DEVPATH?
77
78
79
BLKDEV=scsi/$HOST/bus0/target0/lun0
80
81
82
# Mount all partitions on this device
83
: host devices are `ls -m /dev/$BLKDEV`
84
85
86
87
case "$ACTION" in
88
add)
89
    # Figure out user to which to assign mounted partition devices
90
    CONSOLEUSER=`stat -c%U /dev/console 2>/dev/null`
91
    if [ -z "$CONSOLEUSER" ]
92
    then
93
        set `ls -l /dev/console`
94
        CONSOLEUSER=$3
95
    fi
96
97
    [ -n "$CONSOLEUSER" ] || CONSOLEUSER=root
98
    PASSWD=`getent passwd $CONSOLEUSER 2>/dev/null`
99
    if [ -z "$PASSWD" ]
100
    then
101
        PASSWD=`grep "$CONSOLEUSER" /etc/passwd||grep root /etc/passwd`
102
    fi
103
    if [ -z "$PASSWD" ]
104
    then
105
        mesg Could not get password entry for $CONSOLEUSER
106
        exit 1
107
    fi
108
109
    set `echo $PASSWD | sed 's/:/ /g'`
110
    if [ $# -lt 4 ]
111
    then
112
        mesg Bad password entry for $CONSOLEUSER
113
        exit 1
114
    fi
115
116
    # These options should prevent abuse and make it writeable for the
117
    # console user.
118
    if grep -q supermount /proc/filesystems
119
    then
120
        MOUNTOPTS="-s -t supermount -onoatime,nosuid,umask=077,uid=$3,gid=$4"
121
    else
122
        MOUNTOPTS="-s -onoatime,sync,dirsync,nosuid,umask=077,uid=$3,gid=$4"
123
    fi
124
125
    # Write the remover as we go
126
    echo ". /etc/hotplug/usb/usb-storage.remove" > "$REMOVER"
127
128
    # Mount each partition device
129
    for p in `ls /dev/$BLKDEV` ;
130
    do
131
        if [ "$p" != "disc" ]
132
        then
133
134
            # If is there a symbolic link here, use it
135
            PARTDEV=`find /dev -lname $BLKDEV/$p`
136
            [ -z "$PARTDEV" ] && PARTDEV="/dev/$BLKDEV/$p"
137
       
138
            : Need to mount $PARTDEV
139
140
	    # Mount it
141
142
	    # Make sure we have support for vfat
143
	    modprobe -q vfat
144
145
146
	    # Find the name
147
	    
148
149
	    # Find out where we mount it
150
	    MOUNTPATH=/mnt/usb/storage
151
	    if is_path_mounted "$MOUNTPATH"
152
	    then
153
	        count=1
154
	        while is_path_mounted "${MOUNTPATH}_${count}"
155
	        do
156
	            count=$(( $count + 1 ))
157
	        done
158
	        MOUNTPATH="${MOUNTPATH}_${count}"
159
	    fi
160
161
	    # Find out device info to make a nice alias
162
163
	    VendorID=`cat $SYSFS$DEVPATH/../idVendor`
164
	    ProductID=`cat $SYSFS$DEVPATH/../idProduct`
165
166
	    PRODUCT=$VendorID.$ProductID
167
	    if [ -x /usr/sbin/lsusb ]
168
	    then
169
		set `lsusb -d 0x$VendorID:0x$ProductID`
170
		shift 6
171
		PRODUCT="$*"
172
            fi
173
	    ALIAS=/mnt/usb/`clean_filename "$PRODUCT"`
174
	    if [ -e "$ALIAS" ]
175
	    then
176
	        count=1
177
	        while [ -e "${ALIAS}_${count}" ]
178
	        do
179
	            count=$(( $count + 1 ))
180
	        done
181
	        ALIAS="${ALIAS}_${count}"
182
	    fi
183
184
            # Make sure it's a directory
185
	    if [ -e "$MOUNTPATH" ]
186
	    then
187
	        if [ ! -d "$MOUNTPATH" ]
188
	        then
189
	            mesg $MOUNTPATH exists but is not a directory
190
	            continue
191
  	        fi
192
	    else
193
	        mkdir -p "$MOUNTPATH"
194
	        if [ $? -ne 0 ]
195
	        then
196
		    mesg Could not create mountpoint $MOUNTPATH
197
		    continue
198
	        fi
199
	    fi
200
201
	    mesg Mounting $PARTDEV on $MOUNTPATH, options $MOUNTOPTS
202
203
	    mount $MOUNTOPTS $PARTDEV $MOUNTPATH
204
205
	    ln -s $MOUNTPATH $ALIAS
206
207
       	    echo "remove $PARTDEV" >> "$REMOVER"
208
	fi
209
210
    done
211
212
    chmod +x "$REMOVER"
213
    ;;
214
215
remove)
216
    # Umount each partition device
217
    mesg Shouldn\'t be here -- $REMOVER missing?
218
    ;;
219
220
*)
221
    exit 1;;
222
esac
223
(-) (+31 lines)
Added Link Here
1
remove ( ) {
2
    local DEVICE=$1
3
4
    : Need to umount $DEVICE
5
6
    # What dir is mounted to $DEVICE
7
    while read dev path rest
8
    do
9
	if [ "$dev" = "$DEVICE" ]
10
	then
11
	    MOUNTPATH="$path"
12
	    break
13
	fi
14
    done < /proc/self/mounts
15
16
    # If is isn't ours, never mind
17
    echo "$MOUNTPATH" | grep -q ^/mnt/usb || return 0
18
19
    # Bizarrely wrong if it isn't a dir
20
    [ -d "$MOUNTPATH" ] || return 1 
21
22
    #remove its alias
23
    ALIAS=`find /mnt/usb -lname $MOUNTPATH`
24
    [ -L "$ALIAS" ] && rm $ALIAS
25
    
26
    umount -lf "$MOUNTPATH"
27
    #unmount it
28
	    
29
    #delete it
30
    rmdir "$MOUNTPATH"
31
}

Return to bug 57633