Sample Header Ad - 728x90

What's the difference between device properties and device attributes in udev?

1 vote
1 answer
2546 views
For udev device entries, what is the technical difference between a "property" and an "attribute"? How are they customarily created (generated?) and used? Which one is the better source of truth? I'm asking in the context of a Raspberrypi Python application that should detect any hot-plugged serial port adapters and display the "relevant" device information (whatever that is) to the user, to enable them recognise their devices. In particular, I use [the pyudev library](https://pyudev.readthedocs.io/en/latest/) to interface with libudev, and my plan is to search for devices from the tty subsystem that are provided by a usb-serial subsystem device. I've looked through the properties and attributes by some test devices I had lying around, to see what values they provide and where. So far, they all have in common that there is a subsystem: tty->(subsystem: usb-serial->)subsystem: usb, device_type: usb_interface->subsystem: usb, device_type: usb_device device ancestor chain (below the USB hub) that relates to the adapter, and the values like vendor, model and serial number are duplicated in various properties and attributes all over the four devices (or sometimes three, [ACM* tty devices](https://rfc1149.net/blog/2013/03/05/what-is-the-difference-between-devttyusbx-and-devttyacmx/) have no usb-serial). So which one should I access? Is there any (written) convention which attributes/properties such devices bring with them, and where can I find it? I've read (or at least skimmed over) [various](https://wiki.archlinux.org/title/udev) [documentation](https://wiki.debian.org/udev) [pages](https://opensource.com/article/18/11/udev) , but they mostly describe how to write your own udev rules, which is not what I'm after. I understood from the udev manual ([](https://linux.die.net/man/7/udev) , [](https://www.freedesktop.org/software/systemd/man/udev.html)) that ATTR is used for values stored in sysfs attributes of the device, and ENV is used for "device properties", but both can be matched and also written. I suppose there are some default rules that inherit values from a parent device to a child device, but that's happening for both properties and attributes alike? [This answer](https://unix.stackexchange.com/a/598900/190272) says "*If both ENV and ATTR contain the same information - you can use any of them, there is no any difference.*", which doesn't leave me any wiser.
Asked by Bergi (115 rep)
Sep 1, 2022, 11:23 PM
Last activity: Sep 2, 2022, 01:55 AM