FuUdevDevice: fwupd Reference Manual

## FuUdevDevice FuUdevDevice |

## Functions

FuUdevDevice * | fu_udev_device_new ()
FuUdevDevice * | fu_udev_device_new_with_context ()
GUdevDevice * | fu_udev_device_get_dev ()
void | fu_udev_device_set_dev ()
const gchar * | fu_udev_device_get_device_file ()
const gchar * | fu_udev_device_get_sysfs_path ()
const gchar * | fu_udev_device_get_subsystem ()
const gchar * | fu_udev_device_get_bind_id ()
void | fu_udev_device_set_bind_id ()
const gchar * | fu_udev_device_get_driver ()
guint32 | fu_udev_device_get_vendor ()
guint32 | fu_udev_device_get_model ()
guint32 | fu_udev_device_get_subsystem_vendor ()
guint32 | fu_udev_device_get_subsystem_model ()
guint8 | fu_udev_device_get_revision ()
guint64 | fu_udev_device_get_number ()
guint | fu_udev_device_get_slot_depth ()
gboolean | fu_udev_device_set_physical_id ()
gboolean | fu_udev_device_set_logical_id ()
void | fu_udev_device_set_flags ()
gint | fu_udev_device_get_fd ()
void | fu_udev_device_set_fd ()
gboolean | fu_udev_device_ioctl ()
gboolean | fu_udev_device_ioctl_full ()
gboolean | fu_udev_device_pwrite ()
gboolean | fu_udev_device_pwrite_full ()
gboolean | fu_udev_device_pread ()
gboolean | fu_udev_device_pread_full ()
gboolean | fu_udev_device_seek ()
const gchar * | fu_udev_device_get_sysfs_attr ()
gboolean | fu_udev_device_get_sysfs_attr_uint64 ()
gchar * | fu_udev_device_get_parent_name ()
gboolean | fu_udev_device_write_sysfs ()
const gchar * | fu_udev_device_get_devtype ()
GPtrArray * | fu_udev_device_get_siblings_with_subsystem ()
GPtrArray * | fu_udev_device_get_children_with_subsystem ()
FuUdevDevice * | fu_udev_device_get_parent_with_subsystem ()

## Types and Values

#define | G_UDEV_TYPE_DEVICE
#define | GUdevDevice
#define | FU_TYPE_UDEV_DEVICE
struct | FuUdevDeviceClass
enum | FuUdevDeviceFlags
| FuUdevDevice

## Description

## Functions

### fu_udev_device_new ()

    FuUdevDevice *
    fu_udev_device_new (GUdevDevice *udev_device);

`fu_udev_device_new` is deprecated and should not be used in newly-written code.

Creates a new FuUdevDevice.

#### Parameters

udev_device | a GUdevDevice |

#### Returns

a FuUdevDevice.

[transfer full]

Since: 1.1.2

### fu_udev_device_new_with_context ()

    FuUdevDevice *
    fu_udev_device_new_with_context (FuContext *ctx,
                                     GUdevDevice *udev_device);

Creates a new FuUdevDevice.

#### Parameters

ctx | a FuContext. | [nullable]
udev_device | a GUdevDevice |

#### Returns

a FuUdevDevice.

[transfer full]

Since: 1.7.1

### fu_udev_device_get_dev ()

    GUdevDevice *
    fu_udev_device_get_dev (FuUdevDevice *self);

Gets the GUdevDevice.

#### Parameters

self | a FuUdevDevice |

#### Returns

a GUdevDevice, or `NULL`.

[transfer none]

Since: 1.1.2

### fu_udev_device_set_dev ()

    void
    fu_udev_device_set_dev (FuUdevDevice *self,
                            GUdevDevice *udev_device);

Sets the GUdevDevice. This may need to be used to replace the actual device used for reads and writes before the device is probed.

#### Parameters

self | a FuUdevDevice |
udev_device | a GUdevDevice |

Since: 1.6.2

### fu_udev_device_get_device_file ()

    const gchar *
    fu_udev_device_get_device_file (FuUdevDevice *self);

Gets the device node.

#### Parameters

self | a FuUdevDevice |

#### Returns

a device file, or NULL if unset

Since: 1.3.1

### fu_udev_device_get_sysfs_path ()

    const gchar *
    fu_udev_device_get_sysfs_path (FuUdevDevice *self);

Gets the device sysfs path, e.g. `/sys/devices/pci0000:00/0000:00:14.0`.

#### Parameters

self | a FuUdevDevice |

#### Returns

a local path, or NULL if unset or invalid

Since: 1.1.2

### fu_udev_device_get_subsystem ()

    const gchar *
    fu_udev_device_get_subsystem (FuUdevDevice *self);

Gets the device subsystem, e.g. `pci`

#### Parameters

self | a FuUdevDevice |

#### Returns

a subsystem, or NULL if unset or invalid

Since: 1.1.2

### fu_udev_device_get_bind_id ()

    const gchar *
    fu_udev_device_get_bind_id (FuUdevDevice *self);

Gets the device ID used for binding the device, e.g. `pci:1:2:3`

#### Parameters

self | a FuUdevDevice |

#### Returns

a bind_id, or NULL if unset or invalid

Since: 1.7.2

### fu_udev_device_set_bind_id ()

    void
    fu_udev_device_set_bind_id (FuUdevDevice *self,
                                const gchar *bind_id);

Sets the device ID used for binding the device, e.g. `pci:1:2:3`

#### Parameters

self | a FuUdevDevice |
bind_id | a bind-id string, e.g. `pci:0:0:1` |

Since: 1.7.2

### fu_udev_device_get_driver ()

    const gchar *
    fu_udev_device_get_driver (FuUdevDevice *self);

Gets the device driver, e.g. `psmouse`.

#### Parameters

self | a FuUdevDevice |

#### Returns

a subsystem, or NULL if unset or invalid

Since: 1.5.3

### fu_udev_device_get_vendor ()

    guint32
    fu_udev_device_get_vendor (FuUdevDevice *self);

Gets the device vendor code.

#### Parameters

self | a FuUdevDevice |

#### Returns

a vendor code, or 0 if unset or invalid

Since: 1.1.2

### fu_udev_device_get_model ()

    guint32
    fu_udev_device_get_model (FuUdevDevice *self);

Gets the device device code.

#### Parameters

self | a FuUdevDevice |

#### Returns

a vendor code, or 0 if unset or invalid

Since: 1.1.2

### fu_udev_device_get_subsystem_vendor ()

    guint32
    fu_udev_device_get_subsystem_vendor (FuUdevDevice *self);

Gets the device subsystem vendor code.

#### Parameters

self | a FuUdevDevice |

#### Returns

a vendor code, or 0 if unset or invalid

Since: 1.5.0

### fu_udev_device_get_subsystem_model ()

    guint32
    fu_udev_device_get_subsystem_model (FuUdevDevice *self);

Gets the device subsystem model code.

#### Parameters

self | a FuUdevDevice |

#### Returns

a vendor code, or 0 if unset or invalid

Since: 1.5.0

### fu_udev_device_get_revision ()

    guint8
    fu_udev_device_get_revision (FuUdevDevice *self);

Gets the device revision.

#### Parameters

self | a FuUdevDevice |

#### Returns

a vendor code, or 0 if unset or invalid

Since: 1.1.2

### fu_udev_device_get_number ()

    guint64
    fu_udev_device_get_number (FuUdevDevice *self);

Gets the device number, if any.

#### Parameters

self | a FuUdevDevice |

#### Returns

integer, 0 if the data is unavailable, or `G_MAXUINT64` if the feature is not available

Since: 1.5.0

### fu_udev_device_get_slot_depth ()

    guint
    fu_udev_device_get_slot_depth (FuUdevDevice *self,
                                   const gchar *subsystem);

Determine how far up a chain a given device is

#### Parameters

self | a FuUdevDevice |
subsystem | a subsystem |

#### Returns

unsigned integer

Since: 1.2.4

### fu_udev_device_set_physical_id ()

    gboolean
    fu_udev_device_set_physical_id (FuUdevDevice *self,
                                    const gchar *subsystems,
                                    GError **error);

Sets the physical ID from the device subsystem. Plugins should choose the subsystem that is "deepest" in the udev tree, for instance choosing `usb` over `pci` for a mouse device.

#### Parameters

self | a FuUdevDevice |
subsystems | a subsystem string, e.g. `pci,usb` |
error | optional return location for an error. | [nullable]

#### Returns

`TRUE` if the physical device was set.

Since: 1.1.2

### fu_udev_device_set_logical_id ()

    gboolean
    fu_udev_device_set_logical_id (FuUdevDevice *self,
                                   const gchar *subsystem,
                                   GError **error);

Sets the logical ID from the device subsystem. Plugins should choose the subsystem that most relevant in the udev tree, for instance choosing `hid` over `usb` for a mouse device.

#### Parameters

self | a FuUdevDevice |
subsystem | a subsystem string, e.g. `pci,usb` |
error | optional return location for an error. | [nullable]

#### Returns

`TRUE` if the logical device was set.

Since: 1.5.8

### fu_udev_device_set_flags ()

    void
    fu_udev_device_set_flags (FuUdevDevice *self,
                              FuUdevDeviceFlags flags);

Sets the parameters to use when opening the device.

For example `FU_UDEV_DEVICE_FLAG_OPEN_READ` means that `fu_device_open()` would use `O_RDONLY` rather than `O_RDWR` which is the default.

#### Parameters

self | a FuUdevDevice |
flags | udev device flags, e.g. `FU_UDEV_DEVICE_FLAG_OPEN_READ` |

Since: 1.3.6

### fu_udev_device_get_fd ()

    gint
    fu_udev_device_get_fd (FuUdevDevice *self);

Gets the file descriptor if the device is open.

#### Parameters

self | a FuUdevDevice |

#### Returns

positive integer, or -1 if the device is not open

Since: 1.3.3

### fu_udev_device_set_fd ()

    void
    fu_udev_device_set_fd (FuUdevDevice *self,
                           gint fd);

Replace the file descriptor to use when the device has already been opened. This object will automatically `close()` `fd` when `fu_device_close()` is called.

#### Parameters

self | a FuUdevDevice |
fd | a valid file descriptor |

Since: 1.3.3

### fu_udev_device_ioctl ()

    gboolean
    fu_udev_device_ioctl (FuUdevDevice *self,
                          gulong request,
                          guint8 *buf,
                          gint *rc,
                          GError **error);

Control a device using a low-level request.

#### Parameters

self | a FuUdevDevice |
request | request number |
buf | a buffer to use, which *must* be large enough for the request |
rc | the raw return value from the ioctl. | [out][nullable]
error | optional return location for an error. | [nullable]

#### Returns

`TRUE` for success

Since: 1.3.3

### fu_udev_device_ioctl_full ()

    gboolean
    fu_udev_device_ioctl_full (FuUdevDevice *self,
                               gulong request,
                               guint8 *buf,
                               gint *rc,
                               guint timeout,
                               GError **error);

Control a device using a low-level request.

#### Parameters

self | a FuUdevDevice |
request | request number |
buf | a buffer to use, which *must* be large enough for the request |
rc | the raw return value from the ioctl. | [out][nullable]
timeout | timeout in ms for the retry action, see `FU_UDEV_DEVICE_FLAG_IOCTL_RETRY` |
error | optional return location for an error. | [nullable]

#### Returns

`TRUE` for success

Since: 1.8.1

### fu_udev_device_pwrite ()

    gboolean
    fu_udev_device_pwrite (FuUdevDevice *self,
                           goffset port,
                           guint8 data,
                           GError **error);

Write to a file descriptor at a given offset.

#### Parameters

self | a FuUdevDevice |
port | offset address |
data | value |
error | optional return location for an error. | [nullable]

#### Returns

`TRUE` for success

Since: 1.3.3

### fu_udev_device_pwrite_full ()

    gboolean
    fu_udev_device_pwrite_full (FuUdevDevice *self,
                                goffset port,
                                const guint8 *buf,
                                gsize bufsz,
                                GError **error);

Write a buffer to a file descriptor at a given offset.

#### Parameters

self | a FuUdevDevice |
port | offset address |
buf | data. | [out]
bufsz | size of `data` |
error | optional return location for an error. | [nullable]

#### Returns

`TRUE` for success

Since: 1.4.5

### fu_udev_device_pread ()

    gboolean
    fu_udev_device_pread (FuUdevDevice *self,
                          goffset port,
                          guint8 *data,
                          GError **error);

Read from a file descriptor at a given offset.

#### Parameters

self | a FuUdevDevice |
port | offset address |
data | value. | [out]
error | optional return location for an error. | [nullable]

#### Returns

`TRUE` for success

Since: 1.3.3

### fu_udev_device_pread_full ()

    gboolean
    fu_udev_device_pread_full (FuUdevDevice *self,
                               goffset port,
                               guint8 *buf,
                               gsize bufsz,
                               GError **error);

Read a buffer from a file descriptor at a given offset.

#### Parameters

self | a FuUdevDevice |
port | offset address |
buf | data. | [in]
bufsz | size of `buf` |
error | optional return location for an error. | [nullable]

#### Returns

`TRUE` for success

Since: 1.4.5

### fu_udev_device_seek ()

    gboolean
    fu_udev_device_seek (FuUdevDevice *self,
                         goffset offset,
                         GError **error);

Seeks a file descriptor to a given offset.

#### Parameters

self | a FuUdevDevice |
offset | offset address |
error | optional return location for an error. | [nullable]

#### Returns

`TRUE` for success

Since: 1.7.2

### fu_udev_device_get_sysfs_attr ()

    const gchar *
    fu_udev_device_get_sysfs_attr (FuUdevDevice *self,
                                   const gchar *attr,
                                   GError **error);

Reads an arbitrary sysfs attribute 'attr' associated with UDEV device

#### Parameters

self | a FuUdevDevice |
attr | name of attribute to get |
error | optional return location for an error. | [nullable]

#### Returns

string or NULL

Since: 1.4.5

### fu_udev_device_get_sysfs_attr_uint64 ()

    gboolean
    fu_udev_device_get_sysfs_attr_uint64 (FuUdevDevice *self,
                                          const gchar *attr,
                                          guint64 *value,
                                          GError **error);

Reads an arbitrary sysfs attribute 'attr' associated with UDEV device as a uint64.

#### Parameters

self | a FuUdevDevice |
attr | name of attribute to get |
value | value to return. | [out][optional]
error | optional return location for an error. | [nullable]

#### Returns

`TRUE` for success

Since: 1.7.2

### fu_udev_device_get_parent_name ()

    gchar *
    fu_udev_device_get_parent_name (FuUdevDevice *self);

Returns the name of the direct ancestor of this device

#### Parameters

self | a FuUdevDevice |

#### Returns

string or NULL if unset or invalid

Since: 1.4.5

### fu_udev_device_write_sysfs ()

    gboolean
    fu_udev_device_write_sysfs (FuUdevDevice *self,
                                const gchar *attribute,
                                const gchar *val,
                                GError **error);

Writes data into a sysfs attribute

#### Parameters

self | a FuUdevDevice |
attribute | sysfs attribute name |
val | data to write into the attribute |
error | optional return location for an error. | [nullable]

#### Returns

`TRUE` for success

Since: 1.4.5

### fu_udev_device_get_devtype ()

    const gchar *
    fu_udev_device_get_devtype (FuUdevDevice *self);

Returns the Udev device type

#### Parameters

self | a FuUdevDevice |

#### Returns

device type specified in the uevent

Since: 1.4.5

### fu_udev_device_get_siblings_with_subsystem ()

    GPtrArray *
    fu_udev_device_get_siblings_with_subsystem
                                   (FuUdevDevice *self,
                                    const gchar *subsystem);

Get a list of devices that are siblings of self and have the provided subsystem.

#### Parameters

self | a FuUdevDevice |
subsystem | the name of a udev subsystem |

#### Returns

devices.

[element-type FuUdevDevice][transfer full]

Since: 1.6.0

### fu_udev_device_get_children_with_subsystem ()

    GPtrArray *
    fu_udev_device_get_children_with_subsystem
                                   (FuUdevDevice *self,
                                    const gchar *subsystem);

Get a list of devices that are children of self and have the provided subsystem.

#### Parameters

self | a FuUdevDevice |
subsystem | the name of a udev subsystem |

#### Returns

devices.

[element-type FuUdevDevice][transfer full]

Since: 1.6.2

### fu_udev_device_get_parent_with_subsystem ()

    FuUdevDevice *
    fu_udev_device_get_parent_with_subsystem
                                   (FuUdevDevice *self,
                                    const gchar *subsystem);

Get the device that is a parent of self and has the provided subsystem.

#### Parameters

self | a FuUdevDevice |
subsystem | the name of a udev subsystem |

#### Returns

device, or `NULL`.

[transfer full]

Since: 1.7.6

## Types and Values

### G_UDEV_TYPE_DEVICE

    #define G_UDEV_TYPE_DEVICE G_TYPE_OBJECT

### GUdevDevice

    #define GUdevDevice	   GObject

### FU_TYPE_UDEV_DEVICE

    #define FU_TYPE_UDEV_DEVICE (fu_udev_device_get_type())

### struct FuUdevDeviceClass

    struct FuUdevDeviceClass {
    	FuDeviceClass parent_class;
    	gpointer __reserved[31];
    };

### enum FuUdevDeviceFlags

Flags used when opening the device using `fu_device_open()`.

#### Members

FU_UDEV_DEVICE_FLAG_NONE | No flags set |
FU_UDEV_DEVICE_FLAG_OPEN_READ | Open the device read-only |
FU_UDEV_DEVICE_FLAG_OPEN_WRITE | Open the device write-only |
FU_UDEV_DEVICE_FLAG_VENDOR_FROM_PARENT | Get the vendor ID fallback from the parent |
FU_UDEV_DEVICE_FLAG_USE_CONFIG | Read and write from the device config |
FU_UDEV_DEVICE_FLAG_OPEN_NONBLOCK | Open nonblocking, e.g. O_NONBLOCK |
FU_UDEV_DEVICE_FLAG_OPEN_SYNC | Open sync, e.g. O_SYNC |
FU_UDEV_DEVICE_FLAG_IOCTL_RETRY | Retry the `ioctl()` call when required |

### FuUdevDevice

    typedef struct _FuUdevDevice FuUdevDevice;

A UDev device, typically only available on Linux.

See also: [class`FuDevice` ]