3 # Unbinding usb-storage from the BlackBarry.
5 # Copyright (C) 2008 Niels de Vos <nixpanic@users.sourceforge.net>
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 # Disconnecting the BlackBerry from usb-storage is needed as btool needs to
23 # change the active USB-configuration.
25 # This script searched for any usb-storage devices and disconnects the
26 # device from the usb-storage driver. The driver kept loaded and therefore
27 # the barry-tools do not influence other usb-storage devices anymore.
29 # To enable debugging, use "export DEBUG=1" before execting this script.
32 # vendor as deteced by sd_mod (regex regex for egrep)
33 SD_VENDOR
='^RIM[[:space:]]*$'
34 # vendor as detected by usb-vendorId (regex for egrep)
37 # the sysfs-file for disconnecting the device from usb-storage
38 USB_STORAGE_UNBIND
='/sys/bus/usb/drivers/usb-storage/unbind'
41 # enable debugging with "export DEBUG=1"
44 [ -n "${DEBUG}" ] && echo "${@}" >&2
49 # find all vendor files (SCSI-specific) for USB-devices -> usb-storage
50 USB_STORAGE_VENDORS
=$
(find /sys
/devices
-name vendor
-path '*/usb*/host*/target*')
52 for USB_STORAGE_VENDOR
in ${USB_STORAGE_VENDORS}
54 # check if the file contains 'RIM' (file provided by sd_mod)
55 if ! egrep -q "${SD_VENDOR}" "${USB_STORAGE_VENDOR}"
57 debug
"device is not produced by ${SD_VENDOR}"
61 # find the vendorId (file provided by usbcore)
62 # a subdirectory on the same level as idVendor contains the important
63 # usb-device-id (the id looks like 4-1:1.0)
64 USB_IDVENDOR
="${USB_STORAGE_VENDOR}"
65 while [ ! -e "${USB_IDVENDOR}/../idVendor" ]
67 # go on with the parent directory
68 USB_IDVENDOR
=$
(dirname "${USB_IDVENDOR}")
70 # the unique usb-device-id (for usb-storage) is on this level
71 USB_DEVID
=$
(basename "${USB_IDVENDOR}")
72 USB_IDVENDOR
="${USB_IDVENDOR}/../idVendor"
74 # check if the file contains '0fca' (the RIM USB-vendorId)
75 if ! egrep -q "${USB_VENDOR}" "${USB_IDVENDOR}"
77 debug
"device does not have USB-vendorId ${USB_VENDOR}"
81 # found+verified all needed info, now do the disconnect!
82 debug
"going to unbind ${USB_DEVID} from usb-storage"
83 echo -n "${USB_DEVID}" > "${USB_STORAGE_UNBIND}"