2 * libudev - interface to udev device information
4 * Copyright (C) 2008-2010 Kay Sievers <kay.sievers@vrfy.org>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
24 #include <sys/ioctl.h>
25 #include <sys/socket.h>
26 #include <linux/sockios.h>
29 #include "libudev-private.h"
32 * SECTION:libudev-device
33 * @short_description: kernel sys devices
35 * Representation of kernel sys devices. Devices are uniquely identified
36 * by their syspath, every device has exactly one path in the kernel sys
37 * filesystem. Devices usually belong to a kernel subsystem, and and have
38 * a unique name inside that subsystem.
44 * Opaque object representing one kernel sys device.
48 struct udev_device *parent_device;
64 size_t monitor_buf_len;
65 struct udev_list_node devlinks_list;
66 struct udev_list_node properties_list;
67 struct udev_list_node sysattr_value_list;
68 struct udev_list_node sysattr_list;
69 struct udev_list_node tags_list;
70 unsigned long long int seqnum;
71 unsigned long long int usec_initialized;
82 bool devlinks_uptodate;
90 bool sysattr_list_read;
94 struct udev_list_entry *udev_device_add_property(struct udev_device *udev_device, const char *key, const char *value)
96 udev_device->envp_uptodate = false;
98 struct udev_list_entry *list_entry;
100 list_entry = udev_device_get_properties_list_entry(udev_device);
101 list_entry = udev_list_entry_get_by_name(list_entry, key);
102 if (list_entry != NULL)
103 udev_list_entry_delete(list_entry);
106 return udev_list_entry_add(udev_device->udev, &udev_device->properties_list, key, value, 1, 0);
109 static struct udev_list_entry *udev_device_add_property_from_string(struct udev_device *udev_device, const char *property)
111 char name[UTIL_LINE_SIZE];
114 util_strscpy(name, sizeof(name), property);
115 val = strchr(name, '=');
122 return udev_device_add_property(udev_device, name, val);
126 * parse property string, and if needed, update internal values accordingly
128 * udev_device_add_property_from_string_parse_finish() needs to be
129 * called after adding properties, and its return value checked
131 * udev_device_set_info_loaded() needs to be set, to avoid trying
132 * to use a device without a DEVPATH set
134 void udev_device_add_property_from_string_parse(struct udev_device *udev_device, const char *property)
136 if (strncmp(property, "DEVPATH=", 8) == 0) {
137 char path[UTIL_PATH_SIZE];
139 util_strscpyl(path, sizeof(path), udev_get_sys_path(udev_device->udev), &property[8], NULL);
140 udev_device_set_syspath(udev_device, path);
141 } else if (strncmp(property, "SUBSYSTEM=", 10) == 0) {
142 udev_device_set_subsystem(udev_device, &property[10]);
143 } else if (strncmp(property, "DEVTYPE=", 8) == 0) {
144 udev_device_set_devtype(udev_device, &property[8]);
145 } else if (strncmp(property, "DEVNAME=", 8) == 0) {
146 if (property[8] == '/')
147 udev_device_set_devnode(udev_device, &property[8]);
149 udev_device_set_knodename(udev_device, &property[8]);
150 } else if (strncmp(property, "DEVLINKS=", 9) == 0) {
151 char devlinks[UTIL_PATH_SIZE];
155 util_strscpy(devlinks, sizeof(devlinks), &property[9]);
157 next = strchr(slink, ' ');
158 while (next != NULL) {
160 udev_device_add_devlink(udev_device, slink, 0);
162 next = strchr(slink, ' ');
164 if (slink[0] != '\0')
165 udev_device_add_devlink(udev_device, slink, 0);
166 } else if (strncmp(property, "TAGS=", 5) == 0) {
167 char tags[UTIL_PATH_SIZE];
170 util_strscpy(tags, sizeof(tags), &property[5]);
171 next = strchr(tags, ':');
174 while (next[0] != '\0') {
178 next = strchr(tag, ':');
183 udev_device_add_tag(udev_device, tag);
186 } else if (strncmp(property, "DRIVER=", 7) == 0) {
187 udev_device_set_driver(udev_device, &property[7]);
188 } else if (strncmp(property, "ACTION=", 7) == 0) {
189 udev_device_set_action(udev_device, &property[7]);
190 } else if (strncmp(property, "MAJOR=", 6) == 0) {
191 udev_device->maj = strtoull(&property[6], NULL, 10);
192 } else if (strncmp(property, "MINOR=", 6) == 0) {
193 udev_device->min = strtoull(&property[6], NULL, 10);
194 } else if (strncmp(property, "DEVPATH_OLD=", 12) == 0) {
195 udev_device_set_devpath_old(udev_device, &property[12]);
196 } else if (strncmp(property, "SEQNUM=", 7) == 0) {
197 udev_device_set_seqnum(udev_device, strtoull(&property[7], NULL, 10));
198 } else if (strncmp(property, "TIMEOUT=", 8) == 0) {
199 udev_device_set_timeout(udev_device, strtoull(&property[8], NULL, 10));
200 } else if (strncmp(property, "IFINDEX=", 8) == 0) {
201 udev_device_set_ifindex(udev_device, strtoull(&property[8], NULL, 10));
203 udev_device_add_property_from_string(udev_device, property);
207 int udev_device_add_property_from_string_parse_finish(struct udev_device *udev_device)
209 if (udev_device->maj > 0)
210 udev_device_set_devnum(udev_device, makedev(udev_device->maj, udev_device->min));
211 udev_device->maj = 0;
212 udev_device->min = 0;
214 if (udev_device->devpath == NULL || udev_device->subsystem == NULL)
220 * udev_device_get_property_value:
221 * @udev_device: udev device
222 * @key: property name
224 * Returns: the value of a device property, or #NULL if there is no such property.
226 const char *udev_device_get_property_value(struct udev_device *udev_device, const char *key)
228 struct udev_list_entry *list_entry;
230 if (udev_device == NULL)
235 list_entry = udev_device_get_properties_list_entry(udev_device);
236 list_entry = udev_list_entry_get_by_name(list_entry, key);
237 return udev_list_entry_get_value(list_entry);
240 int udev_device_read_db(struct udev_device *udev_device, const char *dbfile)
242 char filename[UTIL_PATH_SIZE];
243 char line[UTIL_LINE_SIZE];
246 /* providing a database file will always force-load it */
247 if (dbfile == NULL) {
250 if (udev_device->db_loaded)
252 udev_device->db_loaded = true;
254 id = udev_device_get_id_filename(udev_device);
257 util_strscpyl(filename, sizeof(filename), udev_get_run_path(udev_device->udev), "/data/", id, NULL);
261 f = fopen(dbfile, "re");
263 info(udev_device->udev, "no db file to read %s: %m\n", dbfile);
266 udev_device->is_initialized = true;
268 while (fgets(line, sizeof(line), f)) {
271 struct udev_list_entry *entry;
280 util_strscpyl(filename, sizeof(filename), udev_get_dev_path(udev_device->udev), "/", val, NULL);
281 udev_device_set_devnode(udev_device, filename);
284 util_strscpyl(filename, sizeof(filename), udev_get_dev_path(udev_device->udev), "/", val, NULL);
285 udev_device_add_devlink(udev_device, filename, 0);
288 udev_device_set_devlink_priority(udev_device, atoi(val));
291 entry = udev_device_add_property_from_string(udev_device, val);
292 udev_list_entry_set_flags(entry, 1);
295 udev_device_add_tag(udev_device, val);
298 udev_device_set_watch_handle(udev_device, atoi(val));
301 udev_device_set_usec_initialized(udev_device, strtoull(val, NULL, 10));
307 info(udev_device->udev, "device %p filled with db file data\n", udev_device);
311 int udev_device_read_uevent_file(struct udev_device *udev_device)
313 char filename[UTIL_PATH_SIZE];
315 char line[UTIL_LINE_SIZE];
319 if (udev_device->uevent_loaded)
322 util_strscpyl(filename, sizeof(filename), udev_device->syspath, "/uevent", NULL);
323 f = fopen(filename, "re");
326 udev_device->uevent_loaded = true;
328 while (fgets(line, sizeof(line), f)) {
331 pos = strchr(line, '\n');
336 if (strncmp(line, "DEVTYPE=", 8) == 0)
337 udev_device_set_devtype(udev_device, &line[8]);
338 else if (strncmp(line, "MAJOR=", 6) == 0)
339 maj = strtoull(&line[6], NULL, 10);
340 else if (strncmp(line, "MINOR=", 6) == 0)
341 min = strtoull(&line[6], NULL, 10);
342 else if (strncmp(line, "IFINDEX=", 8) == 0)
343 udev_device_set_ifindex(udev_device, strtoull(&line[8], NULL, 10));
344 else if (strncmp(line, "DEVNAME=", 8) == 0)
345 udev_device_set_knodename(udev_device, &line[8]);
347 udev_device_add_property_from_string(udev_device, line);
350 udev_device->devnum = makedev(maj, min);
355 void udev_device_set_info_loaded(struct udev_device *device)
357 device->info_loaded = true;
360 struct udev_device *udev_device_new(struct udev *udev)
362 struct udev_device *udev_device;
363 struct udev_list_entry *list_entry;
368 udev_device = calloc(1, sizeof(struct udev_device));
369 if (udev_device == NULL)
371 udev_device->refcount = 1;
372 udev_device->udev = udev;
373 udev_list_init(&udev_device->devlinks_list);
374 udev_list_init(&udev_device->properties_list);
375 udev_list_init(&udev_device->sysattr_value_list);
376 udev_list_init(&udev_device->sysattr_list);
377 udev_list_init(&udev_device->tags_list);
378 udev_device->timeout = -1;
379 udev_device->watch_handle = -1;
380 /* copy global properties */
381 udev_list_entry_foreach(list_entry, udev_get_properties_list_entry(udev))
382 udev_device_add_property(udev_device,
383 udev_list_entry_get_name(list_entry),
384 udev_list_entry_get_value(list_entry));
385 dbg(udev_device->udev, "udev_device: %p created\n", udev_device);
390 * udev_device_new_from_syspath:
391 * @udev: udev library context
392 * @syspath: sys device path including sys directory
394 * Create new udev device, and fill in information from the sys
395 * device and the udev database entry. The syspath is the absolute
396 * path to the device, including the sys mount point.
398 * The initial refcount is 1, and needs to be decremented to
399 * release the resources of the udev device.
401 * Returns: a new udev device, or #NULL, if it does not exist
403 struct udev_device *udev_device_new_from_syspath(struct udev *udev, const char *syspath)
407 char path[UTIL_PATH_SIZE];
410 struct udev_device *udev_device;
417 /* path starts in sys */
418 len = strlen(udev_get_sys_path(udev));
419 if (strncmp(syspath, udev_get_sys_path(udev), len) != 0) {
420 info(udev, "not in sys :%s\n", syspath);
424 /* path is not a root directory */
425 subdir = &syspath[len+1];
426 pos = strrchr(subdir, '/');
427 if (pos == NULL || pos[1] == '\0' || pos < &subdir[2]) {
428 dbg(udev, "not a subdir :%s\n", syspath);
432 /* resolve possible symlink to real path */
433 util_strscpy(path, sizeof(path), syspath);
434 util_resolve_sys_link(udev, path, sizeof(path));
436 if (strncmp(&path[len], "/devices/", 9) == 0) {
437 char file[UTIL_PATH_SIZE];
439 /* all "devices" require a "uevent" file */
440 util_strscpyl(file, sizeof(file), path, "/uevent", NULL);
441 if (stat(file, &statbuf) != 0) {
442 dbg(udev, "not a device: %s\n", syspath);
446 /* everything else just needs to be a directory */
447 if (stat(path, &statbuf) != 0 || !S_ISDIR(statbuf.st_mode)) {
448 dbg(udev, "directory not found: %s\n", syspath);
453 udev_device = udev_device_new(udev);
454 if (udev_device == NULL)
457 udev_device_set_syspath(udev_device, path);
458 info(udev, "device %p has devpath '%s'\n", udev_device, udev_device_get_devpath(udev_device));
464 * udev_device_new_from_devnum:
465 * @udev: udev library context
466 * @type: char or block device
467 * @devnum: device major/minor number
469 * Create new udev device, and fill in information from the sys
470 * device and the udev database entry. The device is looked-up
471 * by its major/minor number and type. Character and block device
472 * numbers are not unique across the two types.
474 * The initial refcount is 1, and needs to be decremented to
475 * release the resources of the udev device.
477 * Returns: a new udev device, or #NULL, if it does not exist
479 struct udev_device *udev_device_new_from_devnum(struct udev *udev, char type, dev_t devnum)
481 char path[UTIL_PATH_SIZE];
482 const char *type_str;
486 else if (type == 'c')
491 /* use /sys/dev/{block,char}/<maj>:<min> link */
492 snprintf(path, sizeof(path), "%s/dev/%s/%u:%u",
493 udev_get_sys_path(udev), type_str, major(devnum), minor(devnum));
494 return udev_device_new_from_syspath(udev, path);
497 struct udev_device *udev_device_new_from_id_filename(struct udev *udev, char *id)
501 char subsys[UTIL_PATH_SIZE];
507 if (sscanf(id, "%c%i:%i", &type, &maj, &min) != 3)
509 return udev_device_new_from_devnum(udev, type, makedev(maj, min));
513 struct udev_device *dev;
516 ifindex = strtoul(&id[1], NULL, 10);
520 sk = socket(PF_INET, SOCK_DGRAM, 0);
523 memset(&ifr, 0x00, sizeof(struct ifreq));
524 ifr.ifr_ifindex = ifindex;
525 if (ioctl(sk, SIOCGIFNAME, &ifr) != 0) {
531 dev = udev_device_new_from_subsystem_sysname(udev, "net", ifr.ifr_name);
534 if (udev_device_get_ifindex(dev) == ifindex)
536 udev_device_unref(dev);
540 util_strscpy(subsys, sizeof(subsys), &id[1]);
541 sysname = strchr(subsys, ':');
545 sysname = &sysname[1];
546 return udev_device_new_from_subsystem_sysname(udev, subsys, sysname);
553 * udev_device_new_from_subsystem_sysname:
554 * @udev: udev library context
555 * @subsystem: the subsystem of the device
556 * @sysname: the name of the device
558 * Create new udev device, and fill in information from the sys device
559 * and the udev database entry. The device is looked up by the subsystem
560 * and name string of the device, like "mem" / "zero", or "block" / "sda".
562 * The initial refcount is 1, and needs to be decremented to
563 * release the resources of the udev device.
565 * Returns: a new udev device, or #NULL, if it does not exist
567 struct udev_device *udev_device_new_from_subsystem_sysname(struct udev *udev, const char *subsystem, const char *sysname)
569 char path_full[UTIL_PATH_SIZE];
575 l = util_strpcpyl(&path, sizeof(path_full), udev_get_sys_path(udev), NULL);
577 if (strcmp(subsystem, "subsystem") == 0) {
578 util_strscpyl(path, l, "/subsystem/", sysname, NULL);
579 if (stat(path_full, &statbuf) == 0)
582 util_strscpyl(path, l, "/bus/", sysname, NULL);
583 if (stat(path_full, &statbuf) == 0)
586 util_strscpyl(path, l, "/class/", sysname, NULL);
587 if (stat(path_full, &statbuf) == 0)
592 if (strcmp(subsystem, "module") == 0) {
593 util_strscpyl(path, l, "/module/", sysname, NULL);
594 if (stat(path_full, &statbuf) == 0)
599 if (strcmp(subsystem, "drivers") == 0) {
600 char subsys[UTIL_NAME_SIZE];
603 util_strscpy(subsys, sizeof(subsys), sysname);
604 driver = strchr(subsys, ':');
605 if (driver != NULL) {
609 util_strscpyl(path, l, "/subsystem/", subsys, "/drivers/", driver, NULL);
610 if (stat(path_full, &statbuf) == 0)
613 util_strscpyl(path, l, "/bus/", subsys, "/drivers/", driver, NULL);
614 if (stat(path_full, &statbuf) == 0)
620 util_strscpyl(path, l, "/subsystem/", subsystem, "/devices/", sysname, NULL);
621 if (stat(path_full, &statbuf) == 0)
624 util_strscpyl(path, l, "/bus/", subsystem, "/devices/", sysname, NULL);
625 if (stat(path_full, &statbuf) == 0)
628 util_strscpyl(path, l, "/class/", subsystem, "/", sysname, NULL);
629 if (stat(path_full, &statbuf) == 0)
634 return udev_device_new_from_syspath(udev, path_full);
638 * udev_device_new_from_environment
639 * @udev: udev library context
641 * Create new udev device, and fill in information from the
642 * current process environment. This only works reliable if
643 * the process is called from a udev rule. It is usually used
644 * for tools executed from IMPORT= rules.
646 * The initial refcount is 1, and needs to be decremented to
647 * release the resources of the udev device.
649 * Returns: a new udev device, or #NULL, if it does not exist
651 struct udev_device *udev_device_new_from_environment(struct udev *udev)
654 struct udev_device *udev_device;
656 udev_device = udev_device_new(udev);
657 if (udev_device == NULL)
659 udev_device_set_info_loaded(udev_device);
661 for (i = 0; environ[i] != NULL; i++)
662 udev_device_add_property_from_string_parse(udev_device, environ[i]);
664 if (udev_device_add_property_from_string_parse_finish(udev_device) < 0) {
665 info(udev, "missing values, invalid device\n");
666 udev_device_unref(udev_device);
673 static struct udev_device *device_new_from_parent(struct udev_device *udev_device)
675 struct udev_device *udev_device_parent = NULL;
676 char path[UTIL_PATH_SIZE];
679 util_strscpy(path, sizeof(path), udev_device->syspath);
680 subdir = &path[strlen(udev_get_sys_path(udev_device->udev))+1];
684 pos = strrchr(subdir, '/');
685 if (pos == NULL || pos < &subdir[2])
688 udev_device_parent = udev_device_new_from_syspath(udev_device->udev, path);
689 if (udev_device_parent != NULL)
690 return udev_device_parent;
696 * udev_device_get_parent:
697 * @udev_device: the device to start searching from
699 * Find the next parent device, and fill in information from the sys
700 * device and the udev database entry.
702 * The returned the device is not referenced. It is attached to the
703 * child device, and will be cleaned up when the child device
706 * It is not necessarily just the upper level directory, empty or not
707 * recognized sys directories are ignored.
709 * It can be called as many times as needed, without caring about
712 * Returns: a new udev device, or #NULL, if it no parent exist.
714 struct udev_device *udev_device_get_parent(struct udev_device *udev_device)
716 if (udev_device == NULL)
718 if (!udev_device->parent_set) {
719 udev_device->parent_set = true;
720 udev_device->parent_device = device_new_from_parent(udev_device);
722 if (udev_device->parent_device != NULL)
723 dbg(udev_device->udev, "returning existing parent %p\n", udev_device->parent_device);
724 return udev_device->parent_device;
728 * udev_device_get_parent_with_subsystem_devtype:
729 * @udev_device: udev device to start searching from
730 * @subsystem: the subsystem of the device
731 * @devtype: the type (DEVTYPE) of the device
733 * Find the next parent device, with a matching subsystem and devtype
734 * value, and fill in information from the sys device and the udev
737 * If devtype is #NULL, only subsystem is checked, and any devtype will
740 * The returned the device is not referenced. It is attached to the
741 * child device, and will be cleaned up when the child device
744 * It can be called as many times as needed, without caring about
747 * Returns: a new udev device, or #NULL if no matching parent exists.
749 struct udev_device *udev_device_get_parent_with_subsystem_devtype(struct udev_device *udev_device, const char *subsystem, const char *devtype)
751 struct udev_device *parent;
753 if (subsystem == NULL)
756 parent = udev_device_get_parent(udev_device);
757 while (parent != NULL) {
758 const char *parent_subsystem;
759 const char *parent_devtype;
761 parent_subsystem = udev_device_get_subsystem(parent);
762 if (parent_subsystem != NULL && strcmp(parent_subsystem, subsystem) == 0) {
765 parent_devtype = udev_device_get_devtype(parent);
766 if (parent_devtype != NULL && strcmp(parent_devtype, devtype) == 0)
769 parent = udev_device_get_parent(parent);
775 * udev_device_get_udev:
776 * @udev_device: udev device
778 * Retrieve the udev library context the device was created with.
780 * Returns: the udev library context
782 struct udev *udev_device_get_udev(struct udev_device *udev_device)
784 if (udev_device == NULL)
786 return udev_device->udev;
791 * @udev_device: udev device
793 * Take a reference of a udev device.
795 * Returns: the passed udev device
797 struct udev_device *udev_device_ref(struct udev_device *udev_device)
799 if (udev_device == NULL)
801 udev_device->refcount++;
807 * @udev_device: udev device
809 * Drop a reference of a udev device. If the refcount reaches zero,
810 * the resources of the device will be released.
813 void udev_device_unref(struct udev_device *udev_device)
815 if (udev_device == NULL)
817 udev_device->refcount--;
818 if (udev_device->refcount > 0)
820 if (udev_device->parent_device != NULL)
821 udev_device_unref(udev_device->parent_device);
822 free(udev_device->syspath);
823 free(udev_device->sysname);
824 free(udev_device->devnode);
825 free(udev_device->subsystem);
826 free(udev_device->devtype);
827 udev_list_cleanup_entries(udev_device->udev, &udev_device->devlinks_list);
828 udev_list_cleanup_entries(udev_device->udev, &udev_device->properties_list);
829 udev_list_cleanup_entries(udev_device->udev, &udev_device->sysattr_value_list);
830 udev_list_cleanup_entries(udev_device->udev, &udev_device->sysattr_list);
831 udev_list_cleanup_entries(udev_device->udev, &udev_device->tags_list);
832 free(udev_device->action);
833 free(udev_device->driver);
834 free(udev_device->devpath_old);
835 free(udev_device->sysname_old);
836 free(udev_device->knodename);
837 free(udev_device->id_filename);
838 free(udev_device->envp);
839 free(udev_device->monitor_buf);
840 dbg(udev_device->udev, "udev_device: %p released\n", udev_device);
845 * udev_device_get_devpath:
846 * @udev_device: udev device
848 * Retrieve the kernel devpath value of the udev device. The path
849 * does not contain the sys mount point, and starts with a '/'.
851 * Returns: the devpath of the udev device
853 const char *udev_device_get_devpath(struct udev_device *udev_device)
855 if (udev_device == NULL)
857 return udev_device->devpath;
861 * udev_device_get_syspath:
862 * @udev_device: udev device
864 * Retrieve the sys path of the udev device. The path is an
865 * absolute path and starts with the sys mount point.
867 * Returns: the sys path of the udev device
869 const char *udev_device_get_syspath(struct udev_device *udev_device)
871 if (udev_device == NULL)
873 return udev_device->syspath;
877 * udev_device_get_sysname:
878 * @udev_device: udev device
880 * Returns: the sys name of the device device
882 const char *udev_device_get_sysname(struct udev_device *udev_device)
884 if (udev_device == NULL)
886 return udev_device->sysname;
890 * udev_device_get_sysnum:
891 * @udev_device: udev device
893 * Returns: the trailing number of of the device name
895 const char *udev_device_get_sysnum(struct udev_device *udev_device)
897 if (udev_device == NULL)
899 return udev_device->sysnum;
903 * udev_device_get_devnode:
904 * @udev_device: udev device
906 * Retrieve the device node file name belonging to the udev device.
907 * The path is an absolute path, and starts with the device directory.
909 * Returns: the device node file name of the udev device, or #NULL if no device node exists
911 const char *udev_device_get_devnode(struct udev_device *udev_device)
913 if (udev_device == NULL)
915 if (!udev_device->info_loaded) {
916 udev_device_read_uevent_file(udev_device);
917 udev_device_read_db(udev_device, NULL);
920 /* we might get called before we handled an event and have a db, use the kernel-provided name */
921 if (udev_device->devnode == NULL && udev_device_get_knodename(udev_device) != NULL) {
922 char filename[UTIL_NAME_SIZE];
924 util_strscpyl(filename, sizeof(filename), udev_get_dev_path(udev_device->udev), "/",
925 udev_device_get_knodename(udev_device), NULL);
926 udev_device_set_devnode(udev_device, filename);
927 return udev_device->devnode;
930 return udev_device->devnode;
934 * udev_device_get_subsystem:
935 * @udev_device: udev device
937 * Retrieve the subsystem string of the udev device. The string does not
940 * Returns: the subsystem name of the udev device, or #NULL if it can not be determined
942 const char *udev_device_get_subsystem(struct udev_device *udev_device)
944 char subsystem[UTIL_NAME_SIZE];
946 if (udev_device == NULL)
948 if (!udev_device->subsystem_set) {
949 udev_device->subsystem_set = true;
950 /* read "subsystem" link */
951 if (util_get_sys_subsystem(udev_device->udev, udev_device->syspath, subsystem, sizeof(subsystem)) > 0) {
952 udev_device_set_subsystem(udev_device, subsystem);
953 return udev_device->subsystem;
956 if (strncmp(udev_device->devpath, "/module/", 8) == 0) {
957 udev_device_set_subsystem(udev_device, "module");
958 return udev_device->subsystem;
960 if (strstr(udev_device->devpath, "/drivers/") != NULL) {
961 udev_device_set_subsystem(udev_device, "drivers");
962 return udev_device->subsystem;
964 if (strncmp(udev_device->devpath, "/subsystem/", 11) == 0 ||
965 strncmp(udev_device->devpath, "/class/", 7) == 0 ||
966 strncmp(udev_device->devpath, "/bus/", 5) == 0) {
967 udev_device_set_subsystem(udev_device, "subsystem");
968 return udev_device->subsystem;
971 return udev_device->subsystem;
975 * udev_device_get_devtype:
976 * @udev_device: udev device
978 * Retrieve the devtype string of the udev device.
980 * Returns: the devtype name of the udev device, or #NULL if it can not be determined
982 const char *udev_device_get_devtype(struct udev_device *udev_device)
984 if (udev_device == NULL)
986 if (!udev_device->devtype_set) {
987 udev_device->devtype_set = true;
988 udev_device_read_uevent_file(udev_device);
990 return udev_device->devtype;
994 * udev_device_get_devlinks_list_entry:
995 * @udev_device: udev device
997 * Retrieve the list of device links pointing to the device file of
998 * the udev device. The next list entry can be retrieved with
999 * udev_list_entry_next(), which returns #NULL if no more entries exist.
1000 * The devlink path can be retrieved from the list entry by
1001 * udev_list_entry_get_name(). The path is an absolute path, and starts with
1002 * the device directory.
1004 * Returns: the first entry of the device node link list
1006 struct udev_list_entry *udev_device_get_devlinks_list_entry(struct udev_device *udev_device)
1008 if (udev_device == NULL)
1010 if (!udev_device->info_loaded)
1011 udev_device_read_db(udev_device, NULL);
1012 return udev_list_get_entry(&udev_device->devlinks_list);
1015 void udev_device_cleanup_devlinks_list(struct udev_device *udev_device)
1017 udev_device->devlinks_uptodate = false;
1018 udev_list_cleanup_entries(udev_device->udev, &udev_device->devlinks_list);
1022 * udev_device_get_properties_list_entry:
1023 * @udev_device: udev device
1025 * Retrieve the list of key/value device properties of the udev
1026 * device. The next list entry can be retrieved with udev_list_entry_next(),
1027 * which returns #NULL if no more entries exist. The property name
1028 * can be retrieved from the list entry by udev_list_get_name(),
1029 * the property value by udev_list_get_value().
1031 * Returns: the first entry of the property list
1033 struct udev_list_entry *udev_device_get_properties_list_entry(struct udev_device *udev_device)
1035 if (udev_device == NULL)
1037 if (!udev_device->info_loaded) {
1038 udev_device_read_uevent_file(udev_device);
1039 udev_device_read_db(udev_device, NULL);
1041 if (!udev_device->devlinks_uptodate) {
1042 char symlinks[UTIL_PATH_SIZE];
1043 struct udev_list_entry *list_entry;
1045 udev_device->devlinks_uptodate = true;
1046 list_entry = udev_device_get_devlinks_list_entry(udev_device);
1047 if (list_entry != NULL) {
1052 l = util_strpcpyl(&s, sizeof(symlinks), udev_list_entry_get_name(list_entry), NULL);
1053 udev_list_entry_foreach(list_entry, udev_list_entry_get_next(list_entry))
1054 l = util_strpcpyl(&s, l, " ", udev_list_entry_get_name(list_entry), NULL);
1055 udev_device_add_property(udev_device, "DEVLINKS", symlinks);
1058 if (!udev_device->tags_uptodate) {
1059 udev_device->tags_uptodate = true;
1060 if (udev_device_get_tags_list_entry(udev_device) != NULL) {
1061 char tags[UTIL_PATH_SIZE];
1062 struct udev_list_entry *list_entry;
1067 l = util_strpcpyl(&s, sizeof(tags), ":", NULL);
1068 udev_list_entry_foreach(list_entry, udev_device_get_tags_list_entry(udev_device))
1069 l = util_strpcpyl(&s, l, udev_list_entry_get_name(list_entry), ":", NULL);
1070 udev_device_add_property(udev_device, "TAGS", tags);
1073 return udev_list_get_entry(&udev_device->properties_list);
1077 * udev_device_get_driver:
1078 * @udev_device: udev device
1080 * Returns: the driver string, or #NULL if there is no driver attached.
1082 const char *udev_device_get_driver(struct udev_device *udev_device)
1084 char driver[UTIL_NAME_SIZE];
1086 if (udev_device == NULL)
1088 if (!udev_device->driver_set) {
1089 udev_device->driver_set = true;
1090 if (util_get_sys_driver(udev_device->udev, udev_device->syspath, driver, sizeof(driver)) > 0)
1091 udev_device->driver = strdup(driver);
1093 return udev_device->driver;
1097 * udev_device_get_devnum:
1098 * @udev_device: udev device
1100 * Returns: the device major/minor number.
1102 dev_t udev_device_get_devnum(struct udev_device *udev_device)
1104 if (udev_device == NULL)
1105 return makedev(0, 0);
1106 if (!udev_device->info_loaded)
1107 udev_device_read_uevent_file(udev_device);
1108 return udev_device->devnum;
1112 * udev_device_get_action:
1113 * @udev_device: udev device
1115 * This is only valid if the device was received through a monitor. Devices read from
1116 * sys do not have an action string. Usual actions are: add, remove, change, online,
1119 * Returns: the kernel action value, or #NULL if there is no action value available.
1121 const char *udev_device_get_action(struct udev_device *udev_device)
1123 if (udev_device == NULL)
1125 return udev_device->action;
1129 * udev_device_get_devnum:
1130 * @udev_device: udev device
1132 * This is only valid if the device was received through a monitor. Devices read from
1133 * sys do not have a sequence number.
1135 * Returns: the kernel event sequence number, or 0 if there is no sequence number available.
1137 unsigned long long int udev_device_get_seqnum(struct udev_device *udev_device)
1139 if (udev_device == NULL)
1141 return udev_device->seqnum;
1145 * udev_device_get_usec_since_initialized:
1146 * @udev_device: udev device
1148 * Return the number of microseconds passed since udev set up the
1149 * device for the first time.
1151 * This is only implemented for devices with need to store properties
1152 * in the udev database. All other devices return 0 here.
1154 * Returns: the number of microseconds since the device was first seen.
1156 unsigned long long int udev_device_get_usec_since_initialized(struct udev_device *udev_device)
1158 unsigned long long now;
1160 if (udev_device == NULL)
1162 if (!udev_device->info_loaded)
1163 udev_device_read_db(udev_device, NULL);
1164 if (udev_device->usec_initialized == 0)
1169 return now - udev_device->usec_initialized;
1172 unsigned long long udev_device_get_usec_initialized(struct udev_device *udev_device)
1174 return udev_device->usec_initialized;
1177 void udev_device_set_usec_initialized(struct udev_device *udev_device, unsigned long long usec_initialized)
1179 udev_device->usec_initialized = usec_initialized;
1183 * udev_device_get_sysattr_value:
1184 * @udev_device: udev device
1185 * @sysattr: attribute name
1187 * The retrieved value is cached in the device. Repeated calls will return the same
1188 * value and not open the attribute again.
1190 * Returns: the content of a sys attribute file, or #NULL if there is no sys attribute value.
1192 const char *udev_device_get_sysattr_value(struct udev_device *udev_device, const char *sysattr)
1194 struct udev_list_entry *list_entry;
1195 char path[UTIL_PATH_SIZE];
1197 struct stat statbuf;
1200 const char *val = NULL;
1202 if (udev_device == NULL)
1204 if (sysattr == NULL)
1207 /* look for possibly already cached result */
1208 udev_list_entry_foreach(list_entry, udev_list_get_entry(&udev_device->sysattr_value_list)) {
1209 if (strcmp(udev_list_entry_get_name(list_entry), sysattr) == 0) {
1210 dbg(udev_device->udev, "got '%s' (%s) from cache\n",
1211 sysattr, udev_list_entry_get_value(list_entry));
1212 return udev_list_entry_get_value(list_entry);
1216 util_strscpyl(path, sizeof(path), udev_device_get_syspath(udev_device), "/", sysattr, NULL);
1217 if (lstat(path, &statbuf) != 0) {
1218 dbg(udev_device->udev, "no attribute '%s', keep negative entry\n", path);
1219 udev_list_entry_add(udev_device->udev, &udev_device->sysattr_value_list, sysattr, NULL, 0, 0);
1223 if (S_ISLNK(statbuf.st_mode)) {
1224 char target[UTIL_NAME_SIZE];
1228 /* some core links return the last element of the target path */
1229 if (strcmp(sysattr, "driver") != 0 &&
1230 strcmp(sysattr, "subsystem") != 0 &&
1231 strcmp(sysattr, "module") != 0)
1234 len = readlink(path, target, sizeof(target));
1235 if (len <= 0 || len == sizeof(target))
1239 pos = strrchr(target, '/');
1242 dbg(udev_device->udev, "cache '%s' with link value '%s'\n", sysattr, pos);
1243 list_entry = udev_list_entry_add(udev_device->udev, &udev_device->sysattr_value_list, sysattr, pos, 0, 0);
1244 val = udev_list_entry_get_value(list_entry);
1250 /* skip directories */
1251 if (S_ISDIR(statbuf.st_mode))
1254 /* skip non-readable files */
1255 if ((statbuf.st_mode & S_IRUSR) == 0)
1258 /* read attribute value */
1259 fd = open(path, O_RDONLY|O_CLOEXEC);
1261 dbg(udev_device->udev, "attribute '%s' can not be opened\n", path);
1264 size = read(fd, value, sizeof(value));
1268 if (size == sizeof(value))
1271 /* got a valid value, store it in cache and return it */
1273 util_remove_trailing_chars(value, '\n');
1274 dbg(udev_device->udev, "'%s' has attribute value '%s'\n", path, value);
1275 list_entry = udev_list_entry_add(udev_device->udev, &udev_device->sysattr_value_list, sysattr, value, 0, 0);
1276 val = udev_list_entry_get_value(list_entry);
1281 static int udev_device_sysattr_list_read(struct udev_device *udev_device)
1283 struct dirent *dent;
1287 if (udev_device == NULL)
1289 if (udev_device->sysattr_list_read)
1292 dir = opendir(udev_device_get_syspath(udev_device));
1294 dbg(udev_device->udev, "sysfs dir '%s' can not be opened\n",
1295 udev_device_get_syspath(udev_device));
1299 for (dent = readdir(dir); dent != NULL; dent = readdir(dir)) {
1300 char path[UTIL_PATH_SIZE];
1301 struct stat statbuf;
1303 /* only handle symlinks and regular files */
1304 if (dent->d_type != DT_LNK && dent->d_type != DT_REG)
1307 util_strscpyl(path, sizeof(path), udev_device_get_syspath(udev_device), "/", dent->d_name, NULL);
1308 if (lstat(path, &statbuf) != 0)
1310 if ((statbuf.st_mode & S_IRUSR) == 0)
1313 udev_list_entry_add(udev_device->udev, &udev_device->sysattr_list,
1314 dent->d_name, NULL, 0, 0);
1319 dbg(udev_device->udev, "found %d sysattrs for '%s'\n", num, udev_device_get_syspath(udev_device));
1320 udev_device->sysattr_list_read = true;
1326 * udev_device_get_sysattr_list_entry:
1327 * @udev_device: udev device
1329 * Retrieve the list of available sysattrs, with value being empty;
1330 * This just return all available sysfs attributes for a particular
1331 * device without reading their values.
1333 * Returns: the first entry of the property list
1335 struct udev_list_entry *udev_device_get_sysattr_list_entry(struct udev_device *udev_device)
1337 if (!udev_device->sysattr_list_read) {
1339 ret = udev_device_sysattr_list_read(udev_device);
1344 return udev_list_get_entry(&udev_device->sysattr_list);
1347 int udev_device_set_syspath(struct udev_device *udev_device, const char *syspath)
1352 free(udev_device->syspath);
1353 udev_device->syspath = strdup(syspath);
1354 if (udev_device->syspath == NULL)
1356 udev_device->devpath = &udev_device->syspath[strlen(udev_get_sys_path(udev_device->udev))];
1357 udev_device_add_property(udev_device, "DEVPATH", udev_device->devpath);
1359 pos = strrchr(udev_device->syspath, '/');
1362 udev_device->sysname = strdup(&pos[1]);
1363 if (udev_device->sysname == NULL)
1366 /* some devices have '!' in their name, change that to '/' */
1368 while (udev_device->sysname[len] != '\0') {
1369 if (udev_device->sysname[len] == '!')
1370 udev_device->sysname[len] = '/';
1374 /* trailing number */
1375 while (len > 0 && isdigit(udev_device->sysname[--len]))
1376 udev_device->sysnum = &udev_device->sysname[len];
1378 /* sysname is completely numeric */
1380 udev_device->sysnum = NULL;
1385 int udev_device_set_subsystem(struct udev_device *udev_device, const char *subsystem)
1387 free(udev_device->subsystem);
1388 udev_device->subsystem = strdup(subsystem);
1389 if (udev_device->subsystem == NULL)
1391 udev_device->subsystem_set = true;
1392 udev_device_add_property(udev_device, "SUBSYSTEM", udev_device->subsystem);
1396 int udev_device_set_devtype(struct udev_device *udev_device, const char *devtype)
1398 free(udev_device->devtype);
1399 udev_device->devtype = strdup(devtype);
1400 if (udev_device->devtype == NULL)
1402 udev_device->devtype_set = true;
1403 udev_device_add_property(udev_device, "DEVTYPE", udev_device->devtype);
1407 int udev_device_set_devnode(struct udev_device *udev_device, const char *devnode)
1409 free(udev_device->devnode);
1410 udev_device->devnode = strdup(devnode);
1411 if (udev_device->devnode == NULL)
1413 udev_device_add_property(udev_device, "DEVNAME", udev_device->devnode);
1417 int udev_device_add_devlink(struct udev_device *udev_device, const char *devlink, int unique)
1419 struct udev_list_entry *list_entry;
1421 udev_device->devlinks_uptodate = false;
1422 list_entry = udev_list_entry_add(udev_device->udev, &udev_device->devlinks_list, devlink, NULL, 1, 0);
1423 if (list_entry == NULL)
1426 udev_list_entry_set_flags(list_entry, 1);
1430 const char *udev_device_get_id_filename(struct udev_device *udev_device)
1432 if (udev_device->id_filename == NULL) {
1433 if (udev_device_get_subsystem(udev_device) == NULL)
1436 if (major(udev_device_get_devnum(udev_device)) > 0) {
1437 /* use dev_t -- b259:131072, c254:0 */
1438 if (asprintf(&udev_device->id_filename, "%c%u:%u",
1439 strcmp(udev_device_get_subsystem(udev_device), "block") == 0 ? 'b' : 'c',
1440 major(udev_device_get_devnum(udev_device)),
1441 minor(udev_device_get_devnum(udev_device))) < 0)
1442 udev_device->id_filename = NULL;
1443 } else if (udev_device_get_ifindex(udev_device) > 0) {
1444 /* use netdev ifindex -- n3 */
1445 if (asprintf(&udev_device->id_filename, "n%u", udev_device_get_ifindex(udev_device)) < 0)
1446 udev_device->id_filename = NULL;
1449 * use $subsys:$syname -- pci:0000:00:1f.2
1450 * sysname() has '!' translated, get it from devpath
1452 const char *sysname;
1453 sysname = strrchr(udev_device->devpath, '/');
1454 if (sysname == NULL)
1456 sysname = &sysname[1];
1457 if (asprintf(&udev_device->id_filename, "+%s:%s", udev_device_get_subsystem(udev_device), sysname) < 0)
1458 udev_device->id_filename = NULL;
1461 return udev_device->id_filename;
1465 * udev_device_get_is_initialized:
1466 * @udev_device: udev device
1468 * Check if udev has already handled the device and has set up
1469 * device node permissions and context, or has renamed a network
1472 * This is only implemented for devices with a device node
1473 * or network interfaces. All other devices return 1 here.
1475 * Returns: 1 if the device is set up. 0 otherwise.
1477 int udev_device_get_is_initialized(struct udev_device *udev_device)
1479 if (!udev_device->info_loaded)
1480 udev_device_read_db(udev_device, NULL);
1481 return udev_device->is_initialized;
1484 void udev_device_set_is_initialized(struct udev_device *udev_device)
1486 udev_device->is_initialized = true;
1489 int udev_device_add_tag(struct udev_device *udev_device, const char *tag)
1491 if (strchr(tag, ':') != NULL || strchr(tag, ' ') != NULL)
1493 udev_device->tags_uptodate = false;
1494 if (udev_list_entry_add(udev_device->udev, &udev_device->tags_list, tag, NULL, 1, 0) != NULL)
1499 void udev_device_cleanup_tags_list(struct udev_device *udev_device)
1501 udev_device->tags_uptodate = false;
1502 udev_list_cleanup_entries(udev_device->udev, &udev_device->tags_list);
1506 * udev_device_get_tags_list_entry:
1507 * @udev_device: udev device
1509 * Retrieve the list of tags attached to the udev device. The next
1510 * list entry can be retrieved with udev_list_entry_next(),
1511 * which returns #NULL if no more entries exist. The tag string
1512 * can be retrieved from the list entry by udev_list_get_name().
1514 * Returns: the first entry of the tag list
1516 struct udev_list_entry *udev_device_get_tags_list_entry(struct udev_device *udev_device)
1518 if (udev_device == NULL)
1520 return udev_list_get_entry(&udev_device->tags_list);
1523 int udev_device_has_tag(struct udev_device *udev_device, const char *tag)
1525 struct udev_list_entry *list_entry;
1527 if (!udev_device->info_loaded)
1528 udev_device_read_db(udev_device, NULL);
1529 list_entry = udev_device_get_tags_list_entry(udev_device);
1530 list_entry = udev_list_entry_get_by_name(list_entry, tag);
1531 if (list_entry != NULL)
1536 #define ENVP_SIZE 128
1537 #define MONITOR_BUF_SIZE 4096
1538 static int update_envp_monitor_buf(struct udev_device *udev_device)
1540 struct udev_list_entry *list_entry;
1545 /* monitor buffer of property strings */
1546 free(udev_device->monitor_buf);
1547 udev_device->monitor_buf_len = 0;
1548 udev_device->monitor_buf = malloc(MONITOR_BUF_SIZE);
1549 if (udev_device->monitor_buf == NULL)
1552 /* envp array, strings will point into monitor buffer */
1553 if (udev_device->envp == NULL)
1554 udev_device->envp = malloc(sizeof(char *) * ENVP_SIZE);
1555 if (udev_device->envp == NULL)
1559 s = udev_device->monitor_buf;
1560 l = MONITOR_BUF_SIZE;
1561 udev_list_entry_foreach(list_entry, udev_device_get_properties_list_entry(udev_device)) {
1564 key = udev_list_entry_get_name(list_entry);
1565 /* skip private variables */
1569 /* add string to envp array */
1570 udev_device->envp[i++] = s;
1571 if (i+1 >= ENVP_SIZE)
1574 /* add property string to monitor buffer */
1575 l = util_strpcpyl(&s, l, key, "=", udev_list_entry_get_value(list_entry), NULL);
1578 /* advance past the trailing '\0' that util_strpcpyl() guarantees */
1582 udev_device->envp[i] = NULL;
1583 udev_device->monitor_buf_len = s - udev_device->monitor_buf;
1584 udev_device->envp_uptodate = true;
1585 dbg(udev_device->udev, "filled envp/monitor buffer, %u properties, %zu bytes\n",
1586 i, udev_device->monitor_buf_len);
1590 char **udev_device_get_properties_envp(struct udev_device *udev_device)
1592 if (!udev_device->envp_uptodate)
1593 if (update_envp_monitor_buf(udev_device) != 0)
1595 return udev_device->envp;
1598 ssize_t udev_device_get_properties_monitor_buf(struct udev_device *udev_device, const char **buf)
1600 if (!udev_device->envp_uptodate)
1601 if (update_envp_monitor_buf(udev_device) != 0)
1603 *buf = udev_device->monitor_buf;
1604 return udev_device->monitor_buf_len;
1607 int udev_device_set_action(struct udev_device *udev_device, const char *action)
1609 free(udev_device->action);
1610 udev_device->action = strdup(action);
1611 if (udev_device->action == NULL)
1613 udev_device_add_property(udev_device, "ACTION", udev_device->action);
1617 int udev_device_set_driver(struct udev_device *udev_device, const char *driver)
1619 free(udev_device->driver);
1620 udev_device->driver = strdup(driver);
1621 if (udev_device->driver == NULL)
1623 udev_device->driver_set = true;
1624 udev_device_add_property(udev_device, "DRIVER", udev_device->driver);
1628 const char *udev_device_get_devpath_old(struct udev_device *udev_device)
1630 return udev_device->devpath_old;
1633 int udev_device_set_devpath_old(struct udev_device *udev_device, const char *devpath_old)
1638 free(udev_device->devpath_old);
1639 udev_device->devpath_old = strdup(devpath_old);
1640 if (udev_device->devpath_old == NULL)
1642 udev_device_add_property(udev_device, "DEVPATH_OLD", udev_device->devpath_old);
1644 pos = strrchr(udev_device->devpath_old, '/');
1647 udev_device->sysname_old = strdup(&pos[1]);
1648 if (udev_device->sysname_old == NULL)
1651 /* some devices have '!' in their name, change that to '/' */
1653 while (udev_device->sysname_old[len] != '\0') {
1654 if (udev_device->sysname_old[len] == '!')
1655 udev_device->sysname_old[len] = '/';
1661 const char *udev_device_get_sysname_old(struct udev_device *udev_device)
1663 if (udev_device == NULL)
1665 return udev_device->sysname_old;
1668 const char *udev_device_get_knodename(struct udev_device *udev_device)
1670 return udev_device->knodename;
1673 int udev_device_set_knodename(struct udev_device *udev_device, const char *knodename)
1675 free(udev_device->knodename);
1676 udev_device->knodename = strdup(knodename);
1677 if (udev_device->knodename == NULL)
1679 /* do not overwrite the udev property with the kernel property */
1680 if (udev_device->devnode == NULL)
1681 udev_device_add_property(udev_device, "DEVNAME", udev_device->knodename);
1685 int udev_device_get_timeout(struct udev_device *udev_device)
1687 return udev_device->timeout;
1690 int udev_device_set_timeout(struct udev_device *udev_device, int timeout)
1694 udev_device->timeout = timeout;
1695 snprintf(num, sizeof(num), "%u", timeout);
1696 udev_device_add_property(udev_device, "TIMEOUT", num);
1700 int udev_device_set_seqnum(struct udev_device *udev_device, unsigned long long int seqnum)
1704 udev_device->seqnum = seqnum;
1705 snprintf(num, sizeof(num), "%llu", seqnum);
1706 udev_device_add_property(udev_device, "SEQNUM", num);
1710 int udev_device_set_devnum(struct udev_device *udev_device, dev_t devnum)
1714 udev_device->devnum = devnum;
1716 snprintf(num, sizeof(num), "%u", major(devnum));
1717 udev_device_add_property(udev_device, "MAJOR", num);
1718 snprintf(num, sizeof(num), "%u", minor(devnum));
1719 udev_device_add_property(udev_device, "MINOR", num);
1723 int udev_device_get_devlink_priority(struct udev_device *udev_device)
1725 if (!udev_device->info_loaded)
1726 udev_device_read_db(udev_device, NULL);
1727 return udev_device->devlink_priority;
1730 int udev_device_set_devlink_priority(struct udev_device *udev_device, int prio)
1732 udev_device->devlink_priority = prio;
1736 int udev_device_get_watch_handle(struct udev_device *udev_device)
1738 if (!udev_device->info_loaded)
1739 udev_device_read_db(udev_device, NULL);
1740 return udev_device->watch_handle;
1743 int udev_device_set_watch_handle(struct udev_device *udev_device, int handle)
1745 udev_device->watch_handle = handle;
1749 int udev_device_get_ifindex(struct udev_device *udev_device)
1751 if (!udev_device->info_loaded)
1752 udev_device_read_uevent_file(udev_device);
1753 return udev_device->ifindex;
1756 int udev_device_set_ifindex(struct udev_device *udev_device, int ifindex)
1760 udev_device->ifindex = ifindex;
1761 snprintf(num, sizeof(num), "%u", ifindex);
1762 udev_device_add_property(udev_device, "IFINDEX", num);
1766 bool udev_device_get_db_persist(struct udev_device *udev_device)
1768 return udev_device->db_persist;
1771 void udev_device_set_db_persist(struct udev_device *udev_device)
1773 udev_device->db_persist = true;