udev_device

udev_device — kernel sys devices

Functions

struct udev_device * udev_device_ref ()
struct udev_device * udev_device_unref ()
struct udev * udev_device_get_udev ()
struct udev_device * udev_device_new_from_syspath ()
struct udev_device * udev_device_new_from_devnum ()
struct udev_device * udev_device_new_from_subsystem_sysname ()
struct udev_device * udev_device_new_from_device_id ()
struct udev_device * udev_device_new_from_environment ()
struct udev_device * udev_device_get_parent ()
struct udev_device * udev_device_get_parent_with_subsystem_devtype ()
const char * udev_device_get_devpath ()
const char * udev_device_get_subsystem ()
const char * udev_device_get_devtype ()
const char * udev_device_get_syspath ()
const char * udev_device_get_sysname ()
const char * udev_device_get_sysnum ()
const char * udev_device_get_devnode ()
int udev_device_get_is_initialized ()
struct udev_list_entry * udev_device_get_devlinks_list_entry ()
struct udev_list_entry * udev_device_get_properties_list_entry ()
struct udev_list_entry * udev_device_get_tags_list_entry ()
const char * udev_device_get_property_value ()
const char * udev_device_get_driver ()
dev_t udev_device_get_devnum ()
const char * udev_device_get_action ()
const char * udev_device_get_sysattr_value ()
int udev_device_set_sysattr_value ()
struct udev_list_entry * udev_device_get_sysattr_list_entry ()
unsigned long long int udev_device_get_seqnum ()
unsigned long long int udev_device_get_usec_since_initialized ()
int udev_device_has_tag ()

Types and Values

struct udev_device

Object Hierarchy


Description

Representation of kernel sys devices. Devices are uniquely identified by their syspath, every device has exactly one path in the kernel sys filesystem. Devices usually belong to a kernel subsystem, and have a unique name inside that subsystem.

Functions

udev_device_ref ()

struct udev_device *
udev_device_ref (struct udev_device *udev_device);

Take a reference of a udev device.

Parameters

udev_device

udev device

 

Returns

the passed udev device


udev_device_unref ()

struct udev_device *
udev_device_unref (struct udev_device *udev_device);

Drop a reference of a udev device. If the refcount reaches zero, the resources of the device will be released.

Parameters

udev_device

udev device

 

Returns

NULL


udev_device_get_udev ()

struct udev *
udev_device_get_udev (struct udev_device *udev_device);

Retrieve the udev library context the device was created with.

Parameters

udev_device

udev device

 

Returns

the udev library context


udev_device_new_from_syspath ()

struct udev_device *
udev_device_new_from_syspath (struct udev *udev,
                              const char *syspath);

Create new udev device, and fill in information from the sys device and the udev database entry. The syspath is the absolute path to the device, including the sys mount point.

The initial refcount is 1, and needs to be decremented to release the resources of the udev device.

Parameters

udev

udev library context

 

syspath

sys device path including sys directory

 

Returns

a new udev device, or NULL, if it does not exist


udev_device_new_from_devnum ()

struct udev_device *
udev_device_new_from_devnum (struct udev *udev,
                             char type,
                             dev_t devnum);

Create new udev device, and fill in information from the sys device and the udev database entry. The device is looked-up by its major/minor number and type. Character and block device numbers are not unique across the two types.

The initial refcount is 1, and needs to be decremented to release the resources of the udev device.

Parameters

udev

udev library context

 

type

char or block device

 

devnum

device major/minor number

 

Returns

a new udev device, or NULL, if it does not exist


udev_device_new_from_subsystem_sysname ()

struct udev_device *
udev_device_new_from_subsystem_sysname
                               (struct udev *udev,
                                const char *subsystem,
                                const char *sysname);

Create new udev device, and fill in information from the sys device and the udev database entry. The device is looked up by the subsystem and name string of the device, like "mem" / "zero", or "block" / "sda".

The initial refcount is 1, and needs to be decremented to release the resources of the udev device.

Parameters

udev

udev library context

 

subsystem

the subsystem of the device

 

sysname

the name of the device

 

Returns

a new udev device, or NULL, if it does not exist


udev_device_new_from_device_id ()

struct udev_device *
udev_device_new_from_device_id (struct udev *udev,
                                const char *id);

Create new udev device, and fill in information from the sys device and the udev database entry. The device is looked-up by a special string: b8:2 - block device major:minor c128:1 - char device major:minor n3 - network device ifindex +sound:card29 - kernel driver core subsystem:device name

The initial refcount is 1, and needs to be decremented to release the resources of the udev device.

Parameters

udev

udev library context

 

id

text string identifying a kernel device

 

Returns

a new udev device, or NULL, if it does not exist


udev_device_new_from_environment ()

struct udev_device *
udev_device_new_from_environment (struct udev *udev);

Create new udev device, and fill in information from the current process environment. This only works reliable if the process is called from a udev rule. It is usually used for tools executed from IMPORT= rules.

The initial refcount is 1, and needs to be decremented to release the resources of the udev device.

Parameters

udev

udev library context

 

Returns

a new udev device, or NULL, if it does not exist


udev_device_get_parent ()

struct udev_device *
udev_device_get_parent (struct udev_device *udev_device);

Find the next parent device, and fill in information from the sys device and the udev database entry.

Returned device is not referenced. It is attached to the child device, and will be cleaned up when the child device is cleaned up.

It is not necessarily just the upper level directory, empty or not recognized sys directories are ignored.

It can be called as many times as needed, without caring about references.

Parameters

udev_device

the device to start searching from

 

Returns

a new udev device, or NULL, if it no parent exist.


udev_device_get_parent_with_subsystem_devtype ()

struct udev_device *
udev_device_get_parent_with_subsystem_devtype
                               (struct udev_device *udev_device,
                                const char *subsystem,
                                const char *devtype);

Find the next parent device, with a matching subsystem and devtype value, and fill in information from the sys device and the udev database entry.

If devtype is NULL, only subsystem is checked, and any devtype will match.

Returned device is not referenced. It is attached to the child device, and will be cleaned up when the child device is cleaned up.

It can be called as many times as needed, without caring about references.

Parameters

udev_device

udev device to start searching from

 

subsystem

the subsystem of the device

 

devtype

the type (DEVTYPE) of the device

 

Returns

a new udev device, or NULL if no matching parent exists.


udev_device_get_devpath ()

const char *
udev_device_get_devpath (struct udev_device *udev_device);

Retrieve the kernel devpath value of the udev device. The path does not contain the sys mount point, and starts with a '/'.

Parameters

udev_device

udev device

 

Returns

the devpath of the udev device


udev_device_get_subsystem ()

const char *
udev_device_get_subsystem (struct udev_device *udev_device);

Retrieve the subsystem string of the udev device. The string does not contain any "/".

Parameters

udev_device

udev device

 

Returns

the subsystem name of the udev device, or NULL if it can not be determined


udev_device_get_devtype ()

const char *
udev_device_get_devtype (struct udev_device *udev_device);

Retrieve the devtype string of the udev device.

Parameters

udev_device

udev device

 

Returns

the devtype name of the udev device, or NULL if it can not be determined


udev_device_get_syspath ()

const char *
udev_device_get_syspath (struct udev_device *udev_device);

Retrieve the sys path of the udev device. The path is an absolute path and starts with the sys mount point.

Parameters

udev_device

udev device

 

Returns

the sys path of the udev device


udev_device_get_sysname ()

const char *
udev_device_get_sysname (struct udev_device *udev_device);

Get the kernel device name in /sys.

Parameters

udev_device

udev device

 

Returns

the name string of the device device


udev_device_get_sysnum ()

const char *
udev_device_get_sysnum (struct udev_device *udev_device);

Get the instance number of the device.

Parameters

udev_device

udev device

 

Returns

the trailing number string of the device name


udev_device_get_devnode ()

const char *
udev_device_get_devnode (struct udev_device *udev_device);

Retrieve the device node file name belonging to the udev device. The path is an absolute path, and starts with the device directory.

Parameters

udev_device

udev device

 

Returns

the device node file name of the udev device, or NULL if no device node exists


udev_device_get_is_initialized ()

int
udev_device_get_is_initialized (struct udev_device *udev_device);

Check if udev has already handled the device and has set up device node permissions and context, or has renamed a network device.

This is only implemented for devices with a device node or network interfaces. All other devices return 1 here.

Parameters

udev_device

udev device

 

Returns

1 if the device is set up. 0 otherwise.


udev_device_get_devlinks_list_entry ()

struct udev_list_entry *
udev_device_get_devlinks_list_entry (struct udev_device *udev_device);

Retrieve the list of device links pointing to the device file of the udev device. The next list entry can be retrieved with udev_list_entry_get_next(), which returns NULL if no more entries exist. The devlink path can be retrieved from the list entry by udev_list_entry_get_name(). The path is an absolute path, and starts with the device directory.

Parameters

udev_device

udev device

 

Returns

the first entry of the device node link list


udev_device_get_properties_list_entry ()

struct udev_list_entry *
udev_device_get_properties_list_entry (struct udev_device *udev_device);

Retrieve the list of key/value device properties of the udev device. The next list entry can be retrieved with udev_list_entry_get_next(), which returns NULL if no more entries exist. The property name can be retrieved from the list entry by udev_list_entry_get_name(), the property value by udev_list_entry_get_value().

Parameters

udev_device

udev device

 

Returns

the first entry of the property list


udev_device_get_tags_list_entry ()

struct udev_list_entry *
udev_device_get_tags_list_entry (struct udev_device *udev_device);

Retrieve the list of tags attached to the udev device. The next list entry can be retrieved with udev_list_entry_get_next(), which returns NULL if no more entries exist. The tag string can be retrieved from the list entry by udev_list_entry_get_name().

Parameters

udev_device

udev device

 

Returns

the first entry of the tag list


udev_device_get_property_value ()

const char *
udev_device_get_property_value (struct udev_device *udev_device,
                                const char *key);

Get the value of a given property.

Parameters

udev_device

udev device

 

key

property name

 

Returns

the property string, or NULL if there is no such property.


udev_device_get_driver ()

const char *
udev_device_get_driver (struct udev_device *udev_device);

Get the kernel driver name.

Parameters

udev_device

udev device

 

Returns

the driver name string, or NULL if there is no driver attached.


udev_device_get_devnum ()

dev_t
udev_device_get_devnum (struct udev_device *udev_device);

Get the device major/minor number.

Parameters

udev_device

udev device

 

Returns

the dev_t number.


udev_device_get_action ()

const char *
udev_device_get_action (struct udev_device *udev_device);

This is only valid if the device was received through a monitor. Devices read from sys do not have an action string. Usual actions are: add, remove, change, online, offline.

Parameters

udev_device

udev device

 

Returns

the kernel action value, or NULL if there is no action value available.


udev_device_get_sysattr_value ()

const char *
udev_device_get_sysattr_value (struct udev_device *udev_device,
                               const char *sysattr);

The retrieved value is cached in the device. Repeated calls will return the same value and not open the attribute again.

Parameters

udev_device

udev device

 

sysattr

attribute name

 

Returns

the content of a sys attribute file, or NULL if there is no sys attribute value.


udev_device_set_sysattr_value ()

int
udev_device_set_sysattr_value (struct udev_device *udev_device,
                               const char *sysattr,
                               char *value);

Update the contents of the sys attribute and the cached value of the device.

Parameters

udev_device

udev device

 

sysattr

attribute name

 

value

new value to be set

 

Returns

Negative error code on failure or 0 on success.


udev_device_get_sysattr_list_entry ()

struct udev_list_entry *
udev_device_get_sysattr_list_entry (struct udev_device *udev_device);

Retrieve the list of available sysattrs, with value being empty; This just return all available sysfs attributes for a particular device without reading their values.

Parameters

udev_device

udev device

 

Returns

the first entry of the property list


udev_device_get_seqnum ()

unsigned long long int
udev_device_get_seqnum (struct udev_device *udev_device);

This is only valid if the device was received through a monitor. Devices read from sys do not have a sequence number.

Parameters

udev_device

udev device

 

Returns

the kernel event sequence number, or 0 if there is no sequence number available.


udev_device_get_usec_since_initialized ()

unsigned long long int
udev_device_get_usec_since_initialized
                               (struct udev_device *udev_device);

Return the number of microseconds passed since udev set up the device for the first time.

This is only implemented for devices with need to store properties in the udev database. All other devices return 0 here.

Parameters

udev_device

udev device

 

Returns

the number of microseconds since the device was first seen.


udev_device_has_tag ()

int
udev_device_has_tag (struct udev_device *udev_device,
                     const char *tag);

Check if a given device has a certain tag associated.

Parameters

udev_device

udev device

 

tag

tag name

 

Returns

1 if the tag is found. 0 otherwise.

Types and Values

struct udev_device

struct udev_device;

Opaque object representing one kernel sys device.