static void do_list_local () { struct udev *udev; struct udev_enumerate *enumerate; struct udev_list_entry *devices, *dev_list_entry; struct udev_device *dev; const gchar *path; const gchar *idVendor; const gchar *idProduct; const gchar *bConfValue; const gchar *bNumIntfs; const gchar *busid; /* Create libudev context. */ udev = udev_new (); /* Create libudev device enumeration. */ enumerate = udev_enumerate_new (udev); /* Take only USB devices that are not hubs and do not have * the bInterfaceNumber attribute, i.e. are not interfaces. */ udev_enumerate_add_match_subsystem (enumerate, "usb"); udev_enumerate_add_nomatch_sysattr (enumerate, "bDeviceClass", "09"); udev_enumerate_add_nomatch_sysattr (enumerate, "bInterfaceNumber", NULL); udev_enumerate_scan_devices (enumerate); devices = udev_enumerate_get_list_entry (enumerate); /* Show information about each device. */ udev_list_entry_foreach (dev_list_entry, devices) { path = udev_list_entry_get_name (dev_list_entry); dev = udev_device_new_from_syspath (udev, path); /* Get device information. */ idVendor = udev_device_get_sysattr_value (dev, "idVendor"); idProduct = udev_device_get_sysattr_value (dev, "idProduct"); bConfValue = udev_device_get_sysattr_value (dev, "bConfigurationValue"); bNumIntfs = udev_device_get_sysattr_value (dev, "bNumInterfaces"); busid = udev_device_get_sysname (dev); if (!idVendor || !idProduct || !bConfValue || !bNumIntfs) { g_printerr ("problem getting device attributes: %s\n", g_strerror (errno)); break; } g_print (" - busid %s (%.4s:%.4s)\n\n", busid, idVendor, idProduct); udev_device_unref (dev); }
udevGetDevices(struct udev *udev, virUdevStatus status) { struct udev_enumerate *enumerate; /* Create a new enumeration to create a list */ enumerate = udev_enumerate_new(udev); if (!enumerate) return NULL; /* Enumerate all network subsystem devices */ udev_enumerate_add_match_subsystem(enumerate, "net"); /* Ignore devices that are part of a bridge */ udev_enumerate_add_nomatch_sysattr(enumerate, "brport/state", NULL); /* State of the device */ switch (status) { case VIR_UDEV_IFACE_ACTIVE: udev_enumerate_add_match_sysattr(enumerate, "operstate", "up"); break; case VIR_UDEV_IFACE_INACTIVE: udev_enumerate_add_match_sysattr(enumerate, "operstate", "down"); break; case VIR_UDEV_IFACE_ALL: break; } /* We don't want to see the TUN devices that QEMU creates for other guests * running on this machine. By saying nomatch NULL, we just are getting * devices without the tun_flags sysattr. */ udev_enumerate_add_nomatch_sysattr(enumerate, "tun_flags", NULL); return enumerate; }