sd-device.c revision 8927b1dad2d4a7330174cb924090b4635a2547fb
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen This file is part of systemd.
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen Copyright 2008-2012 Kay Sievers <kay@vrfy.org>
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen Copyright 2014 Tom Gundersen <teg@jklm.no>
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen systemd is free software; you can redistribute it and/or modify it
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen under the terms of the GNU Lesser General Public License as published by
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen the Free Software Foundation; either version 2.1 of the License, or
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen (at your option) any later version.
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen systemd is distributed in the hope that it will be useful, but
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen WITHOUT ANY WARRANTY; without even the implied warranty of
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen Lesser General Public License for more details.
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen You should have received a copy of the GNU Lesser General Public License
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen along with systemd; If not, see <http://www.gnu.org/licenses/>.
12e0f830f592ec4c6bb49ac7ae1e0e84f74105e3Tom Gundersen _cleanup_device_unref_ sd_device *device = NULL;
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen_public_ sd_device *sd_device_ref(sd_device *device) {
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen_public_ sd_device *sd_device_unref(sd_device *device) {
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen ordered_hashmap_free_free_free(device->properties);
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen ordered_hashmap_free_free_free(device->properties_db);
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen hashmap_free_free_free(device->sysattr_values);
return NULL;
if (db)
if (_value) {
if (!key)
return -ENOMEM;
if (!value)
return -ENOMEM;
if (!db) {
const char *devpath;
return -EINVAL;
if (verify) {
if (r == -ENOENT)
return -ENODEV;
else if (r == -EINVAL) {
if (!syspath) {
return -ENODEV;
return -errno;
char *path;
return -ENODEV;
return -errno;
return -ENODEV;
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 -ENODEV;
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,
if (r == -EACCES)
else if (r == -ENOENT)
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 -ENODEV;
return -ENOENT;
if (!subsystem)
return -ENOMEM;
const char *syspath;
char *path;
if (r < 0 && r != -ENOENT)
_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;
} else if (r == -ENOENT)
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 -ENOMEM;
} else if (ifindex > 0) {
return -ENOMEM;
const char *sysname;
if (!sysname)
return -EINVAL;
if (!subsystem)
return -EINVAL;
return -ENOMEM;
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;
ordered_hashmap_iterate(device->properties, &device->properties_iterator, (void**)&value, (const void**)&key);
if (_value)
return key;
const char *key;
const char *value;
return NULL;
return NULL;
ordered_hashmap_iterate(device->properties, &device->properties_iterator, (void**)&value, (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;