On Fri, Nov 30, 2012 at 12:28:01AM +0000, Jorge Almeida wrote > When a pen is inserted, this is what is set: > > ACTION=add > 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 > SUBSYSTEM=block > MAJOR=8 > MINOR=48 > DEVNAME=sdd > DEVTYPE=disk > SEQNUM=1750
[...deletia...] > I'm supposing that the environment on netlink is the same as with the hotplug > mechanism. Would this be true? This is almost exactly what I remember from when I was writing/testing/debugging my automount scripts. The one difference I remember is that when mdev handled it, there was no "DEVNAME" variable, but rather it was "MDEV". But otherwise identical. Two important notes... 1) For a USB mass storage device (pen or external hard drive) with N partitions, the hotplug handler will get N+1 events when inserting and also when removing. E.g. if your pen drive has 3 partitions, you'll get 4 events... * one for /dev/sdd * one for /dev/sdd1 * one for /dev/sdd2 * one for /dev/sdd3 2) There is one exception to the above rule. Sometimes, Windows will format an entire pen as one large partition, without a partition table. This requires an ugly hack in my script. If DEVTYPE is "disk", it checks for the string "FAT" in the first 512 bytes of the device (bleagh). Here's an excerpt from my script at https://wiki.gentoo.org/wiki/Mdev/Automount_USB/automount ###################################################################### if [ "X${ACTION}" == "Xadd" ] ; then # # Flag for mounting if it's a regular partition if [ "X${DEVTYPE}" == "Xpartition" ] ; then partition=1 ; # # Further checks if DEVTYPE is disk; looking for weird setup where the # entire USB key is formatted as one partition, without the standard # partition table. elif [ "X${DEVTYPE}" == "Xdisk" ] ; then # # If it's "disk", check for string "FAT" in first 512 bytes of device. # Flag as a partition if the string is found. if dd if=${MDEV} bs=512 count=1 2>/dev/null | grep "FAT" 1>/dev/null ; then partition=1 fi fi fi ###################################################################### The important line is... if dd if=${MDEV} bs=512 count=1 2>/dev/null | grep "FAT" 1>/dev/null ; Would you be OK if the devices were always mounted in /media ? The reason I ask is that my scripts use pmount, which can take an optional label argument. E.g. if MDEV is "sdd1" pmount --umask 007 --noatime /dev/${MDEV} would create /media/sdd1 pmount --umask 007 --noatime /dev/${MDEV} my_pendrive_1 would create /media/my_pendrive_1 I always wanted to add that functionality to the scripts, but never got around to it. > BTW, the idea behind this is: > -- have s6-devd listen to the netlink interface > (http://www.skarnet.org/software/s6-linux-utils/s6-devd.html) > > -- when a device is inserted, s6-devd launches a program that tries to > obtain the serial number, uses it as key to seek a string some_name > in a constant database, and creates the symlink /dev/some_name --> > $DEVNAME. On failure, exec mdev with the environment passed by > the kernel. The way I'm thinking of doing it is to... * launch my script (with minor changes) * on an "add" action invoke your program to look for a match * if a match is found, use the optional label, otherwise use the default name in variable MDEV Actually, if I was writing it, I would add a few lines to my script for the "add" ACTION * label=${MDEV} * look for a "serial" file in the PCI path of the newly-inserted device * if found; then grep through a textfile to match the contents of the "serial" file if matched; then label=custom_name if [ ${#MDEV} -gt 3 ]; then label="${label}_${MDEV:3}" fi fi fi pmount --umask 007 --noatime /dev/${MDEV} ${label} -- Walter Dnes <waltd...@waltdnes.org> We are apparently better off trying to avoid udev like the plague. Linus Torvalds; 2012/10/03 https://lkml.org/lkml/2012/10/3/349