#!/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.
# 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;
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
{
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;
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));
udev_device_unref(device_loop);
}
}
- udev_enumerate_unref(enumerate);
+ udev_enumerate_unref(udev_enumerate);
return device;
}
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;
}
/**
- * 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];
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);
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);
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));
devices_scan_subsystems(udev, subsysdir, "/drivers",
NULL, NULL,
&udev_enumerate->devices_list);
- return udev_enumerate;
+ return 0;
}
/* 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
{ "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";
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:
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));
udev_device_unref(device);
}
}
- udev_enumerate_unref(enumerate);
+ udev_enumerate_unref(udev_enumerate);
return 0;
}