GUdevDevice

GUdevDevice — Get information about a device

Functions

const gchar * g_udev_device_get_subsystem ()
const gchar * g_udev_device_get_devtype ()
const gchar * g_udev_device_get_name ()
const gchar * g_udev_device_get_number ()
const gchar * g_udev_device_get_sysfs_path ()
const gchar * g_udev_device_get_driver ()
const gchar * g_udev_device_get_action ()
guint64 g_udev_device_get_seqnum ()
GUdevDeviceType g_udev_device_get_device_type ()
GUdevDeviceNumber g_udev_device_get_device_number ()
const gchar * g_udev_device_get_device_file ()
const gchar * const * g_udev_device_get_device_file_symlinks ()
GUdevDevice * g_udev_device_get_parent ()
GUdevDevice * g_udev_device_get_parent_with_subsystem ()
const gchar * const * g_udev_device_get_tags ()
gboolean g_udev_device_get_is_initialized ()
guint64 g_udev_device_get_usec_since_initialized ()
const gchar * const * g_udev_device_get_property_keys ()
gboolean g_udev_device_has_property ()
const gchar * g_udev_device_get_property ()
gint g_udev_device_get_property_as_int ()
guint64 g_udev_device_get_property_as_uint64 ()
gdouble g_udev_device_get_property_as_double ()
gboolean g_udev_device_get_property_as_boolean ()
const gchar * const * g_udev_device_get_property_as_strv ()
const gchar * const * g_udev_device_get_sysfs_attr_keys ()
gboolean g_udev_device_has_sysfs_attr ()
const gchar * g_udev_device_get_sysfs_attr ()
gint g_udev_device_get_sysfs_attr_as_int ()
guint64 g_udev_device_get_sysfs_attr_as_uint64 ()
gdouble g_udev_device_get_sysfs_attr_as_double ()
gboolean g_udev_device_get_sysfs_attr_as_boolean ()
const gchar * const * g_udev_device_get_sysfs_attr_as_strv ()
gboolean g_udev_device_has_sysfs_attr_uncached ()
const gchar * g_udev_device_get_sysfs_attr_uncached ()
gint g_udev_device_get_sysfs_attr_as_int_uncached ()
guint64 g_udev_device_get_sysfs_attr_as_uint64_uncached ()
gdouble g_udev_device_get_sysfs_attr_as_double_uncached ()
gboolean g_udev_device_get_sysfs_attr_as_boolean_uncached ()
const gchar * const * g_udev_device_get_sysfs_attr_as_strv_uncached ()

Types and Values

Object Hierarchy

    GObject
    ╰── GUdevDevice

Description

The GUdevDevice class is used to get information about a specific device. Note that you cannot instantiate a GUdevDevice object yourself. Instead you must use GUdevClient to obtain GUdevDevice objects.

To get basic information about a device, use g_udev_device_get_subsystem(), g_udev_device_get_devtype(), g_udev_device_get_name(), g_udev_device_get_number(), g_udev_device_get_sysfs_path(), g_udev_device_get_driver(), g_udev_device_get_action(), g_udev_device_get_seqnum(), g_udev_device_get_device_type(), g_udev_device_get_device_number(), g_udev_device_get_device_file(), g_udev_device_get_device_file_symlinks().

To navigate the device tree, use g_udev_device_get_parent() and g_udev_device_get_parent_with_subsystem().

To access udev properties for the device, use g_udev_device_get_property_keys(), g_udev_device_has_property(), g_udev_device_get_property(), g_udev_device_get_property_as_int(), g_udev_device_get_property_as_uint64(), g_udev_device_get_property_as_double(), g_udev_device_get_property_as_boolean() and g_udev_device_get_property_as_strv().

To access sysfs attributes for the device, use g_udev_device_get_sysfs_attr_keys(), g_udev_device_has_sysfs_attr(), g_udev_device_get_sysfs_attr(), g_udev_device_get_sysfs_attr_as_int(), g_udev_device_get_sysfs_attr_as_uint64(), g_udev_device_get_sysfs_attr_as_double(), g_udev_device_get_sysfs_attr_as_boolean() and g_udev_device_get_sysfs_attr_as_strv().

Note that all getters on GUdevDevice are non-reffing – returned values are owned by the object, should not be freed and are only valid as long as the object is alive.

By design, GUdevDevice will not react to changes for a device – it only contains a snapshot of information when the GUdevDevice object was created. To work with changes, you typically connect to the “uevent” signal on a GUdevClient and get a new GUdevDevice whenever an event happens.

Functions

g_udev_device_get_subsystem ()

const gchar *
g_udev_device_get_subsystem (GUdevDevice *device);

Gets the subsystem for device .

Parameters

device

A GUdevDevice.

 

Returns

The subsystem for device .


g_udev_device_get_devtype ()

const gchar *
g_udev_device_get_devtype (GUdevDevice *device);

Gets the device type for device .

Parameters

device

A GUdevDevice.

 

Returns

The devtype for device .


g_udev_device_get_name ()

const gchar *
g_udev_device_get_name (GUdevDevice *device);

Gets the name of device , e.g. "sda3".

Parameters

device

A GUdevDevice.

 

Returns

The name of device .


g_udev_device_get_number ()

const gchar *
g_udev_device_get_number (GUdevDevice *device);

Gets the number of device , e.g. "3" if g_udev_device_get_name() returns "sda3".

Parameters

device

A GUdevDevice.

 

Returns

The number of device .


g_udev_device_get_sysfs_path ()

const gchar *
g_udev_device_get_sysfs_path (GUdevDevice *device);

Gets the sysfs path for device .

Parameters

device

A GUdevDevice.

 

Returns

The sysfs path for device .


g_udev_device_get_driver ()

const gchar *
g_udev_device_get_driver (GUdevDevice *device);

Gets the name of the driver used for device .

Parameters

device

A GUdevDevice.

 

Returns

The name of the driver for device or NULL if unknown.

[nullable]


g_udev_device_get_action ()

const gchar *
g_udev_device_get_action (GUdevDevice *device);

Gets the most recent action (e.g. "add", "remove", "change", etc.) for device .

Parameters

device

A GUdevDevice.

 

Returns

An action string.


g_udev_device_get_seqnum ()

guint64
g_udev_device_get_seqnum (GUdevDevice *device);

Gets the most recent sequence number for device .

Parameters

device

A GUdevDevice.

 

Returns

A sequence number.


g_udev_device_get_device_type ()

GUdevDeviceType
g_udev_device_get_device_type (GUdevDevice *device);

Gets the type of the device file, if any, for device .

Parameters

device

A GUdevDevice.

 

Returns

The device number for device or G_UDEV_DEVICE_TYPE_NONE if the device does not have a device file.


g_udev_device_get_device_number ()

GUdevDeviceNumber
g_udev_device_get_device_number (GUdevDevice *device);

Gets the device number, if any, for device .

Parameters

device

A GUdevDevice.

 

Returns

The device number for device or 0 if unknown.


g_udev_device_get_device_file ()

const gchar *
g_udev_device_get_device_file (GUdevDevice *device);

Gets the device file for device .

Parameters

device

A GUdevDevice.

 

Returns

The device file for device or NULL if no device file exists.

[nullable]


g_udev_device_get_device_file_symlinks ()

const gchar * const *
g_udev_device_get_device_file_symlinks
                               (GUdevDevice *device);

Gets a list of symlinks (in /dev) that points to the device file for device .

Parameters

device

A GUdevDevice.

 

Returns

A NULL terminated string array of symlinks. This array is owned by device and should not be freed by the caller.

[transfer none][array zero-terminated=1][element-type utf8]


g_udev_device_get_parent ()

GUdevDevice *
g_udev_device_get_parent (GUdevDevice *device);

Gets the immediate parent of device , if any.

Parameters

device

A GUdevDevice.

 

Returns

A GUdevDevice or NULL if device has no parent. Free with g_object_unref().

[nullable][transfer full]


g_udev_device_get_parent_with_subsystem ()

GUdevDevice *
g_udev_device_get_parent_with_subsystem
                               (GUdevDevice *device,
                                const gchar *subsystem,
                                const gchar *devtype);

Walks up the chain of parents of device and returns the first device encountered where subsystem and devtype matches, if any.

Parameters

device

A GUdevDevice.

 

subsystem

The subsystem of the parent to get.

 

devtype

The devtype of the parent to get or NULL.

[allow-none]

Returns

A GUdevDevice or NULL if device has no parent with subsystem and devtype . Free with g_object_unref().

[nullable][transfer full]


g_udev_device_get_tags ()

const gchar * const *
g_udev_device_get_tags (GUdevDevice *device);

Gets all tags for device .

Parameters

device

A GUdevDevice.

 

Returns

A NULL terminated string array of tags. This array is owned by device and should not be freed by the caller.

[transfer none][array zero-terminated=1][element-type utf8]

Since: 165


g_udev_device_get_is_initialized ()

gboolean
g_udev_device_get_is_initialized (GUdevDevice *device);

Gets whether device has been initialized.

Parameters

device

A GUdevDevice.

 

Returns

Whether device has been initialized.

Since: 165


g_udev_device_get_usec_since_initialized ()

guint64
g_udev_device_get_usec_since_initialized
                               (GUdevDevice *device);

Gets number of micro-seconds since device was initialized.

This only works for devices with properties in the udev database. All other devices return 0.

Parameters

device

A GUdevDevice.

 

Returns

Number of micro-seconds since device was initialized or 0 if unknown.

Since: 165


g_udev_device_get_property_keys ()

const gchar * const *
g_udev_device_get_property_keys (GUdevDevice *device);

Gets all keys for properties on device .

Parameters

device

A GUdevDevice.

 

Returns

A NULL terminated string array of property keys. This array is owned by device and should not be freed by the caller.

[transfer none][array zero-terminated=1][element-type utf8]


g_udev_device_has_property ()

gboolean
g_udev_device_has_property (GUdevDevice *device,
                            const gchar *key);

Check if a the property with the given key exists.

Parameters

device

A GUdevDevice.

 

key

Name of property.

 

Returns

TRUE only if the value for key exist.


g_udev_device_get_property ()

const gchar *
g_udev_device_get_property (GUdevDevice *device,
                            const gchar *key);

Look up the value for key on device .

Parameters

device

A GUdevDevice.

 

key

Name of property.

 

Returns

The value for key or NULL if key doesn't exist on device . Do not free this string, it is owned by device .

[nullable]


g_udev_device_get_property_as_int ()

gint
g_udev_device_get_property_as_int (GUdevDevice *device,
                                   const gchar *key);

Look up the value for key on device and convert it to an integer using strtol().

Parameters

device

A GUdevDevice.

 

key

Name of property.

 

Returns

The value for key or 0 if key doesn't exist or isn't an integer.


g_udev_device_get_property_as_uint64 ()

guint64
g_udev_device_get_property_as_uint64 (GUdevDevice *device,
                                      const gchar *key);

Look up the value for key on device and convert it to an unsigned 64-bit integer using g_ascii_strtoull().

Parameters

device

A GUdevDevice.

 

key

Name of property.

 

Returns

The value for key or 0 if key doesn't exist or isn't a guint64.


g_udev_device_get_property_as_double ()

gdouble
g_udev_device_get_property_as_double (GUdevDevice *device,
                                      const gchar *key);

Look up the value for key on device and convert it to a double precision floating point number using g_ascii_strtod().

Parameters

device

A GUdevDevice.

 

key

Name of property.

 

Returns

The value for key or 0.0 if key doesn't exist or isn't a gdouble.


g_udev_device_get_property_as_boolean ()

gboolean
g_udev_device_get_property_as_boolean (GUdevDevice *device,
                                       const gchar *key);

Look up the value for key on device and convert it to an boolean. This is done by doing a case-insensitive string comparison on the string value against "1" and "true".

Parameters

device

A GUdevDevice.

 

key

Name of property.

 

Returns

The value for key or FALSE if key doesn't exist or isn't a gboolean.


g_udev_device_get_property_as_strv ()

const gchar * const *
g_udev_device_get_property_as_strv (GUdevDevice *device,
                                    const gchar *key);

Look up the value for key on device and return the result of splitting it into non-empty tokens split at white space (only space (' '), form-feed ('\f'), newline ('\n'), carriage return ('\r'), horizontal tab ('\t'), and vertical tab ('\v') are considered; the locale is not taken into account).

Parameters

device

A GUdevDevice.

 

key

Name of property.

 

Returns

The value of key on device split into tokens or NULL if key doesn't exist. This array is owned by device and should not be freed by the caller.

[nullable][transfer none][array zero-terminated=1][element-type utf8]


g_udev_device_get_sysfs_attr_keys ()

const gchar * const *
g_udev_device_get_sysfs_attr_keys (GUdevDevice *device);

Gets all keys for sysfs attributes on device .

Parameters

device

A GUdevDevice.

 

Returns

A NULL terminated string array of sysfs attribute keys. This array is owned by device and should not be freed by the caller.

[transfer none][array zero-terminated=1][element-type utf8]


g_udev_device_has_sysfs_attr ()

gboolean
g_udev_device_has_sysfs_attr (GUdevDevice *device,
                              const gchar *key);

Check if a the sysfs attribute with the given key exists. The retrieved value is cached in the device. Repeated calls will return the same result and not check for the presence of the attribute again, unless updated through one of the "uncached" functions.

Parameters

device

A GUdevDevice.

 

key

Name of sysfs attribute.

 

Returns

TRUE only if the value for key exist.


g_udev_device_get_sysfs_attr ()

const gchar *
g_udev_device_get_sysfs_attr (GUdevDevice *device,
                              const gchar *name);

Look up the sysfs attribute with name on device . The retrieved value is cached in the device. Repeated calls will return the same value and not open the attribute again, unless updated through one of the "uncached" functions.

Parameters

device

A GUdevDevice.

 

name

Name of the sysfs attribute.

 

Returns

The value of the sysfs attribute or NULL if there is no such attribute. Do not free this string, it is owned by device .

[nullable]


g_udev_device_get_sysfs_attr_as_int ()

gint
g_udev_device_get_sysfs_attr_as_int (GUdevDevice *device,
                                     const gchar *name);

Look up the sysfs attribute with name on device and convert it to an integer using strtol(). The retrieved value is cached in the device. Repeated calls will return the same value and not open the attribute again, unless updated through one of the "uncached" functions.

Parameters

device

A GUdevDevice.

 

name

Name of the sysfs attribute.

 

Returns

The value of the sysfs attribute or 0 if there is no such attribute.


g_udev_device_get_sysfs_attr_as_uint64 ()

guint64
g_udev_device_get_sysfs_attr_as_uint64
                               (GUdevDevice *device,
                                const gchar *name);

Look up the sysfs attribute with name on device and convert it to an unsigned 64-bit integer using g_ascii_strtoull(). The retrieved value is cached in the device. Repeated calls will return the same value and not open the attribute again, unless updated through one of the "uncached" functions.

Parameters

device

A GUdevDevice.

 

name

Name of the sysfs attribute.

 

Returns

The value of the sysfs attribute or 0 if there is no such attribute.


g_udev_device_get_sysfs_attr_as_double ()

gdouble
g_udev_device_get_sysfs_attr_as_double
                               (GUdevDevice *device,
                                const gchar *name);

Look up the sysfs attribute with name on device and convert it to a double precision floating point number using g_ascii_strtod(). The retrieved value is cached in the device. Repeated calls will return the same value and not open the attribute again, unless updated through one of the "uncached" functions.

Parameters

device

A GUdevDevice.

 

name

Name of the sysfs attribute.

 

Returns

The value of the sysfs attribute or 0.0 if there is no such attribute.


g_udev_device_get_sysfs_attr_as_boolean ()

gboolean
g_udev_device_get_sysfs_attr_as_boolean
                               (GUdevDevice *device,
                                const gchar *name);

Look up the sysfs attribute with name on device and convert it to an boolean. This is done by doing a case-insensitive string comparison on the string value against "1", "true", "Y" and "y". The retrieved value is cached in the device. Repeated calls will return the same value and not open the attribute again, unless updated through one of the "uncached" functions.

Parameters

device

A GUdevDevice.

 

name

Name of the sysfs attribute.

 

Returns

The value of the sysfs attribute or FALSE if there is no such attribute.


g_udev_device_get_sysfs_attr_as_strv ()

const gchar * const *
g_udev_device_get_sysfs_attr_as_strv (GUdevDevice *device,
                                      const gchar *name);

Look up the sysfs attribute with name on device and return the result of splitting it into non-empty tokens split at white space (only space (' '), form-feed ('\f'), newline ('\n'), carriage return ('\r'), horizontal tab ('\t'), and vertical tab ('\v') are considered; the locale is not taken into account).

The retrieved value is cached in the device. Repeated calls will return the same value and not open the attribute again, unless updated through one of the "uncached" functions.

Parameters

device

A GUdevDevice.

 

name

Name of the sysfs attribute.

 

Returns

The value of the sysfs attribute split into tokens or NULL if there is no such attribute. This array is owned by device and should not be freed by the caller.

[nullable][transfer none][array zero-terminated=1][element-type utf8]


g_udev_device_has_sysfs_attr_uncached ()

gboolean
g_udev_device_has_sysfs_attr_uncached (GUdevDevice *device,
                                       const gchar *key);

Check if a the sysfs attribute with the given key exists. The retrieved value is cached in the device. Repeated calls will return the same result and not check for the presence of the attribute again, unless updated through one of the "uncached" functions.

Parameters

device

A GUdevDevice.

 

key

Name of sysfs attribute.

 

Returns

TRUE only if the value for key exist.

Since: 234


g_udev_device_get_sysfs_attr_uncached ()

const gchar *
g_udev_device_get_sysfs_attr_uncached (GUdevDevice *device,
                                       const gchar *name);

Look up the sysfs attribute with name on device . This function does blocking I/O, and updates the sysfs attributes cache.

Before version 238 the uncached getters would not strip trailing newlines.

Parameters

device

A GUdevDevice.

 

name

Name of the sysfs attribute.

 

Returns

The value of the sysfs attribute or NULL if there is no such attribute. Do not free this string, it is owned by device .

[nullable]

Since: 234


g_udev_device_get_sysfs_attr_as_int_uncached ()

gint
g_udev_device_get_sysfs_attr_as_int_uncached
                               (GUdevDevice *device,
                                const gchar *name);

Look up the sysfs attribute with name on device and convert it to an integer using strtol(). This function does blocking I/O, and updates the sysfs attributes cache.

Before version 238 the uncached getters would not strip trailing newlines.

Parameters

device

A GUdevDevice.

 

name

Name of the sysfs attribute.

 

Returns

The value of the sysfs attribute or 0 if there is no such attribute.

Since: 234


g_udev_device_get_sysfs_attr_as_uint64_uncached ()

guint64
g_udev_device_get_sysfs_attr_as_uint64_uncached
                               (GUdevDevice *device,
                                const gchar *name);

Look up the sysfs attribute with name on device and convert it to an unsigned 64-bit integer using g_ascii_strtoull(). This function does blocking I/O, and updates the sysfs attributes cache.

Before version 238 the uncached getters would not strip trailing newlines.

Parameters

device

A GUdevDevice.

 

name

Name of the sysfs attribute.

 

Returns

The value of the sysfs attribute or 0 if there is no such attribute.

Since: 234


g_udev_device_get_sysfs_attr_as_double_uncached ()

gdouble
g_udev_device_get_sysfs_attr_as_double_uncached
                               (GUdevDevice *device,
                                const gchar *name);

Look up the sysfs attribute with name on device and convert it to a double precision floating point number using g_ascii_strtod(). This function does blocking I/O, and updates the sysfs attributes cache.

Before version 238 the uncached getters would not strip trailing newlines.

Parameters

device

A GUdevDevice.

 

name

Name of the sysfs attribute.

 

Returns

The value of the sysfs attribute or 0.0 if there is no such attribute.

Since: 234


g_udev_device_get_sysfs_attr_as_boolean_uncached ()

gboolean
g_udev_device_get_sysfs_attr_as_boolean_uncached
                               (GUdevDevice *device,
                                const gchar *name);

Look up the sysfs attribute with name on device and convert it to an boolean. This is done by doing a case-insensitive string comparison on the string value against "1", "true", "Y" and "y". This function does blocking I/O, and updates the sysfs attributes cache.

Before version 238 the uncached getters would not strip trailing newlines.

Parameters

device

A GUdevDevice.

 

name

Name of the sysfs attribute.

 

Returns

The value of the sysfs attribute or FALSE if there is no such attribute.

Since: 234


g_udev_device_get_sysfs_attr_as_strv_uncached ()

const gchar * const *
g_udev_device_get_sysfs_attr_as_strv_uncached
                               (GUdevDevice *device,
                                const gchar *name);

Look up the sysfs attribute with name on device and return the result of splitting it into non-empty tokens split at white space (only space (' '), form-feed ('\f'), newline ('\n'), carriage return ('\r'), horizontal tab ('\t'), and vertical tab ('\v') are considered; the locale is not taken into account).

This function does blocking I/O, and updates the sysfs attributes cache.

Parameters

device

A GUdevDevice.

 

name

Name of the sysfs attribute.

 

Returns

The value of the sysfs attribute split into tokens or NULL if there is no such attribute. This array is owned by device and should not be freed by the caller.

Before version 238 the uncached getters would not strip trailing newlines.

[nullable][transfer none][array zero-terminated=1][element-type utf8]

Since: 234

Types and Values

GUdevDevice

typedef struct _GUdevDevice GUdevDevice;

The GUdevDevice struct is opaque and should not be accessed directly.


struct GUdevDeviceClass

struct GUdevDeviceClass {
  GObjectClass parent_class;
};

Class structure for GUdevDevice.

Members