/*
* libudev - interface to udev device information
*
- * Copyright (C) 2008-2009 Kay Sievers <kay.sievers@vrfy.org>
+ * Copyright (C) 2008-2010 Kay Sievers <kay.sievers@vrfy.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
util_strscpy(path, sizeof(path), syspath);
util_resolve_sys_link(udev, path, sizeof(path));
- /* try to resolve the silly block layout if needed */
- if (strncmp(&path[len], "/block/", 7) == 0) {
- char block[UTIL_PATH_SIZE];
- char part[UTIL_PATH_SIZE];
-
- util_strscpy(block, sizeof(block), path);
- pos = strrchr(block, '/');
- if (pos == NULL)
- return NULL;
- util_strscpy(part, sizeof(part), pos);
- pos[0] = '\0';
- if (util_resolve_sys_link(udev, block, sizeof(block)) == 0)
- util_strscpyl(path, sizeof(path), block, part, NULL);
- }
-
- /* path exists in sys */
- if (strncmp(&syspath[len], "/devices/", 9) == 0 ||
- strncmp(&syspath[len], "/class/", 7) == 0 ||
- strncmp(&syspath[len], "/block/", 7) == 0) {
+ if (strncmp(&syspath[len], "/devices/", 9) == 0) {
char file[UTIL_PATH_SIZE];
/* all "devices" require a "uevent" file */
{
char path[UTIL_PATH_SIZE];
const char *type_str;
- struct udev_enumerate *udev_enumerate;
- struct udev_list_entry *list_entry;
- struct udev_device *device = NULL;
if (type == 'b')
type_str = "block";
else
return NULL;
- /* /sys/dev/{block,char}/<maj>:<min> link */
- 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 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')
- udev_enumerate_add_match_subsystem(udev_enumerate, "block");
- else if (type == 'c')
- udev_enumerate_add_nomatch_subsystem(udev_enumerate, "block");
- udev_enumerate_scan_devices(udev_enumerate);
- 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));
- if (device_loop != NULL) {
- if (udev_device_get_devnum(device_loop) == devnum) {
- if (type == 'b' && strcmp(udev_device_get_subsystem(device_loop), "block") != 0)
- continue;
- if (type == 'c' && strcmp(udev_device_get_subsystem(device_loop), "block") == 0)
- continue;
- device = device_loop;
- break;
- }
- udev_device_unref(device_loop);
- }
- }
- udev_enumerate_unref(udev_enumerate);
- return device;
+ /* use /sys/dev/{block,char}/<maj>:<min> link */
+ snprintf(path, sizeof(path), "%s/dev/%s/%u:%u",
+ udev_get_sys_path(udev), type_str, major(devnum), minor(devnum));
+ return udev_device_new_from_syspath(udev, path);
}
/**
char path[UTIL_PATH_SIZE];
const char *subdir;
- /* follow "device" link in deprecated sys layout */
- if (strncmp(udev_device->devpath, "/class/", 7) == 0 ||
- strncmp(udev_device->devpath, "/block/", 7) == 0) {
- util_strscpyl(path, sizeof(path), udev_device->syspath, "/device", NULL);
- if (util_resolve_sys_link(udev_device->udev, path, sizeof(path)) == 0) {
- udev_device_parent = udev_device_new_from_syspath(udev_device->udev, path);
- if (udev_device_parent != NULL)
- return udev_device_parent;
- }
- }
-
util_strscpy(path, sizeof(path), udev_device->syspath);
subdir = &path[strlen(udev_get_sys_path(udev_device->udev))+1];
- while (1) {
+ for (;;) {
char *pos;
pos = strrchr(subdir, '/');
* value, and fill in information from the sys device and the udev
* database entry.
*
+ * If devtype is #NULL, only subsystem is checked, and any devtype will
+ * match.
+ *
* The returned the device is not referenced. It is attached to the
* child device, and will be cleaned up when the child device
* is cleaned up.
if (list_entry == NULL)
return -ENOMEM;
if (unique)
- udev_list_entry_set_flag(list_entry, 1);
+ udev_list_entry_set_flags(list_entry, 1);
return 0;
}
struct udev_list_entry *udev_device_add_property_from_string(struct udev_device *udev_device, const char *property)
{
- char name[UTIL_PATH_SIZE];
+ char name[UTIL_LINE_SIZE];
char *val;
util_strscpy(name, sizeof(name), property);
l = util_strpcpyl(&s, l, key, "=", udev_list_entry_get_value(list_entry), NULL);
if (l == 0)
return -EINVAL;
+ /* advance past the trailing '\0' that util_strpcpyl() guarantees */
s++;
+ l--;
}
udev_device->envp[i] = NULL;
udev_device->monitor_buf_len = s - udev_device->monitor_buf;