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;
83 bool devlinks_uptodate;
91 bool sysattr_list_read;
95 struct udev_list_entry *udev_device_add_property(struct udev_device *udev_device, const char *key, const char *value)
97 udev_device->envp_uptodate = false;
99 struct udev_list_entry *list_entry;
101 list_entry = udev_device_get_properties_list_entry(udev_device);
102 list_entry = udev_list_entry_get_by_name(list_entry, key);
103 if (list_entry != NULL)
104 udev_list_entry_delete(list_entry);
107 return udev_list_entry_add(udev_device->udev, &udev_device->properties_list, key, value, 1, 0);
110 static struct udev_list_entry *udev_device_add_property_from_string(struct udev_device *udev_device, const char *property)
112 char name[UTIL_LINE_SIZE];
115 util_strscpy(name, sizeof(name), property);
116 val = strchr(name, '=');
123 return udev_device_add_property(udev_device, name, val);
127 * parse property string, and if needed, update internal values accordingly
129 * udev_device_add_property_from_string_parse_finish() needs to be
130 * called after adding properties, and its return value checked
132 * udev_device_set_info_loaded() needs to be set, to avoid trying
133 * to use a device without a DEVPATH set
135 void udev_device_add_property_from_string_parse(struct udev_device *udev_device, const char *property)
137 if (strncmp(property, "DEVPATH=", 8) == 0) {
138 char path[UTIL_PATH_SIZE];
140 util_strscpyl(path, sizeof(path), udev_get_sys_path(udev_device->udev), &property[8], NULL);
141 udev_device_set_syspath(udev_device, path);
142 } else if (strncmp(property, "SUBSYSTEM=", 10) == 0) {
143 udev_device_set_subsystem(udev_device, &property[10]);
144 } else if (strncmp(property, "DEVTYPE=", 8) == 0) {
145 udev_device_set_devtype(udev_device, &property[8]);
146 } else if (strncmp(property, "DEVNAME=", 8) == 0) {
147 if (property[8] == '/')
148 udev_device_set_devnode(udev_device, &property[8]);
150 udev_device_set_knodename(udev_device, &property[8]);
151 } else if (strncmp(property, "DEVLINKS=", 9) == 0) {
152 char devlinks[UTIL_PATH_SIZE];
156 util_strscpy(devlinks, sizeof(devlinks), &property[9]);
158 next = strchr(slink, ' ');
159 while (next != NULL) {
161 udev_device_add_devlink(udev_device, slink, 0);
163 next = strchr(slink, ' ');
165 if (slink[0] != '\0')
166 udev_device_add_devlink(udev_device, slink, 0);
167 } else if (strncmp(property, "TAGS=", 5) == 0) {
168 char tags[UTIL_PATH_SIZE];
171 util_strscpy(tags, sizeof(tags), &property[5]);
172 next = strchr(tags, ':');
175 while (next[0] != '\0') {
179 next = strchr(tag, ':');
184 udev_device_add_tag(udev_device, tag);
187 } else if (strncmp(property, "DRIVER=", 7) == 0) {
188 udev_device_set_driver(udev_device, &property[7]);
189 } else if (strncmp(property, "ACTION=", 7) == 0) {
190 udev_device_set_action(udev_device, &property[7]);
191 } else if (strncmp(property, "MAJOR=", 6) == 0) {
192 udev_device->maj = strtoull(&property[6], NULL, 10);
193 } else if (strncmp(property, "MINOR=", 6) == 0) {
194 udev_device->min = strtoull(&property[6], NULL, 10);
195 } else if (strncmp(property, "DEVPATH_OLD=", 12) == 0) {
196 udev_device_set_devpath_old(udev_device, &property[12]);
197 } else if (strncmp(property, "SEQNUM=", 7) == 0) {
198 udev_device_set_seqnum(udev_device, strtoull(&property[7], NULL, 10));
199 } else if (strncmp(property, "TIMEOUT=", 8) == 0) {
200 udev_device_set_timeout(udev_device, strtoull(&property[8], NULL, 10));
201 } else if (strncmp(property, "IFINDEX=", 8) == 0) {
202 udev_device_set_ifindex(udev_device, strtoull(&property[8], NULL, 10));
204 udev_device_add_property_from_string(udev_device, property);
208 int udev_device_add_property_from_string_parse_finish(struct udev_device *udev_device)
210 if (udev_device->maj > 0)
211 udev_device_set_devnum(udev_device, makedev(udev_device->maj, udev_device->min));
212 udev_device->maj = 0;
213 udev_device->min = 0;
215 if (udev_device->devpath == NULL || udev_device->subsystem == NULL)
221 * udev_device_get_property_value:
222 * @udev_device: udev device
223 * @key: property name
225 * Returns: the value of a device property, or #NULL if there is no such property.
227 const char *udev_device_get_property_value(struct udev_device *udev_device, const char *key)
229 struct udev_list_entry *list_entry;
231 if (udev_device == NULL)
236 list_entry = udev_device_get_properties_list_entry(udev_device);
237 list_entry = udev_list_entry_get_by_name(list_entry, key);
238 return udev_list_entry_get_value(list_entry);
241 int udev_device_read_db(struct udev_device *udev_device, const char *dbfile)
243 char filename[UTIL_PATH_SIZE];
244 char line[UTIL_LINE_SIZE];
247 /* providing a database file will always force-load it */
248 if (dbfile == NULL) {
251 if (udev_device->db_loaded)
253 udev_device->db_loaded = true;
255 id = udev_device_get_id_filename(udev_device);
258 util_strscpyl(filename, sizeof(filename), udev_get_run_path(udev_device->udev), "/data/", id, NULL);
262 f = fopen(dbfile, "re");
264 info(udev_device->udev, "no db file to read %s: %m\n", dbfile);
267 udev_device->is_initialized = true;
269 while (fgets(line, sizeof(line), f)) {
272 struct udev_list_entry *entry;
281 util_strscpyl(filename, sizeof(filename), udev_get_dev_path(udev_device->udev), "/", val, NULL);
282 udev_device_set_devnode(udev_device, filename);
285 util_strscpyl(filename, sizeof(filename), udev_get_dev_path(udev_device->udev), "/", val, NULL);
286 udev_device_add_devlink(udev_device, filename, 0);
289 udev_device_set_devlink_priority(udev_device, atoi(val));
292 entry = udev_device_add_property_from_string(udev_device, val);
293 udev_list_entry_set_flags(entry, 1);
296 udev_device_add_tag(udev_device, val);
299 udev_device_set_watch_handle(udev_device, atoi(val));
302 udev_device_set_usec_initialized(udev_device, strtoull(val, NULL, 10));
308 info(udev_device->udev, "device %p filled with db file data\n", udev_device);
312 int udev_device_read_uevent_file(struct udev_device *udev_device)
314 char filename[UTIL_PATH_SIZE];
316 char line[UTIL_LINE_SIZE];
320 if (udev_device->uevent_loaded)
323 util_strscpyl(filename, sizeof(filename), udev_device->syspath, "/uevent", NULL);
324 f = fopen(filename, "re");
327 udev_device->uevent_loaded = true;
329 while (fgets(line, sizeof(line), f)) {
332 pos = strchr(line, '\n');
337 if (strncmp(line, "DEVTYPE=", 8) == 0)
338 udev_device_set_devtype(udev_device, &line[8]);
339 else if (strncmp(line, "MAJOR=", 6) == 0)
340 maj = strtoull(&line[6], NULL, 10);
341 else if (strncmp(line, "MINOR=", 6) == 0)
342 min = strtoull(&line[6], NULL, 10);
343 else if (strncmp(line, "IFINDEX=", 8) == 0)
344 udev_device_set_ifindex(udev_device, strtoull(&line[8], NULL, 10));
345 else if (strncmp(line, "DEVNAME=", 8) == 0)
346 udev_device_set_knodename(udev_device, &line[8]);
348 udev_device_add_property_from_string(udev_device, line);
351 udev_device->devnum = makedev(maj, min);
356 void udev_device_set_info_loaded(struct udev_device *device)
358 device->info_loaded = true;
361 struct udev_device *udev_device_new(struct udev *udev)
363 struct udev_device *udev_device;
364 struct udev_list_entry *list_entry;
369 udev_device = calloc(1, sizeof(struct udev_device));
370 if (udev_device == NULL)
372 udev_device->refcount = 1;
373 udev_device->udev = udev;
374 udev_list_init(&udev_device->devlinks_list);
375 udev_list_init(&udev_device->properties_list);
376 udev_list_init(&udev_device->sysattr_value_list);
377 udev_list_init(&udev_device->sysattr_list);
378 udev_list_init(&udev_device->tags_list);
379 udev_device->event_timeout = -1;
380 udev_device->watch_handle = -1;
381 /* copy global properties */
382 udev_list_entry_foreach(list_entry, udev_get_properties_list_entry(udev))
383 udev_device_add_property(udev_device,
384 udev_list_entry_get_name(list_entry),
385 udev_list_entry_get_value(list_entry));
386 dbg(udev_device->udev, "udev_device: %p created\n", udev_device);
391 * udev_device_new_from_syspath:
392 * @udev: udev library context
393 * @syspath: sys device path including sys directory
395 * Create new udev device, and fill in information from the sys
396 * device and the udev database entry. The syspath is the absolute
397 * path to the device, including the sys mount point.
399 * The initial refcount is 1, and needs to be decremented to
400 * release the resources of the udev device.
402 * Returns: a new udev device, or #NULL, if it does not exist
404 struct udev_device *udev_device_new_from_syspath(struct udev *udev, const char *syspath)
408 char path[UTIL_PATH_SIZE];
411 struct udev_device *udev_device;
418 /* path starts in sys */
419 len = strlen(udev_get_sys_path(udev));
420 if (strncmp(syspath, udev_get_sys_path(udev), len) != 0) {
421 info(udev, "not in sys :%s\n", syspath);
425 /* path is not a root directory */
426 subdir = &syspath[len+1];
427 pos = strrchr(subdir, '/');
428 if (pos == NULL || pos[1] == '\0' || pos < &subdir[2]) {
429 dbg(udev, "not a subdir :%s\n", syspath);
433 /* resolve possible symlink to real path */
434 util_strscpy(path, sizeof(path), syspath);
435 util_resolve_sys_link(udev, path, sizeof(path));
437 if (strncmp(&path[len], "/devices/", 9) == 0) {
438 char file[UTIL_PATH_SIZE];
440 /* all "devices" require a "uevent" file */
441 util_strscpyl(file, sizeof(file), path, "/uevent", NULL);
442 if (stat(file, &statbuf) != 0) {
443 dbg(udev, "not a device: %s\n", syspath);
447 /* everything else just needs to be a directory */
448 if (stat(path, &statbuf) != 0 || !S_ISDIR(statbuf.st_mode)) {
449 dbg(udev, "directory not found: %s\n", syspath);
454 udev_device = udev_device_new(udev);
455 if (udev_device == NULL)
458 udev_device_set_syspath(udev_device, path);
459 info(udev, "device %p has devpath '%s'\n", udev_device, udev_device_get_devpath(udev_device));
465 * udev_device_new_from_devnum:
466 * @udev: udev library context
467 * @type: char or block device
468 * @devnum: device major/minor number
470 * Create new udev device, and fill in information from the sys
471 * device and the udev database entry. The device is looked-up
472 * by its major/minor number and type. Character and block device
473 * numbers are not unique across the two types.
475 * The initial refcount is 1, and needs to be decremented to
476 * release the resources of the udev device.
478 * Returns: a new udev device, or #NULL, if it does not exist
480 struct udev_device *udev_device_new_from_devnum(struct udev *udev, char type, dev_t devnum)
482 char path[UTIL_PATH_SIZE];
483 const char *type_str;
487 else if (type == 'c')
492 /* use /sys/dev/{block,char}/<maj>:<min> link */
493 snprintf(path, sizeof(path), "%s/dev/%s/%u:%u",
494 udev_get_sys_path(udev), type_str, major(devnum), minor(devnum));
495 return udev_device_new_from_syspath(udev, path);
498 struct udev_device *udev_device_new_from_id_filename(struct udev *udev, char *id)
502 char subsys[UTIL_PATH_SIZE];
508 if (sscanf(id, "%c%i:%i", &type, &maj, &min) != 3)
510 return udev_device_new_from_devnum(udev, type, makedev(maj, min));
514 struct udev_device *dev;
517 ifindex = strtoul(&id[1], NULL, 10);
521 sk = socket(PF_INET, SOCK_DGRAM, 0);
524 memset(&ifr, 0x00, sizeof(struct ifreq));
525 ifr.ifr_ifindex = ifindex;
526 if (ioctl(sk, SIOCGIFNAME, &ifr) != 0) {
532 dev = udev_device_new_from_subsystem_sysname(udev, "net", ifr.ifr_name);
535 if (udev_device_get_ifindex(dev) == ifindex)
537 udev_device_unref(dev);
541 util_strscpy(subsys, sizeof(subsys), &id[1]);
542 sysname = strchr(subsys, ':');
546 sysname = &sysname[1];
547 return udev_device_new_from_subsystem_sysname(udev, subsys, sysname);
554 * udev_device_new_from_subsystem_sysname:
555 * @udev: udev library context
556 * @subsystem: the subsystem of the device
557 * @sysname: the name of the device
559 * Create new udev device, and fill in information from the sys device
560 * and the udev database entry. The device is looked up by the subsystem
561 * and name string of the device, like "mem" / "zero", or "block" / "sda".
563 * The initial refcount is 1, and needs to be decremented to
564 * release the resources of the udev device.
566 * Returns: a new udev device, or #NULL, if it does not exist
568 struct udev_device *udev_device_new_from_subsystem_sysname(struct udev *udev, const char *subsystem, const char *sysname)
570 char path_full[UTIL_PATH_SIZE];
576 l = util_strpcpyl(&path, sizeof(path_full), udev_get_sys_path(udev), NULL);
578 if (strcmp(subsystem, "subsystem") == 0) {
579 util_strscpyl(path, l, "/subsystem/", sysname, NULL);
580 if (stat(path_full, &statbuf) == 0)
583 util_strscpyl(path, l, "/bus/", sysname, NULL);
584 if (stat(path_full, &statbuf) == 0)
587 util_strscpyl(path, l, "/class/", sysname, NULL);
588 if (stat(path_full, &statbuf) == 0)
593 if (strcmp(subsystem, "module") == 0) {
594 util_strscpyl(path, l, "/module/", sysname, NULL);
595 if (stat(path_full, &statbuf) == 0)
600 if (strcmp(subsystem, "drivers") == 0) {
601 char subsys[UTIL_NAME_SIZE];
604 util_strscpy(subsys, sizeof(subsys), sysname);
605 driver = strchr(subsys, ':');
606 if (driver != NULL) {
610 util_strscpyl(path, l, "/subsystem/", subsys, "/drivers/", driver, NULL);
611 if (stat(path_full, &statbuf) == 0)
614 util_strscpyl(path, l, "/bus/", subsys, "/drivers/", driver, NULL);
615 if (stat(path_full, &statbuf) == 0)
621 util_strscpyl(path, l, "/subsystem/", subsystem, "/devices/", sysname, NULL);
622 if (stat(path_full, &statbuf) == 0)
625 util_strscpyl(path, l, "/bus/", subsystem, "/devices/", sysname, NULL);
626 if (stat(path_full, &statbuf) == 0)
629 util_strscpyl(path, l, "/class/", subsystem, "/", sysname, NULL);
630 if (stat(path_full, &statbuf) == 0)
635 return udev_device_new_from_syspath(udev, path_full);
639 * udev_device_new_from_environment
640 * @udev: udev library context
642 * Create new udev device, and fill in information from the
643 * current process environment. This only works reliable if
644 * the process is called from a udev rule. It is usually used
645 * for tools executed from IMPORT= rules.
647 * The initial refcount is 1, and needs to be decremented to
648 * release the resources of the udev device.
650 * Returns: a new udev device, or #NULL, if it does not exist
652 struct udev_device *udev_device_new_from_environment(struct udev *udev)
655 struct udev_device *udev_device;
657 udev_device = udev_device_new(udev);
658 if (udev_device == NULL)
660 udev_device_set_info_loaded(udev_device);
662 for (i = 0; environ[i] != NULL; i++)
663 udev_device_add_property_from_string_parse(udev_device, environ[i]);
665 if (udev_device_add_property_from_string_parse_finish(udev_device) < 0) {
666 info(udev, "missing values, invalid device\n");
667 udev_device_unref(udev_device);
674 static struct udev_device *device_new_from_parent(struct udev_device *udev_device)
676 struct udev_device *udev_device_parent = NULL;
677 char path[UTIL_PATH_SIZE];
680 util_strscpy(path, sizeof(path), udev_device->syspath);
681 subdir = &path[strlen(udev_get_sys_path(udev_device->udev))+1];
685 pos = strrchr(subdir, '/');
686 if (pos == NULL || pos < &subdir[2])
689 udev_device_parent = udev_device_new_from_syspath(udev_device->udev, path);
690 if (udev_device_parent != NULL)
691 return udev_device_parent;
697 * udev_device_get_parent:
698 * @udev_device: the device to start searching from
700 * Find the next parent device, and fill in information from the sys
701 * device and the udev database entry.
703 * The returned the device is not referenced. It is attached to the
704 * child device, and will be cleaned up when the child device
707 * It is not necessarily just the upper level directory, empty or not
708 * recognized sys directories are ignored.
710 * It can be called as many times as needed, without caring about
713 * Returns: a new udev device, or #NULL, if it no parent exist.
715 struct udev_device *udev_device_get_parent(struct udev_device *udev_device)
717 if (udev_device == NULL)
719 if (!udev_device->parent_set) {
720 udev_device->parent_set = true;
721 udev_device->parent_device = device_new_from_parent(udev_device);
723 if (udev_device->parent_device != NULL)
724 dbg(udev_device->udev, "returning existing parent %p\n", udev_device->parent_device);
725 return udev_device->parent_device;
729 * udev_device_get_parent_with_subsystem_devtype:
730 * @udev_device: udev device to start searching from
731 * @subsystem: the subsystem of the device
732 * @devtype: the type (DEVTYPE) of the device
734 * Find the next parent device, with a matching subsystem and devtype
735 * value, and fill in information from the sys device and the udev
738 * If devtype is #NULL, only subsystem is checked, and any devtype will
741 * The returned the device is not referenced. It is attached to the
742 * child device, and will be cleaned up when the child device
745 * It can be called as many times as needed, without caring about
748 * Returns: a new udev device, or #NULL if no matching parent exists.
750 struct udev_device *udev_device_get_parent_with_subsystem_devtype(struct udev_device *udev_device, const char *subsystem, const char *devtype)
752 struct udev_device *parent;
754 if (subsystem == NULL)
757 parent = udev_device_get_parent(udev_device);
758 while (parent != NULL) {
759 const char *parent_subsystem;
760 const char *parent_devtype;
762 parent_subsystem = udev_device_get_subsystem(parent);
763 if (parent_subsystem != NULL && strcmp(parent_subsystem, subsystem) == 0) {
766 parent_devtype = udev_device_get_devtype(parent);
767 if (parent_devtype != NULL && strcmp(parent_devtype, devtype) == 0)
770 parent = udev_device_get_parent(parent);
776 * udev_device_get_udev:
777 * @udev_device: udev device
779 * Retrieve the udev library context the device was created with.
781 * Returns: the udev library context
783 struct udev *udev_device_get_udev(struct udev_device *udev_device)
785 if (udev_device == NULL)
787 return udev_device->udev;
792 * @udev_device: udev device
794 * Take a reference of a udev device.
796 * Returns: the passed udev device
798 struct udev_device *udev_device_ref(struct udev_device *udev_device)
800 if (udev_device == NULL)
802 udev_device->refcount++;
808 * @udev_device: udev device
810 * Drop a reference of a udev device. If the refcount reaches zero,
811 * the resources of the device will be released.
814 void udev_device_unref(struct udev_device *udev_device)
816 if (udev_device == NULL)
818 udev_device->refcount--;
819 if (udev_device->refcount > 0)
821 if (udev_device->parent_device != NULL)
822 udev_device_unref(udev_device->parent_device);
823 free(udev_device->syspath);
824 free(udev_device->sysname);
825 free(udev_device->devnode);
826 free(udev_device->subsystem);
827 free(udev_device->devtype);
828 udev_list_cleanup_entries(udev_device->udev, &udev_device->devlinks_list);
829 udev_list_cleanup_entries(udev_device->udev, &udev_device->properties_list);
830 udev_list_cleanup_entries(udev_device->udev, &udev_device->sysattr_value_list);
831 udev_list_cleanup_entries(udev_device->udev, &udev_device->sysattr_list);
832 udev_list_cleanup_entries(udev_device->udev, &udev_device->tags_list);
833 free(udev_device->action);
834 free(udev_device->driver);
835 free(udev_device->devpath_old);
836 free(udev_device->sysname_old);
837 free(udev_device->knodename);
838 free(udev_device->id_filename);
839 free(udev_device->envp);
840 free(udev_device->monitor_buf);
841 dbg(udev_device->udev, "udev_device: %p released\n", udev_device);
846 * udev_device_get_devpath:
847 * @udev_device: udev device
849 * Retrieve the kernel devpath value of the udev device. The path
850 * does not contain the sys mount point, and starts with a '/'.
852 * Returns: the devpath of the udev device
854 const char *udev_device_get_devpath(struct udev_device *udev_device)
856 if (udev_device == NULL)
858 return udev_device->devpath;
862 * udev_device_get_syspath:
863 * @udev_device: udev device
865 * Retrieve the sys path of the udev device. The path is an
866 * absolute path and starts with the sys mount point.
868 * Returns: the sys path of the udev device
870 const char *udev_device_get_syspath(struct udev_device *udev_device)
872 if (udev_device == NULL)
874 return udev_device->syspath;
878 * udev_device_get_sysname:
879 * @udev_device: udev device
881 * Returns: the sys name of the device device
883 const char *udev_device_get_sysname(struct udev_device *udev_device)
885 if (udev_device == NULL)
887 return udev_device->sysname;
891 * udev_device_get_sysnum:
892 * @udev_device: udev device
894 * Returns: the trailing number of of the device name
896 const char *udev_device_get_sysnum(struct udev_device *udev_device)
898 if (udev_device == NULL)
900 return udev_device->sysnum;
904 * udev_device_get_devnode:
905 * @udev_device: udev device
907 * Retrieve the device node file name belonging to the udev device.
908 * The path is an absolute path, and starts with the device directory.
910 * Returns: the device node file name of the udev device, or #NULL if no device node exists
912 const char *udev_device_get_devnode(struct udev_device *udev_device)
914 if (udev_device == NULL)
916 if (!udev_device->info_loaded) {
917 udev_device_read_uevent_file(udev_device);
918 udev_device_read_db(udev_device, NULL);
921 /* we might get called before we handled an event and have a db, use the kernel-provided name */
922 if (udev_device->devnode == NULL && udev_device_get_knodename(udev_device) != NULL) {
923 char filename[UTIL_NAME_SIZE];
925 util_strscpyl(filename, sizeof(filename), udev_get_dev_path(udev_device->udev), "/",
926 udev_device_get_knodename(udev_device), NULL);
927 udev_device_set_devnode(udev_device, filename);
928 return udev_device->devnode;
931 return udev_device->devnode;
935 * udev_device_get_subsystem:
936 * @udev_device: udev device
938 * Retrieve the subsystem string of the udev device. The string does not
941 * Returns: the subsystem name of the udev device, or #NULL if it can not be determined
943 const char *udev_device_get_subsystem(struct udev_device *udev_device)
945 char subsystem[UTIL_NAME_SIZE];
947 if (udev_device == NULL)
949 if (!udev_device->subsystem_set) {
950 udev_device->subsystem_set = true;
951 /* read "subsystem" link */
952 if (util_get_sys_subsystem(udev_device->udev, udev_device->syspath, subsystem, sizeof(subsystem)) > 0) {
953 udev_device_set_subsystem(udev_device, subsystem);
954 return udev_device->subsystem;
957 if (strncmp(udev_device->devpath, "/module/", 8) == 0) {
958 udev_device_set_subsystem(udev_device, "module");
959 return udev_device->subsystem;
961 if (strstr(udev_device->devpath, "/drivers/") != NULL) {
962 udev_device_set_subsystem(udev_device, "drivers");
963 return udev_device->subsystem;
965 if (strncmp(udev_device->devpath, "/subsystem/", 11) == 0 ||
966 strncmp(udev_device->devpath, "/class/", 7) == 0 ||
967 strncmp(udev_device->devpath, "/bus/", 5) == 0) {
968 udev_device_set_subsystem(udev_device, "subsystem");
969 return udev_device->subsystem;
972 return udev_device->subsystem;
976 * udev_device_get_devtype:
977 * @udev_device: udev device
979 * Retrieve the devtype string of the udev device.
981 * Returns: the devtype name of the udev device, or #NULL if it can not be determined
983 const char *udev_device_get_devtype(struct udev_device *udev_device)
985 if (udev_device == NULL)
987 if (!udev_device->devtype_set) {
988 udev_device->devtype_set = true;
989 udev_device_read_uevent_file(udev_device);
991 return udev_device->devtype;
995 * udev_device_get_devlinks_list_entry:
996 * @udev_device: udev device
998 * Retrieve the list of device links pointing to the device file of
999 * the udev device. The next list entry can be retrieved with
1000 * udev_list_entry_next(), which returns #NULL if no more entries exist.
1001 * The devlink path can be retrieved from the list entry by
1002 * udev_list_entry_get_name(). The path is an absolute path, and starts with
1003 * the device directory.
1005 * Returns: the first entry of the device node link list
1007 struct udev_list_entry *udev_device_get_devlinks_list_entry(struct udev_device *udev_device)
1009 if (udev_device == NULL)
1011 if (!udev_device->info_loaded)
1012 udev_device_read_db(udev_device, NULL);
1013 return udev_list_get_entry(&udev_device->devlinks_list);
1016 void udev_device_cleanup_devlinks_list(struct udev_device *udev_device)
1018 udev_device->devlinks_uptodate = false;
1019 udev_list_cleanup_entries(udev_device->udev, &udev_device->devlinks_list);
1023 * udev_device_get_properties_list_entry:
1024 * @udev_device: udev device
1026 * Retrieve the list of key/value device properties of the udev
1027 * device. The next list entry can be retrieved with udev_list_entry_next(),
1028 * which returns #NULL if no more entries exist. The property name
1029 * can be retrieved from the list entry by udev_list_get_name(),
1030 * the property value by udev_list_get_value().
1032 * Returns: the first entry of the property list
1034 struct udev_list_entry *udev_device_get_properties_list_entry(struct udev_device *udev_device)
1036 if (udev_device == NULL)
1038 if (!udev_device->info_loaded) {
1039 udev_device_read_uevent_file(udev_device);
1040 udev_device_read_db(udev_device, NULL);
1042 if (!udev_device->devlinks_uptodate) {
1043 char symlinks[UTIL_PATH_SIZE];
1044 struct udev_list_entry *list_entry;
1046 udev_device->devlinks_uptodate = true;
1047 list_entry = udev_device_get_devlinks_list_entry(udev_device);
1048 if (list_entry != NULL) {
1053 l = util_strpcpyl(&s, sizeof(symlinks), udev_list_entry_get_name(list_entry), NULL);
1054 udev_list_entry_foreach(list_entry, udev_list_entry_get_next(list_entry))
1055 l = util_strpcpyl(&s, l, " ", udev_list_entry_get_name(list_entry), NULL);
1056 udev_device_add_property(udev_device, "DEVLINKS", symlinks);
1059 if (!udev_device->tags_uptodate) {
1060 udev_device->tags_uptodate = true;
1061 if (udev_device_get_tags_list_entry(udev_device) != NULL) {
1062 char tags[UTIL_PATH_SIZE];
1063 struct udev_list_entry *list_entry;
1068 l = util_strpcpyl(&s, sizeof(tags), ":", NULL);
1069 udev_list_entry_foreach(list_entry, udev_device_get_tags_list_entry(udev_device))
1070 l = util_strpcpyl(&s, l, udev_list_entry_get_name(list_entry), ":", NULL);
1071 udev_device_add_property(udev_device, "TAGS", tags);
1074 return udev_list_get_entry(&udev_device->properties_list);
1078 * udev_device_get_driver:
1079 * @udev_device: udev device
1081 * Returns: the driver string, or #NULL if there is no driver attached.
1083 const char *udev_device_get_driver(struct udev_device *udev_device)
1085 char driver[UTIL_NAME_SIZE];
1087 if (udev_device == NULL)
1089 if (!udev_device->driver_set) {
1090 udev_device->driver_set = true;
1091 if (util_get_sys_driver(udev_device->udev, udev_device->syspath, driver, sizeof(driver)) > 0)
1092 udev_device->driver = strdup(driver);
1094 return udev_device->driver;
1098 * udev_device_get_devnum:
1099 * @udev_device: udev device
1101 * Returns: the device major/minor number.
1103 dev_t udev_device_get_devnum(struct udev_device *udev_device)
1105 if (udev_device == NULL)
1106 return makedev(0, 0);
1107 if (!udev_device->info_loaded)
1108 udev_device_read_uevent_file(udev_device);
1109 return udev_device->devnum;
1113 * udev_device_get_action:
1114 * @udev_device: udev device
1116 * This is only valid if the device was received through a monitor. Devices read from
1117 * sys do not have an action string. Usual actions are: add, remove, change, online,
1120 * Returns: the kernel action value, or #NULL if there is no action value available.
1122 const char *udev_device_get_action(struct udev_device *udev_device)
1124 if (udev_device == NULL)
1126 return udev_device->action;
1130 * udev_device_get_devnum:
1131 * @udev_device: udev device
1133 * This is only valid if the device was received through a monitor. Devices read from
1134 * sys do not have a sequence number.
1136 * Returns: the kernel event sequence number, or 0 if there is no sequence number available.
1138 unsigned long long int udev_device_get_seqnum(struct udev_device *udev_device)
1140 if (udev_device == NULL)
1142 return udev_device->seqnum;
1146 * udev_device_get_usec_since_initialized:
1147 * @udev_device: udev device
1149 * Return the number of microseconds passed since udev set up the
1150 * device for the first time.
1152 * This is only implemented for devices with need to store properties
1153 * in the udev database. All other devices return 0 here.
1155 * Returns: the number of microseconds since the device was first seen.
1157 unsigned long long int udev_device_get_usec_since_initialized(struct udev_device *udev_device)
1159 unsigned long long now;
1161 if (udev_device == NULL)
1163 if (!udev_device->info_loaded)
1164 udev_device_read_db(udev_device, NULL);
1165 if (udev_device->usec_initialized == 0)
1167 now = usec_monotonic();
1170 return now - udev_device->usec_initialized;
1173 unsigned long long udev_device_get_usec_initialized(struct udev_device *udev_device)
1175 return udev_device->usec_initialized;
1178 void udev_device_set_usec_initialized(struct udev_device *udev_device, unsigned long long usec_initialized)
1180 udev_device->usec_initialized = usec_initialized;
1184 * udev_device_get_sysattr_value:
1185 * @udev_device: udev device
1186 * @sysattr: attribute name
1188 * The retrieved value is cached in the device. Repeated calls will return the same
1189 * value and not open the attribute again.
1191 * Returns: the content of a sys attribute file, or #NULL if there is no sys attribute value.
1193 const char *udev_device_get_sysattr_value(struct udev_device *udev_device, const char *sysattr)
1195 struct udev_list_entry *list_entry;
1196 char path[UTIL_PATH_SIZE];
1198 struct stat statbuf;
1201 const char *val = NULL;
1203 if (udev_device == NULL)
1205 if (sysattr == NULL)
1208 /* look for possibly already cached result */
1209 udev_list_entry_foreach(list_entry, udev_list_get_entry(&udev_device->sysattr_value_list)) {
1210 if (strcmp(udev_list_entry_get_name(list_entry), sysattr) == 0) {
1211 dbg(udev_device->udev, "got '%s' (%s) from cache\n",
1212 sysattr, udev_list_entry_get_value(list_entry));
1213 return udev_list_entry_get_value(list_entry);
1217 util_strscpyl(path, sizeof(path), udev_device_get_syspath(udev_device), "/", sysattr, NULL);
1218 if (lstat(path, &statbuf) != 0) {
1219 dbg(udev_device->udev, "no attribute '%s', keep negative entry\n", path);
1220 udev_list_entry_add(udev_device->udev, &udev_device->sysattr_value_list, sysattr, NULL, 0, 0);
1224 if (S_ISLNK(statbuf.st_mode)) {
1225 char target[UTIL_NAME_SIZE];
1229 /* some core links return the last element of the target path */
1230 if (strcmp(sysattr, "driver") != 0 &&
1231 strcmp(sysattr, "subsystem") != 0 &&
1232 strcmp(sysattr, "module") != 0)
1235 len = readlink(path, target, sizeof(target));
1236 if (len <= 0 || len == sizeof(target))
1240 pos = strrchr(target, '/');
1243 dbg(udev_device->udev, "cache '%s' with link value '%s'\n", sysattr, pos);
1244 list_entry = udev_list_entry_add(udev_device->udev, &udev_device->sysattr_value_list, sysattr, pos, 0, 0);
1245 val = udev_list_entry_get_value(list_entry);
1251 /* skip directories */
1252 if (S_ISDIR(statbuf.st_mode))
1255 /* skip non-readable files */
1256 if ((statbuf.st_mode & S_IRUSR) == 0)
1259 /* read attribute value */
1260 fd = open(path, O_RDONLY|O_CLOEXEC);
1262 dbg(udev_device->udev, "attribute '%s' can not be opened\n", path);
1265 size = read(fd, value, sizeof(value));
1269 if (size == sizeof(value))
1272 /* got a valid value, store it in cache and return it */
1274 util_remove_trailing_chars(value, '\n');
1275 dbg(udev_device->udev, "'%s' has attribute value '%s'\n", path, value);
1276 list_entry = udev_list_entry_add(udev_device->udev, &udev_device->sysattr_value_list, sysattr, value, 0, 0);
1277 val = udev_list_entry_get_value(list_entry);
1282 static int udev_device_sysattr_list_read(struct udev_device *udev_device)
1284 struct dirent *dent;
1288 if (udev_device == NULL)
1290 if (udev_device->sysattr_list_read)
1293 dir = opendir(udev_device_get_syspath(udev_device));
1295 dbg(udev_device->udev, "sysfs dir '%s' can not be opened\n",
1296 udev_device_get_syspath(udev_device));
1300 for (dent = readdir(dir); dent != NULL; dent = readdir(dir)) {
1301 char path[UTIL_PATH_SIZE];
1302 struct stat statbuf;
1304 /* only handle symlinks and regular files */
1305 if (dent->d_type != DT_LNK && dent->d_type != DT_REG)
1308 util_strscpyl(path, sizeof(path), udev_device_get_syspath(udev_device), "/", dent->d_name, NULL);
1309 if (lstat(path, &statbuf) != 0)
1311 if ((statbuf.st_mode & S_IRUSR) == 0)
1314 udev_list_entry_add(udev_device->udev, &udev_device->sysattr_list,
1315 dent->d_name, NULL, 0, 0);
1320 dbg(udev_device->udev, "found %d sysattrs for '%s'\n", num, udev_device_get_syspath(udev_device));
1321 udev_device->sysattr_list_read = true;
1327 * udev_device_get_sysattr_list_entry:
1328 * @udev_device: udev device
1330 * Retrieve the list of available sysattrs, with value being empty;
1331 * This just return all available sysfs attributes for a particular
1332 * device without reading their values.
1334 * Returns: the first entry of the property list
1336 struct udev_list_entry *udev_device_get_sysattr_list_entry(struct udev_device *udev_device)
1338 if (!udev_device->sysattr_list_read) {
1340 ret = udev_device_sysattr_list_read(udev_device);
1345 return udev_list_get_entry(&udev_device->sysattr_list);
1348 int udev_device_set_syspath(struct udev_device *udev_device, const char *syspath)
1353 free(udev_device->syspath);
1354 udev_device->syspath = strdup(syspath);
1355 if (udev_device->syspath == NULL)
1357 udev_device->devpath = &udev_device->syspath[strlen(udev_get_sys_path(udev_device->udev))];
1358 udev_device_add_property(udev_device, "DEVPATH", udev_device->devpath);
1360 pos = strrchr(udev_device->syspath, '/');
1363 udev_device->sysname = strdup(&pos[1]);
1364 if (udev_device->sysname == NULL)
1367 /* some devices have '!' in their name, change that to '/' */
1369 while (udev_device->sysname[len] != '\0') {
1370 if (udev_device->sysname[len] == '!')
1371 udev_device->sysname[len] = '/';
1375 /* trailing number */
1376 while (len > 0 && isdigit(udev_device->sysname[--len]))
1377 udev_device->sysnum = &udev_device->sysname[len];
1379 /* sysname is completely numeric */
1381 udev_device->sysnum = NULL;
1386 int udev_device_set_subsystem(struct udev_device *udev_device, const char *subsystem)
1388 free(udev_device->subsystem);
1389 udev_device->subsystem = strdup(subsystem);
1390 if (udev_device->subsystem == NULL)
1392 udev_device->subsystem_set = true;
1393 udev_device_add_property(udev_device, "SUBSYSTEM", udev_device->subsystem);
1397 int udev_device_set_devtype(struct udev_device *udev_device, const char *devtype)
1399 free(udev_device->devtype);
1400 udev_device->devtype = strdup(devtype);
1401 if (udev_device->devtype == NULL)
1403 udev_device->devtype_set = true;
1404 udev_device_add_property(udev_device, "DEVTYPE", udev_device->devtype);
1408 int udev_device_set_devnode(struct udev_device *udev_device, const char *devnode)
1410 free(udev_device->devnode);
1411 udev_device->devnode = strdup(devnode);
1412 if (udev_device->devnode == NULL)
1414 udev_device_add_property(udev_device, "DEVNAME", udev_device->devnode);
1418 int udev_device_add_devlink(struct udev_device *udev_device, const char *devlink, int unique)
1420 struct udev_list_entry *list_entry;
1422 udev_device->devlinks_uptodate = false;
1423 list_entry = udev_list_entry_add(udev_device->udev, &udev_device->devlinks_list, devlink, NULL, 1, 0);
1424 if (list_entry == NULL)
1427 udev_list_entry_set_flags(list_entry, 1);
1431 const char *udev_device_get_id_filename(struct udev_device *udev_device)
1433 if (udev_device->id_filename == NULL) {
1434 if (udev_device_get_subsystem(udev_device) == NULL)
1437 if (major(udev_device_get_devnum(udev_device)) > 0) {
1438 /* use dev_t -- b259:131072, c254:0 */
1439 if (asprintf(&udev_device->id_filename, "%c%u:%u",
1440 strcmp(udev_device_get_subsystem(udev_device), "block") == 0 ? 'b' : 'c',
1441 major(udev_device_get_devnum(udev_device)),
1442 minor(udev_device_get_devnum(udev_device))) < 0)
1443 udev_device->id_filename = NULL;
1444 } else if (udev_device_get_ifindex(udev_device) > 0) {
1445 /* use netdev ifindex -- n3 */
1446 if (asprintf(&udev_device->id_filename, "n%u", udev_device_get_ifindex(udev_device)) < 0)
1447 udev_device->id_filename = NULL;
1450 * use $subsys:$syname -- pci:0000:00:1f.2
1451 * sysname() has '!' translated, get it from devpath
1453 const char *sysname;
1454 sysname = strrchr(udev_device->devpath, '/');
1455 if (sysname == NULL)
1457 sysname = &sysname[1];
1458 if (asprintf(&udev_device->id_filename, "+%s:%s", udev_device_get_subsystem(udev_device), sysname) < 0)
1459 udev_device->id_filename = NULL;
1462 return udev_device->id_filename;
1466 * udev_device_get_is_initialized:
1467 * @udev_device: udev device
1469 * Check if udev has already handled the device and has set up
1470 * device node permissions and context, or has renamed a network
1473 * This is only implemented for devices with a device node
1474 * or network interfaces. All other devices return 1 here.
1476 * Returns: 1 if the device is set up. 0 otherwise.
1478 int udev_device_get_is_initialized(struct udev_device *udev_device)
1480 if (!udev_device->info_loaded)
1481 udev_device_read_db(udev_device, NULL);
1482 return udev_device->is_initialized;
1485 void udev_device_set_is_initialized(struct udev_device *udev_device)
1487 udev_device->is_initialized = true;
1490 int udev_device_add_tag(struct udev_device *udev_device, const char *tag)
1492 if (strchr(tag, ':') != NULL || strchr(tag, ' ') != NULL)
1494 udev_device->tags_uptodate = false;
1495 if (udev_list_entry_add(udev_device->udev, &udev_device->tags_list, tag, NULL, 1, 0) != NULL)
1500 void udev_device_cleanup_tags_list(struct udev_device *udev_device)
1502 udev_device->tags_uptodate = false;
1503 udev_list_cleanup_entries(udev_device->udev, &udev_device->tags_list);
1507 * udev_device_get_tags_list_entry:
1508 * @udev_device: udev device
1510 * Retrieve the list of tags attached to the udev device. The next
1511 * list entry can be retrieved with udev_list_entry_next(),
1512 * which returns #NULL if no more entries exist. The tag string
1513 * can be retrieved from the list entry by udev_list_get_name().
1515 * Returns: the first entry of the tag list
1517 struct udev_list_entry *udev_device_get_tags_list_entry(struct udev_device *udev_device)
1519 if (udev_device == NULL)
1521 return udev_list_get_entry(&udev_device->tags_list);
1524 int udev_device_has_tag(struct udev_device *udev_device, const char *tag)
1526 struct udev_list_entry *list_entry;
1528 if (!udev_device->info_loaded)
1529 udev_device_read_db(udev_device, NULL);
1530 list_entry = udev_device_get_tags_list_entry(udev_device);
1531 list_entry = udev_list_entry_get_by_name(list_entry, tag);
1532 if (list_entry != NULL)
1537 #define ENVP_SIZE 128
1538 #define MONITOR_BUF_SIZE 4096
1539 static int update_envp_monitor_buf(struct udev_device *udev_device)
1541 struct udev_list_entry *list_entry;
1546 /* monitor buffer of property strings */
1547 free(udev_device->monitor_buf);
1548 udev_device->monitor_buf_len = 0;
1549 udev_device->monitor_buf = malloc(MONITOR_BUF_SIZE);
1550 if (udev_device->monitor_buf == NULL)
1553 /* envp array, strings will point into monitor buffer */
1554 if (udev_device->envp == NULL)
1555 udev_device->envp = malloc(sizeof(char *) * ENVP_SIZE);
1556 if (udev_device->envp == NULL)
1560 s = udev_device->monitor_buf;
1561 l = MONITOR_BUF_SIZE;
1562 udev_list_entry_foreach(list_entry, udev_device_get_properties_list_entry(udev_device)) {
1565 key = udev_list_entry_get_name(list_entry);
1566 /* skip private variables */
1570 /* add string to envp array */
1571 udev_device->envp[i++] = s;
1572 if (i+1 >= ENVP_SIZE)
1575 /* add property string to monitor buffer */
1576 l = util_strpcpyl(&s, l, key, "=", udev_list_entry_get_value(list_entry), NULL);
1579 /* advance past the trailing '\0' that util_strpcpyl() guarantees */
1583 udev_device->envp[i] = NULL;
1584 udev_device->monitor_buf_len = s - udev_device->monitor_buf;
1585 udev_device->envp_uptodate = true;
1586 dbg(udev_device->udev, "filled envp/monitor buffer, %u properties, %zu bytes\n",
1587 i, udev_device->monitor_buf_len);
1591 char **udev_device_get_properties_envp(struct udev_device *udev_device)
1593 if (!udev_device->envp_uptodate)
1594 if (update_envp_monitor_buf(udev_device) != 0)
1596 return udev_device->envp;
1599 ssize_t udev_device_get_properties_monitor_buf(struct udev_device *udev_device, const char **buf)
1601 if (!udev_device->envp_uptodate)
1602 if (update_envp_monitor_buf(udev_device) != 0)
1604 *buf = udev_device->monitor_buf;
1605 return udev_device->monitor_buf_len;
1608 int udev_device_set_action(struct udev_device *udev_device, const char *action)
1610 free(udev_device->action);
1611 udev_device->action = strdup(action);
1612 if (udev_device->action == NULL)
1614 udev_device_add_property(udev_device, "ACTION", udev_device->action);
1618 int udev_device_set_driver(struct udev_device *udev_device, const char *driver)
1620 free(udev_device->driver);
1621 udev_device->driver = strdup(driver);
1622 if (udev_device->driver == NULL)
1624 udev_device->driver_set = true;
1625 udev_device_add_property(udev_device, "DRIVER", udev_device->driver);
1629 const char *udev_device_get_devpath_old(struct udev_device *udev_device)
1631 return udev_device->devpath_old;
1634 int udev_device_set_devpath_old(struct udev_device *udev_device, const char *devpath_old)
1639 free(udev_device->devpath_old);
1640 udev_device->devpath_old = strdup(devpath_old);
1641 if (udev_device->devpath_old == NULL)
1643 udev_device_add_property(udev_device, "DEVPATH_OLD", udev_device->devpath_old);
1645 pos = strrchr(udev_device->devpath_old, '/');
1648 udev_device->sysname_old = strdup(&pos[1]);
1649 if (udev_device->sysname_old == NULL)
1652 /* some devices have '!' in their name, change that to '/' */
1654 while (udev_device->sysname_old[len] != '\0') {
1655 if (udev_device->sysname_old[len] == '!')
1656 udev_device->sysname_old[len] = '/';
1662 const char *udev_device_get_sysname_old(struct udev_device *udev_device)
1664 if (udev_device == NULL)
1666 return udev_device->sysname_old;
1669 const char *udev_device_get_knodename(struct udev_device *udev_device)
1671 return udev_device->knodename;
1674 int udev_device_set_knodename(struct udev_device *udev_device, const char *knodename)
1676 free(udev_device->knodename);
1677 udev_device->knodename = strdup(knodename);
1678 if (udev_device->knodename == NULL)
1680 /* do not overwrite the udev property with the kernel property */
1681 if (udev_device->devnode == NULL)
1682 udev_device_add_property(udev_device, "DEVNAME", udev_device->knodename);
1686 int udev_device_get_timeout(struct udev_device *udev_device)
1688 return udev_device->timeout;
1691 int udev_device_set_timeout(struct udev_device *udev_device, int timeout)
1693 udev_device->timeout = timeout;
1696 int udev_device_get_event_timeout(struct udev_device *udev_device)
1698 if (!udev_device->info_loaded)
1699 udev_device_read_db(udev_device, NULL);
1700 return udev_device->event_timeout;
1703 int udev_device_set_event_timeout(struct udev_device *udev_device, int event_timeout)
1707 udev_device->event_timeout = event_timeout;
1708 snprintf(num, sizeof(num), "%u", event_timeout);
1709 udev_device_add_property(udev_device, "TIMEOUT", num);
1713 int udev_device_set_seqnum(struct udev_device *udev_device, unsigned long long int seqnum)
1717 udev_device->seqnum = seqnum;
1718 snprintf(num, sizeof(num), "%llu", seqnum);
1719 udev_device_add_property(udev_device, "SEQNUM", num);
1723 int udev_device_set_devnum(struct udev_device *udev_device, dev_t devnum)
1727 udev_device->devnum = devnum;
1729 snprintf(num, sizeof(num), "%u", major(devnum));
1730 udev_device_add_property(udev_device, "MAJOR", num);
1731 snprintf(num, sizeof(num), "%u", minor(devnum));
1732 udev_device_add_property(udev_device, "MINOR", num);
1736 int udev_device_get_devlink_priority(struct udev_device *udev_device)
1738 if (!udev_device->info_loaded)
1739 udev_device_read_db(udev_device, NULL);
1740 return udev_device->devlink_priority;
1743 int udev_device_set_devlink_priority(struct udev_device *udev_device, int prio)
1745 udev_device->devlink_priority = prio;
1749 int udev_device_get_watch_handle(struct udev_device *udev_device)
1751 if (!udev_device->info_loaded)
1752 udev_device_read_db(udev_device, NULL);
1753 return udev_device->watch_handle;
1756 int udev_device_set_watch_handle(struct udev_device *udev_device, int handle)
1758 udev_device->watch_handle = handle;
1762 int udev_device_get_ifindex(struct udev_device *udev_device)
1764 if (!udev_device->info_loaded)
1765 udev_device_read_uevent_file(udev_device);
1766 return udev_device->ifindex;
1769 int udev_device_set_ifindex(struct udev_device *udev_device, int ifindex)
1773 udev_device->ifindex = ifindex;
1774 snprintf(num, sizeof(num), "%u", ifindex);
1775 udev_device_add_property(udev_device, "IFINDEX", num);
1779 bool udev_device_get_db_persist(struct udev_device *udev_device)
1781 return udev_device->db_persist;
1784 void udev_device_set_db_persist(struct udev_device *udev_device)
1786 udev_device->db_persist = true;