udev-builtin-hwdb.c revision 6824690f140f45064157d220a24b9afbeb1d093f
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering This file is part of systemd.
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering Copyright 2012 Kay Sievers <kay@vrfy.org>
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering systemd is free software; you can redistribute it and/or modify it
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering under the terms of the GNU Lesser General Public License as published by
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering the Free Software Foundation; either version 2.1 of the License, or
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering (at your option) any later version.
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering systemd is distributed in the hope that it will be useful, but
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering WITHOUT ANY WARRANTY; without even the implied warranty of
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering Lesser General Public License for more details.
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering You should have received a copy of the GNU Lesser General Public License
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering along with systemd; If not, see <http://www.gnu.org/licenses/>.
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poetteringint udev_builtin_hwdb_lookup(struct udev_device *dev,
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering const char *modalias, const char *filter, bool test) {
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering udev_list_entry_foreach(entry, udev_hwdb_get_properties_list_entry(hwdb, modalias, 0)) {
9d12709626bccc0cae677a7035f62efe6aabb4abLennart Poettering if (filter && fnmatch(filter, udev_list_entry_get_name(entry), FNM_NOESCAPE) != 0)
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poetteringstatic const char *modalias_usb(struct udev_device *dev, char *s, size_t size) {
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering const char *v, *p;
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering v = udev_device_get_sysattr_value(dev, "idVendor");
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering p = udev_device_get_sysattr_value(dev, "idProduct");
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering snprintf(s, size, "usb:v%04Xp%04X*", vn, pn);
a1da85830bfaa77b9eb9c54693e5573559c97e50Tom Gundersenstatic int udev_builtin_hwdb_search(struct udev_device *dev, struct udev_device *srcdev,
a1da85830bfaa77b9eb9c54693e5573559c97e50Tom Gundersen const char *subsystem, const char *filter, bool test) {
a1da85830bfaa77b9eb9c54693e5573559c97e50Tom Gundersen for (d = srcdev; d; d = udev_device_get_parent(d)) {
e56056e93d33619a3acf13e483900b4f8938228fThomas Hindoe Paaboel Andersen /* look only at devices of a specific subsystem */
e56056e93d33619a3acf13e483900b4f8938228fThomas Hindoe Paaboel Andersen if (subsystem && !streq(dsubsys, subsystem))
a1da85830bfaa77b9eb9c54693e5573559c97e50Tom Gundersen /* the usb_device does not have a modalias, compose one */
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering modalias = modalias_usb(d, s, sizeof(s));
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering modalias = udev_device_get_property_value(d, "MODALIAS");
a1da85830bfaa77b9eb9c54693e5573559c97e50Tom Gundersen n = udev_builtin_hwdb_lookup(dev, modalias, filter, test);
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poetteringstatic int builtin_hwdb(struct udev_device *dev, int argc, char *argv[], bool test) {
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering { "filter", required_argument, NULL, 'f' },
89f7c8465cd1ab37347dd0c15920bce31e8225dfLennart Poettering { "device", required_argument, NULL, 'd' },
a1da85830bfaa77b9eb9c54693e5573559c97e50Tom Gundersen { "subsystem", required_argument, NULL, 's' },
aa1936ea1a89c2bb968ba33e3274898a4eeae771Lennart Poettering option = getopt_long(argc, argv, "s", options, NULL);
5b30bef856e89a571df57b7b953e9a1409d9acedLennart Poettering /* query a specific key given as argument */
9d12709626bccc0cae677a7035f62efe6aabb4abLennart Poettering if (udev_builtin_hwdb_lookup(dev, argv[optind], filter, test) > 0)
9d12709626bccc0cae677a7035f62efe6aabb4abLennart Poettering /* read data from another device than the device we will store the data */
aa1936ea1a89c2bb968ba33e3274898a4eeae771Lennart Poettering srcdev = udev_device_new_from_device_id(udev_device_get_udev(dev), device);
aa1936ea1a89c2bb968ba33e3274898a4eeae771Lennart Poettering if (udev_builtin_hwdb_search(dev, srcdev, subsystem, filter, test) < 0)
aa1936ea1a89c2bb968ba33e3274898a4eeae771Lennart Poettering/* called at udev startup and reload */
aa1936ea1a89c2bb968ba33e3274898a4eeae771Lennart Poetteringstatic int builtin_hwdb_init(struct udev *udev)
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering/* called on udev shutdown and reload request */
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poetteringstatic void builtin_hwdb_exit(struct udev *udev)
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering/* called every couple of seconds during event activity; 'true' if config has changed */
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poetteringstatic bool builtin_hwdb_validate(struct udev *udev)