Replacement for hal-get-property and hal-find-by-capacity in udev?

I need to migrate a bash script that uses legacy HAL tools like hal-get-property or hal-find-by-capability for udev. HAL claims that HAL was merged into udev, but I could not find useful information on how to properly port this script to udev.

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

hal-find-by-capability --capability storage

which will give me a list of UDI (unique device identifier) ​​that looks like this:

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

If now I want to find out if /org/freedesktop/Hal/devices/storage_model_Virtual_disk removable, I can run the following query

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

and it will answer true or false .

So my question is:
How can I do these things without hal?
sysfsutils ( systool ) may work, but does not seem to be a proper replacement.
Does this work with udevadm info ?

+4
source share
1 answer

After you edit, what you need to do is more understandable. First, you need to find the devices you are about to request. The easiest way to do this is to actually scan sysfs. If you want to request a specific device, you just need to tell udev the place in sysfs where the device is described. Therefore, if you are looking for sdb , you can, for example, go through /block/sdb or select the correct node from /dev/block or something like that. If you have a path to your devices, say $DEVPATH , you can do something like:

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

This will result in the release of a large amount of information, including deletion. Another set of information is displayed if you replace attribute-walk with query=property , however I could not find the deletion information.

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


Depending on what you are going to do, you can also read the udev rules , which allow you to run a script when the device is connected (by matching with the values ​​specified by --attribute-walk ). You can also easily set up ownership and permissions, etc.

0
source

Source: https://habr.com/ru/post/1444784/


All Articles