udev_device

## udev_device udev_device — kernel sys devices |

## Synopsis

    struct              udev_device;
    struct udev_device * udev_device_ref                    (struct udev_device *udev_device);
    void                udev_device_unref                   (struct udev_device *udev_device);
    struct udev *       udev_device_get_udev                (struct udev_device *udev_device);
    struct udev_device * udev_device_new_from_syspath       (struct udev *udev,
                                                             const char *syspath);
    struct udev_device * udev_device_new_from_devnum        (struct udev *udev,
                                                             char type,
                                                             dev_t devnum);
    struct udev_device * udev_device_new_from_subsystem_sysname
                                                            (struct udev *udev,
                                                             const char *subsystem,
                                                             const char *sysname);
    struct udev_device * udev_device_new_from_environment   (struct udev *udev);
    struct udev_device * udev_device_get_parent             (struct udev_device *udev_device);
    struct udev_device * udev_device_get_parent_with_subsystem_devtype
                                                            (struct udev_device *udev_device,
                                                             const char *subsystem,
                                                             const char *devtype);
    const char *        udev_device_get_devpath             (struct udev_device *udev_device);
    const char *        udev_device_get_subsystem           (struct udev_device *udev_device);
    const char *        udev_device_get_devtype             (struct udev_device *udev_device);
    const char *        udev_device_get_syspath             (struct udev_device *udev_device);
    const char *        udev_device_get_sysname             (struct udev_device *udev_device);
    const char *        udev_device_get_sysnum              (struct udev_device *udev_device);
    const char *        udev_device_get_devnode             (struct udev_device *udev_device);
    int                 udev_device_get_is_initialized      (struct udev_device *udev_device);
    struct udev_list_entry * udev_device_get_devlinks_list_entry
                                                            (struct udev_device *udev_device);
    struct udev_list_entry * udev_device_get_properties_list_entry
                                                            (struct udev_device *udev_device);
    struct udev_list_entry * udev_device_get_tags_list_entry
                                                            (struct udev_device *udev_device);
    const char *        udev_device_get_property_value      (struct udev_device *udev_device,
                                                             const char *key);
    const char *        udev_device_get_driver              (struct udev_device *udev_device);
    dev_t               udev_device_get_devnum              (struct udev_device *udev_device);
    const char *        udev_device_get_action              (struct udev_device *udev_device);
    const char *        udev_device_get_sysattr_value       (struct udev_device *udev_device,
                                                             const char *sysattr);
    struct udev_list_entry * udev_device_get_sysattr_list_entry
                                                            (struct udev_device *udev_device);
    unsigned long long int udev_device_get_seqnum           (struct udev_device *udev_device);
    unsigned long long int udev_device_get_usec_since_initialized
                                                            (struct udev_device *udev_device);
    int                 udev_device_has_tag                 (struct udev_device *udev_device,
                                                             const char *tag);

## 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 and have a unique name inside that subsystem.

## Details

### struct udev_device

    struct udev_device;

Opaque object representing one kernel sys device.

### udev_device_ref ()

    struct udev_device * udev_device_ref                    (struct udev_device *udev_device);

Take a reference of a udev device.

`udev_device` : | udev device
Returns : | the passed udev device

### udev_device_unref ()

    void                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.

`udev_device` : | udev device

### 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.

`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.

`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.

`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.

`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_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.

`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.

The returned the 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.

`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.

The returned the 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.

`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 '/'.

`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 "/".

`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.

`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.

`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);

`udev_device` : | udev device
Returns : | the sys name of the device device

### udev_device_get_sysnum ()

    const char *        udev_device_get_sysnum              (struct udev_device *udev_device);

`udev_device` : | udev device
Returns : | the trailing number of 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.

`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.

`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_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.

`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_next()`, which returns NULL if no more entries exist. The property name can be retrieved from the list entry by `udev_list_get_name()`, the property value by `udev_list_get_value()`.

`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_next()`, which returns NULL if no more entries exist. The tag string can be retrieved from the list entry by `udev_list_get_name()`.

`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);

`udev_device` : | udev device
`key` : | property name
Returns : | the value of a device property, or NULL if there is no such property.

### udev_device_get_driver ()

    const char *        udev_device_get_driver              (struct udev_device *udev_device);

`udev_device` : | udev device
Returns : | the driver string, or NULL if there is no driver attached.

### udev_device_get_devnum ()

    dev_t               udev_device_get_devnum              (struct udev_device *udev_device);

`udev_device` : | udev device
Returns : | the device major/minor 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.

`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.

`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_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.

`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.

`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.

`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);