2 * libudev - interface to udev device information
4 * Copyright (C) 2008 Kay Sievers <kay.sievers@vrfy.org>
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
31 #include "libudev-private.h"
36 struct udev_device *parent_device;
42 struct udev_list_node devlink_list;
43 struct udev_list_node properties_list;
51 unsigned long long int seqnum;
52 int num_fake_partitions;
55 struct udev_list_node attr_list;
59 static size_t devpath_to_db_path(struct udev *udev, const char *devpath, char *filename, size_t len)
63 /* translate to location of db file */
64 util_strlcpy(filename, udev_get_dev_path(udev), len);
65 start = util_strlcat(filename, "/.udev/db/", len);
66 util_strlcat(filename, devpath, len);
67 return util_path_encode(&filename[start], len - start);
70 static int device_read_db(struct udev_device *udev_device)
73 char filename[UTIL_PATH_SIZE];
74 char line[UTIL_LINE_SIZE];
77 devpath_to_db_path(udev_device->udev, udev_device->devpath, filename, sizeof(filename));
79 if (lstat(filename, &stats) != 0) {
80 info(udev_device->udev, "no db file to read %s: %m\n", filename);
83 if ((stats.st_mode & S_IFMT) == S_IFLNK) {
84 char target[UTIL_PATH_SIZE];
88 target_len = readlink(filename, target, sizeof(target));
90 target[target_len] = '\0';
92 info(udev_device->udev, "error reading db link %s: %m\n", filename);
96 next = strchr(target, ' ');
101 if (asprintf(&udev_device->devnode, "%s/%s", udev_get_dev_path(udev_device->udev), target) < 0)
103 while (next != NULL) {
104 char linkname[UTIL_PATH_SIZE];
108 next = strchr(next, ' ');
113 util_strlcpy(linkname, udev_get_dev_path(udev_device->udev), sizeof(linkname));
114 util_strlcat(linkname, "/", sizeof(linkname));
115 util_strlcat(linkname, lnk, sizeof(linkname));
116 udev_device_add_devlink(udev_device, linkname);
118 info(udev_device->udev, "device %p filled with db symlink data '%s'\n", udev_device, udev_device->devnode);
122 f = fopen(filename, "r");
124 info(udev_device->udev, "error reading db file %s: %m\n", filename);
127 while (fgets(line, sizeof(line), f)) {
139 asprintf(&udev_device->devnode, "%s/%s", udev_get_dev_path(udev_device->udev), val);
142 util_strlcpy(filename, udev_get_dev_path(udev_device->udev), sizeof(filename));
143 util_strlcat(filename, "/", sizeof(filename));
144 util_strlcat(filename, val, sizeof(filename));
145 udev_device_add_devlink(udev_device, filename);
148 udev_device_set_devlink_priority(udev_device, atoi(val));
151 udev_device_set_event_timeout(udev_device, atoi(val));
154 udev_device_set_num_fake_partitions(udev_device, atoi(val));
157 udev_device_set_ignore_remove(udev_device, atoi(val));
160 udev_device_add_property_from_string(udev_device, val);
166 info(udev_device->udev, "device %p filled with db file data\n", udev_device);
170 static int device_read_uevent_file(struct udev_device *udev_device)
172 char filename[UTIL_PATH_SIZE];
174 char line[UTIL_LINE_SIZE];
178 util_strlcpy(filename, udev_device->syspath, sizeof(filename));
179 util_strlcat(filename, "/uevent", sizeof(filename));
180 f = fopen(filename, "r");
184 while (fgets(line, sizeof(line), f)) {
187 pos = strchr(line, '\n');
192 if (strncmp(line, "MAJOR=", 6) == 0)
193 maj = strtoull(&line[6], NULL, 10);
194 else if (strncmp(line, "MINOR=", 6) == 0)
195 min = strtoull(&line[6], NULL, 10);
197 udev_device_add_property_from_string(udev_device, line);
200 udev_device->devnum = makedev(maj, min);
206 static void device_load_info(struct udev_device *device)
208 device_read_uevent_file(device);
209 device_read_db(device);
210 device->info_loaded = 1;
213 void udev_device_set_info_loaded(struct udev_device *device)
215 device->info_loaded = 1;
218 struct udev_device *device_new(struct udev *udev)
220 struct udev_device *udev_device;
225 udev_device = malloc(sizeof(struct udev_device));
226 if (udev_device == NULL)
228 memset(udev_device, 0x00, sizeof(struct udev_device));
229 udev_device->refcount = 1;
230 udev_device->udev = udev;
231 udev_list_init(&udev_device->devlink_list);
232 udev_list_init(&udev_device->properties_list);
233 udev_list_init(&udev_device->attr_list);
234 info(udev_device->udev, "udev_device: %p created\n", udev_device);
239 * udev_device_new_from_syspath:
240 * @udev: udev library context
241 * @syspath: sys device path including sys directory
243 * Create new udev device, and fill in information from the sys
244 * device and the udev database entry. The sypath is the absolute
245 * path to the device, including the sys mount point.
247 * The initial refcount is 1, and needs to be decremented to
248 * release the ressources of the udev device.
250 * Returns: a new udev device, or #NULL, if it does not exist
252 struct udev_device *udev_device_new_from_syspath(struct udev *udev, const char *syspath)
256 char path[UTIL_PATH_SIZE];
259 struct udev_device *udev_device;
266 /* path starts in sys */
267 len = strlen(udev_get_sys_path(udev));
268 if (strncmp(syspath, udev_get_sys_path(udev), len) != 0) {
269 info(udev, "not in sys :%s\n", syspath);
273 /* path is not a root directory */
274 subdir = &syspath[len+1];
275 pos = strrchr(subdir, '/');
276 if (pos == NULL || pos < &subdir[2]) {
277 info(udev, "not a subdir :%s\n", syspath);
281 /* resolve possible symlink to real path */
282 util_strlcpy(path, syspath, sizeof(path));
283 util_resolve_sys_link(udev, path, sizeof(path));
285 /* try to resolve the silly block layout if needed */
286 if (strncmp(&path[len], "/block/", 7) == 0) {
287 char block[UTIL_PATH_SIZE];
288 char part[UTIL_PATH_SIZE];
290 util_strlcpy(block, path, sizeof(block));
291 pos = strrchr(block, '/');
294 util_strlcpy(part, pos, sizeof(part));
296 if (util_resolve_sys_link(udev, block, sizeof(block)) == 0) {
297 util_strlcpy(path, block, sizeof(path));
298 util_strlcat(path, part, sizeof(path));
302 /* path exists in sys */
303 if (strncmp(&syspath[len], "/devices/", 9) == 0 ||
304 strncmp(&syspath[len], "/class/", 7) == 0 ||
305 strncmp(&syspath[len], "/block/", 7) == 0) {
306 char file[UTIL_PATH_SIZE];
308 /* all "devices" require a "uevent" file */
309 util_strlcpy(file, path, sizeof(file));
310 util_strlcat(file, "/uevent", sizeof(file));
311 if (stat(file, &statbuf) != 0) {
312 info(udev, "not a device: %s\n", syspath);
316 /* everything else just needs to be a directory */
317 if (stat(path, &statbuf) != 0 || !S_ISDIR(statbuf.st_mode)) {
318 info(udev, "directory not found: %s\n", syspath);
323 udev_device = device_new(udev);
324 if (udev_device == NULL)
327 udev_device_set_syspath(udev_device, path);
328 info(udev, "device %p has devpath '%s'\n", udev_device, udev_device_get_devpath(udev_device));
333 struct udev_device *udev_device_new_from_devnum(struct udev *udev, char type, dev_t devnum)
335 char path[UTIL_PATH_SIZE];
336 const char *type_str;
337 struct udev_enumerate *udev_enumerate;
338 struct udev_list_entry *list_entry;
339 struct udev_device *device = NULL;
343 else if (type == 'c')
348 /* /sys/dev/{block,char}/<maj>:<min> link */
349 snprintf(path, sizeof(path), "%s/dev/%s/%u:%u", udev_get_sys_path(udev),
350 type_str, major(devnum), minor(devnum));
351 if (util_resolve_sys_link(udev, path, sizeof(path)) == 0)
352 return udev_device_new_from_syspath(udev, path);
354 udev_enumerate = udev_enumerate_new(udev);
355 if (udev_enumerate == NULL)
358 /* fallback to search sys devices for the major/minor */
360 udev_enumerate_add_match_subsystem(udev_enumerate, "block");
361 else if (type == 'c')
362 udev_enumerate_add_nomatch_subsystem(udev_enumerate, "block");
363 udev_enumerate_scan_devices(udev_enumerate);
364 udev_list_entry_foreach(list_entry, udev_enumerate_get_list_entry(udev_enumerate)) {
365 struct udev_device *device_loop;
367 device_loop = udev_device_new_from_syspath(udev, udev_list_entry_get_name(list_entry));
368 if (device_loop != NULL) {
369 if (udev_device_get_devnum(device_loop) == devnum) {
370 if (type == 'b' && strcmp(udev_device_get_subsystem(device_loop), "block") != 0)
372 if (type == 'c' && strcmp(udev_device_get_subsystem(device_loop), "block") == 0)
374 device = device_loop;
377 udev_device_unref(device_loop);
380 udev_enumerate_unref(udev_enumerate);
384 struct udev_device *udev_device_new_from_subsystem_sysname(struct udev *udev, const char *subsystem, const char *sysname)
387 char path_full[UTIL_PATH_SIZE];
391 sys_path_len = util_strlcpy(path_full, udev_get_sys_path(udev), sizeof(path_full));
392 path = &path_full[sys_path_len];
394 if (strcmp(subsystem, "subsystem") == 0) {
395 util_strlcpy(path, "/subsystem/", sizeof(path_full) - sys_path_len);
396 util_strlcat(path, sysname, sizeof(path_full) - sys_path_len);
397 if (stat(path_full, &statbuf) == 0)
400 util_strlcpy(path, "/bus/", sizeof(path_full) - sys_path_len);
401 util_strlcat(path, sysname, sizeof(path_full) - sys_path_len);
402 if (stat(path_full, &statbuf) == 0)
405 util_strlcpy(path, "/class/", sizeof(path_full) - sys_path_len);
406 util_strlcat(path, sysname, sizeof(path_full) - sys_path_len);
407 if (stat(path_full, &statbuf) == 0)
412 if (strcmp(subsystem, "module") == 0) {
413 util_strlcpy(path, "/module/", sizeof(path_full) - sys_path_len);
414 util_strlcat(path, sysname, sizeof(path_full) - sys_path_len);
415 if (stat(path_full, &statbuf) == 0)
420 if (strcmp(subsystem, "drivers") == 0) {
421 char subsys[UTIL_NAME_SIZE];
424 util_strlcpy(subsys, sysname, sizeof(subsys));
425 driver = strchr(subsys, ':');
426 if (driver != NULL) {
429 util_strlcpy(path, "/subsystem/", sizeof(path_full) - sys_path_len);
430 util_strlcat(path, subsys, sizeof(path_full) - sys_path_len);
431 util_strlcat(path, "/drivers/", sizeof(path_full) - sys_path_len);
432 util_strlcat(path, driver, sizeof(path_full) - sys_path_len);
433 if (stat(path_full, &statbuf) == 0)
436 util_strlcpy(path, "/bus/", sizeof(path_full) - sys_path_len);
437 util_strlcat(path, subsys, sizeof(path_full) - sys_path_len);
438 util_strlcat(path, "/drivers/", sizeof(path_full) - sys_path_len);
439 util_strlcat(path, driver, sizeof(path_full) - sys_path_len);
440 if (stat(path_full, &statbuf) == 0)
446 util_strlcpy(path, "/subsystem/", sizeof(path_full) - sys_path_len);
447 util_strlcat(path, subsystem, sizeof(path_full) - sys_path_len);
448 util_strlcat(path, "/devices/", sizeof(path_full) - sys_path_len);
449 util_strlcat(path, sysname, sizeof(path_full) - sys_path_len);
450 if (stat(path_full, &statbuf) == 0)
453 util_strlcpy(path, "/bus/", sizeof(path_full) - sys_path_len);
454 util_strlcat(path, subsystem, sizeof(path_full) - sys_path_len);
455 util_strlcat(path, "/devices/", sizeof(path_full) - sys_path_len);
456 util_strlcat(path, sysname, sizeof(path_full) - sys_path_len);
457 if (stat(path_full, &statbuf) == 0)
460 util_strlcpy(path, "/class/", sizeof(path_full) - sys_path_len);
461 util_strlcat(path, subsystem, sizeof(path_full) - sys_path_len);
462 util_strlcat(path, "/", sizeof(path_full) - sys_path_len);
463 util_strlcat(path, sysname, sizeof(path_full) - sys_path_len);
464 if (stat(path_full, &statbuf) == 0)
469 return udev_device_new_from_syspath(udev, path_full);
472 static struct udev_device *device_new_from_parent(struct udev_device *udev_device)
474 struct udev_device *udev_device_parent = NULL;
475 char path[UTIL_PATH_SIZE];
478 /* follow "device" link in deprecated sys layout */
479 if (strncmp(udev_device->devpath, "/class/", 7) == 0 ||
480 strncmp(udev_device->devpath, "/block/", 7) == 0) {
481 util_strlcpy(path, udev_device->syspath, sizeof(path));
482 util_strlcat(path, "/device", sizeof(path));
483 if (util_resolve_sys_link(udev_device->udev, path, sizeof(path)) == 0)
484 udev_device_parent = udev_device_new_from_syspath(udev_device->udev, path);
485 return udev_device_parent;
488 util_strlcpy(path, udev_device->syspath, sizeof(path));
489 subdir = &path[strlen(udev_get_sys_path(udev_device->udev))+1];
493 pos = strrchr(subdir, '/');
494 if (pos == NULL || pos < &subdir[2])
497 udev_device_parent = udev_device_new_from_syspath(udev_device->udev, path);
498 if (udev_device_parent != NULL)
499 return udev_device_parent;
504 struct udev_device *udev_device_get_parent(struct udev_device *udev_device)
506 if (udev_device == NULL)
509 if (udev_device->parent_device != NULL) {
510 info(udev_device->udev, "returning existing parent %p\n", udev_device->parent_device);
511 return udev_device->parent_device;
513 udev_device->parent_device = device_new_from_parent(udev_device);
514 return udev_device->parent_device;
517 struct udev_device *udev_device_get_parent_with_subsystem(struct udev_device *udev_device, const char *subsystem)
519 struct udev_device *parent;
521 parent = udev_device_get_parent(udev_device);
522 while (parent != NULL) {
523 const char *parent_subsystem;
525 parent_subsystem = udev_device_get_subsystem(parent);
526 if (parent_subsystem != NULL && strcmp(parent_subsystem, subsystem) == 0)
528 parent = udev_device_get_parent(parent);
534 * udev_device_get_udev:
535 * @udev_device: udev device
537 * Retrieve the udev library context the device was created with.
539 * Returns: the udev library context
541 struct udev *udev_device_get_udev(struct udev_device *udev_device)
543 if (udev_device == NULL)
545 return udev_device->udev;
550 * @udev_device: udev device
552 * Take a reference of a udev device.
554 * Returns: the passed udev device
556 struct udev_device *udev_device_ref(struct udev_device *udev_device)
558 if (udev_device == NULL)
560 udev_device->refcount++;
566 * @udev_device: udev device
568 * Drop a reference of a udev device. If the refcount reaches zero,
569 * the ressources of the device will be released.
572 void udev_device_unref(struct udev_device *udev_device)
574 if (udev_device == NULL)
576 udev_device->refcount--;
577 if (udev_device->refcount > 0)
579 if (udev_device->parent_device != NULL)
580 udev_device_unref(udev_device->parent_device);
581 free(udev_device->syspath);
582 free(udev_device->devnode);
583 free(udev_device->subsystem);
584 udev_list_cleanup(udev_device->udev, &udev_device->devlink_list);
585 udev_list_cleanup(udev_device->udev, &udev_device->properties_list);
586 free(udev_device->action);
587 free(udev_device->driver);
588 free(udev_device->devpath_old);
589 free(udev_device->physdevpath);
590 udev_list_cleanup(udev_device->udev, &udev_device->attr_list);
591 info(udev_device->udev, "udev_device: %p released\n", udev_device);
596 * udev_device_get_devpath:
597 * @udev_device: udev device
599 * Retrieve the kernel devpath value of the udev device. The path
600 * does not contain the sys mount point, and starts with a '/'.
602 * Returns: the devpath of the udev device
604 const char *udev_device_get_devpath(struct udev_device *udev_device)
606 if (udev_device == NULL)
608 return udev_device->devpath;
612 * udev_device_get_syspath:
613 * @udev_device: udev device
615 * Retrieve the sys path of the udev device. The path is an
616 * absolute path and starts with the sys mount point.
618 * Returns: the sys path of the udev device
620 const char *udev_device_get_syspath(struct udev_device *udev_device)
622 if (udev_device == NULL)
624 return udev_device->syspath;
627 const char *udev_device_get_sysname(struct udev_device *udev_device)
629 if (udev_device == NULL)
631 return udev_device->sysname;
635 * udev_device_get_devnode:
636 * @udev_device: udev device
638 * Retrieve the device node file name belonging to the udev device.
639 * The path is an absolute path, and starts with the device directory.
641 * Returns: the device node file name of the udev device, or #NULL if no device node exists
643 const char *udev_device_get_devnode(struct udev_device *udev_device)
645 if (udev_device == NULL)
647 if (!udev_device->info_loaded)
648 device_load_info(udev_device);
649 return udev_device->devnode;
653 * udev_device_get_subsystem:
654 * @udev_device: udev device
656 * Retrieve the subsystem string of the udev device. The string does not
659 * Returns: the subsystem name of the udev device, or #NULL if it can not be determined
661 const char *udev_device_get_subsystem(struct udev_device *udev_device)
663 char subsystem[UTIL_NAME_SIZE];
665 if (udev_device == NULL)
667 if (udev_device->subsystem != NULL)
668 return udev_device->subsystem;
670 /* read "subsytem" link */
671 if (util_get_sys_subsystem(udev_device->udev, udev_device->syspath, subsystem, sizeof(subsystem)) > 0) {
672 udev_device->subsystem = strdup(subsystem);
673 return udev_device->subsystem;
677 if (strncmp(udev_device->devpath, "/module/", 8) == 0) {
678 udev_device->subsystem = strdup("module");
679 return udev_device->subsystem;
681 if (strstr(udev_device->devpath, "/drivers/") != NULL) {
682 udev_device->subsystem = strdup("drivers");
683 return udev_device->subsystem;
685 if (strncmp(udev_device->devpath, "/subsystem/", 11) == 0 ||
686 strncmp(udev_device->devpath, "/class/", 7) == 0 ||
687 strncmp(udev_device->devpath, "/bus/", 5) == 0) {
688 udev_device->subsystem = strdup("subsystem");
689 return udev_device->subsystem;
695 * udev_device_get_devlinks_list_entry:
696 * @udev_device: udev device
698 * Retrieve the list of device links pointing to the device file of
699 * the udev device. The next list entry can be retrieved with
700 * udev_list_entry_next(), which returns #NULL if no more entries exist.
701 * The devlink path can be retrieved from the list entry by
702 * udev_list_entry_get_name(). The path is an absolute path, and starts with
703 * the device directory.
705 * Returns: the first entry of the device node link list
707 struct udev_list_entry *udev_device_get_devlinks_list_entry(struct udev_device *udev_device)
709 if (udev_device == NULL)
711 if (!udev_device->info_loaded)
712 device_load_info(udev_device);
713 return udev_list_get_entry(&udev_device->devlink_list);
717 * udev_device_get_properties_list_entry:
718 * @udev_device: udev device
720 * Retrieve the list of key/value device properties of the udev
721 * device. The next list entry can be retrieved with udev_list_entry_next(),
722 * which returns #NULL if no more entries exist. The property name
723 * can be retrieved from the list entry by udev_list_get_name(),
724 * the property value by udev_list_get_value().
726 * Returns: the first entry of the property list
728 struct udev_list_entry *udev_device_get_properties_list_entry(struct udev_device *udev_device)
730 if (udev_device == NULL)
732 if (!udev_device->info_loaded)
733 device_load_info(udev_device);
734 return udev_list_get_entry(&udev_device->properties_list);
737 const char *udev_device_get_driver(struct udev_device *udev_device)
739 char driver[UTIL_NAME_SIZE];
741 if (udev_device == NULL)
743 if (udev_device->driver != NULL)
744 return udev_device->driver;
745 if (util_get_sys_driver(udev_device->udev, udev_device->syspath, driver, sizeof(driver)) < 2)
747 udev_device->driver = strdup(driver);
748 return udev_device->driver;
751 dev_t udev_device_get_devnum(struct udev_device *udev_device)
753 if (udev_device == NULL)
754 return makedev(0, 0);
755 if (!udev_device->info_loaded)
756 device_load_info(udev_device);
757 return udev_device->devnum;
760 const char *udev_device_get_action(struct udev_device *udev_device)
762 if (udev_device == NULL)
764 return udev_device->action;
767 unsigned long long int udev_device_get_seqnum(struct udev_device *udev_device)
769 if (udev_device == NULL)
771 return udev_device->seqnum;
774 const char *udev_device_get_attr_value(struct udev_device *udev_device, const char *attr)
776 struct udev_list_entry *list_entry;
777 char path[UTIL_PATH_SIZE];
778 char value[UTIL_NAME_SIZE];
782 const char *val = NULL;
784 /* look for possibly already cached result */
785 udev_list_entry_foreach(list_entry, udev_list_get_entry(&udev_device->attr_list)) {
786 if (strcmp(udev_list_entry_get_name(list_entry), attr) == 0) {
787 info(udev_device->udev, "got '%s' (%s) from cache\n", attr, udev_list_entry_get_value(list_entry));
788 return udev_list_entry_get_value(list_entry);
792 util_strlcpy(path, udev_device_get_syspath(udev_device), sizeof(path));
793 util_strlcat(path, "/", sizeof(path));
794 util_strlcat(path, attr, sizeof(path));
796 if (lstat(path, &statbuf) != 0) {
797 info(udev_device->udev, "stat '%s' failed: %m\n", path);
801 if (S_ISLNK(statbuf.st_mode)) {
802 /* links return the last element of the target path */
803 char target[UTIL_NAME_SIZE];
807 len = readlink(path, target, sizeof(target));
810 pos = strrchr(target, '/');
813 info(udev_device->udev, "cache '%s' with link value '%s'\n", attr, pos);
814 list_entry = udev_list_entry_add(udev_device->udev, &udev_device->attr_list, attr, pos, 0, 0);
815 val = udev_list_entry_get_value(list_entry);
821 /* skip directories */
822 if (S_ISDIR(statbuf.st_mode))
825 /* skip non-readable files */
826 if ((statbuf.st_mode & S_IRUSR) == 0)
829 /* read attribute value */
830 fd = open(path, O_RDONLY);
832 info(udev_device->udev, "attribute '%s' can not be opened\n", path);
835 size = read(fd, value, sizeof(value));
839 if (size == sizeof(value))
842 /* got a valid value, store it in cache and return it */
844 util_remove_trailing_chars(value, '\n');
845 info(udev_device->udev, "'%s' has attribute value '%s'\n", path, value);
846 list_entry = udev_list_entry_add(udev_device->udev, &udev_device->attr_list, attr, value, 0, 0);
847 val = udev_list_entry_get_value(list_entry);
851 int udev_device_set_syspath(struct udev_device *udev_device, const char *syspath)
855 free(udev_device->syspath);
856 udev_device->syspath = strdup(syspath);
857 if (udev_device->syspath == NULL)
859 udev_device->devpath = &udev_device->syspath[strlen(udev_get_sys_path(udev_device->udev))];
860 udev_device_add_property(udev_device, "DEVPATH", udev_device->devpath);
861 pos = strrchr(udev_device->syspath, '/');
864 udev_device->sysname = &pos[1];
868 int udev_device_set_subsystem(struct udev_device *udev_device, const char *subsystem)
870 udev_device->subsystem = strdup(subsystem);
871 if (udev_device->subsystem == NULL)
873 udev_device_add_property(udev_device, "SUBSYSTEM", udev_device->subsystem);
877 int udev_device_set_devnode(struct udev_device *udev_device, const char *devnode)
879 udev_device->devnode = strdup(devnode);
880 if (udev_device->devnode == NULL)
882 udev_device_add_property(udev_device, "DEVNODE", udev_device->devnode);
886 int udev_device_add_devlink(struct udev_device *udev_device, const char *devlink)
888 char symlinks[UTIL_PATH_SIZE];
889 struct udev_list_entry *list_entry;
891 if (udev_list_entry_add(udev_device->udev, &udev_device->devlink_list, devlink, NULL, 1, 0) == NULL)
894 list_entry = udev_device_get_devlinks_list_entry(udev_device);
895 util_strlcpy(symlinks, udev_list_entry_get_name(list_entry), sizeof(symlinks));
896 udev_list_entry_foreach(list_entry, udev_list_entry_get_next(list_entry)) {
897 util_strlcat(symlinks, " ", sizeof(symlinks));
898 util_strlcat(symlinks, udev_list_entry_get_name(list_entry), sizeof(symlinks));
900 udev_device_add_property(udev_device, "DEVLINKS", symlinks);
905 int udev_device_add_property(struct udev_device *udev_device, const char *key, const char *value)
907 if (udev_list_entry_add(udev_device->udev, &udev_device->properties_list, key, value, 1, 0) == NULL)
912 int udev_device_add_property_from_string(struct udev_device *udev_device, const char *property)
914 char name[UTIL_PATH_SIZE];
917 strncpy(name, property, sizeof(name));
918 val = strchr(name, '=');
925 udev_device_add_property(udev_device, name, val);
929 int udev_device_set_action(struct udev_device *udev_device, const char *action)
931 udev_device_add_property(udev_device, "ACTION", action);
932 udev_device->action = strdup(action);
933 if (udev_device->action == NULL)
938 int udev_device_set_driver(struct udev_device *udev_device, const char *driver)
940 udev_device->driver = strdup(driver);
941 if (udev_device->driver == NULL)
946 const char *udev_device_get_devpath_old(struct udev_device *udev_device)
948 return udev_device->devpath_old;
951 int udev_device_set_devpath_old(struct udev_device *udev_device, const char *devpath_old)
953 udev_device->devpath_old = strdup(devpath_old);
954 if (udev_device->devpath_old == NULL)
959 const char *udev_device_get_physdevpath(struct udev_device *udev_device)
961 return udev_device->physdevpath;
964 int udev_device_set_physdevpath(struct udev_device *udev_device, const char *physdevpath)
966 udev_device->physdevpath = strdup(physdevpath);
967 if (udev_device->physdevpath == NULL)
972 int udev_device_get_timeout(struct udev_device *udev_device)
974 return udev_device->timeout;
977 int udev_device_set_timeout(struct udev_device *udev_device, int timeout)
979 udev_device->timeout = timeout;
982 int udev_device_get_event_timeout(struct udev_device *udev_device)
984 if (!udev_device->info_loaded)
985 device_load_info(udev_device);
986 return udev_device->event_timeout;
989 int udev_device_set_event_timeout(struct udev_device *udev_device, int event_timeout)
991 udev_device->event_timeout = event_timeout;
995 int udev_device_set_seqnum(struct udev_device *udev_device, unsigned long long int seqnum)
997 udev_device->seqnum = seqnum;
1001 int udev_device_set_devnum(struct udev_device *udev_device, dev_t devnum)
1003 udev_device->devnum = devnum;
1007 int udev_device_get_num_fake_partitions(struct udev_device *udev_device)
1009 if (!udev_device->info_loaded)
1010 device_load_info(udev_device);
1011 return udev_device->num_fake_partitions;
1014 int udev_device_set_num_fake_partitions(struct udev_device *udev_device, int num)
1016 udev_device->num_fake_partitions = num;
1020 int udev_device_get_devlink_priority(struct udev_device *udev_device)
1022 if (!udev_device->info_loaded)
1023 device_load_info(udev_device);
1024 return udev_device->devlink_priority;
1027 int udev_device_set_devlink_priority(struct udev_device *udev_device, int prio)
1029 udev_device->devlink_priority = prio;
1033 int udev_device_get_ignore_remove(struct udev_device *udev_device)
1035 if (!udev_device->info_loaded)
1036 device_load_info(udev_device);
1037 return udev_device->ignore_remove;
1040 int udev_device_set_ignore_remove(struct udev_device *udev_device, int ignore)
1042 udev_device->ignore_remove = ignore;