plugin-base: better detection of physical device

This commit is contained in:
Dan Williams
2009-06-29 10:08:56 -04:00
parent c6d0174b41
commit fe7acaf457

View File

@@ -680,34 +680,49 @@ get_driver_name (GUdevDevice *device)
static GUdevDevice * static GUdevDevice *
real_find_physical_device (MMPluginBase *plugin, GUdevDevice *child) real_find_physical_device (MMPluginBase *plugin, GUdevDevice *child)
{ {
GUdevDevice *iter, *old = NULL; GUdevDevice *parent = NULL, *physdev = NULL;
const char *bus, *type; const char *subsys, *type;
g_return_val_if_fail (child != NULL, NULL); g_return_val_if_fail (child != NULL, NULL);
bus = g_udev_device_get_property (child, "ID_BUS"); subsys = g_udev_device_get_subsystem (child);
if (!bus) g_assert (subsys);
return NULL; if (strcmp (subsys, "usb") && strcmp (subsys, "pci")) {
/* Try the parent */
parent = g_udev_device_get_parent (child);
if (!parent)
goto out;
subsys = g_udev_device_get_subsystem (parent);
if (strcmp (subsys, "usb") && strcmp (subsys, "pci"))
goto out;
}
if (!strcmp (subsys, "usb")) {
GUdevDevice *iter, *old = NULL;
if (!strcmp (bus, "usb")) {
/* Walk the parents to find the 'usb_device' for this device. */ /* Walk the parents to find the 'usb_device' for this device. */
iter = g_object_ref (child); iter = g_object_ref (child);
while (iter) { while (iter) {
type = g_udev_device_get_devtype (iter); type = g_udev_device_get_devtype (iter);
if (type && !strcmp (type, "usb_device")) if (type && !strcmp (type, "usb_device")) {
return iter; physdev = iter;
break;
}
old = iter; old = iter;
iter = g_udev_device_get_parent (old); iter = g_udev_device_get_parent (old);
g_object_unref (old); g_object_unref (old);
} }
g_object_unref (child); } else if (!strcmp (subsys, "pci"))
} else if (!strcmp (bus, "pci")) { physdev = g_udev_device_get_parent (child);
return g_udev_device_get_parent (child);
}
// FIXME: pci and pcmcia/cardbus? (like Sierra 850/860) // FIXME: pcmcia (like Sierra 850/860)
return NULL;
out:
if (parent)
g_object_unref (parent);
return physdev;
} }
static MMPluginSupportsResult static MMPluginSupportsResult