/** * gmw_probe_use_device: **/ static gboolean gmw_probe_use_device (GUdevClient *udev_client, const gchar *block_dev, GCancellable *cancellable, GError **error) { _cleanup_object_unref_ GUdevDevice *udev_device = NULL; GmwProbeDevice *dev; /* create worker object */ dev = g_new0 (GmwProbeDevice, 1); dev->block_dev = g_strdup (block_dev); dev->data_save = g_ptr_array_new_with_free_func ((GDestroyNotify) gmw_probe_block_free); /* find udev device */ udev_device = g_udev_client_query_by_device_file (udev_client, block_dev); if (udev_device == NULL) { g_set_error (error, GMW_ERROR, GMW_ERROR_FAILED, "Failed to find %s", block_dev); gmw_probe_device_free (dev); return FALSE; } dev->udev_device = g_udev_device_get_parent_with_subsystem (udev_device, "usb", "usb_device"); if (dev->udev_device == NULL) { g_set_error_literal (error, GMW_ERROR, GMW_ERROR_FAILED, "Not a USB device"); gmw_probe_device_free (dev); return FALSE; } /* actually do the scanning now */ if (!gmw_probe_scan_device (dev, cancellable, error)) { gmw_probe_device_free (dev); return FALSE; } /* success */ gmw_probe_device_free (dev); return TRUE; }
/* <internal> * storaged_linux_drive_object_should_include_device: * @client: A #GUdevClient. * @device: A #StoragedLinuxDevice. * @out_vpd: Return location for unique ID or %NULL. * * Checks if we should even construct a #StoragedLinuxDriveObject for @device. * * Returns: %TRUE if we should construct an object, %FALSE otherwise. */ gboolean storaged_linux_drive_object_should_include_device (GUdevClient *client, StoragedLinuxDevice *device, gchar **out_vpd) { gboolean ret; gchar *vpd; ret = FALSE; vpd = NULL; /* The 'block' subsystem encompasses several objects with varying * DEVTYPE including * * - disk * - partition * * and we are only interested in the first. */ if (g_strcmp0 (g_udev_device_get_devtype (device->udev_device), "disk") != 0) goto out; vpd = check_for_vpd (device->udev_device); if (vpd == NULL) { const gchar *name; const gchar *vendor; const gchar *model; const gchar *dm_uuid; GUdevDevice *parent; name = g_udev_device_get_name (device->udev_device); /* workaround for floppy devices */ if (g_str_has_prefix (name, "fd")) { vpd = g_strdup_printf ("pcfloppy_%s", name); goto found; } /* workaround for missing serial/wwn on virtio-blk */ if (g_str_has_prefix (name, "vd")) { vpd = g_strdup (name); goto found; } /* workaround for missing serial/wwn on VMware */ vendor = g_udev_device_get_property (device->udev_device, "ID_VENDOR"); model = g_udev_device_get_property (device->udev_device, "ID_MODEL"); if (g_str_has_prefix (name, "sd") && vendor != NULL && g_strcmp0 (vendor, "VMware") == 0 && model != NULL && g_str_has_prefix (model, "Virtual")) { vpd = g_strdup (name); goto found; } /* workaround for missing serial/wwn on firewire devices */ parent = g_udev_device_get_parent_with_subsystem (device->udev_device, "firewire", NULL); if (parent != NULL) { vpd = g_strdup (name); g_object_unref (parent); goto found; } /* dm-multipath */ if (is_dm_multipath (device)) { gchar **slaves; guint n; slaves = storaged_daemon_util_resolve_links (g_udev_device_get_sysfs_path (device->udev_device), "slaves"); for (n = 0; slaves[n] != NULL; n++) { GUdevDevice *slave; slave = g_udev_client_query_by_sysfs_path (client, slaves[n]); if (slave != NULL) { vpd = check_for_vpd (slave); if (vpd != NULL) { g_object_unref (slave); g_strfreev (slaves); goto found; } g_object_unref (slave); } } g_strfreev (slaves); } } found: if (vpd != NULL) { if (out_vpd != NULL) { *out_vpd = vpd; vpd = NULL; } ret = TRUE; } out: g_free (vpd); return ret; }