I'm trying to get access to the partition type (the one-byte field in the master boot record) in udev, so that I can set ownership and permissions based on partition type. The challenge is of course that while I want to set the owner, etc. of sda1, the partition table is actually part of its parent, sda. (Of course, there are actually lots of disks, not just sda)
I've managed to get the partition type of all the primary partitions imported into udev database entry each disk. This adds four ENV entries to each disk, one per possible primary partition. They look like this, as shown by udevadmin info --query=all:
E: LOCAL_PARTTYPE_P1=fd
E: LOCAL_PARTTYPE_P2=da
E: LOCAL_PARTTYPE_P3=00
E: LOCAL_PARTTYPE_P4=00
I can then get access to those in the partition device (sda1) by using an IMPORT{parent}. The partition number (1–4) can be found in ATTR{partition}. The problem is getting the type of this partition.
It seems like ENV{LOCAL_PARTTYPE}="$env{LOCAL_PARTTYPE_P$attr{partition}}" should do this, but it doesn't work. If you take off the leading $, the generated name is correct, udev just won't do the indirect lookup.
The only way I've found to do it is this awkward line: IMPORT{program}="/bin/sh -c 'echo LOCAL_PARTTYPE=$$LOCAL_PARTTYPE_P$attr{partition}'" which works because ENV entries are passed as environment variables to programs udev runs, and thus the shell can do the expansion and echo it right back.
I could also duplicate everything for each possible partition number (doable, since I'm only using primary partitions), but that strikes me as even worse:
$ATTR{partition}=="1", $ENV{LOCAL_PARTTYPE_P1}=="da", OWNER="grid", ...
$ATTR{partition}=="2", $ENV{LOCAL_PARTTYPE_P2}=="da", OWNER="grid", ...
⋮
Is there a good way to do this?
IMPORT{program}=", you refer to a method of setting a device property, whereas below that, you present rules for matching a device. Your description does not put it clearly, what is your attempt at each point. – rozcietrzewiacz Nov 10 '11 at 23:57udevadm info --query=all --name=/dev/sda1, I clearly haveID_PART_ENTRY_TYPE=0x83andID_FS_TYPE=ext4. Don't you have those or do they not satisfy your needs? – rozcietrzewiacz Nov 11 '11 at 17:42ID_PART_TABLE_TYPE=dos, notID_PART_ENTRY_TYPE. Debian Squeeze apparently doesn't have a new-enough udev, orblkidrather. I suppose backporting util-linux would be an option. – derobert Nov 11 '11 at 18:09