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
27 #include "gudevdevice.h"
28 #include "gudevprivate.h"
32 * @short_description: Get information about a device
34 * The #GUdevDevice class is used to get information about a specific
35 * device. Note that you cannot instantiate a #GUdevDevice object
36 * yourself. Instead you must use #GUdevClient to obtain #GUdevDevice
39 * To get basic information about a device, use
40 * g_udev_device_get_subsystem(), g_udev_device_get_devtype(),
41 * g_udev_device_get_name(), g_udev_device_get_number(),
42 * g_udev_device_get_sysfs_path(), g_udev_device_get_driver(),
43 * g_udev_device_get_action(), g_udev_device_get_seqnum(),
44 * g_udev_device_get_device_type(), g_udev_device_get_device_number(),
45 * g_udev_device_get_device_file(),
46 * g_udev_device_get_device_file_symlinks().
48 * To navigate the device tree, use g_udev_device_get_parent() and
49 * g_udev_device_get_parent_with_subsystem().
51 * To access udev properties for the device, use
52 * g_udev_device_get_property_keys(),
53 * g_udev_device_has_property(),
54 * g_udev_device_get_property(),
55 * g_udev_device_get_property_as_int(),
56 * g_udev_device_get_property_as_uint64(),
57 * g_udev_device_get_property_as_double(),
58 * g_udev_device_get_property_as_boolean() and
59 * g_udev_device_get_property_as_strv().
61 * To access sysfs attributes for the device, use
62 * g_udev_device_get_sysfs_attr_keys(),
63 * g_udev_device_has_sysfs_attr(),
64 * g_udev_device_get_sysfs_attr(),
65 * g_udev_device_get_sysfs_attr_as_int(),
66 * g_udev_device_get_sysfs_attr_as_uint64(),
67 * g_udev_device_get_sysfs_attr_as_double(),
68 * g_udev_device_get_sysfs_attr_as_boolean() and
69 * g_udev_device_get_sysfs_attr_as_strv().
71 * Note that all getters on #GUdevDevice are non-reffing – returned
72 * values are owned by the object, should not be freed and are only
73 * valid as long as the object is alive.
75 * By design, #GUdevDevice will not react to changes for a device – it
76 * only contains a snapshot of information when the #GUdevDevice
77 * object was created. To work with changes, you typically connect to
78 * the #GUdevClient::uevent signal on a #GUdevClient and get a new
79 * #GUdevDevice whenever an event happens.
82 struct _GUdevDevicePrivate
84 struct udev_device *udevice;
86 /* computed ondemand and cached */
87 gchar **device_file_symlinks;
88 gchar **property_keys;
89 gchar **sysfs_attr_keys;
91 GHashTable *prop_strvs;
92 GHashTable *sysfs_attr_strvs;
95 G_DEFINE_TYPE (GUdevDevice, g_udev_device, G_TYPE_OBJECT)
98 g_udev_device_finalize (GObject *object)
100 GUdevDevice *device = G_UDEV_DEVICE (object);
102 g_strfreev (device->priv->device_file_symlinks);
103 g_strfreev (device->priv->property_keys);
104 g_strfreev (device->priv->sysfs_attr_keys);
105 g_strfreev (device->priv->tags);
107 if (device->priv->udevice != NULL)
108 udev_device_unref (device->priv->udevice);
110 if (device->priv->prop_strvs != NULL)
111 g_hash_table_unref (device->priv->prop_strvs);
113 if (device->priv->sysfs_attr_strvs != NULL)
114 g_hash_table_unref (device->priv->sysfs_attr_strvs);
116 if (G_OBJECT_CLASS (g_udev_device_parent_class)->finalize != NULL)
117 (* G_OBJECT_CLASS (g_udev_device_parent_class)->finalize) (object);
121 g_udev_device_class_init (GUdevDeviceClass *klass)
123 GObjectClass *gobject_class = (GObjectClass *) klass;
125 gobject_class->finalize = g_udev_device_finalize;
127 g_type_class_add_private (klass, sizeof (GUdevDevicePrivate));
131 g_udev_device_init (GUdevDevice *device)
133 device->priv = G_TYPE_INSTANCE_GET_PRIVATE (device,
140 _g_udev_device_new (struct udev_device *udevice)
144 device = G_UDEV_DEVICE (g_object_new (G_UDEV_TYPE_DEVICE, NULL));
145 device->priv->udevice = udev_device_ref (udevice);
151 * g_udev_device_get_subsystem:
152 * @device: A #GUdevDevice.
154 * Gets the subsystem for @device.
156 * Returns: The subsystem for @device.
159 g_udev_device_get_subsystem (GUdevDevice *device)
161 g_return_val_if_fail (G_UDEV_IS_DEVICE (device), NULL);
162 return udev_device_get_subsystem (device->priv->udevice);
166 * g_udev_device_get_devtype:
167 * @device: A #GUdevDevice.
169 * Gets the device type for @device.
171 * Returns: The devtype for @device.
174 g_udev_device_get_devtype (GUdevDevice *device)
176 g_return_val_if_fail (G_UDEV_IS_DEVICE (device), NULL);
177 return udev_device_get_devtype (device->priv->udevice);
181 * g_udev_device_get_name:
182 * @device: A #GUdevDevice.
184 * Gets the name of @device, e.g. "sda3".
186 * Returns: The name of @device.
189 g_udev_device_get_name (GUdevDevice *device)
191 g_return_val_if_fail (G_UDEV_IS_DEVICE (device), NULL);
192 return udev_device_get_sysname (device->priv->udevice);
196 * g_udev_device_get_number:
197 * @device: A #GUdevDevice.
199 * Gets the number of @device, e.g. "3" if g_udev_device_get_name() returns "sda3".
201 * Returns: The number of @device.
204 g_udev_device_get_number (GUdevDevice *device)
206 g_return_val_if_fail (G_UDEV_IS_DEVICE (device), NULL);
207 return udev_device_get_sysnum (device->priv->udevice);
211 * g_udev_device_get_sysfs_path:
212 * @device: A #GUdevDevice.
214 * Gets the sysfs path for @device.
216 * Returns: The sysfs path for @device.
219 g_udev_device_get_sysfs_path (GUdevDevice *device)
221 g_return_val_if_fail (G_UDEV_IS_DEVICE (device), NULL);
222 return udev_device_get_syspath (device->priv->udevice);
226 * g_udev_device_get_driver:
227 * @device: A #GUdevDevice.
229 * Gets the name of the driver used for @device.
231 * Returns: (nullable): The name of the driver for @device or %NULL if
235 g_udev_device_get_driver (GUdevDevice *device)
237 g_return_val_if_fail (G_UDEV_IS_DEVICE (device), NULL);
238 return udev_device_get_driver (device->priv->udevice);
242 * g_udev_device_get_action:
243 * @device: A #GUdevDevice.
245 * Gets the most recent action (e.g. "add", "remove", "change", etc.) for @device.
247 * Returns: An action string.
250 g_udev_device_get_action (GUdevDevice *device)
252 g_return_val_if_fail (G_UDEV_IS_DEVICE (device), NULL);
253 return udev_device_get_action (device->priv->udevice);
257 * g_udev_device_get_seqnum:
258 * @device: A #GUdevDevice.
260 * Gets the most recent sequence number for @device.
262 * Returns: A sequence number.
265 g_udev_device_get_seqnum (GUdevDevice *device)
267 g_return_val_if_fail (G_UDEV_IS_DEVICE (device), 0);
268 return udev_device_get_seqnum (device->priv->udevice);
272 * g_udev_device_get_device_type:
273 * @device: A #GUdevDevice.
275 * Gets the type of the device file, if any, for @device.
277 * Returns: The device number for @device or #G_UDEV_DEVICE_TYPE_NONE if the device does not have a device file.
280 g_udev_device_get_device_type (GUdevDevice *device)
282 struct stat stat_buf;
283 const gchar *device_file;
284 GUdevDeviceType type;
286 g_return_val_if_fail (G_UDEV_IS_DEVICE (device), G_UDEV_DEVICE_TYPE_NONE);
288 type = G_UDEV_DEVICE_TYPE_NONE;
290 /* TODO: would be better to have support for this in libudev... */
292 device_file = g_udev_device_get_device_file (device);
293 if (device_file == NULL)
296 if (stat (device_file, &stat_buf) != 0)
299 if (S_ISBLK (stat_buf.st_mode))
300 type = G_UDEV_DEVICE_TYPE_BLOCK;
301 else if (S_ISCHR (stat_buf.st_mode))
302 type = G_UDEV_DEVICE_TYPE_CHAR;
309 * g_udev_device_get_device_number:
310 * @device: A #GUdevDevice.
312 * Gets the device number, if any, for @device.
314 * Returns: The device number for @device or 0 if unknown.
317 g_udev_device_get_device_number (GUdevDevice *device)
319 g_return_val_if_fail (G_UDEV_IS_DEVICE (device), 0);
320 return udev_device_get_devnum (device->priv->udevice);
324 * g_udev_device_get_device_file:
325 * @device: A #GUdevDevice.
327 * Gets the device file for @device.
329 * Returns: (nullable): The device file for @device or %NULL if no
330 * device file exists.
333 g_udev_device_get_device_file (GUdevDevice *device)
335 g_return_val_if_fail (G_UDEV_IS_DEVICE (device), NULL);
336 return udev_device_get_devnode (device->priv->udevice);
340 * g_udev_device_get_device_file_symlinks:
341 * @device: A #GUdevDevice.
343 * Gets a list of symlinks (in <literal>/dev</literal>) that points to
344 * the device file for @device.
346 * 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.
348 const gchar * const *
349 g_udev_device_get_device_file_symlinks (GUdevDevice *device)
351 struct udev_list_entry *l;
354 g_return_val_if_fail (G_UDEV_IS_DEVICE (device), NULL);
356 if (device->priv->device_file_symlinks != NULL)
359 p = g_ptr_array_new ();
360 for (l = udev_device_get_devlinks_list_entry (device->priv->udevice); l != NULL; l = udev_list_entry_get_next (l))
362 g_ptr_array_add (p, g_strdup (udev_list_entry_get_name (l)));
364 g_ptr_array_add (p, NULL);
365 device->priv->device_file_symlinks = (gchar **) g_ptr_array_free (p, FALSE);
368 return (const gchar * const *) device->priv->device_file_symlinks;
371 /* ---------------------------------------------------------------------------------------------------- */
374 * g_udev_device_get_parent:
375 * @device: A #GUdevDevice.
377 * Gets the immediate parent of @device, if any.
379 * Returns: (nullable) (transfer full): A #GUdevDevice or %NULL if
380 * @device has no parent. Free with g_object_unref().
383 g_udev_device_get_parent (GUdevDevice *device)
386 struct udev_device *udevice;
388 g_return_val_if_fail (G_UDEV_IS_DEVICE (device), NULL);
392 udevice = udev_device_get_parent (device->priv->udevice);
396 ret = _g_udev_device_new (udevice);
403 * g_udev_device_get_parent_with_subsystem:
404 * @device: A #GUdevDevice.
405 * @subsystem: The subsystem of the parent to get.
406 * @devtype: (allow-none): The devtype of the parent to get or %NULL.
408 * Walks up the chain of parents of @device and returns the first
409 * device encountered where @subsystem and @devtype matches, if any.
411 * Returns: (nullable) (transfer full): A #GUdevDevice or %NULL if
412 * @device has no parent with @subsystem and @devtype. Free with
416 g_udev_device_get_parent_with_subsystem (GUdevDevice *device,
417 const gchar *subsystem,
418 const gchar *devtype)
421 struct udev_device *udevice;
423 g_return_val_if_fail (G_UDEV_IS_DEVICE (device), NULL);
424 g_return_val_if_fail (subsystem != NULL, NULL);
428 udevice = udev_device_get_parent_with_subsystem_devtype (device->priv->udevice,
434 ret = _g_udev_device_new (udevice);
440 /* ---------------------------------------------------------------------------------------------------- */
443 * g_udev_device_get_property_keys:
444 * @device: A #GUdevDevice.
446 * Gets all keys for properties on @device.
448 * 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.
451 g_udev_device_get_property_keys (GUdevDevice *device)
453 struct udev_list_entry *l;
456 g_return_val_if_fail (G_UDEV_IS_DEVICE (device), NULL);
458 if (device->priv->property_keys != NULL)
461 p = g_ptr_array_new ();
462 for (l = udev_device_get_properties_list_entry (device->priv->udevice); l != NULL; l = udev_list_entry_get_next (l))
464 g_ptr_array_add (p, g_strdup (udev_list_entry_get_name (l)));
466 g_ptr_array_add (p, NULL);
467 device->priv->property_keys = (gchar **) g_ptr_array_free (p, FALSE);
470 return (const gchar * const *) device->priv->property_keys;
475 * g_udev_device_has_property:
476 * @device: A #GUdevDevice.
477 * @key: Name of property.
479 * Check if a the property with the given key exists.
481 * Returns: %TRUE only if the value for @key exist.
484 g_udev_device_has_property (GUdevDevice *device,
487 g_return_val_if_fail (G_UDEV_IS_DEVICE (device), FALSE);
488 g_return_val_if_fail (key != NULL, FALSE);
489 return udev_device_get_property_value (device->priv->udevice, key) != NULL;
493 * g_udev_device_get_property:
494 * @device: A #GUdevDevice.
495 * @key: Name of property.
497 * Look up the value for @key on @device.
499 * Returns: (nullable): The value for @key or %NULL if @key doesn't
500 * exist on @device. Do not free this string, it is owned by @device.
503 g_udev_device_get_property (GUdevDevice *device,
506 g_return_val_if_fail (G_UDEV_IS_DEVICE (device), NULL);
507 g_return_val_if_fail (key != NULL, NULL);
508 return udev_device_get_property_value (device->priv->udevice, key);
512 * g_udev_device_get_property_as_int:
513 * @device: A #GUdevDevice.
514 * @key: Name of property.
516 * Look up the value for @key on @device and convert it to an integer
519 * Returns: The value for @key or 0 if @key doesn't exist or
523 g_udev_device_get_property_as_int (GUdevDevice *device,
529 g_return_val_if_fail (G_UDEV_IS_DEVICE (device), 0);
530 g_return_val_if_fail (key != NULL, 0);
533 s = g_udev_device_get_property (device, key);
537 result = strtol (s, NULL, 0);
543 * g_udev_device_get_property_as_uint64:
544 * @device: A #GUdevDevice.
545 * @key: Name of property.
547 * Look up the value for @key on @device and convert it to an unsigned
548 * 64-bit integer using g_ascii_strtoull().
550 * Returns: The value for @key or 0 if @key doesn't exist or isn't a
554 g_udev_device_get_property_as_uint64 (GUdevDevice *device,
560 g_return_val_if_fail (G_UDEV_IS_DEVICE (device), 0);
561 g_return_val_if_fail (key != NULL, 0);
564 s = g_udev_device_get_property (device, key);
568 result = g_ascii_strtoull (s, NULL, 0);
574 * g_udev_device_get_property_as_double:
575 * @device: A #GUdevDevice.
576 * @key: Name of property.
578 * Look up the value for @key on @device and convert it to a double
579 * precision floating point number using strtod().
581 * Returns: The value for @key or 0.0 if @key doesn't exist or isn't a
585 g_udev_device_get_property_as_double (GUdevDevice *device,
591 g_return_val_if_fail (G_UDEV_IS_DEVICE (device), 0.0);
592 g_return_val_if_fail (key != NULL, 0.0);
595 s = g_udev_device_get_property (device, key);
599 result = strtod (s, NULL);
605 * g_udev_device_get_property_as_boolean:
606 * @device: A #GUdevDevice.
607 * @key: Name of property.
609 * Look up the value for @key on @device and convert it to an
610 * boolean. This is done by doing a case-insensitive string comparison
611 * on the string value against "1" and "true".
613 * Returns: The value for @key or %FALSE if @key doesn't exist or
617 g_udev_device_get_property_as_boolean (GUdevDevice *device,
623 g_return_val_if_fail (G_UDEV_IS_DEVICE (device), FALSE);
624 g_return_val_if_fail (key != NULL, FALSE);
627 s = g_udev_device_get_property (device, key);
631 if (strcmp (s, "1") == 0 || g_ascii_strcasecmp (s, "true") == 0)
638 split_at_whitespace (const gchar *s)
644 result = g_strsplit_set (s, " \v\t\r\n", 0);
646 /* remove empty strings, thanks GLib */
647 for (n = 0; result[n] != NULL; n++)
649 if (strlen (result[n]) == 0)
652 for (m = n; result[m] != NULL; m++)
653 result[m] = result[m + 1];
662 * g_udev_device_get_property_as_strv:
663 * @device: A #GUdevDevice.
664 * @key: Name of property.
666 * Look up the value for @key on @device and return the result of
667 * splitting it into non-empty tokens split at white space (only space
668 * (' '), form-feed ('\f'), newline ('\n'), carriage return ('\r'),
669 * horizontal tab ('\t'), and vertical tab ('\v') are considered; the
670 * locale is not taken into account).
672 * Returns: (nullable) (transfer none) (array zero-terminated=1) (element-type utf8):
673 * The value of @key on @device split into tokens or %NULL if @key
674 * doesn't exist. This array is owned by @device and should not be
675 * freed by the caller.
678 g_udev_device_get_property_as_strv (GUdevDevice *device,
684 g_return_val_if_fail (G_UDEV_IS_DEVICE (device), NULL);
685 g_return_val_if_fail (key != NULL, NULL);
687 if (device->priv->prop_strvs != NULL)
689 result = g_hash_table_lookup (device->priv->prop_strvs, key);
695 s = g_udev_device_get_property (device, key);
699 result = split_at_whitespace (s);
703 if (device->priv->prop_strvs == NULL)
704 device->priv->prop_strvs = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, (GDestroyNotify) g_strfreev);
705 g_hash_table_insert (device->priv->prop_strvs, g_strdup (key), result);
708 return (const gchar* const *) result;
711 /* ---------------------------------------------------------------------------------------------------- */
714 * g_udev_device_get_sysfs_attr_keys:
715 * @device: A #GUdevDevice.
717 * Gets all keys for sysfs attributes on @device.
719 * 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.
721 const gchar * const *
722 g_udev_device_get_sysfs_attr_keys (GUdevDevice *device)
724 struct udev_list_entry *l;
727 g_return_val_if_fail (G_UDEV_IS_DEVICE (device), NULL);
729 if (device->priv->sysfs_attr_keys != NULL)
732 p = g_ptr_array_new ();
733 for (l = udev_device_get_sysattr_list_entry (device->priv->udevice); l != NULL; l = udev_list_entry_get_next (l))
735 g_ptr_array_add (p, g_strdup (udev_list_entry_get_name (l)));
737 g_ptr_array_add (p, NULL);
738 device->priv->sysfs_attr_keys = (gchar **) g_ptr_array_free (p, FALSE);
741 return (const gchar * const *) device->priv->sysfs_attr_keys;
745 * g_udev_device_has_sysfs_attr:
746 * @device: A #GUdevDevice.
747 * @key: Name of sysfs attribute.
749 * Check if a the sysfs attribute with the given key exists.
751 * Returns: %TRUE only if the value for @key exist.
754 g_udev_device_has_sysfs_attr (GUdevDevice *device,
757 g_return_val_if_fail (G_UDEV_IS_DEVICE (device), FALSE);
758 g_return_val_if_fail (key != NULL, FALSE);
759 return udev_device_get_sysattr_value (device->priv->udevice, key) != NULL;
763 * g_udev_device_get_sysfs_attr:
764 * @device: A #GUdevDevice.
765 * @name: Name of the sysfs attribute.
767 * Look up the sysfs attribute with @name on @device.
769 * Returns: (nullable): The value of the sysfs attribute or %NULL if
770 * there is no such attribute. Do not free this string, it is owned by
774 g_udev_device_get_sysfs_attr (GUdevDevice *device,
777 g_return_val_if_fail (G_UDEV_IS_DEVICE (device), NULL);
778 g_return_val_if_fail (name != NULL, NULL);
779 return udev_device_get_sysattr_value (device->priv->udevice, name);
783 * g_udev_device_get_sysfs_attr_as_int:
784 * @device: A #GUdevDevice.
785 * @name: Name of the sysfs attribute.
787 * Look up the sysfs attribute with @name on @device and convert it to an integer
790 * Returns: The value of the sysfs attribute or 0 if there is no such
794 g_udev_device_get_sysfs_attr_as_int (GUdevDevice *device,
800 g_return_val_if_fail (G_UDEV_IS_DEVICE (device), 0);
801 g_return_val_if_fail (name != NULL, 0);
804 s = g_udev_device_get_sysfs_attr (device, name);
808 result = strtol (s, NULL, 0);
814 * g_udev_device_get_sysfs_attr_as_uint64:
815 * @device: A #GUdevDevice.
816 * @name: Name of the sysfs attribute.
818 * Look up the sysfs attribute with @name on @device and convert it to an unsigned
819 * 64-bit integer using g_ascii_strtoull().
821 * Returns: The value of the sysfs attribute or 0 if there is no such
825 g_udev_device_get_sysfs_attr_as_uint64 (GUdevDevice *device,
831 g_return_val_if_fail (G_UDEV_IS_DEVICE (device), 0);
832 g_return_val_if_fail (name != NULL, 0);
835 s = g_udev_device_get_sysfs_attr (device, name);
839 result = g_ascii_strtoull (s, NULL, 0);
845 * g_udev_device_get_sysfs_attr_as_double:
846 * @device: A #GUdevDevice.
847 * @name: Name of the sysfs attribute.
849 * Look up the sysfs attribute with @name on @device and convert it to a double
850 * precision floating point number using strtod().
852 * Returns: The value of the sysfs attribute or 0.0 if there is no such
856 g_udev_device_get_sysfs_attr_as_double (GUdevDevice *device,
862 g_return_val_if_fail (G_UDEV_IS_DEVICE (device), 0.0);
863 g_return_val_if_fail (name != NULL, 0.0);
866 s = g_udev_device_get_sysfs_attr (device, name);
870 result = strtod (s, NULL);
876 * g_udev_device_get_sysfs_attr_as_boolean:
877 * @device: A #GUdevDevice.
878 * @name: Name of the sysfs attribute.
880 * Look up the sysfs attribute with @name on @device and convert it to an
881 * boolean. This is done by doing a case-insensitive string comparison
882 * on the string value against "1" and "true".
884 * Returns: The value of the sysfs attribute or %FALSE if there is no such
888 g_udev_device_get_sysfs_attr_as_boolean (GUdevDevice *device,
894 g_return_val_if_fail (G_UDEV_IS_DEVICE (device), FALSE);
895 g_return_val_if_fail (name != NULL, FALSE);
898 s = g_udev_device_get_sysfs_attr (device, name);
902 if (strcmp (s, "1") == 0 || g_ascii_strcasecmp (s, "true") == 0)
909 * g_udev_device_get_sysfs_attr_as_strv:
910 * @device: A #GUdevDevice.
911 * @name: Name of the sysfs attribute.
913 * Look up the sysfs attribute with @name on @device and return the result of
914 * splitting it into non-empty tokens split at white space (only space (' '),
915 * form-feed ('\f'), newline ('\n'), carriage return ('\r'), horizontal
916 * tab ('\t'), and vertical tab ('\v') are considered; the locale is
917 * not taken into account).
919 * Returns: (nullable) (transfer none) (array zero-terminated=1) (element-type utf8):
920 * The value of the sysfs attribute split into tokens or %NULL if
921 * there is no such attribute. This array is owned by @device and
922 * should not be freed by the caller.
924 const gchar * const *
925 g_udev_device_get_sysfs_attr_as_strv (GUdevDevice *device,
931 g_return_val_if_fail (G_UDEV_IS_DEVICE (device), NULL);
932 g_return_val_if_fail (name != NULL, NULL);
934 if (device->priv->sysfs_attr_strvs != NULL)
936 result = g_hash_table_lookup (device->priv->sysfs_attr_strvs, name);
942 s = g_udev_device_get_sysfs_attr (device, name);
946 result = split_at_whitespace (s);
950 if (device->priv->sysfs_attr_strvs == NULL)
951 device->priv->sysfs_attr_strvs = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, (GDestroyNotify) g_strfreev);
952 g_hash_table_insert (device->priv->sysfs_attr_strvs, g_strdup (name), result);
955 return (const gchar* const *) result;
959 * g_udev_device_get_tags:
960 * @device: A #GUdevDevice.
962 * Gets all tags for @device.
964 * 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.
969 g_udev_device_get_tags (GUdevDevice *device)
971 struct udev_list_entry *l;
974 g_return_val_if_fail (G_UDEV_IS_DEVICE (device), NULL);
976 if (device->priv->tags != NULL)
979 p = g_ptr_array_new ();
980 for (l = udev_device_get_tags_list_entry (device->priv->udevice); l != NULL; l = udev_list_entry_get_next (l))
982 g_ptr_array_add (p, g_strdup (udev_list_entry_get_name (l)));
984 g_ptr_array_add (p, NULL);
985 device->priv->tags = (gchar **) g_ptr_array_free (p, FALSE);
988 return (const gchar * const *) device->priv->tags;
992 * g_udev_device_get_is_initialized:
993 * @device: A #GUdevDevice.
995 * Gets whether @device has been initalized.
997 * Returns: Whether @device has been initialized.
1002 g_udev_device_get_is_initialized (GUdevDevice *device)
1004 g_return_val_if_fail (G_UDEV_IS_DEVICE (device), FALSE);
1005 return udev_device_get_is_initialized (device->priv->udevice);
1009 * g_udev_device_get_usec_since_initialized:
1010 * @device: A #GUdevDevice.
1012 * Gets number of micro-seconds since @device was initialized.
1014 * This only works for devices with properties in the udev
1015 * database. All other devices return 0.
1017 * Returns: Number of micro-seconds since @device was initialized or 0 if unknown.
1022 g_udev_device_get_usec_since_initialized (GUdevDevice *device)
1024 g_return_val_if_fail (G_UDEV_IS_DEVICE (device), 0);
1025 return udev_device_get_usec_since_initialized (device->priv->udevice);