linux-hotplug.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* need absolute location/device of usb flash disk
@ 2009-08-03 17:39 Joseph Mack NA3T
  2009-08-04  0:29 ` Jim Paris
                   ` (10 more replies)
  0 siblings, 11 replies; 12+ messages in thread
From: Joseph Mack NA3T @ 2009-08-03 17:39 UTC (permalink / raw)
  To: linux-hotplug

I'm going to be writing images to usb flash disks on 15 
ports on multiple hubs. I need to know which port on a hub 
is associated with which /dev/sd?? device, so I can tell the 
user where to insert their flash key and when the write is 
done.

About 4yrs ago (with '=' syntax), systool would allow me to 
write udev rules like

#if want flash memory recognised differently
#in different positions on external hub
BUS="usb", ID="1-1.1", SYSFS{manufacturer}="PNY     ", SYSFS{product}="USB 2.0 FD      ", NAME="flashA%n"
BUS="usb", ID="1-1.2", SYSFS{manufacturer}="PNY     ", SYSFS{product}="USB 2.0 FD      ", NAME="flashB%n"
BUS="usb", ID="1-1.3", SYSFS{manufacturer}="PNY     ", SYSFS{product}="USB 2.0 FD      ", NAME="flashC%n"
BUS="usb", ID="1-1.4", SYSFS{manufacturer}="PNY     ", SYSFS{product}="USB 2.0 FD      ", NAME="flashD%n"

I'm now running sysfsutils v-2.1.0, udevd v111, uname 
-r=2.6.22.19

My attempt to get this to work now looking at the usb bus

#systool -vb usb

gives

  Device path = "/sys/devices/pci0000:00/0000:00:1d.7/usb4/4-3"
.
.
     product             = "USB Flash Memory"


the following rule (constructed by swiping the above "Device 
path") is ignored (I get /dev/sda* for the usb drive)

BUS="usb", SYSFS{Device path}="/sys/devices/pci0000:00/0000:00:1d.7/usb4/4-3", NAME="flashB%n"


Instead I looked at the scsi bus

# systool -vb scsi
Bus = "scsi"

   Device path = "/sys/devices/pci0000:00/0000:00:1d.7/usb4/4-3/4-3:1.0/host5/target5:0:0/5:0:0:0"
.
.
     model               = "USB Flash Memory"

since the host/target changes on each insertion I tried 
these two rules which are also ignored (get /dev/sda*)


BUS="scsi", SYSFS{Device path}="/sys/devices/pci0000:00/0000:00:1d.7/usb4/4-3/4-3:1.0/*", NAME="flashB%n"
BUS="scsi", SYSFS{Device path}="/sys/devices/pci0000:00/0000:00:1d.7/usb4/*", NAME="flashB%n"

As a control to show that I can construct a rule that 
works, these work

#OK gives devices pny*
BUS="scsi", SYSFS{vendor}="        ", SYSFS{model}="USB Flash Memory", NAME="pny%n"
#OK gives devices flashB*
BUS="scsi", SYSFS{vendor}="        ", SYSFS{model}="USB Flash Memory", NAME="flashB%n"
#OK gives flashB*
BUS="usb", SYSFS{product}="USB Flash Memory", NAME="flashB%n"


#this doesn't work, gives devices like usbdev4.15_ep00
BUS="scsi", SYSFS{modalias}="scsi:t-0x00", NAME="flashB%n"


What should I do to give the device a name determined from 
an absolute location?

Thanks Joe

-- 
Joseph Mack NA3T EME(B,D), FM05lw North Carolina
jmack (at) wm7d (dot) net - azimuthal equidistant map
generator at http://www.wm7d.net/azproj.shtml
Homepage http://www.austintek.com/ It's GNU/Linux!

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: need absolute location/device of usb flash disk
  2009-08-03 17:39 need absolute location/device of usb flash disk Joseph Mack NA3T
@ 2009-08-04  0:29 ` Jim Paris
  2009-08-05 15:56 ` Joseph Mack NA3T
                   ` (9 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: Jim Paris @ 2009-08-04  0:29 UTC (permalink / raw)
  To: linux-hotplug

Joseph Mack NA3T wrote:
> I'm going to be writing images to usb flash disks on 15 ports on multiple 
> hubs. I need to know which port on a hub is associated with which 
> /dev/sd?? device, so I can tell the user where to insert their flash key 
> and when the write is done.
..
> What should I do to give the device a name determined from an absolute 
> location?

Check the links in /dev/disk/by-path, which might already be what you
want, or can at least give you some ideas for how to make your own
links.  On my system they're generated by /lib/udev/rules.d/60-persistent-storage.rules.


-jim


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: need absolute location/device of usb flash disk
  2009-08-03 17:39 need absolute location/device of usb flash disk Joseph Mack NA3T
  2009-08-04  0:29 ` Jim Paris
@ 2009-08-05 15:56 ` Joseph Mack NA3T
  2009-08-05 16:21 ` Kay Sievers
                   ` (8 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: Joseph Mack NA3T @ 2009-08-05 15:56 UTC (permalink / raw)
  To: linux-hotplug

On Mon, 3 Aug 2009, Jim Paris wrote:

> Joseph Mack NA3T wrote:
>> I'm going to be writing images to usb flash disks on 15 ports on multiple
>> hubs. I need to know which port on a hub is associated with which
>> /dev/sd?? device, so I can tell the user where to insert their flash key
>> and when the write is done.
> ..
>> What should I do to give the device a name determined from an absolute
>> location?
>
> Check the links in /dev/disk/by-path,

Thanks didn't know about this.

The entries have specific info about the particular disk at 
that location, whereas I want the rule to apply to any disk. 
So it's not obvious how to use this info.

I've almost got everything I want however.

I started with systool, which is what worked a couple of 
years ago. However apparently it recovers info which is not 
visible to the udev rules system and I was using this info.

Instead starting with

# udevinfo -q path -n /dev/sda1
/block/sda/sda1

# udevinfo -a -p /block/sda/sda1

gives all the info usable by udev rules. Apparently you need 
one rule specific to your device and one (or more?) rules 
from device parents. This gave me rules like

KERNELS="4-3:1.0", SUBSYSTEM="block", NAME="flashL%n"

which work fine. I've now labeled all my ports by location.

There's rules about GROUP in one of my files (50-...)

KERNEL="sd*[!0-9]", ATTR{removable}="1", GROUP="plugdev"
KERNEL="sd*[0-9]", ATTRS{removable}="1", GROUP="plugdev"

I can't use these rules to apply a GROUP to flash disks in 
the usb ports of interest, but not to flash disks in the 
other port. Any ideas on assigning the GROUP?

Thanks Joe

-- 
Joseph Mack NA3T EME(B,D), FM05lw North Carolina
jmack (at) wm7d (dot) net - azimuthal equidistant map
generator at http://www.wm7d.net/azproj.shtml
Homepage http://www.austintek.com/ It's GNU/Linux!

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: need absolute location/device of usb flash disk
  2009-08-03 17:39 need absolute location/device of usb flash disk Joseph Mack NA3T
  2009-08-04  0:29 ` Jim Paris
  2009-08-05 15:56 ` Joseph Mack NA3T
@ 2009-08-05 16:21 ` Kay Sievers
  2009-08-05 16:42 ` Matthias Schwarzott
                   ` (7 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: Kay Sievers @ 2009-08-05 16:21 UTC (permalink / raw)
  To: linux-hotplug

On Wed, Aug 5, 2009 at 17:56, Joseph Mack NA3T<jmack@wm7d.net> wrote:

> KERNELS="4-3:1.0", SUBSYSTEM="block", NAME="flashL%n"
>
> which work fine. I've now labeled all my ports by location.

It's not fine. You just match on a rather random USB enumeration. The
/dev/disk/by-path/ links are longer for good reason.

> There's rules about GROUP in one of my files (50-...)
>
> KERNEL="sd*[!0-9]", ATTR{removable}="1", GROUP="plugdev"
> KERNEL="sd*[0-9]", ATTRS{removable}="1", GROUP="plugdev"
>
> I can't use these rules to apply a GROUP to flash disks in the usb ports of
> interest, but not to flash disks in the other port. Any ideas on assigning
> the GROUP?

A later rule sets GROUP=, and overwrites it, I guess. GROUP:= might work.

Kay

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: need absolute location/device of usb flash disk
  2009-08-03 17:39 need absolute location/device of usb flash disk Joseph Mack NA3T
                   ` (2 preceding siblings ...)
  2009-08-05 16:21 ` Kay Sievers
@ 2009-08-05 16:42 ` Matthias Schwarzott
  2009-08-05 20:26 ` Joseph Mack NA3T
                   ` (6 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: Matthias Schwarzott @ 2009-08-05 16:42 UTC (permalink / raw)
  To: linux-hotplug

On Mittwoch, 5. August 2009, Joseph Mack NA3T wrote:
>
> There's rules about GROUP in one of my files (50-...)
>
> KERNEL="sd*[!0-9]", ATTR{removable}="1", GROUP="plugdev"
> KERNEL="sd*[0-9]", ATTRS{removable}="1", GROUP="plugdev"
>
> I can't use these rules to apply a GROUP to flash disks in
> the usb ports of interest, but not to flash disks in the
> other port. Any ideas on assigning the GROUP?
>
have a look which other files assign GROUP of block devices, and move your 
rules to be after it.
Does your device have removable=1?
Why not match
SUBSYSTEM="block", SUBSYSTEMS="usb", KERNEL="sd*", GROUP="plugdev"

So all sd* devices on usb bus get group set.

Matthias


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: need absolute location/device of usb flash disk
  2009-08-03 17:39 need absolute location/device of usb flash disk Joseph Mack NA3T
                   ` (3 preceding siblings ...)
  2009-08-05 16:42 ` Matthias Schwarzott
@ 2009-08-05 20:26 ` Joseph Mack NA3T
  2009-08-05 21:09 ` Kay Sievers
                   ` (5 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: Joseph Mack NA3T @ 2009-08-05 20:26 UTC (permalink / raw)
  To: linux-hotplug

On Wed, 5 Aug 2009, Kay Sievers wrote:

> On Wed, Aug 5, 2009 at 17:56, Joseph Mack NA3T<jmack@wm7d.net> wrote:
>
>> KERNELS="4-3:1.0", SUBSYSTEM="block", NAME="flashL%n"
>>
>> which work fine. I've now labeled all my ports by location.
>
> It's not fine. You just match on a rather random USB enumeration.

thanks.

> The /dev/disk/by-path/ links are longer for good reason.

Here's the /dev/disk/by-path with the flash disk inserted

pci-0000:00:14.2-usb-0:4:1.0-scsi-0:0:0:0 -> ../../pny
pci-0000:00:14.2-usb-0:4:1.0-scsi-0:0:0:0-part1 -> ../../pny1
pci-0000:00:14.2-usb-0:4:1.0-scsi-0:0:0:0-part4 -> ../../pny4

For this port I've used in my rule

KERNELS="2-4:1.0"

Looking at the output of

udevinfo -a -p /block/sda/sda1

I don't see anything matching the links in /dev/disk/by-path

what should I be looking for in the output of udevinfo?

Thanks Joe

-- 
Joseph Mack NA3T EME(B,D), FM05lw North Carolina
jmack (at) wm7d (dot) net - azimuthal equidistant map
generator at http://www.wm7d.net/azproj.shtml
Homepage http://www.austintek.com/ It's GNU/Linux!

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: need absolute location/device of usb flash disk
  2009-08-03 17:39 need absolute location/device of usb flash disk Joseph Mack NA3T
                   ` (4 preceding siblings ...)
  2009-08-05 20:26 ` Joseph Mack NA3T
@ 2009-08-05 21:09 ` Kay Sievers
  2009-08-06  0:25 ` Joseph Mack NA3T
                   ` (4 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: Kay Sievers @ 2009-08-05 21:09 UTC (permalink / raw)
  To: linux-hotplug

On Wed, Aug 5, 2009 at 22:26, Joseph Mack NA3T<jmack@wm7d.net> wrote:
> On Wed, 5 Aug 2009, Kay Sievers wrote:
>
>> On Wed, Aug 5, 2009 at 17:56, Joseph Mack NA3T<jmack@wm7d.net> wrote:
>>
>>> KERNELS="4-3:1.0", SUBSYSTEM="block", NAME="flashL%n"
>>>
>>> which work fine. I've now labeled all my ports by location.
>>
>> It's not fine. You just match on a rather random USB enumeration.
>
> thanks.
>
>> The /dev/disk/by-path/ links are longer for good reason.
>
> Here's the /dev/disk/by-path with the flash disk inserted
>
> pci-0000:00:14.2-usb-0:4:1.0-scsi-0:0:0:0 -> ../../pny
> pci-0000:00:14.2-usb-0:4:1.0-scsi-0:0:0:0-part1 -> ../../pny1
> pci-0000:00:14.2-usb-0:4:1.0-scsi-0:0:0:0-part4 -> ../../pny4

Do not rename any kernel device name, just add symlinks if needed.
Random stuff breaks if you do that.

> For this port I've used in my rule
>
> KERNELS="2-4:1.0"
>
> Looking at the output of
>
> udevinfo -a -p /block/sda/sda1
>
> I don't see anything matching the links in /dev/disk/by-path

Sure not, because it can't work that way.

> what should I be looking for in the output of udevinfo?

Nothing, just use the plain links which are already created. The
needed logic is _not_ contained in udevinfo or the kernel name.

Kay

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: need absolute location/device of usb flash disk
  2009-08-03 17:39 need absolute location/device of usb flash disk Joseph Mack NA3T
                   ` (5 preceding siblings ...)
  2009-08-05 21:09 ` Kay Sievers
@ 2009-08-06  0:25 ` Joseph Mack NA3T
  2009-08-06  1:35 ` Jim Paris
                   ` (3 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: Joseph Mack NA3T @ 2009-08-06  0:25 UTC (permalink / raw)
  To: linux-hotplug

On Wed, 5 Aug 2009, Kay Sievers wrote:

>> Here's the /dev/disk/by-path with the flash disk inserted
>>
>> pci-0000:00:14.2-usb-0:4:1.0-scsi-0:0:0:0 -> ../../pny
>> pci-0000:00:14.2-usb-0:4:1.0-scsi-0:0:0:0-part1 -> ../../pny1
>> pci-0000:00:14.2-usb-0:4:1.0-scsi-0:0:0:0-part4 -> ../../pny4
>
> Do not rename any kernel device name, just add symlinks if needed.
> Random stuff breaks if you do that.

OK didn't know that.

>> what should I be looking for in the output of udevinfo?
>
> Nothing, just use the plain links which are already 
> created. The needed logic is _not_ contained in udevinfo 
> or the kernel name.

I'm not sure how this relates to my problem.

In case you haven't got my problem, I have 15 ports on USB 
hubs. The user has a flash drive that the computer has never 
seen (and may not see again), which he can insert now, or 
someone may have prefilled the slots with flash drives 
earlier. He tells the program which slot holds the flash 
disk, which file(s) he wants and tells the computer to write 
them. At the end the program tells the user to remove the 
flash drive and the computer has to detect that the slot has 
become empty. All the other slots can be writing or holding 
flash drives at the same time.

To setup I can put flash drives into each slot to find the 
association between a slot and the computer's descriptors, 
but I don't know how to fine the association. How do I use 
the plain links which are created on insertion to know which 
slot a flash drive is sitting in?

Thanks Joe

-- 
Joseph Mack NA3T EME(B,D), FM05lw North Carolina
jmack (at) wm7d (dot) net - azimuthal equidistant map
generator at http://www.wm7d.net/azproj.shtml
Homepage http://www.austintek.com/ It's GNU/Linux!

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: need absolute location/device of usb flash disk
  2009-08-03 17:39 need absolute location/device of usb flash disk Joseph Mack NA3T
                   ` (6 preceding siblings ...)
  2009-08-06  0:25 ` Joseph Mack NA3T
@ 2009-08-06  1:35 ` Jim Paris
  2009-08-06  2:41 ` Joseph Mack NA3T
                   ` (2 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: Jim Paris @ 2009-08-06  1:35 UTC (permalink / raw)
  To: linux-hotplug

Joseph Mack NA3T wrote:
> On Wed, 5 Aug 2009, Kay Sievers wrote:
>
>>> Here's the /dev/disk/by-path with the flash disk inserted
>>>
>>> pci-0000:00:14.2-usb-0:4:1.0-scsi-0:0:0:0 -> ../../pny
>>> pci-0000:00:14.2-usb-0:4:1.0-scsi-0:0:0:0-part1 -> ../../pny1
>>> pci-0000:00:14.2-usb-0:4:1.0-scsi-0:0:0:0-part4 -> ../../pny4
>>
>> Do not rename any kernel device name, just add symlinks if needed.
>> Random stuff breaks if you do that.
>
> OK didn't know that.
>
>>> what should I be looking for in the output of udevinfo?
>>
>> Nothing, just use the plain links which are already created. The needed 
>> logic is _not_ contained in udevinfo or the kernel name.
>
> I'm not sure how this relates to my problem.
>
> In case you haven't got my problem, I have 15 ports on USB hubs. The user 
> has a flash drive that the computer has never seen (and may not see 
> again), which he can insert now, or someone may have prefilled the slots 
> with flash drives earlier. He tells the program which slot holds the 
> flash disk, which file(s) he wants and tells the computer to write them. 
> At the end the program tells the user to remove the flash drive and the 
> computer has to detect that the slot has become empty. All the other 
> slots can be writing or holding flash drives at the same time.
>
> To setup I can put flash drives into each slot to find the association 
> between a slot and the computer's descriptors, but I don't know how to 
> fine the association. How do I use the plain links which are created on 
> insertion to know which slot a flash drive is sitting in?

The links in /dev/disk/by-path really should work for you as-is.
They uniquely identify the physical slot the disk is plugged into.
What specifically about that link is not meeting your needs?

-jim


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: need absolute location/device of usb flash disk
  2009-08-03 17:39 need absolute location/device of usb flash disk Joseph Mack NA3T
                   ` (7 preceding siblings ...)
  2009-08-06  1:35 ` Jim Paris
@ 2009-08-06  2:41 ` Joseph Mack NA3T
  2009-08-06 13:46 ` Joseph Mack NA3T
  2009-08-07 10:22 ` Alan Jenkins
  10 siblings, 0 replies; 12+ messages in thread
From: Joseph Mack NA3T @ 2009-08-06  2:41 UTC (permalink / raw)
  To: linux-hotplug

On Wed, 5 Aug 2009, Jim Paris wrote:

> The links in /dev/disk/by-path really should work for you as-is.
> They uniquely identify the physical slot the disk is plugged into.

I didn't understand that. Let me try it out

Thanks Joe

-- 
Joseph Mack NA3T EME(B,D), FM05lw North Carolina
jmack (at) wm7d (dot) net - azimuthal equidistant map
generator at http://www.wm7d.net/azproj.shtml
Homepage http://www.austintek.com/ It's GNU/Linux!

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: need absolute location/device of usb flash disk
  2009-08-03 17:39 need absolute location/device of usb flash disk Joseph Mack NA3T
                   ` (8 preceding siblings ...)
  2009-08-06  2:41 ` Joseph Mack NA3T
@ 2009-08-06 13:46 ` Joseph Mack NA3T
  2009-08-07 10:22 ` Alan Jenkins
  10 siblings, 0 replies; 12+ messages in thread
From: Joseph Mack NA3T @ 2009-08-06 13:46 UTC (permalink / raw)
  To: linux-hotplug

On Wed, 5 Aug 2009, Joseph Mack NA3T wrote:

> On Wed, 5 Aug 2009, Jim Paris wrote:
>
>> The links in /dev/disk/by-path really should work for you 
>> as-is. They uniquely identify the physical slot the disk 
>> is plugged into.
>
> I didn't understand that. Let me try it out

Well dang. This works. Thanks everyone.

I now see what you're all talking about. I assumed that I 
had to write a udev rule from the contents of 
/dev/disk/by-path. I also thought the contents of this 
directory was changing with each insertion, like the output 
of "udevinfo -a -p $device", but I now see that it isn't.

I'd like only the program of interest to be able to write to 
disks on the external ports. Changing the GROUP and MODE of 
these disks would do it. Is it possible to change the GROUP 
of the ports on the external hubs (and not change the GROUP 
of ports built into the computer)?

Thanks Joe

-- 
Joseph Mack NA3T EME(B,D), FM05lw North Carolina
jmack (at) wm7d (dot) net - azimuthal equidistant map
generator at http://www.wm7d.net/azproj.shtml
Homepage http://www.austintek.com/ It's GNU/Linux!

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: need absolute location/device of usb flash disk
  2009-08-03 17:39 need absolute location/device of usb flash disk Joseph Mack NA3T
                   ` (9 preceding siblings ...)
  2009-08-06 13:46 ` Joseph Mack NA3T
@ 2009-08-07 10:22 ` Alan Jenkins
  10 siblings, 0 replies; 12+ messages in thread
From: Alan Jenkins @ 2009-08-07 10:22 UTC (permalink / raw)
  To: linux-hotplug

On 8/6/09, Joseph Mack NA3T <jmack@wm7d.net> wrote:
> On Wed, 5 Aug 2009, Joseph Mack NA3T wrote:
>
>> On Wed, 5 Aug 2009, Jim Paris wrote:
>>
>>> The links in /dev/disk/by-path really should work for you
>>> as-is. They uniquely identify the physical slot the disk
>>> is plugged into.
>>
>> I didn't understand that. Let me try it out
>
> Well dang. This works. Thanks everyone.
>
> I now see what you're all talking about. I assumed that I
> had to write a udev rule from the contents of
> /dev/disk/by-path. I also thought the contents of this
> directory was changing with each insertion, like the output
> of "udevinfo -a -p $device", but I now see that it isn't.
>
> I'd like only the program of interest to be able to write to
> disks on the external ports. Changing the GROUP and MODE of
> these disks would do it. Is it possible to change the GROUP
> of the ports on the external hubs (and not change the GROUP
> of ports built into the computer)?
>
> Thanks Joe

You should be able to write a rule which matches on SYMLINK.

SYMLINK="disk/by-path/X", GROUP=...

where X is a shell wildcard pattern which matches the desired paths.

Make sure it is run after SYMLINK is set in
60-persistent-storage.rules or whatever it is on your system.

Regard
Alan

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2009-08-07 10:22 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-08-03 17:39 need absolute location/device of usb flash disk Joseph Mack NA3T
2009-08-04  0:29 ` Jim Paris
2009-08-05 15:56 ` Joseph Mack NA3T
2009-08-05 16:21 ` Kay Sievers
2009-08-05 16:42 ` Matthias Schwarzott
2009-08-05 20:26 ` Joseph Mack NA3T
2009-08-05 21:09 ` Kay Sievers
2009-08-06  0:25 ` Joseph Mack NA3T
2009-08-06  1:35 ` Jim Paris
2009-08-06  2:41 ` Joseph Mack NA3T
2009-08-06 13:46 ` Joseph Mack NA3T
2009-08-07 10:22 ` Alan Jenkins

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).