1 /* -*- Mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
3 * Copyright (C) 2008 David Zeuthen <davidz@redhat.com>
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
28 #include "gudevdevice.h"
29 #include "gudevprivate.h"
33 * @short_description: Get information about a device
35 * The #GUdevDevice class is used to get information about a specific
36 * device. Note that you cannot instantiate a #GUdevDevice object
37 * yourself. Instead you must use #GUdevClient to obtain #GUdevDevice
40 * To get basic information about a device, use
41 * g_udev_device_get_subsystem(), g_udev_device_get_devtype(),
42 * g_udev_device_get_name(), g_udev_device_get_number(),
43 * g_udev_device_get_sysfs_path(), g_udev_device_get_driver(),
44 * g_udev_device_get_action(), g_udev_device_get_seqnum(),
45 * g_udev_device_get_device_type(), g_udev_device_get_device_number(),
46 * g_udev_device_get_device_file(),
47 * g_udev_device_get_device_file_symlinks().
49 * To navigate the device tree, use g_udev_device_get_parent() and
50 * g_udev_device_get_parent_with_subsystem().
52 * To access udev properties for the device, use
53 * g_udev_device_get_property_keys(),
54 * g_udev_device_has_property(),
55 * g_udev_device_get_property(),
56 * g_udev_device_get_property_as_int(),
57 * g_udev_device_get_property_as_uint64(),
58 * g_udev_device_get_property_as_double(),
59 * g_udev_device_get_property_as_boolean() and
60 * g_udev_device_get_property_as_strv().
62 * To access sysfs attributes for the device, use
63 * g_udev_device_get_sysfs_attr_keys(),
64 * g_udev_device_has_sysfs_attr(),
65 * g_udev_device_get_sysfs_attr(),
66 * g_udev_device_get_sysfs_attr_as_int(),
67 * g_udev_device_get_sysfs_attr_as_uint64(),
68 * g_udev_device_get_sysfs_attr_as_double(),
69 * g_udev_device_get_sysfs_attr_as_boolean() and
70 * g_udev_device_get_sysfs_attr_as_strv().
72 * Note that all getters on #GUdevDevice are non-reffing – returned
73 * values are owned by the object, should not be freed and are only
74 * valid as long as the object is alive.
76 * By design, #GUdevDevice will not react to changes for a device – it
77 * only contains a snapshot of information when the #GUdevDevice
78 * object was created. To work with changes, you typically connect to
79 * the #GUdevClient::uevent signal on a #GUdevClient and get a new
80 * #GUdevDevice whenever an event happens.
83 struct _GUdevDevicePrivate
85 struct udev_device *udevice;
87 /* computed ondemand and cached */
88 gchar **device_file_symlinks;
89 gchar **property_keys;
90 gchar **sysfs_attr_keys;
92 GHashTable *prop_strvs;
93 GHashTable *sysfs_attr_strvs;
96 G_DEFINE_TYPE (GUdevDevice, g_udev_device, G_TYPE_OBJECT)
99 g_udev_device_finalize (GObject *object)
101 GUdevDevice *device = G_UDEV_DEVICE (object);
103 g_strfreev (device->priv->device_file_symlinks);
104 g_strfreev (device->priv->property_keys);
105 g_strfreev (device->priv->sysfs_attr_keys);
106 g_strfreev (device->priv->tags);
108 if (device->priv->udevice != NULL)
109 udev_device_unref (device->priv->udevice);
111 if (device->priv->prop_strvs != NULL)
112 g_hash_table_unref (device->priv->prop_strvs);
114 if (device->priv->sysfs_attr_strvs != NULL)
115 g_hash_table_unref (device->priv->sysfs_attr_strvs);
117 if (G_OBJECT_CLASS (g_udev_device_parent_class)->finalize != NULL)
118 (* G_OBJECT_CLASS (g_udev_device_parent_class)->finalize) (object);
122 g_udev_device_class_init (GUdevDeviceClass *klass)
124 GObjectClass *gobject_class = (GObjectClass *) klass;
126 gobject_class->finalize = g_udev_device_finalize;
128 g_type_class_add_private (klass, sizeof (GUdevDevicePrivate));
132 g_udev_device_init (GUdevDevice *device)
134 device->priv = G_TYPE_INSTANCE_GET_PRIVATE (device,
141 _g_udev_device_new (struct udev_device *udevice)
145 device = G_UDEV_DEVICE (g_object_new (G_UDEV_TYPE_DEVICE, NULL));
146 device->priv->udevice = udev_device_ref (udevice);
152 * g_udev_device_get_subsystem:
153 * @device: A #GUdevDevice.
155 * Gets the subsystem for @device.
157 * Returns: The subsystem for @device.
160 g_udev_device_get_subsystem (GUdevDevice *device)
162 g_return_val_if_fail (G_UDEV_IS_DEVICE (device), NULL);
163 return udev_device_get_subsystem (device->priv->udevice);
167 * g_udev_device_get_devtype:
168 * @device: A #GUdevDevice.
170 * Gets the device type for @device.
172 * Returns: The devtype for @device.
175 g_udev_device_get_devtype (GUdevDevice *device)
177 g_return_val_if_fail (G_UDEV_IS_DEVICE (device), NULL);
178 return udev_device_get_devtype (device->priv->udevice);
182 * g_udev_device_get_name:
183 * @device: A #GUdevDevice.
185 * Gets the name of @device, e.g. "sda3".
187 * Returns: The name of @device.
190 g_udev_device_get_name (GUdevDevice *device)
192 g_return_val_if_fail (G_UDEV_IS_DEVICE (device), NULL);
193 return udev_device_get_sysname (device->priv->udevice);
197 * g_udev_device_get_number:
198 * @device: A #GUdevDevice.
200 * Gets the number of @device, e.g. "3" if g_udev_device_get_name() returns "sda3".
202 * Returns: The number of @device.
205 g_udev_device_get_number (GUdevDevice *device)
207 g_return_val_if_fail (G_UDEV_IS_DEVICE (device), NULL);
208 return udev_device_get_sysnum (device->priv->udevice);
212 * g_udev_device_get_sysfs_path:
213 * @device: A #GUdevDevice.
215 * Gets the sysfs path for @device.
217 * Returns: The sysfs path for @device.
220 g_udev_device_get_sysfs_path (GUdevDevice *device)
222 g_return_val_if_fail (G_UDEV_IS_DEVICE (device), NULL);
223 return udev_device_get_syspath (device->priv->udevice);
227 * g_udev_device_get_driver:
228 * @device: A #GUdevDevice.
230 * Gets the name of the driver used for @device.
232 * Returns: (nullable): The name of the driver for @device or %NULL if
236 g_udev_device_get_driver (GUdevDevice *device)
238 g_return_val_if_fail (G_UDEV_IS_DEVICE (device), NULL);
239 return udev_device_get_driver (device->priv->udevice);
243 * g_udev_device_get_action:
244 * @device: A #GUdevDevice.
246 * Gets the most recent action (e.g. "add", "remove", "change", etc.) for @device.
248 * Returns: An action string.
251 g_udev_device_get_action (GUdevDevice *device)
253 g_return_val_if_fail (G_UDEV_IS_DEVICE (device), NULL);
254 return udev_device_get_action (device->priv->udevice);
258 * g_udev_device_get_seqnum:
259 * @device: A #GUdevDevice.
261 * Gets the most recent sequence number for @device.
263 * Returns: A sequence number.
266 g_udev_device_get_seqnum (GUdevDevice *device)
268 g_return_val_if_fail (G_UDEV_IS_DEVICE (device), 0);
269 return udev_device_get_seqnum (device->priv->udevice);
273 * g_udev_device_get_device_type:
274 * @device: A #GUdevDevice.
276 * Gets the type of the device file, if any, for @device.
278 * Returns: The device number for @device or #G_UDEV_DEVICE_TYPE_NONE if the device does not have a device file.
281 g_udev_device_get_device_type (GUdevDevice *device)
283 struct stat stat_buf;
284 const gchar *device_file;
285 GUdevDeviceType type;
287 g_return_val_if_fail (G_UDEV_IS_DEVICE (device), G_UDEV_DEVICE_TYPE_NONE);
289 type = G_UDEV_DEVICE_TYPE_NONE;
291 /* TODO: would be better to have support for this in libudev... */
293 device_file = g_udev_device_get_device_file (device);
294 if (device_file == NULL)
297 if (stat (device_file, &stat_buf) != 0)
300 if (S_ISBLK (stat_buf.st_mode))
301 type = G_UDEV_DEVICE_TYPE_BLOCK;
302 else if (S_ISCHR (stat_buf.st_mode))
303 type = G_UDEV_DEVICE_TYPE_CHAR;
310 * g_udev_device_get_device_number:
311 * @device: A #GUdevDevice.
313 * Gets the device number, if any, for @device.
315 * Returns: The device number for @device or 0 if unknown.
318 g_udev_device_get_device_number (GUdevDevice *device)
320 g_return_val_if_fail (G_UDEV_IS_DEVICE (device), 0);
321 return udev_device_get_devnum (device->priv->udevice);
325 * g_udev_device_get_device_file:
326 * @device: A #GUdevDevice.
328 * Gets the device file for @device.
330 * Returns: (nullable): The device file for @device or %NULL if no
331 * device file exists.
334 g_udev_device_get_device_file (GUdevDevice *device)
336 g_return_val_if_fail (G_UDEV_IS_DEVICE (device), NULL);
337 return udev_device_get_devnode (device->priv->udevice);
341 * g_udev_device_get_device_file_symlinks:
342 * @device: A #GUdevDevice.
344 * Gets a list of symlinks (in <literal>/dev</literal>) that points to
345 * the device file for @device.
347 * Returns: (transfer none) (array zero-terminated=1) (element-type utf8): A %NULL terminated string array of symlinks. This array is owned by @device and should not be freed by the caller.
349 const gchar * const *
350 g_udev_device_get_device_file_symlinks (GUdevDevice *device)
352 struct udev_list_entry *l;
355 g_return_val_if_fail (G_UDEV_IS_DEVICE (device), NULL);
357 if (device->priv->device_file_symlinks != NULL)
360 p = g_ptr_array_new ();
361 for (l = udev_device_get_devlinks_list_entry (device->priv->udevice); l != NULL; l = udev_list_entry_get_next (l))
363 g_ptr_array_add (p, g_strdup (udev_list_entry_get_name (l)));
365 g_ptr_array_add (p, NULL);
366 device->priv->device_file_symlinks = (gchar **) g_ptr_array_free (p, FALSE);
369 return (const gchar * const *) device->priv->device_file_symlinks;
372 /* ---------------------------------------------------------------------------------------------------- */
375 * g_udev_device_get_parent:
376 * @device: A #GUdevDevice.
378 * Gets the immediate parent of @device, if any.
380 * Returns: (nullable) (transfer full): A #GUdevDevice or %NULL if
381 * @device has no parent. Free with g_object_unref().
384 g_udev_device_get_parent (GUdevDevice *device)
387 struct udev_device *udevice;
389 g_return_val_if_fail (G_UDEV_IS_DEVICE (device), NULL);
393 udevice = udev_device_get_parent (device->priv->udevice);
397 ret = _g_udev_device_new (udevice);
404 * g_udev_device_get_parent_with_subsystem:
405 * @device: A #GUdevDevice.
406 * @subsystem: The subsystem of the parent to get.
407 * @devtype: (allow-none): The devtype of the parent to get or %NULL.
409 * Walks up the chain of parents of @device and returns the first
410 * device encountered where @subsystem and @devtype matches, if any.
412 * Returns: (nullable) (transfer full): A #GUdevDevice or %NULL if
413 * @device has no parent with @subsystem and @devtype. Free with
417 g_udev_device_get_parent_with_subsystem (GUdevDevice *device,
418 const gchar *subsystem,
419 const gchar *devtype)
422 struct udev_device *udevice;
424 g_return_val_if_fail (G_UDEV_IS_DEVICE (device), NULL);
425 g_return_val_if_fail (subsystem != NULL, NULL);
429 udevice = udev_device_get_parent_with_subsystem_devtype (device->priv->udevice,
435 ret = _g_udev_device_new (udevice);
441 /* ---------------------------------------------------------------------------------------------------- */
444 * g_udev_device_get_property_keys:
445 * @device: A #GUdevDevice.
447 * Gets all keys for properties on @device.
449 * Returns: (transfer none) (array zero-terminated=1) (element-type utf8): A %NULL terminated string array of property keys. This array is owned by @device and should not be freed by the caller.
452 g_udev_device_get_property_keys (GUdevDevice *device)
454 struct udev_list_entry *l;
457 g_return_val_if_fail (G_UDEV_IS_DEVICE (device), NULL);
459 if (device->priv->property_keys != NULL)
462 p = g_ptr_array_new ();
463 for (l = udev_device_get_properties_list_entry (device->priv->udevice); l != NULL; l = udev_list_entry_get_next (l))
465 g_ptr_array_add (p, g_strdup (udev_list_entry_get_name (l)));
467 g_ptr_array_add (p, NULL);
468 device->priv->property_keys = (gchar **) g_ptr_array_free (p, FALSE);
471 return (const gchar * const *) device->priv->property_keys;
476 * g_udev_device_has_property:
477 * @device: A #GUdevDevice.
478 * @key: Name of property.
480 * Check if a the property with the given key exists.
482 * Returns: %TRUE only if the value for @key exist.
485 g_udev_device_has_property (GUdevDevice *device,
488 g_return_val_if_fail (G_UDEV_IS_DEVICE (device), FALSE);
489 g_return_val_if_fail (key != NULL, FALSE);
490 return udev_device_get_property_value (device->priv->udevice, key) != NULL;
494 * g_udev_device_get_property:
495 * @device: A #GUdevDevice.
496 * @key: Name of property.
498 * Look up the value for @key on @device.
500 * Returns: (nullable): The value for @key or %NULL if @key doesn't
501 * exist on @device. Do not free this string, it is owned by @device.
504 g_udev_device_get_property (GUdevDevice *device,
507 g_return_val_if_fail (G_UDEV_IS_DEVICE (device), NULL);
508 g_return_val_if_fail (key != NULL, NULL);
509 return udev_device_get_property_value (device->priv->udevice, key);
513 * g_udev_device_get_property_as_int:
514 * @device: A #GUdevDevice.
515 * @key: Name of property.
517 * Look up the value for @key on @device and convert it to an integer
520 * Returns: The value for @key or 0 if @key doesn't exist or
524 g_udev_device_get_property_as_int (GUdevDevice *device,
530 g_return_val_if_fail (G_UDEV_IS_DEVICE (device), 0);
531 g_return_val_if_fail (key != NULL, 0);
534 s = g_udev_device_get_property (device, key);
538 result = strtol (s, NULL, 0);
544 * g_udev_device_get_property_as_uint64:
545 * @device: A #GUdevDevice.
546 * @key: Name of property.
548 * Look up the value for @key on @device and convert it to an unsigned
549 * 64-bit integer using g_ascii_strtoull().
551 * Returns: The value for @key or 0 if @key doesn't exist or isn't a
555 g_udev_device_get_property_as_uint64 (GUdevDevice *device,
561 g_return_val_if_fail (G_UDEV_IS_DEVICE (device), 0);
562 g_return_val_if_fail (key != NULL, 0);
565 s = g_udev_device_get_property (device, key);
569 result = g_ascii_strtoull (s, NULL, 0);
575 * g_udev_device_get_property_as_double:
576 * @device: A #GUdevDevice.
577 * @key: Name of property.
579 * Look up the value for @key on @device and convert it to a double
580 * precision floating point number using strtod().
582 * Returns: The value for @key or 0.0 if @key doesn't exist or isn't a
586 g_udev_device_get_property_as_double (GUdevDevice *device,
592 g_return_val_if_fail (G_UDEV_IS_DEVICE (device), 0.0);
593 g_return_val_if_fail (key != NULL, 0.0);
596 s = g_udev_device_get_property (device, key);
600 result = strtod (s, NULL);
606 * g_udev_device_get_property_as_boolean:
607 * @device: A #GUdevDevice.
608 * @key: Name of property.
610 * Look up the value for @key on @device and convert it to an
611 * boolean. This is done by doing a case-insensitive string comparison
612 * on the string value against "1" and "true".
614 * Returns: The value for @key or %FALSE if @key doesn't exist or
618 g_udev_device_get_property_as_boolean (GUdevDevice *device,
624 g_return_val_if_fail (G_UDEV_IS_DEVICE (device), FALSE);
625 g_return_val_if_fail (key != NULL, FALSE);
628 s = g_udev_device_get_property (device, key);
632 if (strcmp (s, "1") == 0 || g_ascii_strcasecmp (s, "true") == 0)
639 split_at_whitespace (const gchar *s)
645 result = g_strsplit_set (s, " \v\t\r\n", 0);
647 /* remove empty strings, thanks GLib */
648 for (n = 0; result[n] != NULL; n++)
650 if (strlen (result[n]) == 0)
653 for (m = n; result[m] != NULL; m++)
654 result[m] = result[m + 1];
663 * g_udev_device_get_property_as_strv:
664 * @device: A #GUdevDevice.
665 * @key: Name of property.
667 * Look up the value for @key on @device and return the result of
668 * splitting it into non-empty tokens split at white space (only space
669 * (' '), form-feed ('\f'), newline ('\n'), carriage return ('\r'),
670 * horizontal tab ('\t'), and vertical tab ('\v') are considered; the
671 * locale is not taken into account).
673 * Returns: (nullable) (transfer none) (array zero-terminated=1) (element-type utf8):
674 * The value of @key on @device split into tokens or %NULL if @key
675 * doesn't exist. This array is owned by @device and should not be
676 * freed by the caller.
679 g_udev_device_get_property_as_strv (GUdevDevice *device,
685 g_return_val_if_fail (G_UDEV_IS_DEVICE (device), NULL);
686 g_return_val_if_fail (key != NULL, NULL);
688 if (device->priv->prop_strvs != NULL)
690 result = g_hash_table_lookup (device->priv->prop_strvs, key);
696 s = g_udev_device_get_property (device, key);
700 result = split_at_whitespace (s);
704 if (device->priv->prop_strvs == NULL)
705 device->priv->prop_strvs = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, (GDestroyNotify) g_strfreev);
706 g_hash_table_insert (device->priv->prop_strvs, g_strdup (key), result);
709 return (const gchar* const *) result;
712 /* ---------------------------------------------------------------------------------------------------- */
715 * g_udev_device_get_sysfs_attr_keys:
716 * @device: A #GUdevDevice.
718 * Gets all keys for sysfs attributes on @device.
720 * 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.
722 const gchar * const *
723 g_udev_device_get_sysfs_attr_keys (GUdevDevice *device)
725 struct udev_list_entry *l;
728 g_return_val_if_fail (G_UDEV_IS_DEVICE (device), NULL);
730 if (device->priv->sysfs_attr_keys != NULL)
733 p = g_ptr_array_new ();
734 for (l = udev_device_get_sysattr_list_entry (device->priv->udevice); l != NULL; l = udev_list_entry_get_next (l))
736 g_ptr_array_add (p, g_strdup (udev_list_entry_get_name (l)));
738 g_ptr_array_add (p, NULL);
739 device->priv->sysfs_attr_keys = (gchar **) g_ptr_array_free (p, FALSE);
742 return (const gchar * const *) device->priv->sysfs_attr_keys;
746 * g_udev_device_has_sysfs_attr:
747 * @device: A #GUdevDevice.
748 * @key: Name of sysfs attribute.
750 * Check if a the sysfs attribute with the given key exists.
752 * Returns: %TRUE only if the value for @key exist.
755 g_udev_device_has_sysfs_attr (GUdevDevice *device,
758 g_return_val_if_fail (G_UDEV_IS_DEVICE (device), FALSE);
759 g_return_val_if_fail (key != NULL, FALSE);
760 return udev_device_get_sysattr_value (device->priv->udevice, key) != NULL;
764 * g_udev_device_get_sysfs_attr:
765 * @device: A #GUdevDevice.
766 * @name: Name of the sysfs attribute.
768 * Look up the sysfs attribute with @name on @device.
770 * Returns: (nullable): The value of the sysfs attribute or %NULL if
771 * there is no such attribute. Do not free this string, it is owned by
775 g_udev_device_get_sysfs_attr (GUdevDevice *device,
778 g_return_val_if_fail (G_UDEV_IS_DEVICE (device), NULL);
779 g_return_val_if_fail (name != NULL, NULL);
780 return udev_device_get_sysattr_value (device->priv->udevice, name);
784 * g_udev_device_get_sysfs_attr_as_int:
785 * @device: A #GUdevDevice.
786 * @name: Name of the sysfs attribute.
788 * Look up the sysfs attribute with @name on @device and convert it to an integer
791 * Returns: The value of the sysfs attribute or 0 if there is no such
795 g_udev_device_get_sysfs_attr_as_int (GUdevDevice *device,
801 g_return_val_if_fail (G_UDEV_IS_DEVICE (device), 0);
802 g_return_val_if_fail (name != NULL, 0);
805 s = g_udev_device_get_sysfs_attr (device, name);
809 result = strtol (s, NULL, 0);
815 * g_udev_device_get_sysfs_attr_as_uint64:
816 * @device: A #GUdevDevice.
817 * @name: Name of the sysfs attribute.
819 * Look up the sysfs attribute with @name on @device and convert it to an unsigned
820 * 64-bit integer using g_ascii_strtoull().
822 * Returns: The value of the sysfs attribute or 0 if there is no such
826 g_udev_device_get_sysfs_attr_as_uint64 (GUdevDevice *device,
832 g_return_val_if_fail (G_UDEV_IS_DEVICE (device), 0);
833 g_return_val_if_fail (name != NULL, 0);
836 s = g_udev_device_get_sysfs_attr (device, name);
840 result = g_ascii_strtoull (s, NULL, 0);
846 * g_udev_device_get_sysfs_attr_as_double:
847 * @device: A #GUdevDevice.
848 * @name: Name of the sysfs attribute.
850 * Look up the sysfs attribute with @name on @device and convert it to a double
851 * precision floating point number using strtod().
853 * Returns: The value of the sysfs attribute or 0.0 if there is no such
857 g_udev_device_get_sysfs_attr_as_double (GUdevDevice *device,
863 g_return_val_if_fail (G_UDEV_IS_DEVICE (device), 0.0);
864 g_return_val_if_fail (name != NULL, 0.0);
867 s = g_udev_device_get_sysfs_attr (device, name);
871 result = strtod (s, NULL);
877 * g_udev_device_get_sysfs_attr_as_boolean:
878 * @device: A #GUdevDevice.
879 * @name: Name of the sysfs attribute.
881 * Look up the sysfs attribute with @name on @device and convert it to an
882 * boolean. This is done by doing a case-insensitive string comparison
883 * on the string value against "1" and "true".
885 * Returns: The value of the sysfs attribute or %FALSE if there is no such
889 g_udev_device_get_sysfs_attr_as_boolean (GUdevDevice *device,
895 g_return_val_if_fail (G_UDEV_IS_DEVICE (device), FALSE);
896 g_return_val_if_fail (name != NULL, FALSE);
899 s = g_udev_device_get_sysfs_attr (device, name);
903 if (strcmp (s, "1") == 0 || g_ascii_strcasecmp (s, "true") == 0)
910 * g_udev_device_get_sysfs_attr_as_strv:
911 * @device: A #GUdevDevice.
912 * @name: Name of the sysfs attribute.
914 * Look up the sysfs attribute with @name on @device and return the result of
915 * splitting it into non-empty tokens split at white space (only space (' '),
916 * form-feed ('\f'), newline ('\n'), carriage return ('\r'), horizontal
917 * tab ('\t'), and vertical tab ('\v') are considered; the locale is
918 * not taken into account).
920 * Returns: (nullable) (transfer none) (array zero-terminated=1) (element-type utf8):
921 * The value of the sysfs attribute split into tokens or %NULL if
922 * there is no such attribute. This array is owned by @device and
923 * should not be freed by the caller.
925 const gchar * const *
926 g_udev_device_get_sysfs_attr_as_strv (GUdevDevice *device,
932 g_return_val_if_fail (G_UDEV_IS_DEVICE (device), NULL);
933 g_return_val_if_fail (name != NULL, NULL);
935 if (device->priv->sysfs_attr_strvs != NULL)
937 result = g_hash_table_lookup (device->priv->sysfs_attr_strvs, name);
943 s = g_udev_device_get_sysfs_attr (device, name);
947 result = split_at_whitespace (s);
951 if (device->priv->sysfs_attr_strvs == NULL)
952 device->priv->sysfs_attr_strvs = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, (GDestroyNotify) g_strfreev);
953 g_hash_table_insert (device->priv->sysfs_attr_strvs, g_strdup (name), result);
956 return (const gchar* const *) result;
960 * g_udev_device_get_tags:
961 * @device: A #GUdevDevice.
963 * Gets all tags for @device.
965 * Returns: (transfer none) (array zero-terminated=1) (element-type utf8): A %NULL terminated string array of tags. This array is owned by @device and should not be freed by the caller.
970 g_udev_device_get_tags (GUdevDevice *device)
972 struct udev_list_entry *l;
975 g_return_val_if_fail (G_UDEV_IS_DEVICE (device), NULL);
977 if (device->priv->tags != NULL)
980 p = g_ptr_array_new ();
981 for (l = udev_device_get_tags_list_entry (device->priv->udevice); l != NULL; l = udev_list_entry_get_next (l))
983 g_ptr_array_add (p, g_strdup (udev_list_entry_get_name (l)));
985 g_ptr_array_add (p, NULL);
986 device->priv->tags = (gchar **) g_ptr_array_free (p, FALSE);
989 return (const gchar * const *) device->priv->tags;
993 * g_udev_device_get_is_initialized:
994 * @device: A #GUdevDevice.
996 * Gets whether @device has been initalized.
998 * Returns: Whether @device has been initialized.
1003 g_udev_device_get_is_initialized (GUdevDevice *device)
1005 g_return_val_if_fail (G_UDEV_IS_DEVICE (device), FALSE);
1006 return udev_device_get_is_initialized (device->priv->udevice);
1010 * g_udev_device_get_usec_since_initialized:
1011 * @device: A #GUdevDevice.
1013 * Gets number of micro-seconds since @device was initialized.
1015 * This only works for devices with properties in the udev
1016 * database. All other devices return 0.
1018 * Returns: Number of micro-seconds since @device was initialized or 0 if unknown.
1023 g_udev_device_get_usec_since_initialized (GUdevDevice *device)
1025 g_return_val_if_fail (G_UDEV_IS_DEVICE (device), 0);
1026 return udev_device_get_usec_since_initialized (device->priv->udevice);