static int ide_dev_initfn(IDEDevice *dev, IDEDriveKind kind)

{

    IDEBus *bus = DO_UPCAST(IDEBus, qbus, dev->qdev.parent_bus);

    IDEState *s = bus->ifs + dev->unit;

    const char *serial;

    DriveInfo *dinfo;



    if (dev->conf.discard_granularity && dev->conf.discard_granularity != 512) {

        error_report("discard_granularity must be 512 for ide");

        return -1;

    }



    serial = dev->serial;

    if (!serial) {

        /* try to fall back to value set with legacy -drive serial=... */

        dinfo = drive_get_by_blockdev(dev->conf.bs);

        if (*dinfo->serial) {

            serial = dinfo->serial;

        }

    }



    if (ide_init_drive(s, dev->conf.bs, kind, dev->version, serial) < 0) {

        return -1;

    }



    if (!dev->version) {

        dev->version = g_strdup(s->version);

    }

    if (!dev->serial) {

        dev->serial = g_strdup(s->drive_serial_str);

    }



    add_boot_device_path(dev->conf.bootindex, &dev->qdev,

                         dev->unit ? "/disk@1" : "/disk@0");



    return 0;

}

static int ide_dev_initfn(IDEDevice *dev, IDEDriveKind kind)

{

    IDEBus *bus = DO_UPCAST(IDEBus, qbus, dev->qdev.parent_bus);

    IDEState *s = bus->ifs + dev->unit;

    const char *serial;

    DriveInfo *dinfo;



    if (dev->conf.discard_granularity && dev->conf.discard_granularity != 512) {

        error_report("discard_granularity must be 512 for ide");

        return -1;

    }



    serial = dev->serial;

    if (!serial) {

        

        dinfo = drive_get_by_blockdev(dev->conf.bs);

        if (*dinfo->serial) {

            serial = dinfo->serial;

        }

    }



    if (ide_init_drive(s, dev->conf.bs, kind, dev->version, serial) < 0) {

        return -1;

    }



    if (!dev->version) {

        dev->version = g_strdup(s->version);

    }

    if (!dev->serial) {

        dev->serial = g_strdup(s->drive_serial_str);

    }



    add_boot_device_path(dev->conf.bootindex, &dev->qdev,

                         dev->unit ? "/disk@1" : "/disk@0");



    return 0;

}

static int FUNC_0(IDEDevice *VAR_0, IDEDriveKind VAR_1)

{

    IDEBus *bus = DO_UPCAST(IDEBus, qbus, VAR_0->qdev.parent_bus);

    IDEState *s = bus->ifs + VAR_0->unit;

    const char *VAR_2;

    DriveInfo *dinfo;



    if (VAR_0->conf.discard_granularity && VAR_0->conf.discard_granularity != 512) {

        error_report("discard_granularity must be 512 for ide");

        return -1;

    }



    VAR_2 = VAR_0->VAR_2;

    if (!VAR_2) {

        

        dinfo = drive_get_by_blockdev(VAR_0->conf.bs);

        if (*dinfo->VAR_2) {

            VAR_2 = dinfo->VAR_2;

        }

    }



    if (ide_init_drive(s, VAR_0->conf.bs, VAR_1, VAR_0->version, VAR_2) < 0) {

        return -1;

    }



    if (!VAR_0->version) {

        VAR_0->version = g_strdup(s->version);

    }

    if (!VAR_0->VAR_2) {

        VAR_0->VAR_2 = g_strdup(s->drive_serial_str);

    }



    add_boot_device_path(VAR_0->conf.bootindex, &VAR_0->qdev,

                         VAR_0->unit ? "/disk@1" : "/disk@0");



    return 0;

}

static int FUNC_0(IDEDevice *VAR_0, IDEDriveKind VAR_1)
{ IDEBus *bus = DO_UPCAST(IDEBus, qbus, VAR_0->qdev.parent_bus); IDEState *s = bus->ifs + VAR_0->unit; const char *VAR_2; DriveInfo *dinfo; if (VAR_0->conf.discard_granularity && VAR_0->conf.discard_granularity != 512) { error_report("discard_granularity must be 512 for ide"); return -1; } VAR_2 = VAR_0->VAR_2; if (!VAR_2) { dinfo = drive_get_by_blockdev(VAR_0->conf.bs); if (*dinfo->VAR_2) { VAR_2 = dinfo->VAR_2; } } if (ide_init_drive(s, VAR_0->conf.bs, VAR_1, VAR_0->version, VAR_2) < 0) { return -1; } if (!VAR_0->version) { VAR_0->version = g_strdup(s->version); } if (!VAR_0->VAR_2) { VAR_0->VAR_2 = g_strdup(s->drive_serial_str); } add_boot_device_path(VAR_0->conf.bootindex, &VAR_0->qdev,
VAR_0->unit ? "/disk@1" : "/disk@0"); return 0; }