chiark
/
gitweb
/
~ianmdlvl
/
elogind.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
udev: export udev_device_new_from_device_id()
[elogind.git]
/
src
/
libudev
/
libudev-enumerate.c
diff --git
a/src/libudev/libudev-enumerate.c
b/src/libudev/libudev-enumerate.c
index 7b9a732ce6e88d2eddd41bfaac3e02372a10d18d..f0305a488b9f33f573a1e9c8df5cee7eedee4d90 100644
(file)
--- a/
src/libudev/libudev-enumerate.c
+++ b/
src/libudev/libudev-enumerate.c
@@
-65,7
+65,9
@@
struct udev_enumerate {
* udev_enumerate_new:
* @udev: udev library context
*
* udev_enumerate_new:
* @udev: udev library context
*
- * Returns: an enumeration context
+ * Create an enumeration context to scan /sys.
+ *
+ * Returns: an enumeration context.
**/
_public_ struct udev_enumerate *udev_enumerate_new(struct udev *udev)
{
**/
_public_ struct udev_enumerate *udev_enumerate_new(struct udev *udev)
{
@@
-109,16
+111,18
@@
_public_ struct udev_enumerate *udev_enumerate_ref(struct udev_enumerate *udev_e
*
* Drop a reference of an enumeration context. If the refcount reaches zero,
* all resources of the enumeration context will be released.
*
* Drop a reference of an enumeration context. If the refcount reaches zero,
* all resources of the enumeration context will be released.
+ *
+ * Returns: the passed enumeration context if it has still an active reference, or #NULL otherwise.
**/
**/
-_public_
void
udev_enumerate_unref(struct udev_enumerate *udev_enumerate)
+_public_
struct udev_enumerate *
udev_enumerate_unref(struct udev_enumerate *udev_enumerate)
{
unsigned int i;
if (udev_enumerate == NULL)
{
unsigned int i;
if (udev_enumerate == NULL)
- return;
+ return
NULL
;
udev_enumerate->refcount--;
if (udev_enumerate->refcount > 0)
udev_enumerate->refcount--;
if (udev_enumerate->refcount > 0)
- return;
+ return
udev_enumerate
;
udev_list_cleanup(&udev_enumerate->sysattr_match_list);
udev_list_cleanup(&udev_enumerate->sysattr_nomatch_list);
udev_list_cleanup(&udev_enumerate->subsystem_match_list);
udev_list_cleanup(&udev_enumerate->sysattr_match_list);
udev_list_cleanup(&udev_enumerate->sysattr_nomatch_list);
udev_list_cleanup(&udev_enumerate->subsystem_match_list);
@@
-132,13
+136,16
@@
_public_ void udev_enumerate_unref(struct udev_enumerate *udev_enumerate)
free(udev_enumerate->devices[i].syspath);
free(udev_enumerate->devices);
free(udev_enumerate);
free(udev_enumerate->devices[i].syspath);
free(udev_enumerate->devices);
free(udev_enumerate);
+ return NULL;
}
/**
* udev_enumerate_get_udev:
* @udev_enumerate: context
*
}
/**
* udev_enumerate_get_udev:
* @udev_enumerate: context
*
- * Returns: the udev library context.
+ * Get the udev library context.
+ *
+ * Returns: a pointer to the context.
*/
_public_ struct udev *udev_enumerate_get_udev(struct udev_enumerate *udev_enumerate)
{
*/
_public_ struct udev *udev_enumerate_get_udev(struct udev_enumerate *udev_enumerate)
{
@@
-204,12
+211,10
@@
static bool devices_delay_end(struct udev *udev, const char *syspath)
"/block/dm-",
NULL
};
"/block/dm-",
NULL
};
- size_t len;
int i;
int i;
- len = strlen(udev_get_sys_path(udev));
for (i = 0; delay_device_list[i] != NULL; i++) {
for (i = 0; delay_device_list[i] != NULL; i++) {
- if (strstr(
&syspath[len]
, delay_device_list[i]) != NULL)
+ if (strstr(
syspath + strlen("/sys")
, delay_device_list[i]) != NULL)
return true;
}
return false;
return true;
}
return false;
@@
-234,7
+239,7
@@
static size_t devices_delay_later(struct udev *udev, const char *syspath)
c += 11;
c += strcspn(c, "/");
c += 11;
c += strcspn(c, "/");
- if (st
rncmp(c, "/controlC", 9) == 0
)
+ if (st
artswith(c, "/controlC")
)
return c - syspath + 1;
}
return c - syspath + 1;
}
@@
-245,7
+250,9
@@
static size_t devices_delay_later(struct udev *udev, const char *syspath)
* udev_enumerate_get_list_entry:
* @udev_enumerate: context
*
* udev_enumerate_get_list_entry:
* @udev_enumerate: context
*
- * Returns: the first entry of the sorted list of device paths.
+ * Get the first entry of the sorted list of device paths.
+ *
+ * Returns: a udev_list_entry.
*/
_public_ struct udev_list_entry *udev_enumerate_get_list_entry(struct udev_enumerate *udev_enumerate)
{
*/
_public_ struct udev_list_entry *udev_enumerate_get_list_entry(struct udev_enumerate *udev_enumerate)
{
@@
-323,6
+330,8
@@
_public_ struct udev_list_entry *udev_enumerate_get_list_entry(struct udev_enume
* @udev_enumerate: context
* @subsystem: filter for a subsystem of the device to include in the list
*
* @udev_enumerate: context
* @subsystem: filter for a subsystem of the device to include in the list
*
+ * Match only devices belonging to a certain kernel subsystem.
+ *
* Returns: 0 on success, otherwise a negative error value.
*/
_public_ int udev_enumerate_add_match_subsystem(struct udev_enumerate *udev_enumerate, const char *subsystem)
* Returns: 0 on success, otherwise a negative error value.
*/
_public_ int udev_enumerate_add_match_subsystem(struct udev_enumerate *udev_enumerate, const char *subsystem)
@@
-341,6
+350,8
@@
_public_ int udev_enumerate_add_match_subsystem(struct udev_enumerate *udev_enum
* @udev_enumerate: context
* @subsystem: filter for a subsystem of the device to exclude from the list
*
* @udev_enumerate: context
* @subsystem: filter for a subsystem of the device to exclude from the list
*
+ * Match only devices not belonging to a certain kernel subsystem.
+ *
* Returns: 0 on success, otherwise a negative error value.
*/
_public_ int udev_enumerate_add_nomatch_subsystem(struct udev_enumerate *udev_enumerate, const char *subsystem)
* Returns: 0 on success, otherwise a negative error value.
*/
_public_ int udev_enumerate_add_nomatch_subsystem(struct udev_enumerate *udev_enumerate, const char *subsystem)
@@
-360,6
+371,8
@@
_public_ int udev_enumerate_add_nomatch_subsystem(struct udev_enumerate *udev_en
* @sysattr: filter for a sys attribute at the device to include in the list
* @value: optional value of the sys attribute
*
* @sysattr: filter for a sys attribute at the device to include in the list
* @value: optional value of the sys attribute
*
+ * Match only devices with a certain /sys device attribute.
+ *
* Returns: 0 on success, otherwise a negative error value.
*/
_public_ int udev_enumerate_add_match_sysattr(struct udev_enumerate *udev_enumerate, const char *sysattr, const char *value)
* Returns: 0 on success, otherwise a negative error value.
*/
_public_ int udev_enumerate_add_match_sysattr(struct udev_enumerate *udev_enumerate, const char *sysattr, const char *value)
@@
-379,6
+392,8
@@
_public_ int udev_enumerate_add_match_sysattr(struct udev_enumerate *udev_enumer
* @sysattr: filter for a sys attribute at the device to exclude from the list
* @value: optional value of the sys attribute
*
* @sysattr: filter for a sys attribute at the device to exclude from the list
* @value: optional value of the sys attribute
*
+ * Match only devices not having a certain /sys device attribute.
+ *
* Returns: 0 on success, otherwise a negative error value.
*/
_public_ int udev_enumerate_add_nomatch_sysattr(struct udev_enumerate *udev_enumerate, const char *sysattr, const char *value)
* Returns: 0 on success, otherwise a negative error value.
*/
_public_ int udev_enumerate_add_nomatch_sysattr(struct udev_enumerate *udev_enumerate, const char *sysattr, const char *value)
@@
-418,6
+433,8
@@
exit:
* @property: filter for a property of the device to include in the list
* @value: value of the property
*
* @property: filter for a property of the device to include in the list
* @value: value of the property
*
+ * Match only devices with a certain property.
+ *
* Returns: 0 on success, otherwise a negative error value.
*/
_public_ int udev_enumerate_add_match_property(struct udev_enumerate *udev_enumerate, const char *property, const char *value)
* Returns: 0 on success, otherwise a negative error value.
*/
_public_ int udev_enumerate_add_match_property(struct udev_enumerate *udev_enumerate, const char *property, const char *value)
@@
-436,6
+453,8
@@
_public_ int udev_enumerate_add_match_property(struct udev_enumerate *udev_enume
* @udev_enumerate: context
* @tag: filter for a tag of the device to include in the list
*
* @udev_enumerate: context
* @tag: filter for a tag of the device to include in the list
*
+ * Match only devices with a certain tag.
+ *
* Returns: 0 on success, otherwise a negative error value.
*/
_public_ int udev_enumerate_add_match_tag(struct udev_enumerate *udev_enumerate, const char *tag)
* Returns: 0 on success, otherwise a negative error value.
*/
_public_ int udev_enumerate_add_match_tag(struct udev_enumerate *udev_enumerate, const char *tag)
@@
-505,6
+524,8
@@
_public_ int udev_enumerate_add_match_is_initialized(struct udev_enumerate *udev
* @udev_enumerate: context
* @sysname: filter for the name of the device to include in the list
*
* @udev_enumerate: context
* @sysname: filter for the name of the device to include in the list
*
+ * Match only devices with a given /sys device name.
+ *
* Returns: 0 on success, otherwise a negative error value.
*/
_public_ int udev_enumerate_add_match_sysname(struct udev_enumerate *udev_enumerate, const char *sysname)
* Returns: 0 on success, otherwise a negative error value.
*/
_public_ int udev_enumerate_add_match_sysname(struct udev_enumerate *udev_enumerate, const char *sysname)
@@
-597,13
+618,10
@@
static bool match_tag(struct udev_enumerate *udev_enumerate, struct udev_device
static bool match_parent(struct udev_enumerate *udev_enumerate, struct udev_device *dev)
{
static bool match_parent(struct udev_enumerate *udev_enumerate, struct udev_device *dev)
{
- const char *parent;
-
if (udev_enumerate->parent_match == NULL)
return true;
if (udev_enumerate->parent_match == NULL)
return true;
- parent = udev_device_get_devpath(udev_enumerate->parent_match);
- return strncmp(parent, udev_device_get_devpath(dev), strlen(parent)) == 0;
+ return startswith(udev_device_get_devpath(dev), udev_device_get_devpath(udev_enumerate->parent_match));
}
static bool match_sysname(struct udev_enumerate *udev_enumerate, const char *sysname)
}
static bool match_sysname(struct udev_enumerate *udev_enumerate, const char *sysname)
@@
-624,7
+642,6
@@
static bool match_sysname(struct udev_enumerate *udev_enumerate, const char *sys
static int scan_dir_and_add_devices(struct udev_enumerate *udev_enumerate,
const char *basedir, const char *subdir1, const char *subdir2)
{
static int scan_dir_and_add_devices(struct udev_enumerate *udev_enumerate,
const char *basedir, const char *subdir1, const char *subdir2)
{
- struct udev *udev = udev_enumerate_get_udev(udev_enumerate);
char path[UTIL_PATH_SIZE];
size_t l;
char *s;
char path[UTIL_PATH_SIZE];
size_t l;
char *s;
@@
-632,7
+649,7
@@
static int scan_dir_and_add_devices(struct udev_enumerate *udev_enumerate,
struct dirent *dent;
s = path;
struct dirent *dent;
s = path;
- l = util_strpcpyl(&s, sizeof(path),
udev_get_sys_path(udev), "
/", basedir, NULL);
+ l = util_strpcpyl(&s, sizeof(path),
"/sys
/", basedir, NULL);
if (subdir1 != NULL)
l = util_strpcpyl(&s, l, "/", subdir1, NULL);
if (subdir2 != NULL)
if (subdir1 != NULL)
l = util_strpcpyl(&s, l, "/", subdir1, NULL);
if (subdir2 != NULL)
@@
-707,13
+724,11
@@
static bool match_subsystem(struct udev_enumerate *udev_enumerate, const char *s
static int scan_dir(struct udev_enumerate *udev_enumerate, const char *basedir, const char *subdir, const char *subsystem)
{
static int scan_dir(struct udev_enumerate *udev_enumerate, const char *basedir, const char *subdir, const char *subsystem)
{
- struct udev *udev = udev_enumerate_get_udev(udev_enumerate);
-
char path[UTIL_PATH_SIZE];
DIR *dir;
struct dirent *dent;
char path[UTIL_PATH_SIZE];
DIR *dir;
struct dirent *dent;
- util_strscpyl(path, sizeof(path),
udev_get_sys_path(udev), "
/", basedir, NULL);
+ util_strscpyl(path, sizeof(path),
"/sys
/", basedir, NULL);
dir = opendir(path);
if (dir == NULL)
return -1;
dir = opendir(path);
if (dir == NULL)
return -1;
@@
-756,7
+771,6
@@
_public_ int udev_enumerate_add_syspath(struct udev_enumerate *udev_enumerate, c
static int scan_devices_tags(struct udev_enumerate *udev_enumerate)
{
static int scan_devices_tags(struct udev_enumerate *udev_enumerate)
{
- struct udev *udev = udev_enumerate_get_udev(udev_enumerate);
struct udev_list_entry *list_entry;
/* scan only tagged devices, use tags reverse-index, instead of searching all devices in /sys */
struct udev_list_entry *list_entry;
/* scan only tagged devices, use tags reverse-index, instead of searching all devices in /sys */
@@
-765,8
+779,7
@@
static int scan_devices_tags(struct udev_enumerate *udev_enumerate)
struct dirent *dent;
char path[UTIL_PATH_SIZE];
struct dirent *dent;
char path[UTIL_PATH_SIZE];
- util_strscpyl(path, sizeof(path), udev_get_run_path(udev), "/tags/",
- udev_list_entry_get_name(list_entry), NULL);
+ util_strscpyl(path, sizeof(path), "/run/udev/tags/", udev_list_entry_get_name(list_entry), NULL);
dir = opendir(path);
if (dir == NULL)
continue;
dir = opendir(path);
if (dir == NULL)
continue;
@@
-776,7
+789,7
@@
static int scan_devices_tags(struct udev_enumerate *udev_enumerate)
if (dent->d_name[0] == '.')
continue;
if (dent->d_name[0] == '.')
continue;
- dev = udev_device_new_from_
id_filename
(udev_enumerate->udev, dent->d_name);
+ dev = udev_device_new_from_
device_id
(udev_enumerate->udev, dent->d_name);
if (dev == NULL)
continue;
if (dev == NULL)
continue;
@@
-861,12
+874,9
@@
static int scan_devices_children(struct udev_enumerate *enumerate)
static int scan_devices_all(struct udev_enumerate *udev_enumerate)
{
static int scan_devices_all(struct udev_enumerate *udev_enumerate)
{
- struct udev *udev = udev_enumerate_get_udev(udev_enumerate);
- char base[UTIL_PATH_SIZE];
struct stat statbuf;
struct stat statbuf;
- util_strscpyl(base, sizeof(base), udev_get_sys_path(udev), "/subsystem", NULL);
- if (stat(base, &statbuf) == 0) {
+ if (stat("/sys/subsystem", &statbuf) == 0) {
/* we have /subsystem/, forget all the old stuff */
scan_dir(udev_enumerate, "subsystem", "devices", NULL);
} else {
/* we have /subsystem/, forget all the old stuff */
scan_dir(udev_enumerate, "subsystem", "devices", NULL);
} else {
@@
-880,6
+890,9
@@
static int scan_devices_all(struct udev_enumerate *udev_enumerate)
* udev_enumerate_scan_devices:
* @udev_enumerate: udev enumeration context
*
* udev_enumerate_scan_devices:
* @udev_enumerate: udev enumeration context
*
+ * Scan /sys for all devices which match the given filters. No matches
+ * will return all currently available devices.
+ *
* Returns: 0 on success, otherwise a negative error value.
**/
_public_ int udev_enumerate_scan_devices(struct udev_enumerate *udev_enumerate)
* Returns: 0 on success, otherwise a negative error value.
**/
_public_ int udev_enumerate_scan_devices(struct udev_enumerate *udev_enumerate)
@@
-903,12
+916,12
@@
_public_ int udev_enumerate_scan_devices(struct udev_enumerate *udev_enumerate)
* udev_enumerate_scan_subsystems:
* @udev_enumerate: udev enumeration context
*
* udev_enumerate_scan_subsystems:
* @udev_enumerate: udev enumeration context
*
+ * Scan /sys for all kernel subsystems, including buses, classes, drivers.
+ *
* Returns: 0 on success, otherwise a negative error value.
**/
_public_ int udev_enumerate_scan_subsystems(struct udev_enumerate *udev_enumerate)
{
* Returns: 0 on success, otherwise a negative error value.
**/
_public_ int udev_enumerate_scan_subsystems(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;
struct stat statbuf;
const char *subsysdir;
@@
-919,8
+932,7
@@
_public_ int udev_enumerate_scan_subsystems(struct udev_enumerate *udev_enumerat
if (match_subsystem(udev_enumerate, "module"))
scan_dir_and_add_devices(udev_enumerate, "module", NULL, NULL);
if (match_subsystem(udev_enumerate, "module"))
scan_dir_and_add_devices(udev_enumerate, "module", NULL, NULL);
- util_strscpyl(base, sizeof(base), udev_get_sys_path(udev), "/subsystem", NULL);
- if (stat(base, &statbuf) == 0)
+ if (stat("/sys/subsystem", &statbuf) == 0)
subsysdir = "subsystem";
else
subsysdir = "bus";
subsysdir = "subsystem";
else
subsysdir = "bus";