gboolean fu_plugin_update_prepare (FuPlugin *plugin, FwupdInstallFlags flags, FuDevice *device, GError **error) { FuPluginData *data = fu_plugin_get_data (plugin); g_autoptr(GUdevDevice) udevice = NULL; const gchar *devpath; /* only run for thunderbolt plugin */ if (g_strcmp0 (fu_device_get_plugin (device), "thunderbolt") != 0) return TRUE; /* reset any timers that might still be running from coldplug */ if (data->timeout_id != 0) { g_source_remove (data->timeout_id); data->timeout_id = 0; } devpath = fu_device_get_metadata (device, "sysfs-path"); udevice = g_udev_client_query_by_sysfs_path (data->udev, devpath); if (udevice != NULL) { data->needs_forcepower = FALSE; return TRUE; } data->updating = TRUE; if (!fu_plugin_thunderbolt_power_set (plugin, TRUE, error)) return FALSE; data->needs_forcepower = TRUE; /* wait for the device to come back onto the bus */ fu_device_set_status (device, FWUPD_STATUS_DEVICE_RESTART); for (guint i = 0; i < 5; i++) { g_autoptr(GUdevDevice) udevice_tmp = NULL; g_usleep (TBT_NEW_DEVICE_TIMEOUT * G_USEC_PER_SEC); udevice_tmp = g_udev_client_query_by_sysfs_path (data->udev, devpath); if (udevice_tmp != NULL) return TRUE; } /* device did not wake up */ g_set_error (error, FWUPD_ERROR, FWUPD_ERROR_NOT_SUPPORTED, "device did not wake up when required"); return FALSE; }
static void update_dmi (Manager *manager) { GUdevClient *client = NULL; GUdevDevice *device = NULL; GString *str; gchar *s; /* TODO: Probably need some other and/or better heuristics to yield * useful info on as many systems as possible */ client = g_udev_client_new (NULL); device = g_udev_client_query_by_sysfs_path (client, "/sys/devices/virtual/dmi/id"); if (device == NULL) goto out; str = g_string_new (NULL); g_string_append_printf (str, "%s %s (%s)", g_udev_device_get_sysfs_attr (device, "bios_vendor"), g_udev_device_get_sysfs_attr (device, "bios_version"), g_udev_device_get_sysfs_attr (device, "bios_date")); cockpit_manager_set_bios (COCKPIT_MANAGER (manager), str->str); g_string_free (str, TRUE); str = g_string_new (NULL); g_string_append_printf (str, "%s %s", g_udev_device_get_sysfs_attr (device, "sys_vendor"), g_udev_device_get_sysfs_attr (device, "product_name")); s = get_stripped_sysfs_attr (device, "product_version"); if (s != NULL) { g_string_append_printf (str, " (%s)", s); g_free (s); } cockpit_manager_set_system (COCKPIT_MANAGER (manager), str->str); g_string_free (str, TRUE); s = get_stripped_sysfs_attr (device, "product_serial"); if (s == NULL) s = get_stripped_sysfs_attr (device, "chassis_serial"); cockpit_manager_set_system_serial (COCKPIT_MANAGER (manager), s); out: g_clear_object (&device); g_clear_object (&client); }
static void debug_modem_info (MMManager *self, MMBaseModem *modem, const gchar *path) { GUdevDevice *physdev; const gchar *subsys; physdev = g_udev_client_query_by_sysfs_path (self->priv->udev, mm_base_modem_get_device (modem)); subsys = (physdev ? g_udev_device_get_subsystem (physdev) : NULL); mm_dbg ("(%s): '%s' modem, VID 0x%04X PID 0x%04X (%s)", path, mm_base_modem_get_plugin (modem), (mm_base_modem_get_vendor_id (modem) & 0xFFFF), (mm_base_modem_get_product_id (modem) & 0xFFFF), subsys ? subsys : "unknown"); if (physdev) g_object_unref (physdev); }
/* <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; }
/** * pk_device_rebind: **/ static gboolean pk_device_rebind (GUdevClient *client, const gchar *path, GError **error) { GUdevDevice *device; gint busnum; gint devnum; gboolean ret = FALSE; const gchar *driver; const gchar *subsystem; gchar *bus_id = NULL; GError *error_local = NULL; /* get device */ device = g_udev_client_query_by_sysfs_path (client, path); if (device == NULL) { /* TRANSLATORS: the device could not be found in sysfs */ *error = g_error_new (1, 0, "%s: %s\n", _("Device could not be found"), path); goto out; } /* get properties about the device */ driver = g_udev_device_get_driver (device); subsystem = g_udev_device_get_subsystem (device); busnum = g_udev_device_get_sysfs_attr_as_int (device, "busnum"); devnum = g_udev_device_get_sysfs_attr_as_int (device, "devnum"); /* debug */ if (verbose) { g_debug ("DEVICE: driver:%s, subsystem:%s, busnum:%i, devnum:%i", driver, subsystem, busnum, devnum); } /* form the bus id as recognised by the kernel */ bus_id = g_path_get_basename (path); /* FIXME: sometimes the busnum is incorrect */ if (bus_id == NULL) bus_id = g_strdup_printf ("%i-%i", busnum, devnum); /* unbind device */ ret = pk_device_unbind (path, bus_id, &error_local); if (!ret) { /* TRANSLATORS: we failed to release the current driver */ *error = g_error_new (1, 0, "%s: %s", _("Failed to unregister driver"), error_local->message); g_error_free (error_local); goto out; } /* bind device */ ret = pk_device_bind (bus_id, subsystem, driver, &error_local); if (!ret) { /* TRANSLATORS: we failed to bind the old driver */ *error = g_error_new (1, 0, "%s: %s", _("Failed to register driver"), error_local->message); g_error_free (error_local); goto out; } out: g_free (bus_id); if (device != NULL) g_object_unref (device); return ret; }