1 /* SPDX-License-Identifier: GPL-2.0-or-later */ 2 #pragma once 3 4 #include <stdbool.h> 5 6 #include "sd-device.h" 7 #include "sd-netlink.h" 8 9 typedef enum UdevBuiltinCommand { 10 #if HAVE_BLKID 11 UDEV_BUILTIN_BLKID, 12 #endif 13 UDEV_BUILTIN_BTRFS, 14 UDEV_BUILTIN_HWDB, 15 UDEV_BUILTIN_INPUT_ID, 16 UDEV_BUILTIN_KEYBOARD, 17 #if HAVE_KMOD 18 UDEV_BUILTIN_KMOD, 19 #endif 20 UDEV_BUILTIN_NET_ID, 21 UDEV_BUILTIN_NET_LINK, 22 UDEV_BUILTIN_PATH_ID, 23 UDEV_BUILTIN_USB_ID, 24 #if HAVE_ACL 25 UDEV_BUILTIN_UACCESS, 26 #endif 27 _UDEV_BUILTIN_MAX, 28 _UDEV_BUILTIN_INVALID = -EINVAL, 29 } UdevBuiltinCommand; 30 31 typedef struct UdevBuiltin { 32 const char *name; 33 int (*cmd)(sd_device *dev, sd_netlink **rtnl, int argc, char *argv[], bool test); 34 const char *help; 35 int (*init)(void); 36 void (*exit)(void); 37 bool (*validate)(void); 38 bool run_once; 39 } UdevBuiltin; 40 41 #define UDEV_BUILTIN_CMD_TO_PTR(u) \ 42 ({ \ 43 UdevBuiltinCommand _u = (u); \ 44 _u < 0 ? NULL : (void*)(intptr_t) (_u + 1); \ 45 }) 46 47 #define PTR_TO_UDEV_BUILTIN_CMD(p) \ 48 ({ \ 49 void *_p = (p); \ 50 _p && (intptr_t)(_p) <= _UDEV_BUILTIN_MAX ? \ 51 (UdevBuiltinCommand)((intptr_t)_p - 1) : _UDEV_BUILTIN_INVALID; \ 52 }) 53 54 #if HAVE_BLKID 55 extern const UdevBuiltin udev_builtin_blkid; 56 #endif 57 extern const UdevBuiltin udev_builtin_btrfs; 58 extern const UdevBuiltin udev_builtin_hwdb; 59 extern const UdevBuiltin udev_builtin_input_id; 60 extern const UdevBuiltin udev_builtin_keyboard; 61 #if HAVE_KMOD 62 extern const UdevBuiltin udev_builtin_kmod; 63 #endif 64 extern const UdevBuiltin udev_builtin_net_id; 65 extern const UdevBuiltin udev_builtin_net_setup_link; 66 extern const UdevBuiltin udev_builtin_path_id; 67 extern const UdevBuiltin udev_builtin_usb_id; 68 #if HAVE_ACL 69 extern const UdevBuiltin udev_builtin_uaccess; 70 #endif 71 72 void udev_builtin_init(void); 73 void udev_builtin_exit(void); 74 UdevBuiltinCommand udev_builtin_lookup(const char *command); 75 const char *udev_builtin_name(UdevBuiltinCommand cmd); 76 bool udev_builtin_run_once(UdevBuiltinCommand cmd); 77 int udev_builtin_run(sd_device *dev, sd_netlink **rtnl, UdevBuiltinCommand cmd, const char *command, bool test); 78 void udev_builtin_list(void); 79 bool udev_builtin_validate(void); 80 int udev_builtin_add_property(sd_device *dev, bool test, const char *key, const char *val); 81 int udev_builtin_hwdb_lookup(sd_device *dev, const char *prefix, const char *modalias, 82 const char *filter, bool test); 83