diff options
Diffstat (limited to 'udev/lib')
-rw-r--r-- | udev/lib/Makefile.am | 1 | ||||
-rw-r--r-- | udev/lib/exported_symbols | 12 | ||||
-rw-r--r-- | udev/lib/libudev-device.c | 125 | ||||
-rw-r--r-- | udev/lib/libudev-enumerate.c | 110 | ||||
-rw-r--r-- | udev/lib/libudev-private.h | 12 | ||||
-rw-r--r-- | udev/lib/libudev-util.c | 55 | ||||
-rw-r--r-- | udev/lib/libudev.h | 24 | ||||
-rw-r--r-- | udev/lib/test-libudev.c | 70 |
8 files changed, 197 insertions, 212 deletions
diff --git a/udev/lib/Makefile.am b/udev/lib/Makefile.am index 7329ab6c65..0386465e80 100644 --- a/udev/lib/Makefile.am +++ b/udev/lib/Makefile.am @@ -19,6 +19,7 @@ include_HEADERS =\ libudev_la_SOURCES =\ libudev-private.h \ libudev.c \ + libudev-list.c \ libudev-util.c \ libudev-device.c \ libudev-enumerate.c \ diff --git a/udev/lib/exported_symbols b/udev/lib/exported_symbols index 6b034d4594..e46aecbd37 100644 --- a/udev/lib/exported_symbols +++ b/udev/lib/exported_symbols @@ -9,6 +9,9 @@ udev_get_userdata udev_set_userdata udev_get_sys_path udev_get_dev_path +udev_list_get_next +udev_list_get_name +udev_list_get_value udev_device_new_from_syspath udev_device_new_from_devnum udev_device_get_parent @@ -20,14 +23,17 @@ udev_device_get_devpath udev_device_get_devnode udev_device_get_sysname udev_device_get_subsystem -udev_device_get_devlinks -udev_device_get_properties +udev_device_get_devlinks_list +udev_device_get_properties_list udev_device_get_action udev_device_get_driver udev_device_get_devnum udev_device_get_seqnum udev_device_get_attr_value -udev_enumerate_devices +udev_enumerate_new_from_subsystems +udev_enumerate_ref +udev_enumerate_unref +udev_enumerate_get_devices_list udev_monitor_new_from_socket udev_monitor_new_from_netlink udev_monitor_enable_receiving diff --git a/udev/lib/libudev-device.c b/udev/lib/libudev-device.c index 4a9c815064..a772dbbcf8 100644 --- a/udev/lib/libudev-device.c +++ b/udev/lib/libudev-device.c @@ -40,7 +40,7 @@ struct udev_device { char *devname; char *subsystem; struct list_head link_list; - struct list_head env_list; + struct list_head properties_list; char *action; char *driver; char *devpath_old; @@ -189,7 +189,7 @@ struct udev_device *device_init(struct udev *udev) udev_device->refcount = 1; udev_device->udev = udev; INIT_LIST_HEAD(&udev_device->link_list); - INIT_LIST_HEAD(&udev_device->env_list); + INIT_LIST_HEAD(&udev_device->properties_list); INIT_LIST_HEAD(&udev_device->attr_list); info(udev_device->udev, "udev_device: %p created\n", udev_device); return udev_device; @@ -247,6 +247,9 @@ 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_list *list; + struct udev_device *device = NULL; if (type == 'b') type_str = "block"; @@ -255,12 +258,32 @@ struct udev_device *udev_device_new_from_devnum(struct udev *udev, char type, de else return NULL; + /* /sys/dev/{block,char}/<maj>:<min> links */ snprintf(path, sizeof(path), "%s/dev/%s/%u:%u", udev_get_sys_path(udev), type_str, major(devnum), minor(devnum)); - if (util_resolve_sys_link(udev, path, sizeof(path)) < 0) - return NULL; + if (util_resolve_sys_link(udev, path, sizeof(path)) == 0) + return udev_device_new_from_syspath(udev, path); - return udev_device_new_from_syspath(udev, path); + /* search all sys devices for the major/minor */ + enumerate = udev_enumerate_new_from_subsystems(udev, NULL); + if (enumerate == NULL) + return NULL; + list = udev_enumerate_get_devices_list(enumerate); + while (list != NULL) { + struct udev_device *device_loop; + + device_loop = udev_device_new_from_syspath(udev, udev_list_get_name(list)); + if (device_loop != NULL) { + if (udev_device_get_devnum(device_loop) == devnum) { + device = device_loop; + break; + } + udev_device_unref(device_loop); + } + list = udev_list_get_next(list); + } + udev_enumerate_unref(enumerate); + return device; } static struct udev_device *device_new_from_parent(struct udev_device *udev_device) @@ -357,13 +380,13 @@ void udev_device_unref(struct udev_device *udev_device) free(udev_device->syspath); free(udev_device->devname); free(udev_device->subsystem); - util_name_list_cleanup(udev_device->udev, &udev_device->link_list); - util_name_list_cleanup(udev_device->udev, &udev_device->env_list); + list_cleanup(udev_device->udev, &udev_device->link_list); + list_cleanup(udev_device->udev, &udev_device->properties_list); free(udev_device->action); free(udev_device->driver); free(udev_device->devpath_old); free(udev_device->physdevpath); - util_name_list_cleanup(udev_device->udev, &udev_device->attr_list); + list_cleanup(udev_device->udev, &udev_device->attr_list); info(udev_device->udev, "udev_device: %p released\n", udev_device); free(udev_device); } @@ -466,64 +489,38 @@ const char *udev_device_get_subsystem(struct udev_device *udev_device) } /** - * udev_device_get_devlinks: + * udev_device_get_devlinks_list: * @udev_device: udev device - * @cb: function to be called for every device link found - * @data: data to be passed to the function * - * Retrieve the device links pointing to the device file of the - * udev device. For every device link, the passed function will be - * called with the device link string. - * The path is an absolute path, and starts with the device directory. - * If the function returns 1, remaning device links will be ignored. + * Retrieve the list of device links pointing to the device file of + * the udev device. The next list entry can be retrieved with + * udev_list_next(), which returns #NULL if no more entries exist. + * The devlink path can be retrieved from the list entry by + * udev_list_get_name(). The path is an absolute path, and starts with + * the device directory. * - * Returns: the number of device links passed to the caller, or a negative value on error + * Returns: the first entry of the device node link list **/ -int udev_device_get_devlinks(struct udev_device *udev_device, - int (*cb)(struct udev_device *udev_device, const char *value, void *data), - void *data) +struct udev_list *udev_device_get_devlinks_list(struct udev_device *udev_device) { - struct util_name_entry *name_loop; - int count = 0; - - if (udev_device == NULL) - return -1; - list_for_each_entry(name_loop, &udev_device->link_list, node) { - count++; - if (cb(udev_device, name_loop->name, data) != 0) - break; - } - return count; + return list_get_entry(&udev_device->link_list); } /** - * udev_device_get_properties: + * udev_device_get_properties_list: * @udev_device: udev device - * @cb: function to be called for every property found - * @data: data to be passed to the function * - * Retrieve the property key/value pairs belonging to the - * udev device. For every key/value pair, the passed function will be - * called. If the function returns 1, remaning properties will be - * ignored. + * Retrieve the list of key/value device properties of the udev + * device. The next list entry can be retrieved with udev_list_next(), + * which returns #NULL if no more entries exist. The property name + * can be retrieved from the list entry by udev_list_get_name(), + * the property value by udev_list_get_value(). * - * Returns: the number of properties passed to the caller, or a negative value on error + * Returns: the first entry of the property list **/ -int udev_device_get_properties(struct udev_device *udev_device, - int (*cb)(struct udev_device *udev_device, const char *key, const char *value, void *data), - void *data) +struct udev_list *udev_device_get_properties_list(struct udev_device *udev_device) { - struct util_name_entry *name_loop; - int count = 0; - - if (udev_device == NULL) - return -1; - list_for_each_entry(name_loop, &udev_device->env_list, node) { - count++; - if (cb(udev_device, name_loop->name, name_loop->value, data) != 0) - break; - } - return count; + return list_get_entry(&udev_device->properties_list); } const char *udev_device_get_driver(struct udev_device *udev_device) @@ -563,7 +560,7 @@ unsigned long long int udev_device_get_seqnum(struct udev_device *udev_device) const char *udev_device_get_attr_value(struct udev_device *udev_device, const char *attr) { - struct util_name_entry *name_loop; + struct udev_list *list; char path[UTIL_PATH_SIZE]; char value[UTIL_NAME_SIZE]; struct stat statbuf; @@ -572,11 +569,13 @@ const char *udev_device_get_attr_value(struct udev_device *udev_device, const ch const char *val = NULL; /* look for possibly already cached result */ - list_for_each_entry(name_loop, &udev_device->attr_list, node) { - if (strcmp(name_loop->name, attr) == 0) { - info(udev_device->udev, "'%s' in cache '%s'\n", attr, name_loop->value); - return name_loop->value; + list = list_get_entry(&udev_device->attr_list); + while (list != NULL) { + if (strcmp(udev_list_get_name(list), attr) == 0) { + info(udev_device->udev, "got '%s' (%s) from cache\n", attr, udev_list_get_value(list)); + return udev_list_get_name(list); } + list = udev_list_get_next(list); } util_strlcpy(path, udev_device_get_syspath(udev_device), sizeof(path)); @@ -601,7 +600,8 @@ const char *udev_device_get_attr_value(struct udev_device *udev_device, const ch if (pos != NULL) { pos = &pos[1]; info(udev_device->udev, "cache '%s' with link value '%s'\n", attr, pos); - val = util_name_list_add(udev_device->udev, &udev_device->attr_list, attr, pos, 0)->value; + list = list_insert(udev_device->udev, &udev_device->attr_list, attr, pos, 0); + val = udev_list_get_value(list); } } goto out; @@ -632,7 +632,8 @@ const char *udev_device_get_attr_value(struct udev_device *udev_device, const ch value[size] = '\0'; util_remove_trailing_chars(value, '\n'); info(udev_device->udev, "'%s' has attribute value '%s'\n", path, value); - val = util_name_list_add(udev_device->udev, &udev_device->attr_list, attr, value, 0)->value; + list = list_insert(udev_device->udev, &udev_device->attr_list, attr, value, 0); + val = udev_list_get_value(list); out: return val; } @@ -669,14 +670,14 @@ int device_set_devname(struct udev_device *udev_device, const char *devname) int device_add_devlink(struct udev_device *udev_device, const char *devlink) { - if (util_name_list_add(udev_device->udev, &udev_device->link_list, devlink, NULL, 0) == NULL) + if (list_insert(udev_device->udev, &udev_device->link_list, devlink, NULL, 0) == NULL) return -ENOMEM; return 0; } int device_add_property(struct udev_device *udev_device, const char *key, const char *value) { - if (util_name_list_add(udev_device->udev, &udev_device->env_list, key, value, 0) == NULL) + if (list_insert(udev_device->udev, &udev_device->properties_list, key, value, 0) == NULL) return -ENOMEM; return 0; } diff --git a/udev/lib/libudev-enumerate.c b/udev/lib/libudev-enumerate.c index ca5e30e4a1..80df8bd72d 100644 --- a/udev/lib/libudev-enumerate.c +++ b/udev/lib/libudev-enumerate.c @@ -29,6 +29,38 @@ #include "libudev.h" #include "libudev-private.h" +struct udev_enumerate { + struct udev *udev; + int refcount; + struct list_head devices_list; +}; + +struct udev_enumerate *udev_enumerate_ref(struct udev_enumerate *udev_enumerate) +{ + if (udev_enumerate == NULL) + return NULL; + udev_enumerate->refcount++; + return udev_enumerate; +} + +void udev_enumerate_unref(struct udev_enumerate *udev_enumerate) +{ + if (udev_enumerate == NULL) + return; + udev_enumerate->refcount--; + if (udev_enumerate->refcount > 0) + return; + list_cleanup(udev_enumerate->udev, &udev_enumerate->devices_list); + free(udev_enumerate); +} + +struct udev_list *udev_enumerate_get_devices_list(struct udev_enumerate *udev_enumerate) +{ + if (udev_enumerate == NULL) + return NULL; + return list_get_entry(&udev_enumerate->devices_list); +} + static int devices_scan_subsystem(struct udev *udev, const char *basedir, const char *subsystem, const char *subdir, struct list_head *device_list) @@ -55,7 +87,7 @@ static int devices_scan_subsystem(struct udev *udev, util_strlcat(syspath, "/", sizeof(syspath)); util_strlcat(syspath, dent->d_name, sizeof(syspath)); util_resolve_sys_link(udev, syspath, sizeof(syspath)); - util_name_list_add(udev, device_list, syspath, NULL, 1); + list_insert(udev, device_list, syspath, NULL, 1); } closedir(dir); return 0; @@ -108,72 +140,46 @@ static int devices_delay(struct udev *udev, const char *syspath) } /** - * udev_enumerate_devices: + * udev_enumerate_new_from_subsystems: * @udev: udev library context * @subsystem: the subsystem to enumerate - * @cb: function to be called for every device found - * @data: data to be passed to the function * - * Returns: the number of devices passed to the caller, or a negative value on error + * Returns: an enumeration context **/ -int udev_enumerate_devices(struct udev *udev, const char *subsystem, - int (*cb)(struct udev_device *udev_device, void *data), - void *data) +struct udev_enumerate *udev_enumerate_new_from_subsystems(struct udev *udev, const char *subsystem) { + struct udev_enumerate *udev_enumerate; char base[UTIL_PATH_SIZE]; struct stat statbuf; - struct list_head device_list; - struct util_name_entry *loop_device; - struct util_name_entry *tmp_device; - int cb_rc = 0; - int count = 0; + struct udev_list *list; + + if (udev == NULL) + return NULL; - INIT_LIST_HEAD(&device_list); + udev_enumerate = malloc(sizeof(struct udev_enumerate)); + if (udev_enumerate == NULL) + return NULL; + memset(udev_enumerate, 0x00, (sizeof(struct udev_enumerate))); + udev_enumerate->refcount = 1; + udev_enumerate->udev = udev; + INIT_LIST_HEAD(&udev_enumerate->devices_list); /* if we have /sys/subsystem/, forget all the old stuff */ util_strlcpy(base, udev_get_sys_path(udev), sizeof(base)); util_strlcat(base, "/subsystem", sizeof(base)); if (stat(base, &statbuf) == 0) { - devices_scan_subsystems(udev, "/subsystem", subsystem, "/devices", &device_list); + devices_scan_subsystems(udev, "/subsystem", subsystem, "/devices", &udev_enumerate->devices_list); } else { - devices_scan_subsystems(udev, "/bus", subsystem, "/devices", &device_list); - devices_scan_subsystems(udev, "/class", subsystem, NULL, &device_list); - } - - list_for_each_entry_safe(loop_device, tmp_device, &device_list, node) { - if (devices_delay(udev, loop_device->name)) - continue; - if (cb_rc == 0) { - struct udev_device *device; - - device = udev_device_new_from_syspath(udev, loop_device->name); - if (device != NULL) { - cb_rc = cb(device, data); - count++; - udev_device_unref(device); - } - } - list_del(&loop_device->node); - free(loop_device->name); - free(loop_device); + devices_scan_subsystems(udev, "/bus", subsystem, "/devices", &udev_enumerate->devices_list); + devices_scan_subsystems(udev, "/class", subsystem, NULL, &udev_enumerate->devices_list); } - /* handle remaining delayed devices */ - list_for_each_entry_safe(loop_device, tmp_device, &device_list, node) { - if (cb_rc == 0) { - struct udev_device *device; - - device = udev_device_new_from_syspath(udev, loop_device->name); - if (device != NULL) { - cb_rc = cb(device, data); - count++; - udev_device_unref(device); - } - } - list_del(&loop_device->node); - free(loop_device->name); - free(loop_device); + /* sort delayed devices to the end of the list */ + list = list_get_entry(&udev_enumerate->devices_list); + while (list != NULL) { + if (devices_delay(udev, udev_list_get_name(list))) + list_move_to_end(list, &udev_enumerate->devices_list); + list = udev_list_get_next(list); } - - return count; + return udev_enumerate; } diff --git a/udev/lib/libudev-private.h b/udev/lib/libudev-private.h index c8063d2d64..c80c940b1f 100644 --- a/udev/lib/libudev-private.h +++ b/udev/lib/libudev-private.h @@ -76,7 +76,7 @@ extern int device_set_devlink_priority(struct udev_device *udev_device, int prio extern int device_get_ignore_remove(struct udev_device *udev_device); extern int device_set_ignore_remove(struct udev_device *udev_device, int ignore); -/* udev_ctrl - daemon runtime setup */ +/* libudev-ctrl - daemon runtime setup */ struct udev_ctrl; extern struct udev_ctrl *udev_ctrl_new_from_socket(struct udev *udev, const char *socket_path); extern int udev_ctrl_enable_receiving(struct udev_ctrl *uctrl); @@ -102,6 +102,13 @@ extern int udev_ctrl_get_reload_rules(struct udev_ctrl_msg *ctrl_msg); extern const char *udev_ctrl_get_set_env(struct udev_ctrl_msg *ctrl_msg); extern int udev_ctrl_get_set_max_childs(struct udev_ctrl_msg *ctrl_msg); +/* libudev-list */ +extern struct udev_list *list_insert(struct udev *udev, struct list_head *name_list, + const char *name, const char *value, int sort); +extern struct udev_list *list_get_entry(struct list_head *list); +extern void list_move_to_end(struct udev_list *list_entry, struct list_head *list); +extern void list_cleanup(struct udev *udev, struct list_head *name_list); + /* libudev-utils */ #define UTIL_PATH_SIZE 1024 #define UTIL_LINE_SIZE 2048 @@ -115,9 +122,6 @@ struct util_name_entry { extern ssize_t util_get_sys_subsystem(struct udev *udev, const char *syspath, char *subsystem, size_t size); extern ssize_t util_get_sys_driver(struct udev *udev, const char *syspath, char *driver, size_t size); extern int util_resolve_sys_link(struct udev *udev, char *syspath, size_t size); -extern struct util_name_entry *util_name_list_add(struct udev *udev, struct list_head *name_list, - const char *name, const char *value, int sort); -extern void util_name_list_cleanup(struct udev *udev, struct list_head *name_list); extern int util_log_priority(const char *priority); extern size_t util_path_encode(char *s, size_t len); extern size_t util_path_decode(char *s); diff --git a/udev/lib/libudev-util.c b/udev/lib/libudev-util.c index aa544fea22..0e5bc37d43 100644 --- a/udev/lib/libudev-util.c +++ b/udev/lib/libudev-util.c @@ -97,61 +97,6 @@ int util_resolve_sys_link(struct udev *udev, char *syspath, size_t size) return 0; } -struct util_name_entry *util_name_list_add(struct udev *udev, struct list_head *name_list, - const char *name, const char *value, int sort) -{ - struct util_name_entry *name_loop; - struct util_name_entry *name_new; - - /* avoid duplicate entries */ - list_for_each_entry(name_loop, name_list, node) { - if (strcmp(name_loop->name, name) == 0) { - dbg(udev, "'%s' is already in the list\n", name); - return name_loop; - } - } - - if (sort) { - list_for_each_entry(name_loop, name_list, node) { - if (strcmp(name_loop->name, name) > 0) - break; - } - } - - name_new = malloc(sizeof(struct util_name_entry)); - if (name_new == NULL) - return NULL; - memset(name_new, 0x00, sizeof(struct util_name_entry)); - name_new->name = strdup(name); - if (name_new->name == NULL) { - free(name_new); - return NULL; - } - if (value != NULL) { - name_new->value = strdup(value); - if (name_new->value == NULL) { - free(name_new); - return NULL; - } - } - dbg(udev, "adding '%s=%s'\n", name_new->name, name_new->value); - list_add_tail(&name_new->node, &name_loop->node); - return name_new; -} - -void util_name_list_cleanup(struct udev *udev, struct list_head *name_list) -{ - struct util_name_entry *name_loop; - struct util_name_entry *name_tmp; - - list_for_each_entry_safe(name_loop, name_tmp, name_list, node) { - list_del(&name_loop->node); - free(name_loop->name); - free(name_loop->value); - free(name_loop); - } -} - int util_log_priority(const char *priority) { char *endptr; diff --git a/udev/lib/libudev.h b/udev/lib/libudev.h index e71f6b217a..014b53175b 100644 --- a/udev/lib/libudev.h +++ b/udev/lib/libudev.h @@ -29,7 +29,9 @@ #endif struct udev; +struct udev_list; struct udev_device; +struct udev_enumerate; struct udev_monitor; /* library context */ @@ -52,6 +54,11 @@ extern void udev_selinux_resetfscreatecon(struct udev *udev); extern void udev_selinux_setfscreatecon(struct udev *udev, const char *file, unsigned int mode); extern void udev_selinux_lsetfilecon(struct udev *udev, const char *file, unsigned int mode); +/* list iteration */ +extern struct udev_list *udev_list_get_next(struct udev_list *list_entry); +extern const char *udev_list_get_name(struct udev_list *list_entry); +extern const char *udev_list_get_value(struct udev_list *list_entry); + /* sys devices */ extern struct udev_device *udev_device_new_from_syspath(struct udev *udev, const char *syspath); extern struct udev_device *udev_device_new_from_devnum(struct udev *udev, char type, dev_t devnum); @@ -64,14 +71,8 @@ extern const char *udev_device_get_subsystem(struct udev_device *udev_device); extern const char *udev_device_get_syspath(struct udev_device *udev_device); extern const char *udev_device_get_sysname(struct udev_device *udev_device); extern const char *udev_device_get_devnode(struct udev_device *udev_device); -extern int udev_device_get_devlinks(struct udev_device *udev_device, - int (*cb)(struct udev_device *udev_device, - const char *value, void *data), - void *data); -extern int udev_device_get_properties(struct udev_device *udev_device, - int (*cb)(struct udev_device *udev_device, - const char *key, const char *value, void *data), - void *data); +extern struct udev_list *udev_device_get_devlinks_list(struct udev_device *udev_device); +extern struct udev_list *udev_device_get_properties_list(struct udev_device *udev_device); extern const char *udev_device_get_driver(struct udev_device *udev_device); extern dev_t udev_device_get_devnum(struct udev_device *udev_device); extern const char *udev_device_get_action(struct udev_device *udev_device); @@ -79,9 +80,10 @@ extern unsigned long long int udev_device_get_seqnum(struct udev_device *udev_de extern const char *udev_device_get_attr_value(struct udev_device *udev_device, const char *attr); /* sys enumeration */ -extern int udev_enumerate_devices(struct udev *udev, const char *subsystem, - int (*cb)(struct udev_device *udev_device, void *data), - void *data); +extern struct udev_enumerate *udev_enumerate_new_from_subsystems(struct udev *udev, const char *subsystem); +extern struct udev_enumerate *udev_enumerate_ref(struct udev_enumerate *udev_enumerate); +extern void udev_enumerate_unref(struct udev_enumerate *udev_enumerate); +extern struct udev_list *udev_enumerate_get_devices_list(struct udev_enumerate *udev_enumerate); /* udev and kernel device events */ extern struct udev_monitor *udev_monitor_new_from_socket(struct udev *udev, const char *socket_path); diff --git a/udev/lib/test-libudev.c b/udev/lib/test-libudev.c index 8afd294a2f..fed4350c09 100644 --- a/udev/lib/test-libudev.c +++ b/udev/lib/test-libudev.c @@ -37,22 +37,11 @@ static void log_fn(struct udev *udev, vprintf(format, args); } -static int print_devlinks_cb(struct udev_device *udev_device, const char *value, void *data) -{ - printf("link: '%s'\n", value); - return 0; -} - -static int print_properties_cb(struct udev_device *udev_device, const char *key, const char *value, void *data) -{ - printf("property: '%s=%s'\n", key, value); - return 0; -} - static void print_device(struct udev_device *device) { const char *str; int count; + struct udev_list *list; printf("*** device: %p ***\n", device); str = udev_device_get_action(device); @@ -67,10 +56,28 @@ static void print_device(struct udev_device *device) printf("driver: '%s'\n", str); str = udev_device_get_devnode(device); printf("devname: '%s'\n", str); - count = udev_device_get_devlinks(device, print_devlinks_cb, NULL); + + count = 0; + list = udev_device_get_devlinks_list(device); + while (list != NULL) { + printf("link: '%s'\n", udev_list_get_name(list)); + count++; + list = udev_list_get_next(list); + } printf("found %i links\n", count); - count = udev_device_get_properties(device, print_properties_cb, NULL); + + count = 0; + list = udev_device_get_properties_list(device); + while (list != NULL) { + printf("property: '%s=%s'\n", udev_list_get_name(list), udev_list_get_value(list)); + count++; + list = udev_list_get_next(list); + } printf("found %i properties\n", count); + + str = udev_device_get_attr_value(device, "dev"); + printf("attr{dev}: '%s'\n", str); + printf("\n"); } @@ -99,12 +106,14 @@ static int test_device_parents(struct udev *udev, const char *syspath) if (device == NULL) return -1; + printf("looking at parents\n"); device_parent = device; do { print_device(device_parent); device_parent = udev_device_get_parent(device_parent); } while (device_parent != NULL); + printf("looking at parents again\n"); device_parent = device; do { print_device(device_parent); @@ -129,20 +138,31 @@ static int test_device_devnum(struct udev *udev) return 0; } -static int devices_enum_cb(struct udev_device *device, void *data) -{ - printf("device: '%s' (%s) '%s'\n", - udev_device_get_syspath(device), - udev_device_get_subsystem(device), - udev_device_get_sysname(device)); - return 0; -} - static int test_enumerate(struct udev *udev, const char *subsystem) { - int count; + struct udev_enumerate *enumerate; + struct udev_list *list; + int count = 0; - count = udev_enumerate_devices(udev, subsystem, devices_enum_cb, NULL); + enumerate = udev_enumerate_new_from_subsystems(udev, NULL); + if (enumerate == NULL) + return -1; + list = udev_enumerate_get_devices_list(enumerate); + while (list != NULL) { + struct udev_device *device; + + device = udev_device_new_from_syspath(udev, udev_list_get_name(list)); + if (device != NULL) { + printf("device: '%s' (%s) '%s'\n", + udev_device_get_syspath(device), + udev_device_get_subsystem(device), + udev_device_get_sysname(device)); + udev_device_unref(device); + count++; + } + list = udev_list_get_next(list); + } + udev_enumerate_unref(enumerate); printf("found %i devices\n\n", count); return count; } |