static USBDevice *usb_msd_init(USBBus *bus, const char *filename)

{

    static int nr=0;

    char id[8];

    QemuOpts *opts;

    DriveInfo *dinfo;

    USBDevice *dev;

    const char *p1;

    char fmt[32];



    /* parse -usbdevice disk: syntax into drive opts */

    snprintf(id, sizeof(id), "usb%d", nr++);

    opts = qemu_opts_create(qemu_find_opts("drive"), id, 0);



    p1 = strchr(filename, ':');

    if (p1++) {

        const char *p2;



        if (strstart(filename, "format=", &p2)) {

            int len = MIN(p1 - p2, sizeof(fmt));

            pstrcpy(fmt, len, p2);

            qemu_opt_set(opts, "format", fmt);

        } else if (*filename != ':') {

            printf("unrecognized USB mass-storage option %s\n", filename);

            return NULL;

        }

        filename = p1;

    }

    if (!*filename) {

        printf("block device specification needed\n");

        return NULL;

    }

    qemu_opt_set(opts, "file", filename);

    qemu_opt_set(opts, "if", "none");



    /* create host drive */

    dinfo = drive_init(opts, 0);

    if (!dinfo) {

        qemu_opts_del(opts);

        return NULL;

    }



    /* create guest device */

    dev = usb_create(bus, "usb-storage");

    if (!dev) {

        return NULL;

    }

    if (qdev_prop_set_drive(&dev->qdev, "drive", dinfo->bdrv) < 0) {

        qdev_free(&dev->qdev);

        return NULL;

    }

    if (qdev_init(&dev->qdev) < 0)

        return NULL;



    return dev;

}

static USBDevice *usb_msd_init(USBBus *bus, const char *filename)

{

    static int nr=0;

    char id[8];

    QemuOpts *opts;

    DriveInfo *dinfo;

    USBDevice *dev;

    const char *p1;

    char fmt[32];



    

    snprintf(id, sizeof(id), "usb%d", nr++);

    opts = qemu_opts_create(qemu_find_opts("drive"), id, 0);



    p1 = strchr(filename, ':');

    if (p1++) {

        const char *p2;



        if (strstart(filename, "format=", &p2)) {

            int len = MIN(p1 - p2, sizeof(fmt));

            pstrcpy(fmt, len, p2);

            qemu_opt_set(opts, "format", fmt);

        } else if (*filename != ':') {

            printf("unrecognized USB mass-storage option %s\n", filename);

            return NULL;

        }

        filename = p1;

    }

    if (!*filename) {

        printf("block device specification needed\n");

        return NULL;

    }

    qemu_opt_set(opts, "file", filename);

    qemu_opt_set(opts, "if", "none");



    

    dinfo = drive_init(opts, 0);

    if (!dinfo) {

        qemu_opts_del(opts);

        return NULL;

    }



    

    dev = usb_create(bus, "usb-storage");

    if (!dev) {

        return NULL;

    }

    if (qdev_prop_set_drive(&dev->qdev, "drive", dinfo->bdrv) < 0) {

        qdev_free(&dev->qdev);

        return NULL;

    }

    if (qdev_init(&dev->qdev) < 0)

        return NULL;



    return dev;

}

    opts = qemu_opts_create(qemu_find_opts("drive"), id, 0);
static USBDevice *FUNC_0(USBBus *bus, const char *filename)

{

    static int VAR_0=0;

    char VAR_1[8];

    QemuOpts *opts;

    DriveInfo *dinfo;

    USBDevice *dev;

    const char *VAR_2;

    char VAR_3[32];



    

    snprintf(VAR_1, sizeof(VAR_1), "usb%d", VAR_0++);

    opts = qemu_opts_create(qemu_find_opts("drive"), VAR_1, 0);



    VAR_2 = strchr(filename, ':');

    if (VAR_2++) {

        const char *VAR_4;



        if (strstart(filename, "format=", &VAR_4)) {

            int VAR_5 = MIN(VAR_2 - VAR_4, sizeof(VAR_3));

            pstrcpy(VAR_3, VAR_5, VAR_4);

            qemu_opt_set(opts, "format", VAR_3);

        } else if (*filename != ':') {

            printf("unrecognized USB mass-storage option %s\n", filename);

            return NULL;

        }

        filename = VAR_2;

    }

    if (!*filename) {

        printf("block device specification needed\n");

        return NULL;

    }

    qemu_opt_set(opts, "file", filename);

    qemu_opt_set(opts, "if", "none");



    

    dinfo = drive_init(opts, 0);

    if (!dinfo) {

        qemu_opts_del(opts);

        return NULL;

    }



    

    dev = usb_create(bus, "usb-storage");

    if (!dev) {

        return NULL;

    }

    if (qdev_prop_set_drive(&dev->qdev, "drive", dinfo->bdrv) < 0) {

        qdev_free(&dev->qdev);

        return NULL;

    }

    if (qdev_init(&dev->qdev) < 0)

        return NULL;



    return dev;

}

static USBDevice *FUNC_0(USBBus *bus, const char *filename)
{ static int VAR_0=0; char VAR_1[8]; QemuOpts *opts; DriveInfo *dinfo; USBDevice *dev; const char *VAR_2; char VAR_3[32]; snprintf(VAR_1, sizeof(VAR_1), "usb%d", VAR_0++); opts = qemu_opts_create(qemu_find_opts("drive"), VAR_1, 0); VAR_2 = strchr(filename, ':'); if (VAR_2++) { const char *VAR_4; if (strstart(filename, "format=", &VAR_4)) { int VAR_5 = MIN(VAR_2 - VAR_4, sizeof(VAR_3)); pstrcpy(VAR_3, VAR_5, VAR_4); qemu_opt_set(opts, "format", VAR_3); } else if (*filename != ':') { printf("unrecognized USB mass-storage option %s\n", filename); return NULL; } filename = VAR_2; } if (!*filename) { printf("block device specification needed\n"); return NULL; } qemu_opt_set(opts, "file", filename); qemu_opt_set(opts, "if", "none"); dinfo = drive_init(opts, 0); if (!dinfo) { qemu_opts_del(opts); return NULL; } dev = usb_create(bus, "usb-storage"); if (!dev) { return NULL; } if (qdev_prop_set_drive(&dev->qdev, "drive", dinfo->bdrv) < 0) { qdev_free(&dev->qdev); return NULL; } if (qdev_init(&dev->qdev) < 0)
return NULL; return dev; }