1 |
On Thu, Nov 29, 2012 at 10:35 PM, Walter Dnes <waltdnes@××××××××.org> wrote: |
2 |
> On Thu, Nov 29, 2012 at 07:31:10PM +0000, Jorge Almeida wrote |
3 |
> |
4 |
> |
5 |
> I have a couple of scripts that automount USB devices under mdev. See |
6 |
> https://wiki.gentoo.org/wiki/Mdev for the general setup, and |
7 |
> https://wiki.gentoo.org/wiki/Mdev/Automount_USB and |
8 |
> https://wiki.gentoo.org/wiki/Mdev/Automount_USB/automount |
9 |
> |
10 |
|
11 |
I don't care for automounting, I just want customized symlinks. Using fstab is |
12 |
not a second choice, it is how I want it. |
13 |
|
14 |
> |
15 |
> The output below shows that not every USB device has a serial number, |
16 |
> and the "Patriot Memory" key has a serial number but no manufacturer... |
17 |
> |
18 |
> [d531][waltdnes][~] find /sys/devices/pci0* -name serial | xargs cat |
19 |
> |
20 |
|
21 |
OK. I found that my pens have serial numbers. I setup /proc/sys/kernel/hotplug |
22 |
with a script that prints the environment. When a pen is inserted, this is |
23 |
what is set: |
24 |
|
25 |
ACTION=add |
26 |
DEVPATH=/devices/pci0000:00/0000:00:04.1/usb1/1-4/1-4:1.0/host12/target12:0:0/12:0:0:0/block/sdd |
27 |
SUBSYSTEM=block |
28 |
MAJOR=8 |
29 |
MINOR=48 |
30 |
DEVNAME=sdd |
31 |
DEVTYPE=disk |
32 |
SEQNUM=1750 |
33 |
|
34 |
Following your suggestion: |
35 |
# find /sys/devices/pci0* -name serial |
36 |
/sys/devices/pci0000:00/0000:00:04.0/usb5/serial |
37 |
/sys/devices/pci0000:00/0000:00:04.1/usb1/1-4/serial |
38 |
/sys/devices/pci0000:00/0000:00:04.1/usb1/serial |
39 |
/sys/devices/pci0000:00/0000:00:06.0/usb6/serial |
40 |
/sys/devices/pci0000:00/0000:00:06.1/usb3/3-4/serial |
41 |
/sys/devices/pci0000:00/0000:00:06.1/usb3/serial |
42 |
/sys/devices/pci0000:00/0000:00:0c.0/0000:02:00.0/0000:03:01.0/0000:04:00.0/usb2/serial |
43 |
/sys/devices/pci0000:00/0000:00:0c.0/0000:02:00.0/0000:03:01.0/0000:04:00.0/usb4/serial |
44 |
|
45 |
# cat /sys/devices/pci0000:00/0000:00:04.1/usb1/1-4/serial |
46 |
AA04012700011287 |
47 |
|
48 |
So, the serial number is here. To retrieve it out of $DEVPATH, I can do (in |
49 |
this case, at least!): |
50 |
# cat /sys/devices/pci0000:00/0000:00:04.1/usb1/1-4/1-4:1.0/host12/target12:0:0/12:0:0:0/block/sdd/../../../../../../serial |
51 |
AA04012700011287 |
52 |
|
53 |
I'm assuming that this scenario is consistent for usb pen drives. I'll think |
54 |
of external hard disks next... |
55 |
|
56 |
BTW, the idea behind this is: |
57 |
-- have s6-devd listen to the netlink interface |
58 |
(http://www.skarnet.org/software/s6-linux-utils/s6-devd.html) |
59 |
|
60 |
-- when a device is inserted, s6-devd launches a program that tries to obtain |
61 |
the serial number, uses it as key to seek a string some_name in a constant |
62 |
database, and creates the symlink /dev/some_name --> $DEVNAME. On failure, |
63 |
exec mdev with the environment passed by the kernel. |
64 |
|
65 |
I'm supposing that the environment on netlink is the same as with the hotplug |
66 |
mechanism. Would this be true? |
67 |
|
68 |
I would be interested in hearing any comments... |
69 |
|
70 |
Thanks |
71 |
|
72 |
Joreg Almeida |
73 |
|
74 |
> |
75 |
> -- |
76 |
> Walter Dnes <waltdnes@××××××××.org> |
77 |
> We are apparently better off trying to avoid udev like the plague. |
78 |
|
79 |
Precisely. |
80 |
|
81 |
> Linus Torvalds; 2012/10/03 https://lkml.org/lkml/2012/10/3/349 |
82 |
> |