diff --git a/libfwupdplugin/fu-udev-device.c b/libfwupdplugin/fu-udev-device.c index 250fc2fb7..efc5a19f9 100644 --- a/libfwupdplugin/fu-udev-device.c +++ b/libfwupdplugin/fu-udev-device.c @@ -943,6 +943,32 @@ fu_udev_device_pwrite (FuUdevDevice *self, goffset port, guint8 data, GError **e #endif } +/** + * fu_udev_device_get_parent_name + * @self: A #FuUdevDevice + * + * Returns the name of the direct ancestor of this device + * + * Returns: string or NULL if unset or invalid + * + * Since: 1.4.2 + **/ +gchar * +fu_udev_device_get_parent_name (FuUdevDevice *self) +{ +#ifdef HAVE_GUDEV + FuUdevDevicePrivate *priv = GET_PRIVATE (self); + g_autoptr(GUdevDevice) parent = NULL; + + g_return_val_if_fail (FU_IS_UDEV_DEVICE (self), NULL); + + parent = g_udev_device_get_parent (priv->udev_device); + return parent == NULL ? NULL : g_strdup (g_udev_device_get_name (parent)); +#else + return NULL; +#endif +} + /** * fu_udev_device_get_sysfs_attr: * @self: A #FuUdevDevice diff --git a/libfwupdplugin/fu-udev-device.h b/libfwupdplugin/fu-udev-device.h index 5e82e5d4f..923e9c587 100644 --- a/libfwupdplugin/fu-udev-device.h +++ b/libfwupdplugin/fu-udev-device.h @@ -88,3 +88,4 @@ gboolean fu_udev_device_pread (FuUdevDevice *self, const gchar *fu_udev_device_get_sysfs_attr (FuUdevDevice *self, const gchar *attr, GError **error); +gchar *fu_udev_device_get_parent_name (FuUdevDevice *self); diff --git a/libfwupdplugin/fwupdplugin.map b/libfwupdplugin/fwupdplugin.map index 91dd5d608..3a8456640 100644 --- a/libfwupdplugin/fwupdplugin.map +++ b/libfwupdplugin/fwupdplugin.map @@ -583,6 +583,7 @@ LIBFWUPDPLUGIN_1.4.1 { LIBFWUPDPLUGIN_1.4.2 { global: + fu_udev_device_get_parent_name; fu_udev_device_get_sysfs_attr; local: *; } LIBFWUPDPLUGIN_1.4.1;