static int scsi_disk_emulate_read_toc(SCSIRequest *req, uint8_t *outbuf)

{

    SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, req->dev);

    int start_track, format, msf, toclen;

    uint64_t nb_sectors;



    msf = req->cmd.buf[1] & 2;

    format = req->cmd.buf[2] & 0xf;

    start_track = req->cmd.buf[6];

    bdrv_get_geometry(s->qdev.conf.bs, &nb_sectors);

    DPRINTF("Read TOC (track %d format %d msf %d)\n", start_track, format, msf >> 1);

    nb_sectors /= s->qdev.blocksize / 512;

    switch (format) {

    case 0:

        toclen = cdrom_read_toc(nb_sectors, outbuf, msf, start_track);

        break;

    case 1:

        /* multi session : only a single session defined */

        toclen = 12;

        memset(outbuf, 0, 12);

        outbuf[1] = 0x0a;

        outbuf[2] = 0x01;

        outbuf[3] = 0x01;

        break;

    case 2:

        toclen = cdrom_read_toc_raw(nb_sectors, outbuf, msf, start_track);

        break;

    default:

        return -1;

    }

    return toclen;

}

static int scsi_disk_emulate_read_toc(SCSIRequest *req, uint8_t *outbuf)

{

    SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, req->dev);

    int start_track, format, msf, toclen;

    uint64_t nb_sectors;



    msf = req->cmd.buf[1] & 2;

    format = req->cmd.buf[2] & 0xf;

    start_track = req->cmd.buf[6];

    bdrv_get_geometry(s->qdev.conf.bs, &nb_sectors);

    DPRINTF("Read TOC (track %d format %d msf %d)\n", start_track, format, msf >> 1);

    nb_sectors /= s->qdev.blocksize / 512;

    switch (format) {

    case 0:

        toclen = cdrom_read_toc(nb_sectors, outbuf, msf, start_track);

        break;

    case 1:

        

        toclen = 12;

        memset(outbuf, 0, 12);

        outbuf[1] = 0x0a;

        outbuf[2] = 0x01;

        outbuf[3] = 0x01;

        break;

    case 2:

        toclen = cdrom_read_toc_raw(nb_sectors, outbuf, msf, start_track);

        break;

    default:

        return -1;

    }

    return toclen;

}

static int FUNC_0(SCSIRequest *VAR_0, uint8_t *VAR_1)

{

    SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, VAR_0->dev);

    int VAR_2, VAR_3, VAR_4, VAR_5;

    uint64_t nb_sectors;



    VAR_4 = VAR_0->cmd.buf[1] & 2;

    VAR_3 = VAR_0->cmd.buf[2] & 0xf;

    VAR_2 = VAR_0->cmd.buf[6];

    bdrv_get_geometry(s->qdev.conf.bs, &nb_sectors);

    DPRINTF("Read TOC (track %d VAR_3 %d VAR_4 %d)\n", VAR_2, VAR_3, VAR_4 >> 1);

    nb_sectors /= s->qdev.blocksize / 512;

    switch (VAR_3) {

    case 0:

        VAR_5 = cdrom_read_toc(nb_sectors, VAR_1, VAR_4, VAR_2);

        break;

    case 1:

        

        VAR_5 = 12;

        memset(VAR_1, 0, 12);

        VAR_1[1] = 0x0a;

        VAR_1[2] = 0x01;

        VAR_1[3] = 0x01;

        break;

    case 2:

        VAR_5 = cdrom_read_toc_raw(nb_sectors, VAR_1, VAR_4, VAR_2);

        break;

    default:

        return -1;

    }

    return VAR_5;

}

static int FUNC_0(SCSIRequest *VAR_0, uint8_t *VAR_1)
{ SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, VAR_0->dev); int VAR_2, VAR_3, VAR_4, VAR_5; uint64_t nb_sectors; VAR_4 = VAR_0->cmd.buf[1] & 2; VAR_3 = VAR_0->cmd.buf[2] & 0xf; VAR_2 = VAR_0->cmd.buf[6]; bdrv_get_geometry(s->qdev.conf.bs, &nb_sectors); DPRINTF("Read TOC (track %d VAR_3 %d VAR_4 %d)\n", VAR_2, VAR_3, VAR_4 >> 1); nb_sectors /= s->qdev.blocksize / 512; switch (VAR_3) { case 0:
VAR_5 = cdrom_read_toc(nb_sectors, VAR_1, VAR_4, VAR_2); break; case 1:
VAR_5 = 12; memset(VAR_1, 0, 12); VAR_1[1] = 0x0a; VAR_1[2] = 0x01; VAR_1[3] = 0x01; break; case 2:
VAR_5 = cdrom_read_toc_raw(nb_sectors, VAR_1, VAR_4, VAR_2); break; default:
return -1; } return VAR_5; }