libudev-device.c revision 220893b3cbdbf8932f95c44811b169a8f0d33939
bb24bfa932beddc9a03b661d79a32094d1127696Felix Gabriel Mance * libudev - interface to udev device information
bb24bfa932beddc9a03b661d79a32094d1127696Felix Gabriel Mance * Copyright (C) 2008-2010 Kay Sievers <kay.sievers@vrfy.org>
bb24bfa932beddc9a03b661d79a32094d1127696Felix Gabriel Mance * This library is free software; you can redistribute it and/or
bb24bfa932beddc9a03b661d79a32094d1127696Felix Gabriel Mance * modify it under the terms of the GNU Lesser General Public
bb24bfa932beddc9a03b661d79a32094d1127696Felix Gabriel Mance * License as published by the Free Software Foundation; either
bb24bfa932beddc9a03b661d79a32094d1127696Felix Gabriel Mance * version 2.1 of the License, or (at your option) any later version.
#include <stddef.h>
#include <unistd.h>
#include <stdbool.h>
#include <errno.h>
#include <string.h>
#include <dirent.h>
#include <fcntl.h>
#include <ctype.h>
#include "libudev.h"
#include "libudev-private.h"
struct udev_device {
char *syspath;
const char *devpath;
char *sysname;
const char *sysnum;
char *devnode;
char *subsystem;
char *devtype;
char *driver;
char *action;
char *devpath_old;
char *id_filename;
char **envp;
char *monitor_buf;
unsigned long long int seqnum;
unsigned long long int usec_initialized;
int devlink_priority;
int refcount;
int ifindex;
int watch_handle;
bool parent_set;
bool subsystem_set;
bool devtype_set;
bool devlinks_uptodate;
bool envp_uptodate;
bool tags_uptodate;
bool driver_set;
bool info_loaded;
bool db_loaded;
bool uevent_loaded;
bool is_initialized;
bool sysattr_list_read;
bool db_persist;
return makedev(0, 0);
const char *pos;
return -ENOMEM;
return -EINVAL;
return NULL;
if (util_get_sys_core_link_value(udev_device->udev, "driver", udev_device->syspath, driver, sizeof(driver)) > 0)
return -ENOMEM;
return NULL;
return -ENOMEM;
return -ENOMEM;
return NULL;
if (util_get_sys_core_link_value(udev_device->udev, "subsystem", udev_device->syspath, subsystem, sizeof(subsystem)) > 0) {
struct udev_list_entry *udev_device_add_property(struct udev_device *udev_device, const char *key, const char *value)
return NULL;
static struct udev_list_entry *udev_device_add_property_from_string(struct udev_device *udev_device, const char *property)
char *val;
return NULL;
void udev_device_add_property_from_string_parse(struct udev_device *udev_device, const char *property)
char *slink;
char *next;
char *next;
next++;
char *tag;
next++;
return -EINVAL;
UDEV_EXPORT const char *udev_device_get_property_value(struct udev_device *udev_device, const char *key)
return NULL;
return NULL;
FILE *f;
const char *id;
util_strscpyl(filename, sizeof(filename), udev_get_run_path(udev_device->udev), "/data/", id, NULL);
if (f == NULL) {
const char *val;
switch(line[0]) {
fclose(f);
FILE *f;
int maj = 0;
int min = 0;
if (f == NULL)
char *pos;
fclose(f);
return NULL;
return NULL;
return udev_device;
UDEV_EXPORT struct udev_device *udev_device_new_from_syspath(struct udev *udev, const char *syspath)
const char *subdir;
char *pos;
return NULL;
return NULL;
return NULL;
return NULL;
return NULL;
return NULL;
return NULL;
return udev_device;
UDEV_EXPORT struct udev_device *udev_device_new_from_devnum(struct udev *udev, char type, dev_t devnum)
const char *type_str;
return NULL;
char type;
char *sysname;
switch(id[0]) {
return NULL;
int sk;
int ifindex;
if (ifindex <= 0)
return NULL;
if (sk < 0)
return NULL;
return NULL;
return NULL;
return dev;
return NULL;
return NULL;
return NULL;
UDEV_EXPORT struct udev_device *udev_device_new_from_subsystem_sysname(struct udev *udev, const char *subsystem, const char *sysname)
char *path;
size_t l;
goto found;
goto found;
goto found;
goto out;
goto found;
goto out;
char *driver;
goto found;
goto found;
goto out;
goto found;
goto found;
goto found;
out:
return NULL;
return NULL;
return udev_device;
const char *subdir;
char *pos;
return udev_device_parent;
return NULL;
return NULL;
UDEV_EXPORT struct udev_device *udev_device_get_parent_with_subsystem_devtype(struct udev_device *udev_device, const char *subsystem, const char *devtype)
return NULL;
const char *parent_subsystem;
const char *parent_devtype;
return parent;
return NULL;
return NULL;
return udev_device;
return NULL;
return NULL;
return NULL;
return NULL;
return NULL;
UDEV_EXPORT struct udev_list_entry *udev_device_get_devlinks_list_entry(struct udev_device *udev_device)
return NULL;
UDEV_EXPORT struct udev_list_entry *udev_device_get_properties_list_entry(struct udev_device *udev_device)
return NULL;
size_t l;
s = symlinks;
size_t l;
s = tags;
return NULL;
UDEV_EXPORT unsigned long long int udev_device_get_usec_since_initialized(struct udev_device *udev_device)
unsigned long long now;
if (now == 0)
void udev_device_set_usec_initialized(struct udev_device *udev_device, unsigned long long usec_initialized)
UDEV_EXPORT const char *udev_device_get_sysattr_value(struct udev_device *udev_device, const char *sysattr)
int fd;
return NULL;
return NULL;
goto out;
return NULL;
goto out;
goto out;
goto out;
goto out;
if (fd < 0) {
goto out;
if (size < 0)
goto out;
goto out;
out:
return val;
int num = 0;
if (!dir) {
num++;
return num;
UDEV_EXPORT struct udev_list_entry *udev_device_get_sysattr_list_entry(struct udev_device *udev_device)
int ret;
if (0 > ret)
return NULL;
const char *pos;
return -ENOMEM;
return -EINVAL;
return -ENOMEM;
len = 0;
len++;
if (len == 0)
return -ENOMEM;
return -ENOMEM;
if (unique)
return NULL;
const char *sysname;
return NULL;
if (asprintf(&udev_device->id_filename, "+%s:%s", udev_device_get_subsystem(udev_device), sysname) < 0)
return -EINVAL;
return -ENOMEM;
UDEV_EXPORT struct udev_list_entry *udev_device_get_tags_list_entry(struct udev_device *udev_device)
return NULL;
size_t l;
return -ENOMEM;
return -ENOMEM;
l = MONITOR_BUF_SIZE;
const char *key;
return -EINVAL;
return -EINVAL;
return NULL;
return -EINVAL;
return -ENOMEM;