diff options
Diffstat (limited to 'udev/lib')
-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 |
5 files changed, 67 insertions, 53 deletions
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: |