static int usb_host_scan(void *opaque, USBScanFunc *func)

{

    FILE *f = 0;

    DIR *dir = 0;

    int ret = 0;

    const char *devices = "/devices";

    const char *opened = "husb: opened %s%s\n";

    const char *fs_type[] = {"unknown", "proc", "dev", "sys"};

    char devpath[PATH_MAX];



    /* only check the host once */

    if (!usb_fs_type) {

        f = fopen(USBPROCBUS_PATH "/devices", "r");

        if (f) {

            /* devices found in /proc/bus/usb/ */

            strcpy(devpath, USBPROCBUS_PATH);

            usb_fs_type = USB_FS_PROC;

            fclose(f);

            dprintf(opened, USBPROCBUS_PATH, devices);

        }

        /* try additional methods if an access method hasn't been found yet */

        f = fopen(USBDEVBUS_PATH "/devices", "r");

        if (!usb_fs_type && f) {

            /* devices found in /dev/bus/usb/ */

            strcpy(devpath, USBDEVBUS_PATH);

            usb_fs_type = USB_FS_DEV;

            fclose(f);

            dprintf(opened, USBDEVBUS_PATH, devices);

        }

        dir = opendir(USBSYSBUS_PATH "/devices");

        if (!usb_fs_type && dir) {

            /* devices found in /dev/bus/usb/ (yes - not a mistake!) */

            strcpy(devpath, USBDEVBUS_PATH);

            usb_fs_type = USB_FS_SYS;

            closedir(dir);

            dprintf(opened, USBSYSBUS_PATH, devices);

        }

        if (!usb_fs_type) {

            term_printf("husb: unable to access USB devices\n");

            goto the_end;

        }



        /* the module setting (used later for opening devices) */

        usb_host_device_path = qemu_mallocz(strlen(devpath)+1);

        if (usb_host_device_path) {

            strcpy(usb_host_device_path, devpath);

            term_printf("husb: using %s file-system with %s\n", fs_type[usb_fs_type], usb_host_device_path);

        } else {

            /* out of memory? */

            perror("husb: unable to allocate memory for device path");

            goto the_end;

        }

    }



    switch (usb_fs_type) {

    case USB_FS_PROC:

    case USB_FS_DEV:

        ret = usb_host_scan_dev(opaque, func);

        break;

    case USB_FS_SYS:

        ret = usb_host_scan_sys(opaque, func);

        break;

    }

 the_end:

    return ret;

}

static int usb_host_scan(void *opaque, USBScanFunc *func)

{

    FILE *f = 0;

    DIR *dir = 0;

    int ret = 0;

    const char *devices = "/devices";

    const char *opened = "husb: opened %s%s\n";

    const char *fs_type[] = {"unknown", "proc", "dev", "sys"};

    char devpath[PATH_MAX];



    

    if (!usb_fs_type) {

        f = fopen(USBPROCBUS_PATH "/devices", "r");

        if (f) {

            

            strcpy(devpath, USBPROCBUS_PATH);

            usb_fs_type = USB_FS_PROC;

            fclose(f);

            dprintf(opened, USBPROCBUS_PATH, devices);

        }

        

        f = fopen(USBDEVBUS_PATH "/devices", "r");

        if (!usb_fs_type && f) {

            

            strcpy(devpath, USBDEVBUS_PATH);

            usb_fs_type = USB_FS_DEV;

            fclose(f);

            dprintf(opened, USBDEVBUS_PATH, devices);

        }

        dir = opendir(USBSYSBUS_PATH "/devices");

        if (!usb_fs_type && dir) {

            

            strcpy(devpath, USBDEVBUS_PATH);

            usb_fs_type = USB_FS_SYS;

            closedir(dir);

            dprintf(opened, USBSYSBUS_PATH, devices);

        }

        if (!usb_fs_type) {

            term_printf("husb: unable to access USB devices\n");

            goto the_end;

        }



        

        usb_host_device_path = qemu_mallocz(strlen(devpath)+1);

        if (usb_host_device_path) {

            strcpy(usb_host_device_path, devpath);

            term_printf("husb: using %s file-system with %s\n", fs_type[usb_fs_type], usb_host_device_path);

        } else {

            

            perror("husb: unable to allocate memory for device path");

            goto the_end;

        }

    }



    switch (usb_fs_type) {

    case USB_FS_PROC:

    case USB_FS_DEV:

        ret = usb_host_scan_dev(opaque, func);

        break;

    case USB_FS_SYS:

        ret = usb_host_scan_sys(opaque, func);

        break;

    }

 the_end:

    return ret;

}

        if (!usb_fs_type && f) {         if (!usb_fs_type && dir) {             goto the_end;             goto the_end;  the_end:
static int FUNC_0(void *VAR_0, USBScanFunc *VAR_1)

{

    FILE *f = 0;

    DIR *dir = 0;

    int VAR_2 = 0;

    const char *VAR_3 = "/VAR_3";

    const char *VAR_4 = "husb: VAR_4 %s%s\n";

    const char *VAR_5[] = {"unknown", "proc", "dev", "sys"};

    char VAR_6[PATH_MAX];



    

    if (!usb_fs_type) {

        f = fopen(USBPROCBUS_PATH "/VAR_3", "r");

        if (f) {

            

            strcpy(VAR_6, USBPROCBUS_PATH);

            usb_fs_type = USB_FS_PROC;

            fclose(f);

            dprintf(VAR_4, USBPROCBUS_PATH, VAR_3);

        }

        

        f = fopen(USBDEVBUS_PATH "/VAR_3", "r");

        if (!usb_fs_type && f) {

            

            strcpy(VAR_6, USBDEVBUS_PATH);

            usb_fs_type = USB_FS_DEV;

            fclose(f);

            dprintf(VAR_4, USBDEVBUS_PATH, VAR_3);

        }

        dir = opendir(USBSYSBUS_PATH "/VAR_3");

        if (!usb_fs_type && dir) {

            

            strcpy(VAR_6, USBDEVBUS_PATH);

            usb_fs_type = USB_FS_SYS;

            closedir(dir);

            dprintf(VAR_4, USBSYSBUS_PATH, VAR_3);

        }

        if (!usb_fs_type) {

            term_printf("husb: unable to access USB VAR_3\n");

            goto the_end;

        }



        

        usb_host_device_path = qemu_mallocz(strlen(VAR_6)+1);

        if (usb_host_device_path) {

            strcpy(usb_host_device_path, VAR_6);

            term_printf("husb: using %s file-system with %s\n", VAR_5[usb_fs_type], usb_host_device_path);

        } else {

            

            perror("husb: unable to allocate memory for device path");

            goto the_end;

        }

    }



    switch (usb_fs_type) {

    case USB_FS_PROC:

    case USB_FS_DEV:

        VAR_2 = usb_host_scan_dev(VAR_0, VAR_1);

        break;

    case USB_FS_SYS:

        VAR_2 = usb_host_scan_sys(VAR_0, VAR_1);

        break;

    }

 the_end:

    return VAR_2;

}

static int FUNC_0(void *VAR_0, USBScanFunc *VAR_1)
{ FILE *f = 0; DIR *dir = 0; int VAR_2 = 0; const char *VAR_3 = "/VAR_3"; const char *VAR_4 = "husb: VAR_4 %s%s\n"; const char *VAR_5[] = {"unknown", "proc", "dev", "sys"}; char VAR_6[PATH_MAX]; if (!usb_fs_type) { f = fopen(USBPROCBUS_PATH "/VAR_3", "r"); if (f) { strcpy(VAR_6, USBPROCBUS_PATH); usb_fs_type = USB_FS_PROC; fclose(f); dprintf(VAR_4, USBPROCBUS_PATH, VAR_3); } f = fopen(USBDEVBUS_PATH "/VAR_3", "r"); if (!usb_fs_type && f) { strcpy(VAR_6, USBDEVBUS_PATH); usb_fs_type = USB_FS_DEV; fclose(f); dprintf(VAR_4, USBDEVBUS_PATH, VAR_3); } dir = opendir(USBSYSBUS_PATH "/VAR_3"); if (!usb_fs_type && dir) { strcpy(VAR_6, USBDEVBUS_PATH); usb_fs_type = USB_FS_SYS; closedir(dir); dprintf(VAR_4, USBSYSBUS_PATH, VAR_3); } if (!usb_fs_type) { term_printf("husb: unable to access USB VAR_3\n"); goto the_end; } usb_host_device_path = qemu_mallocz(strlen(VAR_6)+1); if (usb_host_device_path) { strcpy(usb_host_device_path, VAR_6); term_printf("husb: using %s file-system with %s\n", VAR_5[usb_fs_type], usb_host_device_path); } else { perror("husb: unable to allocate memory for device path"); goto the_end; } } switch (usb_fs_type) { case USB_FS_PROC:
case USB_FS_DEV:
VAR_2 = usb_host_scan_dev(VAR_0, VAR_1); break; case USB_FS_SYS:
VAR_2 = usb_host_scan_sys(VAR_0, VAR_1); break; } the_end:
return VAR_2; }