<div dir="ltr"><div><div><div>For gudev -> gudevdevice:<br>- Add support for get_sysfs_attr_keys()<br>- Add support for has_sysfs_attr()<br><br>Note: Only tested against systemd-204 on Ubuntu 13.10's patch-set...<br>
</div></div>RFC1: For some reason libudev cosiders every link or file as sysfs attribute (opposed to udevadm). Is this intended ?<br></div>RFC2: Since this is my first patch, please comment on any changes it needs and I'll iterate. Thank you...<br>
<div><div><div><br>Signed-off-by: Andreas Fuchs <<a href="mailto:anduchs@gmail.com">anduchs@gmail.com</a>><br>---<br> src/gudev/gudevdevice.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++<br> src/gudev/gudevdevice.h |  3 +++<br>
 2 files changed, 56 insertions(+)<br><br>diff --git a/src/gudev/gudevdevice.c b/src/gudev/gudevdevice.c<br>index 6c9e0f5..2c768b7 100644<br>--- a/src/gudev/gudevdevice.c<br>+++ b/src/gudev/gudevdevice.c<br>@@ -59,6 +59,8 @@<br>
  * g_udev_device_get_property_as_strv().<br>  *<br>  * To access sysfs attributes for the device, use<br>+ * g_udev_device_get_sysfs_attr_keys(),<br>+ * g_udev_device_has_sysfs_attr(),<br>  * g_udev_device_get_sysfs_attr(),<br>
  * g_udev_device_get_sysfs_attr_as_int(),<br>  * g_udev_device_get_sysfs_attr_as_uint64(),<br>@@ -84,6 +86,7 @@ struct _GUdevDevicePrivate<br>   /* computed ondemand and cached */<br>   gchar **device_file_symlinks;<br>   gchar **property_keys;<br>
+  gchar **sysfs_attr_keys;<br>   gchar **tags;<br>   GHashTable *prop_strvs;<br>   GHashTable *sysfs_attr_strvs;<br>@@ -98,6 +101,7 @@ g_udev_device_finalize (GObject *object)<br> <br>   g_strfreev (device->priv->device_file_symlinks);<br>
   g_strfreev (device->priv->property_keys);<br>+  g_strfreev (device->priv->sysfs_attr_keys);<br>   g_strfreev (device->priv->tags);<br> <br>   if (device->priv->udevice != NULL)<br>@@ -699,6 +703,55 @@ out:<br>
 /* ---------------------------------------------------------------------------------------------------- */<br> <br> /**<br>+ * g_udev_device_get_sysfs_attr_keys:<br>+ * @device: A #GUdevDevice.<br>+ *<br>+ * Gets all keys for sysfs attributes on @device.<br>
+ *<br>+ * Returns: (transfer none) (array zero-terminated=1) (element-type utf8): A %NULL terminated string array of sysfs attribute keys. This array is owned by @device and should not be freed by the caller.<br>+ */<br>
+const gchar * const *<br>+g_udev_device_get_sysfs_attr_keys (GUdevDevice *device)<br>+{<br>+  struct udev_list_entry *l;<br>+  GPtrArray *p;<br>+<br>+  g_return_val_if_fail (G_UDEV_IS_DEVICE (device), NULL);<br>+<br>+  if (device->priv->sysfs_attr_keys != NULL)<br>
+    goto out;<br>+<br>+  p = g_ptr_array_new ();<br>+  for (l = udev_device_get_sysattr_list_entry (device->priv->udevice); l != NULL; l = udev_list_entry_get_next (l))<br>+    {<br>+      g_ptr_array_add (p, g_strdup (udev_list_entry_get_name (l)));<br>
+    }<br>+  g_ptr_array_add (p, NULL);<br>+  device->priv->sysfs_attr_keys = (gchar **) g_ptr_array_free (p, FALSE);<br>+<br>+ out:<br>+  return (const gchar * const *) device->priv->sysfs_attr_keys;<br>+}<br>
+<br>+/**<br>+ * g_udev_device_has_sysfs_attr:<br>+ * @device: A #GUdevDevice.<br>+ * @key: Name of sysfs attribute.<br>+ *<br>+ * Check if a the sysfs attribute with the given key exists.<br>+ *<br>+ * Returns: %TRUE only if the value for @key exist.<br>
+ */<br>+gboolean<br>+g_udev_device_has_sysfs_attr (GUdevDevice  *device,<br>+                            const gchar  *key)<br>+{<br>+  g_return_val_if_fail (G_UDEV_IS_DEVICE (device), FALSE);<br>+  g_return_val_if_fail (key != NULL, FALSE);<br>
+  return udev_device_get_sysattr_value (device->priv->udevice, key) != NULL;<br>+}<br>+<br>+/**<br>  * g_udev_device_get_sysfs_attr:<br>  * @device: A #GUdevDevice.<br>  * @name: Name of the sysfs attribute.<br>diff --git a/src/gudev/gudevdevice.h b/src/gudev/gudevdevice.h<br>
index 457b961..72ec180 100644<br>--- a/src/gudev/gudevdevice.h<br>+++ b/src/gudev/gudevdevice.h<br>@@ -108,6 +108,9 @@ gboolean            g_udev_device_get_property_as_boolean   (GUdevDevice  *devic<br> const gchar* const *g_udev_device_get_property_as_strv      (GUdevDevice  *device,<br>
                                                              const gchar  *key);<br> <br>+const gchar* const *g_udev_device_get_sysfs_attr_keys       (GUdevDevice  *device);<br>+gboolean            g_udev_device_has_sysfs_attr            (GUdevDevice  *device,<br>
+                                                             const gchar  *key);<br> const gchar        *g_udev_device_get_sysfs_attr            (GUdevDevice  *device,<br>                                                              const gchar  *name);<br>
 gint                g_udev_device_get_sysfs_attr_as_int     (GUdevDevice  *device,<br>-- <br>1.8.3.2<br><br></div></div></div></div>