2 This file is part of systemd.
4 Copyright 2007-2012 Kay Sievers <kay@vrfy.org>
6 systemd is free software; you can redistribute it and/or modify it
7 under the terms of the GNU Lesser General Public License as published by
8 the Free Software Foundation; either version 2.1 of the License, or
9 (at your option) any later version.
11 systemd is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public License
17 along with systemd; If not, see <http://www.gnu.org/licenses/>.
30 static bool initialized;
32 static const struct udev_builtin *builtins[] = {
34 [UDEV_BUILTIN_BLKID] = &udev_builtin_blkid,
36 [UDEV_BUILTIN_BTRFS] = &udev_builtin_btrfs,
38 [UDEV_BUILTIN_FIRMWARE] = &udev_builtin_firmware,
40 [UDEV_BUILTIN_HWDB] = &udev_builtin_hwdb,
41 [UDEV_BUILTIN_INPUT_ID] = &udev_builtin_input_id,
42 [UDEV_BUILTIN_KEYBOARD] = &udev_builtin_keyboard,
44 [UDEV_BUILTIN_KMOD] = &udev_builtin_kmod,
46 [UDEV_BUILTIN_NET_ID] = &udev_builtin_net_id,
47 [UDEV_BUILTIN_PATH_ID] = &udev_builtin_path_id,
48 [UDEV_BUILTIN_USB_ID] = &udev_builtin_usb_id,
50 [UDEV_BUILTIN_UACCESS] = &udev_builtin_uaccess,
54 void udev_builtin_init(struct udev *udev)
61 for (i = 0; i < ELEMENTSOF(builtins); i++)
62 if (builtins[i]->init)
63 builtins[i]->init(udev);
68 void udev_builtin_exit(struct udev *udev)
75 for (i = 0; i < ELEMENTSOF(builtins); i++)
76 if (builtins[i]->exit)
77 builtins[i]->exit(udev);
82 bool udev_builtin_validate(struct udev *udev)
86 for (i = 0; i < ELEMENTSOF(builtins); i++)
87 if (builtins[i]->validate && builtins[i]->validate(udev))
92 void udev_builtin_list(struct udev *udev)
96 for (i = 0; i < ELEMENTSOF(builtins); i++)
97 fprintf(stderr, " %-12s %s\n", builtins[i]->name, builtins[i]->help);
100 const char *udev_builtin_name(enum udev_builtin_cmd cmd)
102 return builtins[cmd]->name;
105 bool udev_builtin_run_once(enum udev_builtin_cmd cmd)
107 return builtins[cmd]->run_once;
110 enum udev_builtin_cmd udev_builtin_lookup(const char *command)
112 char name[UTIL_PATH_SIZE];
113 enum udev_builtin_cmd i;
116 strscpy(name, sizeof(name), command);
117 pos = strchr(name, ' ');
120 for (i = 0; i < ELEMENTSOF(builtins); i++)
121 if (streq(builtins[i]->name, name))
123 return UDEV_BUILTIN_MAX;
126 int udev_builtin_run(struct udev_device *dev, enum udev_builtin_cmd cmd, const char *command, bool test)
128 char arg[UTIL_PATH_SIZE];
132 /* we need '0' here to reset the internal state */
134 strscpy(arg, sizeof(arg), command);
135 udev_build_argv(udev_device_get_udev(dev), arg, &argc, argv);
136 return builtins[cmd]->cmd(dev, argc, argv, test);
139 int udev_builtin_add_property(struct udev_device *dev, bool test, const char *key, const char *val)
141 struct udev_list_entry *entry;
143 entry = udev_device_add_property(dev, key, val);
144 /* store in db, skip private keys */
146 udev_list_entry_set_num(entry, true);
149 printf("%s=%s\n", key, val);