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;
+ dev_t devnum;
int count;
+ struct udev_list_entry *list_entry;
printf("*** device: %p ***\n", device);
str = udev_device_get_action(device);
- printf("action: '%s'\n", str);
+ if (str != NULL)
+ printf("action: '%s'\n", str);
+
str = udev_device_get_syspath(device);
printf("syspath: '%s'\n", str);
+
str = udev_device_get_devpath(device);
printf("devpath: '%s'\n", str);
+
str = udev_device_get_subsystem(device);
- printf("subsystem: '%s'\n", str);
+ if (str != NULL)
+ printf("subsystem: '%s'\n", str);
+
str = udev_device_get_driver(device);
- printf("driver: '%s'\n", str);
+ if (str != NULL)
+ 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);
- printf("found %i links\n", count);
- count = udev_device_get_properties(device, print_properties_cb, NULL);
- printf("found %i properties\n", count);
+ if (str != NULL)
+ printf("devname: '%s'\n", str);
+
+ devnum = udev_device_get_devnum(device);
+ if (major(devnum) > 0)
+ printf("devnum: %u:%u\n", major(devnum), minor(devnum));
+
+ count = 0;
+ list_entry = udev_device_get_devlinks_list_entry(device);
+ while (list_entry != NULL) {
+ printf("link: '%s'\n", udev_list_entry_get_name(list_entry));
+ count++;
+ list_entry = udev_list_entry_get_next(list_entry);
+ }
+ if (count > 0)
+ printf("found %i links\n", count);
+
+ count = 0;
+ list_entry = udev_device_get_properties_list_entry(device);
+ while (list_entry != NULL) {
+ printf("property: '%s=%s'\n",
+ udev_list_entry_get_name(list_entry),
+ udev_list_entry_get_value(list_entry));
+ count++;
+ list_entry = udev_list_entry_get_next(list_entry);
+ }
+ if (count > 0)
+ printf("found %i properties\n", count);
+
+ str = udev_device_get_attr_value(device, "dev");
+ if (str != NULL)
+ printf("attr{dev}: '%s'\n", str);
+
printf("\n");
}
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);
return 0;
}
-static int devices_enum_cb(struct udev_device *device, void *data)
+static int test_enumerate_print_list(struct udev_enumerate *enumerate)
{
- printf("device: '%s' (%s) '%s'\n",
- udev_device_get_syspath(device),
- udev_device_get_subsystem(device),
- udev_device_get_sysname(device));
- return 0;
-}
+ struct udev_list_entry *list_entry;
+ int count = 0;
-static int test_enumerate(struct udev *udev, const char *subsystem)
-{
- int count;
+ udev_list_entry_foreach(list_entry, udev_enumerate_get_list_entry(enumerate)) {
+ struct udev_device *device;
- count = udev_enumerate_devices(udev, subsystem, devices_enum_cb, NULL);
+ device = udev_device_new_from_syspath(udev_enumerate_get_udev(enumerate),
+ udev_list_entry_get_name(list_entry));
+ 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++;
+ }
+ }
printf("found %i devices\n\n", count);
return count;
}
{ "version", 0, NULL, 'V' },
{}
};
+ struct udev_enumerate *enumerate;
const char *syspath = "/devices/virtual/mem/null";
const char *subsystem = NULL;
const char *socket = "@/org/kernel/udev/monitor";
test_device(udev, syspath);
test_device_devnum(udev);
test_device_parents(udev, syspath);
- test_enumerate(udev, subsystem);
+
+ printf("enumerate '%s'\n", subsystem == NULL ? "<all>" : subsystem);
+ enumerate = udev_enumerate_new_from_devices(udev, subsystem, NULL);
+ if (enumerate == NULL)
+ return -1;
+ test_enumerate_print_list(enumerate);
+ udev_enumerate_unref(enumerate);
+
+ printf("enumerate 'block'\n");
+ enumerate = udev_enumerate_new_from_devices(udev, "block", NULL);
+ if (enumerate == NULL)
+ return -1;
+ test_enumerate_print_list(enumerate);
+ udev_enumerate_unref(enumerate);
+
+ printf("enumerate '!block'\n");
+ enumerate = udev_enumerate_new_from_devices(udev, "!block", NULL);
+ if (enumerate == NULL)
+ return -1;
+ test_enumerate_print_list(enumerate);
+ udev_enumerate_unref(enumerate);
+
+ printf("enumerate 'pci, mem, vc'\n");
+ enumerate = udev_enumerate_new_from_devices(udev, "pci", "mem", "vc", NULL);
+ if (enumerate == NULL)
+ return -1;
+ test_enumerate_print_list(enumerate);
+ udev_enumerate_unref(enumerate);
+
test_monitor(udev, socket);
out:
udev_unref(udev);