Top | ![]() |
![]() |
![]() |
![]() |
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.
struct udev_device *
udev_device_ref (struct udev_device *udev_device
);
Take a reference of a udev device.
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.
struct udev *
udev_device_get_udev (struct udev_device *udev_device
);
Retrieve the udev library context the device was created with.
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.
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.
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.
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.
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.
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.
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.
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 '/'.
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 "/".
const char *
udev_device_get_devtype (struct udev_device *udev_device
);
Retrieve the devtype string of the udev device.
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.
const char *
udev_device_get_sysname (struct udev_device *udev_device
);
Get the kernel device name in /sys.
const char *
udev_device_get_sysnum (struct udev_device *udev_device
);
Get the instance number of the device.
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.
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.
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.
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()
.
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()
.
const char * udev_device_get_property_value (struct udev_device *udev_device
,const char *key
);
Get the value of a given property.
const char *
udev_device_get_driver (struct udev_device *udev_device
);
Get the kernel driver name.
dev_t
udev_device_get_devnum (struct udev_device *udev_device
);
Get the device major/minor number.
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.
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.
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.
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.
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.
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.