sd-device.c revision 24eb4a30982ed18d4716bd59c454a72f161d5982
106ecd769d57116ad81efdea2c27557fba062138Ronny Chevalier This file is part of systemd.
106ecd769d57116ad81efdea2c27557fba062138Ronny Chevalier Copyright 2008-2012 Kay Sievers <kay@vrfy.org>
106ecd769d57116ad81efdea2c27557fba062138Ronny Chevalier Copyright 2014 Tom Gundersen <teg@jklm.no>
106ecd769d57116ad81efdea2c27557fba062138Ronny Chevalier systemd is free software; you can redistribute it and/or modify it
106ecd769d57116ad81efdea2c27557fba062138Ronny Chevalier under the terms of the GNU Lesser General Public License as published by
106ecd769d57116ad81efdea2c27557fba062138Ronny Chevalier the Free Software Foundation; either version 2.1 of the License, or
106ecd769d57116ad81efdea2c27557fba062138Ronny Chevalier (at your option) any later version.
106ecd769d57116ad81efdea2c27557fba062138Ronny Chevalier systemd is distributed in the hope that it will be useful, but
106ecd769d57116ad81efdea2c27557fba062138Ronny Chevalier WITHOUT ANY WARRANTY; without even the implied warranty of
106ecd769d57116ad81efdea2c27557fba062138Ronny Chevalier MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
106ecd769d57116ad81efdea2c27557fba062138Ronny Chevalier Lesser General Public License for more details.
106ecd769d57116ad81efdea2c27557fba062138Ronny Chevalier You should have received a copy of the GNU Lesser General Public License
106ecd769d57116ad81efdea2c27557fba062138Ronny Chevalier along with systemd; If not, see <http://www.gnu.org/licenses/>.
106ecd769d57116ad81efdea2c27557fba062138Ronny Chevalier _cleanup_device_unref_ sd_device *device = NULL;
106ecd769d57116ad81efdea2c27557fba062138Ronny Chevalier_public_ sd_device *sd_device_ref(sd_device *device) {
106ecd769d57116ad81efdea2c27557fba062138Ronny Chevalier_public_ sd_device *sd_device_unref(sd_device *device) {
106ecd769d57116ad81efdea2c27557fba062138Ronny Chevalier ordered_hashmap_free_free_free(device->properties);
106ecd769d57116ad81efdea2c27557fba062138Ronny Chevalier ordered_hashmap_free_free_free(device->properties_db);
106ecd769d57116ad81efdea2c27557fba062138Ronny Chevalier hashmap_free_free_free(device->sysattr_values);
106ecd769d57116ad81efdea2c27557fba062138Ronny Chevalierint device_add_property_aux(sd_device *device, const char *_key, const char *_value, bool db) {
106ecd769d57116ad81efdea2c27557fba062138Ronny Chevalier _cleanup_free_ char *key = NULL, *value = NULL, *old_key = NULL, *old_value = NULL;
106ecd769d57116ad81efdea2c27557fba062138Ronny Chevalier r = ordered_hashmap_ensure_allocated(properties, &string_hash_ops);
2de61bbebfe6a1a97709b3277b150cacc30a79cdRonny Chevalier old_value = ordered_hashmap_get2(*properties, key, (void**) &old_key);
2de61bbebfe6a1a97709b3277b150cacc30a79cdRonny Chevalier r = ordered_hashmap_replace(*properties, key, value);
106ecd769d57116ad81efdea2c27557fba062138Ronny Chevalier value = ordered_hashmap_remove2(*properties, _key, (void**) &key);
const char *devpath;
return -EINVAL;
if (verify) {
if (r == -EINVAL) {
if (!syspath) {
return -errno;
} else if (r < 0 && r != -EINVAL) {
char *path;
return -errno;
return -EINVAL;
if (!syspath)
return -ENOMEM;
char *syspath;
_public_ int sd_device_new_from_subsystem_sysname(sd_device **ret, const char *subsystem, const char *sysname) {
char *syspath;
char *driver;
if (driver) {
driver++;
return -EINVAL;
return -ENOENT;
if (!devtype)
return -ENOMEM;
int ifindex, r;
if (ifindex <= 0)
return -EINVAL;
return -ENOMEM;
if (!devname)
return -ENOMEM;
unsigned devmode;
return -EINVAL;
if (!maj)
if (minor) {
if (minor) {
static int handle_uevent_line(sd_device *device, const char *key, const char *value, const char **major, const char **minor) {
char *path;
KEY,
for (i = 0; i < uevent_len; i++) {
switch (state) {
case PRE_KEY:
case KEY:
case PRE_VALUE:
case VALUE:
if (major) {
log_debug("sd-device: could not set 'MAJOR=%s' or 'MINOR=%s' from '%s': %s", major, minor, path, strerror(-r));
switch (id[0]) {
char type;
return -EINVAL;
int ifindex;
return -EINVAL;
if (sk < 0)
return -errno;
return -errno;
return -ENODEV;
char *sysname;
if (!sysname)
return -EINVAL;
sysname ++;
return -EINVAL;
if (!path)
return -ENOMEM;
char *pos;
return -ENOENT;
return -ENOENT;
if (!subsystem)
return -ENOMEM;
const char *syspath;
char *path;
_public_ int sd_device_get_parent_with_subsystem_devtype(sd_device *child, const char *subsystem, const char *devtype, sd_device **ret) {
if (!devtype)
if (!driver)
return -ENOMEM;
const char *syspath;
char *path;
return -ENOENT;
const char *pos;
if (!pos)
return -EINVAL;
pos ++;
return -EINVAL;
if (!sysname)
return -ENOMEM;
len ++;
if (len == 0)
return -EINVAL;
char *value;
if (!key)
return -ENOMEM;
if (!value)
return -EINVAL;
char *path;
switch (key) {
const char *subsystem;
int ifindex, r;
return -errno;
} else if (ifindex > 0) {
return -errno;
const char *sysname;
if (!sysname)
return -EINVAL;
return -errno;
char *path;
char key;
KEY,
if (r == -ENOENT)
for (i = 0; i < db_len; i++) {
switch (state) {
case PRE_KEY:
case KEY:
case PRE_VALUE:
case INVALID_LINE:
case VALUE:
return -EBUSY;
return -ENODATA;
return -EIO;
return NULL;
return NULL;
const char *devlink;
if (devlink)
const char *tag;
if (tag)
const char *key;
const char *value;
return NULL;
value = ordered_hashmap_iterate(device->properties, &device->properties_iterator, (const void**)&key);
if (_value)
return key;
const char *key;
const char *value;
return NULL;
return NULL;
value = ordered_hashmap_iterate(device->properties, &device->properties_iterator, (const void**)&key);
if (_value)
return key;
const char *syspath;
if (!dir)
return -errno;
char *path;
errno = -r;
return NULL;
return NULL;
_public_ int sd_device_get_property_value(sd_device *device, const char *key, const char **_value) {
char *value;
if (!value)
return -ENOENT;
if (!key) {
if (!key)
return -ENOMEM;
if (!key)
return -ENOENT;
if (_value)
_public_ int sd_device_get_sysattr_value(sd_device *device, const char *sysattr, const char **_value) {
char *path;
if (r != -ENOENT) {
if (!cached_value)
return -ENOENT;
if (_value)
return -ENOENT;
return -EINVAL;
return -EINVAL;
return -EPERM;
const char *syspath;
char *path;
if (!_value) {
if (!value)
return -ENOMEM;
return -ENXIO;
return -EINVAL;
return -EISDIR;
return -EACCES;
return -EINVAL;
if (fd < 0)
return -errno;
if (!value)
return -ENOMEM;
if (size < 0)
return -errno;
return -EIO;