mirror of
https://git.proxmox.com/git/fwupd
synced 2025-07-24 22:48:09 +00:00
trivial: Add fu_udev_device_seek() for future code
This commit is contained in:
parent
fe180cbf5d
commit
0fb2ef3aae
@ -1447,6 +1447,57 @@ fu_udev_device_pread_full(FuUdevDevice *self,
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* fu_udev_device_seek:
|
||||
* @self: a #FuUdevDevice
|
||||
* @offset: offset address
|
||||
* @error: (nullable): optional return location for an error
|
||||
*
|
||||
* Seeks a file descriptor to a given offset.
|
||||
*
|
||||
* Returns: %TRUE for success
|
||||
*
|
||||
* Since: 1.7.2
|
||||
**/
|
||||
gboolean
|
||||
fu_udev_device_seek(FuUdevDevice *self, goffset offset, GError **error)
|
||||
{
|
||||
FuUdevDevicePrivate *priv = GET_PRIVATE(self);
|
||||
|
||||
g_return_val_if_fail(FU_IS_UDEV_DEVICE(self), FALSE);
|
||||
g_return_val_if_fail(error == NULL || *error == NULL, FALSE);
|
||||
|
||||
/* not open! */
|
||||
if (priv->fd == 0) {
|
||||
g_set_error(error,
|
||||
FWUPD_ERROR,
|
||||
FWUPD_ERROR_INTERNAL,
|
||||
"%s [%s] has not been opened",
|
||||
fu_device_get_id(FU_DEVICE(self)),
|
||||
fu_device_get_name(FU_DEVICE(self)));
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
#ifdef HAVE_PWRITE
|
||||
if (lseek(priv->fd, offset, SEEK_SET) < 0) {
|
||||
g_set_error(error,
|
||||
G_IO_ERROR,
|
||||
G_IO_ERROR_FAILED,
|
||||
"failed to seek to 0x%04x: %s",
|
||||
(guint)offset,
|
||||
strerror(errno));
|
||||
return FALSE;
|
||||
}
|
||||
return TRUE;
|
||||
#else
|
||||
g_set_error_literal(error,
|
||||
FWUPD_ERROR,
|
||||
FWUPD_ERROR_NOT_SUPPORTED,
|
||||
"Not supported as lseek() is unavailable");
|
||||
return FALSE;
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* fu_udev_device_pwrite_full:
|
||||
* @self: a #FuUdevDevice
|
||||
|
@ -113,6 +113,8 @@ fu_udev_device_pread_full(FuUdevDevice *self,
|
||||
guint8 *buf,
|
||||
gsize bufsz,
|
||||
GError **error) G_GNUC_WARN_UNUSED_RESULT;
|
||||
gboolean
|
||||
fu_udev_device_seek(FuUdevDevice *self, goffset offset, GError **error) G_GNUC_WARN_UNUSED_RESULT;
|
||||
const gchar *
|
||||
fu_udev_device_get_sysfs_attr(FuUdevDevice *self, const gchar *attr, GError **error);
|
||||
gboolean
|
||||
|
@ -950,5 +950,6 @@ LIBFWUPDPLUGIN_1.7.2 {
|
||||
global:
|
||||
fu_context_has_hwid_flag;
|
||||
fu_udev_device_get_sysfs_attr_uint64;
|
||||
fu_udev_device_seek;
|
||||
local: *;
|
||||
} LIBFWUPDPLUGIN_1.7.1;
|
||||
|
Loading…
Reference in New Issue
Block a user