4

I need to port a bash script which uses deprecated HAL tools like hal-get-property or hal-find-by-capability to udev. HAL states that HAL was merged into udev, but I couldn't find useful informations on how to proper port this script to udev.

Example: If I want a list of all storage hardware (with HAL) I could run

hal-find-by-capability --capability storage

which would give me a list of UDI's (Unique Device Identifier) looking like that:

/org/freedesktop/Hal/devices/storage_model_Virtual_disk
/org/freedesktop/Hal/devices/storage_serial_00000000000000000001
/org/freedesktop/Hal/devices/platform_floppy_0_storage

If I now want to find out if /org/freedesktop/Hal/devices/storage_model_Virtual_disk is removable I could issue the following query

hal-get-property --udi /org/freedesktop/Hal/devices/storage_model_Virtual_disk --key storage.removable

and it would answer true or false.

So my question is:
How can I do those things wihout HAL?
sysfsutils (systool) could work, but it doesn't seem to be a proper replacement.
Does this work with udevadm info?

0x80
  • 176
  • 1
  • 6
  • 1
    is ``udevadm info --query=property`` what you're looking for, possibly in the form of ``udevadm info --query=property --name=$2`` and some other argument to select the device. As I don't have hal, I don't know what form the ``--udi`` argument takes, please tell us that. – Jonas Schäfer Nov 08 '12 at 13:33
  • I edited my original question. Does that answer your question? – 0x80 Nov 08 '12 at 15:38

1 Answers1

1

After your edit, what you're up to do is way clearer. First, you have to find the devices you're about to query. The easiest way to do that, is actually scanning the sysfs. If you want to query a specific device, you just have to point udev to a location in the sysfs where the device is described. So if you're looking for sdb, you could for example go via /block/sdb or pick the correct node from /dev/block or anything like that. If you have your devices path, say $DEVPATH, you can do something like:

udevadm info --attribute-walk --name=$DEVPATH

This will spill out a lot of information, including the removability. Another set of information is shown if you replace attribute-walk with query=property, I was unable to find removability info there though.

If you want to do this for multiple devices, find and xargs will be your friends, which is basically your hal-find-by-capability replacement, as you just need to find the correct folder in sysfs.


Depending on what you're up to do, you might also want to read into udev rules, which allow you to trigger the execution of a script when a device is attached (by matching against the values given by --attribute-walk). You can also easily setup ownership and permissions and such things.

Jonas Schäfer
  • 20,140
  • 5
  • 55
  • 69