diff options
author | Kay Sievers <kay.sievers@vrfy.org> | 2008-09-29 02:00:17 +0200 |
---|---|---|
committer | Kay Sievers <kay.sievers@vrfy.org> | 2008-09-29 02:00:17 +0200 |
commit | 438d4c3cd4b89381348f84ef9f8b8937814f8362 (patch) | |
tree | a7490a6be8c149fb785b80b817de2295dce9ccac | |
parent | b03e89cfbaa1fdd0c32bbd54f2b450e17014b522 (diff) |
libudev: enumerate - split new() and scan()
-rwxr-xr-x | test/udev-test.pl | 4 | ||||
-rw-r--r-- | udev/lib/exported_symbols | 5 | ||||
-rw-r--r-- | udev/lib/libudev-device.c | 16 | ||||
-rw-r--r-- | udev/lib/libudev-enumerate.c | 47 | ||||
-rw-r--r-- | udev/lib/libudev.h | 5 | ||||
-rw-r--r-- | udev/lib/test-libudev.c | 47 | ||||
-rw-r--r-- | udev/udevadm-info.c | 11 |
7 files changed, 75 insertions, 60 deletions
diff --git a/test/udev-test.pl b/test/udev-test.pl index 27ff2a7ce0..d7357d713d 100755 --- a/test/udev-test.pl +++ b/test/udev-test.pl @@ -1,6 +1,6 @@ #!/usr/bin/perl -# udev-test +# udev test # # Provides automated testing of the udev binary. # The whole test is self contained in this file, except the matching sysfs tree. @@ -14,7 +14,7 @@ # After creation and removal the result is checked against the # expected value and the result is printed. # -# Copyright (C) 2004-2006 Kay Sievers <kay.sievers@vrfy.org> +# Copyright (C) 2004-2008 Kay Sievers <kay.sievers@vrfy.org> # Copyright (C) 2004 Leann Ogasawara <ogasawara@osdl.org> use warnings; diff --git a/udev/lib/exported_symbols b/udev/lib/exported_symbols index 1877f32e89..21b433e9f5 100644 --- a/udev/lib/exported_symbols +++ b/udev/lib/exported_symbols @@ -31,8 +31,9 @@ udev_device_get_driver udev_device_get_devnum udev_device_get_seqnum udev_device_get_attr_value -udev_enumerate_new_from_devices -udev_enumerate_new_from_subsystems +udev_enumerate_new +udev_enumerate_scan_devices +udev_enumerate_scan_subsystems udev_enumerate_ref udev_enumerate_unref udev_enumerate_get_udev diff --git a/udev/lib/libudev-device.c b/udev/lib/libudev-device.c index 3437d69798..4d000292f2 100644 --- a/udev/lib/libudev-device.c +++ b/udev/lib/libudev-device.c @@ -295,7 +295,7 @@ struct udev_device *udev_device_new_from_devnum(struct udev *udev, char type, de { char path[UTIL_PATH_SIZE]; const char *type_str; - struct udev_enumerate *enumerate; + struct udev_enumerate *udev_enumerate; struct udev_list_entry *list_entry; struct udev_device *device = NULL; @@ -312,14 +312,16 @@ struct udev_device *udev_device_new_from_devnum(struct udev *udev, char type, de if (util_resolve_sys_link(udev, path, sizeof(path)) == 0) return udev_device_new_from_syspath(udev, path); + udev_enumerate = udev_enumerate_new(udev); + if (udev_enumerate == NULL) + return NULL; + /* fallback to search sys devices for the major/minor */ if (type == 'b') - enumerate = udev_enumerate_new_from_devices(udev, "block", NULL); + udev_enumerate_scan_devices(udev_enumerate, "block", NULL); else if (type == 'c') - enumerate = udev_enumerate_new_from_devices(udev, "!block", NULL); - if (enumerate == NULL) - return NULL; - udev_list_entry_foreach(list_entry, udev_enumerate_get_list_entry(enumerate)) { + udev_enumerate_scan_devices(udev_enumerate, "!block", NULL); + udev_list_entry_foreach(list_entry, udev_enumerate_get_list_entry(udev_enumerate)) { struct udev_device *device_loop; device_loop = udev_device_new_from_syspath(udev, udev_list_entry_get_name(list_entry)); @@ -338,7 +340,7 @@ struct udev_device *udev_device_new_from_devnum(struct udev *udev, char type, de udev_device_unref(device_loop); } } - udev_enumerate_unref(enumerate); + udev_enumerate_unref(udev_enumerate); return device; } diff --git a/udev/lib/libudev-enumerate.c b/udev/lib/libudev-enumerate.c index 272b2981fe..266164ae51 100644 --- a/udev/lib/libudev-enumerate.c +++ b/udev/lib/libudev-enumerate.c @@ -167,7 +167,13 @@ static int devices_delay(struct udev *udev, const char *syspath) return 0; } -static struct udev_enumerate *enumerate_new(struct udev *udev) +/** + * udev_enumerate_new: + * @udev: udev library context + * + * Returns: an enumeration context + **/ +struct udev_enumerate *udev_enumerate_new(struct udev *udev) { struct udev_enumerate *udev_enumerate; @@ -182,15 +188,15 @@ static struct udev_enumerate *enumerate_new(struct udev *udev) } /** - * udev_enumerate_new_from_devices: - * @udev: udev library context + * udev_enumerate_scan_devices: + * @udev_enumerate: udev enumeration context * @subsystem: the list of names of subsystems to look for devices * - * Returns: an enumeration context + * Returns: 0 on success. **/ -struct udev_enumerate *udev_enumerate_new_from_devices(struct udev *udev, const char *subsystem, ...) +int udev_enumerate_scan_devices(struct udev_enumerate *udev_enumerate, const char *subsystem, ...) { - struct udev_enumerate *udev_enumerate; + struct udev *udev = udev_enumerate_get_udev(udev_enumerate); va_list vargs; const char *arg; char base[UTIL_PATH_SIZE]; @@ -199,12 +205,8 @@ struct udev_enumerate *udev_enumerate_new_from_devices(struct udev *udev, const struct list_node subsystem_exclude_list; struct udev_list_entry *list_entry; - if (udev == NULL) - return NULL; - - udev_enumerate = enumerate_new(udev); if (udev_enumerate == NULL) - return NULL; + return -EINVAL; va_start(vargs, subsystem); list_init(&subsystem_include_list); @@ -247,10 +249,11 @@ struct udev_enumerate *udev_enumerate_new_from_devices(struct udev *udev, const int exclude_block = (udev_list_entry_get_by_name(exclude_list, "block") != NULL); if (include_block && !exclude_block) { - info(udev, "searching '/block/*/*' dir\n"); + info(udev, "searching '/block/*' dir\n"); /* scan disks */ devices_scan_subsystem(udev, "/block", NULL, NULL, &udev_enumerate->devices_list); /* scan partitions */ + info(udev, "searching '/block/*/*' dir\n"); devices_scan_subsystems(udev, "/block", NULL, NULL, NULL, &udev_enumerate->devices_list); @@ -266,22 +269,24 @@ struct udev_enumerate *udev_enumerate_new_from_devices(struct udev *udev, const if (devices_delay(udev, udev_list_entry_get_name(list_entry))) list_entry_move_to_end(list_entry); } - return udev_enumerate; + return 0; } -struct udev_enumerate *udev_enumerate_new_from_subsystems(struct udev *udev) +/** + * udev_enumerate_scan_subsystems: + * @udev_enumerate: udev enumeration context + * + * Returns: 0 on success. + **/ +int udev_enumerate_scan_subsystems(struct udev_enumerate *udev_enumerate) { - struct udev_enumerate *udev_enumerate; + struct udev *udev = udev_enumerate_get_udev(udev_enumerate); char base[UTIL_PATH_SIZE]; struct stat statbuf; const char *subsysdir; - if (udev == NULL) - return NULL; - - udev_enumerate = enumerate_new(udev); if (udev_enumerate == NULL) - return NULL; + return -EINVAL; util_strlcpy(base, udev_get_sys_path(udev), sizeof(base)); util_strlcat(base, "/subsystem", sizeof(base)); @@ -295,5 +300,5 @@ struct udev_enumerate *udev_enumerate_new_from_subsystems(struct udev *udev) devices_scan_subsystems(udev, subsysdir, "/drivers", NULL, NULL, &udev_enumerate->devices_list); - return udev_enumerate; + return 0; } diff --git a/udev/lib/libudev.h b/udev/lib/libudev.h index 29c4a47e51..427fed7f61 100644 --- a/udev/lib/libudev.h +++ b/udev/lib/libudev.h @@ -94,11 +94,12 @@ extern struct udev_device *udev_monitor_receive_device(struct udev_monitor *udev /* sys enumeration */ struct udev_enumerate; -extern struct udev_enumerate *udev_enumerate_new_from_devices(struct udev *udev, const char *subsystem, ...); -extern struct udev_enumerate *udev_enumerate_new_from_subsystems(struct udev *udev); +extern struct udev_enumerate *udev_enumerate_new(struct udev *udev); extern struct udev_enumerate *udev_enumerate_ref(struct udev_enumerate *udev_enumerate); extern struct udev *udev_enumerate_get_udev(struct udev_enumerate *udev_enumerate); extern void udev_enumerate_unref(struct udev_enumerate *udev_enumerate); +extern int udev_enumerate_scan_devices(struct udev_enumerate *udev_enumerate, const char *subsystem, ...); +extern int udev_enumerate_scan_subsystems(struct udev_enumerate *udev_enumerate); extern struct udev_list_entry *udev_enumerate_get_list_entry(struct udev_enumerate *udev_enumerate); #endif diff --git a/udev/lib/test-libudev.c b/udev/lib/test-libudev.c index 8ef7a6e3bd..0f45413d50 100644 --- a/udev/lib/test-libudev.c +++ b/udev/lib/test-libudev.c @@ -242,7 +242,7 @@ int main(int argc, char *argv[], char *envp[]) { "version", 0, NULL, 'V' }, {} }; - struct udev_enumerate *enumerate; + struct udev_enumerate *udev_enumerate; const char *syspath = "/devices/virtual/mem/null"; const char *subsystem = NULL; const char *socket = "@/org/kernel/udev/monitor"; @@ -306,39 +306,44 @@ int main(int argc, char *argv[], char *envp[]) test_device_parents(udev, syspath); printf("enumerate '%s'\n", subsystem == NULL ? "<all>" : subsystem); - enumerate = udev_enumerate_new_from_devices(udev, subsystem, NULL); - if (enumerate == NULL) + udev_enumerate = udev_enumerate_new(udev); + if (udev_enumerate == NULL) return -1; - test_enumerate_print_list(enumerate); - udev_enumerate_unref(enumerate); + udev_enumerate_scan_devices(udev_enumerate, subsystem, NULL); + test_enumerate_print_list(udev_enumerate); + udev_enumerate_unref(udev_enumerate); printf("enumerate 'block'\n"); - enumerate = udev_enumerate_new_from_devices(udev, "block", NULL); - if (enumerate == NULL) + udev_enumerate = udev_enumerate_new(udev); + if (udev_enumerate == NULL) return -1; - test_enumerate_print_list(enumerate); - udev_enumerate_unref(enumerate); + udev_enumerate_scan_devices(udev_enumerate, "block", NULL); + test_enumerate_print_list(udev_enumerate); + udev_enumerate_unref(udev_enumerate); printf("enumerate '!block'\n"); - enumerate = udev_enumerate_new_from_devices(udev, "!block", NULL); - if (enumerate == NULL) + udev_enumerate = udev_enumerate_new(udev); + if (udev_enumerate == NULL) return -1; - test_enumerate_print_list(enumerate); - udev_enumerate_unref(enumerate); + udev_enumerate_scan_devices(udev_enumerate, "!block", NULL); + test_enumerate_print_list(udev_enumerate); + udev_enumerate_unref(udev_enumerate); printf("enumerate 'pci, mem, vc'\n"); - enumerate = udev_enumerate_new_from_devices(udev, "pci", "mem", "vc", NULL); - if (enumerate == NULL) + udev_enumerate = udev_enumerate_new(udev); + if (udev_enumerate == NULL) return -1; - test_enumerate_print_list(enumerate); - udev_enumerate_unref(enumerate); + udev_enumerate_scan_devices(udev_enumerate, "pci", "mem", "vc", NULL); + test_enumerate_print_list(udev_enumerate); + udev_enumerate_unref(udev_enumerate); printf("enumerate 'subsystem'\n"); - enumerate = udev_enumerate_new_from_subsystems(udev); - if (enumerate == NULL) + udev_enumerate = udev_enumerate_new(udev); + if (udev_enumerate == NULL) return -1; - test_enumerate_print_list(enumerate); - udev_enumerate_unref(enumerate); + udev_enumerate_scan_subsystems(udev_enumerate); + test_enumerate_print_list(udev_enumerate); + udev_enumerate_unref(udev_enumerate); test_monitor(udev, socket); out: diff --git a/udev/udevadm-info.c b/udev/udevadm-info.c index e470ff624d..0a774b057f 100644 --- a/udev/udevadm-info.c +++ b/udev/udevadm-info.c @@ -183,13 +183,14 @@ static int stat_device(const char *name, int export, const char *prefix) static int export_devices(struct udev *udev) { - struct udev_enumerate *enumerate; + struct udev_enumerate *udev_enumerate; struct udev_list_entry *list_entry; - enumerate = udev_enumerate_new_from_devices(udev, NULL); - if (enumerate == NULL) + udev_enumerate = udev_enumerate_new(udev); + if (udev_enumerate == NULL) return -1; - udev_list_entry_foreach(list_entry, udev_enumerate_get_list_entry(enumerate)) { + udev_enumerate_scan_devices(udev_enumerate, NULL); + udev_list_entry_foreach(list_entry, udev_enumerate_get_list_entry(udev_enumerate)) { struct udev_device *device; device = udev_device_new_from_syspath(udev, udev_list_entry_get_name(list_entry)); @@ -199,7 +200,7 @@ static int export_devices(struct udev *udev) udev_device_unref(device); } } - udev_enumerate_unref(enumerate); + udev_enumerate_unref(udev_enumerate); return 0; } |