2 * Copyright (C) 2007-2009 Kay Sievers <kay.sievers@vrfy.org>
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
28 static const struct udev_builtin *builtins[] = {
29 [UDEV_BUILTIN_BLKID] = &udev_builtin_blkid,
30 [UDEV_BUILTIN_FIRMWARE] = &udev_builtin_firmware,
31 [UDEV_BUILTIN_INPUT_ID] = &udev_builtin_input_id,
32 [UDEV_BUILTIN_KMOD] = &udev_builtin_kmod,
33 [UDEV_BUILTIN_PATH_ID] = &udev_builtin_path_id,
34 [UDEV_BUILTIN_PCI_DB] = &udev_builtin_pci_db,
35 [UDEV_BUILTIN_USB_DB] = &udev_builtin_usb_db,
36 [UDEV_BUILTIN_USB_ID] = &udev_builtin_usb_id,
39 int udev_builtin_init(struct udev *udev)
44 for (i = 0; i < ARRAY_SIZE(builtins); i++) {
45 if (builtins[i]->init) {
46 err = builtins[i]->init(udev);
54 void udev_builtin_exit(struct udev *udev)
58 for (i = 0; i < ARRAY_SIZE(builtins); i++)
59 if (builtins[i]->exit)
60 builtins[i]->exit(udev);
63 bool udev_builtin_validate(struct udev *udev)
68 for (i = 0; i < ARRAY_SIZE(builtins); i++)
69 if (builtins[i]->validate)
70 if (builtins[i]->validate(udev))
75 void udev_builtin_list(struct udev *udev)
79 for (i = 0; i < ARRAY_SIZE(builtins); i++)
80 fprintf(stderr, " %-12s %s\n", builtins[i]->name, builtins[i]->help);
83 const char *udev_builtin_name(enum udev_builtin_cmd cmd)
85 return builtins[cmd]->name;
88 bool udev_builtin_run_once(enum udev_builtin_cmd cmd)
90 return builtins[cmd]->run_once;
93 enum udev_builtin_cmd udev_builtin_lookup(const char *command)
95 char name[UTIL_PATH_SIZE];
96 enum udev_builtin_cmd i;
99 util_strscpy(name, sizeof(name), command);
100 pos = strchr(name, ' ');
103 for (i = 0; i < ARRAY_SIZE(builtins); i++)
104 if (strcmp(builtins[i]->name, name) == 0)
106 return UDEV_BUILTIN_MAX;
109 int udev_builtin_run(struct udev_device *dev, enum udev_builtin_cmd cmd, const char *command, bool test)
111 char arg[UTIL_PATH_SIZE];
116 util_strscpy(arg, sizeof(arg), command);
117 udev_build_argv(udev_device_get_udev(dev), arg, &argc, argv);
118 return builtins[cmd]->cmd(dev, argc, argv, test);
121 int udev_builtin_add_property(struct udev_device *dev, bool test, const char *key, const char *val)
123 struct udev_list_entry *entry;
125 entry = udev_device_add_property(dev, key, val);
126 /* store in db, skip private keys */
128 udev_list_entry_set_num(entry, true);
130 info(udev_device_get_udev(dev), "%s=%s\n", key, val);
132 printf("%s=%s\n", key, val);