2 This file is part of systemd.
4 Copyright 2012 Kay Sievers <kay.sievers@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 struct udev_hwdb *hwdb;
32 static int builtin_hwdb(struct udev_device *dev, int argc, char *argv[], bool test) {
33 static const struct option options[] = {
34 { "subsystem", required_argument, NULL, 's' },
37 const char *subsys = NULL;
38 struct udev_device *d;
40 char str[UTIL_NAME_SIZE];
41 struct udev_list_entry *entry;
49 option = getopt_long(argc, argv, "s", options, NULL);
60 /* search the first parent device with a modalias */
61 for (d = dev; d; d = udev_device_get_parent(d)) {
62 const char *dsubsys = udev_device_get_subsystem(d);
64 /* look only at devices of a specific subsystem */
65 if (subsys && dsubsys && !streq(dsubsys, subsys))
68 modalias = udev_device_get_property_value(d, "MODALIAS");
72 /* the usb_device does not have modalias, compose one */
73 if (dsubsys && streq(dsubsys, "usb")) {
77 v = udev_device_get_sysattr_value(d, "idVendor");
80 p = udev_device_get_sysattr_value(d, "idProduct");
83 vn = strtol(v, NULL, 16);
86 pn = strtol(p, NULL, 16);
89 snprintf(str, sizeof(str), "usb:v%04Xp%04X*", vn, pn);
97 udev_list_entry_foreach(entry, udev_hwdb_get_properties_list_entry(hwdb, modalias, 0))
98 if (udev_builtin_add_property(dev, test,
99 udev_list_entry_get_name(entry),
100 udev_list_entry_get_value(entry)) < 0)
105 /* called at udev startup and reload */
106 static int builtin_hwdb_init(struct udev *udev)
110 hwdb = udev_hwdb_new(udev);
116 /* called on udev shutdown and reload request */
117 static void builtin_hwdb_exit(struct udev *udev)
119 hwdb = udev_hwdb_unref(hwdb);
122 /* called every couple of seconds during event activity; 'true' if config has changed */
123 static bool builtin_hwdb_validate(struct udev *udev)
125 return udev_hwdb_validate(hwdb);
128 const struct udev_builtin udev_builtin_hwdb = {
131 .init = builtin_hwdb_init,
132 .exit = builtin_hwdb_exit,
133 .validate = builtin_hwdb_validate,
134 .help = "hardware database",