14

The man page for udev mentions in several places that certain rules options can be used to invoke 'builtin' commands, which are apparently built in to the udev program itself. However, I haven't been able to find any reference documentation that clearly explains what udev builtins are available; what they do and how they are used.

I have searched the web without much success. Does anyone know if there is a reference anywhere that provides details about these builtin commands?

Time4Tea
  • 2,366

3 Answers3

13

If you just run udevadm test-builtin --help it'll list the builtin commands along with a short description for each of them:

udevadm test-builtin --help
udevadm test-builtin [OPTIONS] COMMAND DEVPATH

Test a built-in command.

-h --help Print this message -V --version Print version of the program

Commands: blkid Filesystem and partition probing btrfs btrfs volume management hwdb Hardware database input_id Input device properties keyboard Keyboard scan code to key mapping kmod Kernel module loader net_id Network device properties net_setup_link Configure network link path_id Compose persistent device path usb_id USB device properties uaccess Manage device node user ACL

Unfortunately, as you've noticed, builtins usage is only explained briefly in the manual.
A practical example can be found in the file 50-udev-default.rules available on your system (under /lib/udev/rules.d/) which contains stuff like:

SUBSYSTEM=="usb", ENV{DEVTYPE}=="usb_device", IMPORT{builtin}="usb_id", IMPORT{builtin}="hwdb --subsystem=usb"
SUBSYSTEM=="input", ENV{ID_INPUT}=="", IMPORT{builtin}="input_id"
ENV{MODALIAS}!="", IMPORT{builtin}="hwdb --subsystem=$env{SUBSYSTEM}"
don_crissti
  • 82,805
  • Thanks. I didn't know this and it is helpful. However, I am trying to diagnose a hardware initialization issue during boot, and I think it would really help if I could understand more details of what these functions are actually doing. – Time4Tea Jan 10 '19 at 19:43
  • 2
    udevadm test-builtin by itself didn't do it for me. I had to add --help to get a list. Edited the answer to add the switch! – Codebling Oct 19 '19 at 15:06
  • awsome.amazing/ – Alex Jan 02 '23 at 18:28
5

Unfortunately, this information is missing on manpages and even knowing how to read them(see below) you will find trouble on trying to find that info.

However, the beauty of the opensource relies on having the power to read the sources. If you take a look at the udev-builtin.c source file inside systemd/udev repository and have basic C language knowledge, you will find the following snippet of code: A structure that maps all existing builtin types.

static const struct udev_builtin *builtins[_UDEV_BUILTIN_MAX] = {
#if HAVE_BLKID
        [UDEV_BUILTIN_BLKID] = &udev_builtin_blkid,
#endif
        [UDEV_BUILTIN_BTRFS] = &udev_builtin_btrfs,
        [UDEV_BUILTIN_HWDB] = &udev_builtin_hwdb,
        [UDEV_BUILTIN_INPUT_ID] = &udev_builtin_input_id,
        [UDEV_BUILTIN_KEYBOARD] = &udev_builtin_keyboard,
#if HAVE_KMOD
        [UDEV_BUILTIN_KMOD] = &udev_builtin_kmod,
#endif
        [UDEV_BUILTIN_NET_ID] = &udev_builtin_net_id,
        [UDEV_BUILTIN_NET_LINK] = &udev_builtin_net_setup_link,
        [UDEV_BUILTIN_PATH_ID] = &udev_builtin_path_id,
        [UDEV_BUILTIN_USB_ID] = &udev_builtin_usb_id,
#if HAVE_ACL
        [UDEV_BUILTIN_UACCESS] = &udev_builtin_uaccess,
#endif
};

This struct holds all built-in types, and they map source files depending on what type it is. Example:

Related:

  • 1
    Thanks for your answer, although it seems a bit bizarre that this information is not in the man pages, but can only be found by reading the sources. – Time4Tea Jan 10 '19 at 18:25
  • 1
    Maybe it's not relevant to systemd team document this, as all those actions are pretty much "automatic" (probe keyboard, handle usb, handle network link...) but yeah, i agree with you that even a simple explanation what those are would be great to avoid the loss of time of crawling through sources online... –  Jan 10 '19 at 18:42
1

Not sure, if you don't find anything better, maybe try to explore which builtins are available directly in the source: look for files starting by "udev-builtin"

https://github.com/systemd/systemd/tree/master/src/udev

Rui F Ribeiro
  • 56,709
  • 26
  • 150
  • 232
xCovelus
  • 203