-/*
- * libudev - interface to udev device information
- *
- * 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
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- */
+/***
+ This file is part of systemd.
+
+ Copyright 2008-2012 Kay Sievers <kay@vrfy.org>
+
+ systemd is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation; either version 2.1 of the License, or
+ (at your option) any later version.
+
+ systemd is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with systemd; If not, see <http://www.gnu.org/licenses/>.
+***/
#include <stdio.h>
#include <stdlib.h>
* 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)
{
struct udev_enumerate *udev_enumerate;
+ if (udev == NULL)
+ return NULL;
udev_enumerate = calloc(1, sizeof(struct udev_enumerate));
if (udev_enumerate == NULL)
return NULL;
*
* 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)
- return;
+ return NULL;
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);
free(udev_enumerate->devices[i].syspath);
free(udev_enumerate->devices);
free(udev_enumerate);
+ return NULL;
}
/**
* 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)
{
* 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)
{
* @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)
* @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)
* @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)
* @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)
* @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)
* @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)
* @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)
struct dirent *dent;
s = path;
- l = util_strpcpyl(&s, sizeof(path), "/sys/", basedir, NULL);
+ l = strpcpyl(&s, sizeof(path), "/sys/", basedir, NULL);
if (subdir1 != NULL)
- l = util_strpcpyl(&s, l, "/", subdir1, NULL);
+ l = strpcpyl(&s, l, "/", subdir1, NULL);
if (subdir2 != NULL)
- util_strpcpyl(&s, l, "/", subdir2, NULL);
+ strpcpyl(&s, l, "/", subdir2, NULL);
dir = opendir(path);
if (dir == NULL)
return -ENOENT;
if (!match_sysname(udev_enumerate, dent->d_name))
continue;
- util_strscpyl(syspath, sizeof(syspath), path, "/", dent->d_name, NULL);
+ strscpyl(syspath, sizeof(syspath), path, "/", dent->d_name, NULL);
dev = udev_device_new_from_syspath(udev_enumerate->udev, syspath);
if (dev == NULL)
continue;
DIR *dir;
struct dirent *dent;
- util_strscpyl(path, sizeof(path), "/sys/", basedir, NULL);
+ strscpyl(path, sizeof(path), "/sys/", basedir, NULL);
dir = opendir(path);
if (dir == NULL)
return -1;
struct dirent *dent;
char path[UTIL_PATH_SIZE];
- util_strscpyl(path, sizeof(path), "/run/udev/tags/", udev_list_entry_get_name(list_entry), NULL);
+ strscpyl(path, sizeof(path), "/run/udev/tags/", udev_list_entry_get_name(list_entry), NULL);
dir = opendir(path);
if (dir == NULL)
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;
* 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)
* 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)