From: Martin <drink@hyperlogos.org>
To: linux-hotplug@vger.kernel.org
Subject: Working on a usb-storage hotplug script
Date: Sat, 29 Nov 2003 01:19:30 +0000 [thread overview]
Message-ID: <marc-linux-hotplug-107006883203516@msgid-missing> (raw)
I recently got my first USB flash drive - I have one on loan from work,
but I finally OWN one, so I am motivated to do something with it now.
One of the things I want to have working is hotplugging, with automatic
mounting. The device it's mounted on doesn't matter so much but one of
the absolutely mandatory requirements is that I not need a fstab entry.
This became a requirement when I noticed that plugging the device in,
then unplugging it, then plugging it BACK in resulted in it being
attached first to sdc and then to sdd. (This is a SCSI system.)
Before I go on, some relevant information:
Linux suckit 2.4.20-xfs-r3 #3 SMP Fri Nov 28 14:20:48 PST 2003 i686 AMD
Athlon(tm) Processor AuthenticAMD GNU/Linux
(This is the gentoo xfs-sources version of the kernel.)
Hotplug version 20030805-r2
usbcore, usb-ohci, and usb-storage modules all load as they should.
So I began to google for a usb-storage hotplug script which would do
what I want. Alas, no such thing exists. The closest script I found
really didn't work to begin with, so I set out to write something.
Unfortunately there seems to be no simple way to get from the
information that hotplug will feed one about the connected mass storage
device to the particular scsi device which it has been attached to.
I began by writing a script which probably looks familiar to everyone
who's worked on this problem.
#!/bin/bash
echo "ACTION ${ACTION}" >> /tmp/usblog
echo "PRODUCT ${PRODUCT}" >> /tmp/usblog
echo "TYPE ${TYPE}" >> /tmp/usblog
echo "INTERFACE ${INTERFACE}" >> /tmp/usblog
echo "DEVFS ${DEVFS}" >> /tmp/usblog
echo "DEVICE ${DEVICE}" >> /tmp/usblog
This resulted in the following output upon insertion of my flash drive:
ACTION add
PRODUCT ea0/6828/110
TYPE usb
INTERFACE 8/6/80
DEVFS /proc/bus/usb
DEVICE /proc/bus/usb/001/006
By looking in the usb and scsi nodes under /proc I decided that the only
unique information between the two trees was the serial number.
/proc/bus/usb/devices (as you know) is an ascii file which contains
long descriptions of every connected usb device in the system.
Each device begins with a T: line, here is the entry for my flash drive.
T: Bus\x01 Lev\x01 Prnt\x01 Port\x01 Cnt\x01 Dev#= 6 Spd\x12 MxCh= 0
D: Ver= 1.10 Cls\0(>ifc ) Sub\0 Prot\0 MxPSd #Cfgs= 1
P: Vendor\x0ea0 ProdIDh28 Rev= 1.10
S: Manufacturer=USB
S: Product=Flash Disk
S: SerialNumber#0760A43F777AB2
C:* #Ifs= 1 Cfg#= 1 AtrÄ MxPwr\x100mA
I: If#= 0 Alt= 0 #EPs= 3 Cls\b(stor.) Sub\x06 ProtP Driver=usb-storage
E: AdÅ(I) Atr\x02(Bulk) MxPS= 64 Ivl=0ms
E: Ad\x02(O) Atr\x02(Bulk) MxPS= 64 Ivl=0ms
E: AdÉ(I) Atr\x03(Int.) MxPS= 2 Ivl%5ms
our device is 001/006 which is bus/dev. so we can use the T: line to
find our device. This is useful because there is only one T: line per
device. After this I went to find the serial number (S: SerialNumber=*)
Then I went to look in /proc/scsi/usb-storage-* to find devices.
/proc/scsi/usb-storage-0/1 looks like so:
Host scsi1: usb-storage
Vendor: USB
Product: Flash Disk
Serial Number: 230760A43F777AB2
Protocol: Transparent SCSI
Transport: Bulk
GUID: 0ea06828230760a43f777ab2
Attached: Yes
So we can see that our serial number matches. The first line of the file
tells me the Host which I will obviously need. Looking in /proc/scsi/scsi:
Attached devices:
Host: scsi0 Channel: 00 Id: 00 Lun: 00
Vendor: IBM Model: DDRS-39130D Rev: DC1B
Type: Direct-Access ANSI SCSI revision: 02
Host: scsi0 Channel: 00 Id: 01 Lun: 00
Vendor: SEAGATE Model: ST39140N Rev: 1498
Type: Direct-Access ANSI SCSI revision: 02
Host: scsi0 Channel: 00 Id: 06 Lun: 00
Vendor: IBM Model: CDRM00203 !K Rev: BZ26
Type: CD-ROM ANSI SCSI revision: 02
Host: scsi1 Channel: 00 Id: 00 Lun: 00
Vendor: 64MB Model: HardDrive Rev: 1.88
Type: Direct-Access ANSI SCSI revision: 02
unfortunately the entries here are not really unique in any way if you
have more than one of the same thing. The Revision from the
/proc/bus/usb/devices might be used to HELP identify something, but it
still will not be unique. The question is, what happens when I plug in
another one? Will it get a new host? Answer is yes. The device also
shows up in a new usb-storage-? directory under /proc/scsi. Here is its
entry in usb/devices:
T: Bus\x01 Lev\x01 Prnt\x01 Port\x01 Cnt\x02 Dev#= 6 Spd\x12 MxCh= 0
D: Ver= 1.10 Cls\0(>ifc ) Sub\0 Prot\0 MxPSd #Cfgs= 1
P: Vendor\x0ea0 ProdIDh28 Rev= 1.10
S: Manufacturer=USB
S: Product=Flash Disk
S: SerialNumber#0760A43F777AB2
C:* #Ifs= 1 Cfg#= 1 AtrÄ MxPwr\x100mA
I: If#= 0 Alt= 0 #EPs= 3 Cls\b(stor.) Sub\x06 ProtP Driver=usb-storage
E: AdÅ(I) Atr\x02(Bulk) MxPS= 64 Ivl=0ms
E: Ad\x02(O) Atr\x02(Bulk) MxPS= 64 Ivl=0ms
E: AdÉ(I) Atr\x03(Int.) MxPS= 2 Ivl%5ms
And here is the new entry in /proc/scsi/scsi:
Host: scsi2 Channel: 00 Id: 00 Lun: 00
Vendor: JetFlash Model: 128MB Rev: 1.11
Type: Direct-Access ANSI SCSI revision: 02
Obviously I don't have two identical flash devices to play with, or I
would be using them.
Does the Port\x01 correspond to the usb-storage-? directory in
/proc/scsi? That is the only number which seems to have gone from 0 to
1. I only have two flash devices so I can't tell for sure by installing
another one. The new device has an entry in usb-storage-1/2 rather than
1/1 as I would have suspected. The Cnt\x02 leads me to believe that Port
becomes the usb-storage-? directory and Cnt becomes the filename under
that directory. Are my assumptions correct? If so I can do away with
most of my nonsense about the serial number, it was just the first thing
I came up with.
I do have one further problem before I even start, which is that I don't
seem to get a remove event when I disconnect a flash drive. Is this a
known problem with my version of the kernel or of hotplug?
-------------------------------------------------------
This SF.net email is sponsored by: SF.net Giveback Program.
Does SourceForge.net help you be more productive? Does it
help you create better code? SHARE THE LOVE, and help us help
YOU! Click Here: http://sourceforge.net/donate/
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
Linux-hotplug-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel
next reply other threads:[~2003-11-29 1:19 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-11-29 1:19 Martin [this message]
2003-11-29 12:33 ` Working on a usb-storage hotplug script reflex
2003-11-29 14:06 ` Oliver Neukum
2003-11-29 18:05 ` Marco d'Itri
2003-11-30 11:19 ` reflex
2003-11-30 19:38 ` Greg KH
2003-12-09 9:05 ` Wout Mertens
2003-12-09 16:09 ` Olaf Hering
2003-12-09 16:24 ` Greg KH
2003-12-10 19:29 ` Wout Mertens
2003-12-10 19:41 ` Wout Mertens
2003-12-10 19:49 ` Olaf Hering
2003-12-11 15:37 ` Wout Mertens
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=marc-linux-hotplug-107006883203516@msgid-missing \
--to=drink@hyperlogos.org \
--cc=linux-hotplug@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).