+static struct bus_file {
+ char *bus;
+ char *file;
+} bus_files[] = {
+ { .bus = "scsi", .file = "vendor" },
+ { .bus = "usb", .file = "idVendor" },
+ { .bus = "ide", .file = "detach_state" },
+ { .bus = "pci", .file = "vendor" },
+ {}
+};
+
+#define SECONDS_TO_WAIT_FOR_FILE 10
+static void wait_for_device_to_initialize(struct sysfs_device *sysfs_device)
+{
+ /* sleep until we see the file for this specific bus type show up this
+ * is needed because we can easily out-run the kernel in looking for
+ * these files before the paticular subsystem has created them in the
+ * sysfs tree properly.
+ *
+ * And people thought that the /sbin/hotplug event system was going to
+ * be slow, poo on you for arguing that before even testing it...
+ */
+ struct bus_file *b = &bus_files[0];
+ struct sysfs_attribute *tmpattr;
+ int loop;
+
+ while (1) {
+ if (b->bus == NULL)
+ break;
+ if (strcmp(sysfs_device->bus, b->bus) == 0) {
+ tmpattr = NULL;
+ loop = SECONDS_TO_WAIT_FOR_FILE;
+ while (loop--) {
+ dbg("looking for file '%s' on bus '%s'", b->file, b->bus);
+ tmpattr = sysfs_get_device_attr(sysfs_device, b->file);
+ if (tmpattr) {
+ /* found it! */
+ goto exit;
+ }
+ /* sleep to give the kernel a chance to create the file */
+ sleep(1);
+ }
+ dbg("Timed out waiting for '%s' file, continuing on anyway...", b->file);
+ goto exit;
+ }
+ b++;
+ }
+ dbg("Did not find bus type '%s' on list of bus_id_files, contact greg@kroah.com", sysfs_device->bus);
+exit:
+ return; /* here to prevent compiler warning... */
+}