void ide_sector_read(IDEState *s)

{

    int64_t sector_num;

    int ret, n;



    s->status = READY_STAT | SEEK_STAT;

    s->error = 0; /* not needed by IDE spec, but needed by Windows */

    sector_num = ide_get_sector(s);

    n = s->nsector;

    if (n == 0) {

        /* no more sector to read from disk */

        ide_transfer_stop(s);

    } else {

#if defined(DEBUG_IDE)

        printf("read sector=%" PRId64 "\n", sector_num);

#endif

        if (n > s->req_nb_sectors)

            n = s->req_nb_sectors;



        bdrv_acct_start(s->bs, &s->acct, n * BDRV_SECTOR_SIZE, BDRV_ACCT_READ);

        ret = bdrv_read(s->bs, sector_num, s->io_buffer, n);

        bdrv_acct_done(s->bs, &s->acct);

        if (ret != 0) {

            if (ide_handle_rw_error(s, -ret,

                BM_STATUS_PIO_RETRY | BM_STATUS_RETRY_READ))

            {

                return;

            }

        }

        ide_transfer_start(s, s->io_buffer, 512 * n, ide_sector_read);

        ide_set_irq(s->bus);

        ide_set_sector(s, sector_num + n);

        s->nsector -= n;

    }

}

void ide_sector_read(IDEState *s)

{

    int64_t sector_num;

    int ret, n;



    s->status = READY_STAT | SEEK_STAT;

    s->error = 0; 

    sector_num = ide_get_sector(s);

    n = s->nsector;

    if (n == 0) {

        

        ide_transfer_stop(s);

    } else {

#if defined(DEBUG_IDE)

        printf("read sector=%" PRId64 "\n", sector_num);

#endif

        if (n > s->req_nb_sectors)

            n = s->req_nb_sectors;



        bdrv_acct_start(s->bs, &s->acct, n * BDRV_SECTOR_SIZE, BDRV_ACCT_READ);

        ret = bdrv_read(s->bs, sector_num, s->io_buffer, n);

        bdrv_acct_done(s->bs, &s->acct);

        if (ret != 0) {

            if (ide_handle_rw_error(s, -ret,

                BM_STATUS_PIO_RETRY | BM_STATUS_RETRY_READ))

            {

                return;

            }

        }

        ide_transfer_start(s, s->io_buffer, 512 * n, ide_sector_read);

        ide_set_irq(s->bus);

        ide_set_sector(s, sector_num + n);

        s->nsector -= n;

    }

}

void FUNC_0(IDEState *VAR_0)

{

    int64_t sector_num;

    int VAR_1, VAR_2;



    VAR_0->status = READY_STAT | SEEK_STAT;

    VAR_0->error = 0; 

    sector_num = ide_get_sector(VAR_0);

    VAR_2 = VAR_0->nsector;

    if (VAR_2 == 0) {

        

        ide_transfer_stop(VAR_0);

    } else {

#if defined(DEBUG_IDE)

        printf("read sector=%" PRId64 "\VAR_2", sector_num);

#endif

        if (VAR_2 > VAR_0->req_nb_sectors)

            VAR_2 = VAR_0->req_nb_sectors;



        bdrv_acct_start(VAR_0->bs, &VAR_0->acct, VAR_2 * BDRV_SECTOR_SIZE, BDRV_ACCT_READ);

        VAR_1 = bdrv_read(VAR_0->bs, sector_num, VAR_0->io_buffer, VAR_2);

        bdrv_acct_done(VAR_0->bs, &VAR_0->acct);

        if (VAR_1 != 0) {

            if (ide_handle_rw_error(VAR_0, -VAR_1,

                BM_STATUS_PIO_RETRY | BM_STATUS_RETRY_READ))

            {

                return;

            }

        }

        ide_transfer_start(VAR_0, VAR_0->io_buffer, 512 * VAR_2, FUNC_0);

        ide_set_irq(VAR_0->bus);

        ide_set_sector(VAR_0, sector_num + VAR_2);

        VAR_0->nsector -= VAR_2;

    }

}

void FUNC_0(IDEState *VAR_0)
{ int64_t sector_num; int VAR_1, VAR_2; VAR_0->status = READY_STAT | SEEK_STAT; VAR_0->error = 0; sector_num = ide_get_sector(VAR_0); VAR_2 = VAR_0->nsector; if (VAR_2 == 0) { ide_transfer_stop(VAR_0); } else { #if defined(DEBUG_IDE)
printf("read sector=%" PRId64 "\VAR_2", sector_num); #endif
if (VAR_2 > VAR_0->req_nb_sectors)
VAR_2 = VAR_0->req_nb_sectors; bdrv_acct_start(VAR_0->bs, &VAR_0->acct, VAR_2 * BDRV_SECTOR_SIZE, BDRV_ACCT_READ); VAR_1 = bdrv_read(VAR_0->bs, sector_num, VAR_0->io_buffer, VAR_2); bdrv_acct_done(VAR_0->bs, &VAR_0->acct); if (VAR_1 != 0) { if (ide_handle_rw_error(VAR_0, -VAR_1,
BM_STATUS_PIO_RETRY | BM_STATUS_RETRY_READ))
{ return; } } ide_transfer_start(VAR_0, VAR_0->io_buffer, 512 * VAR_2, FUNC_0); ide_set_irq(VAR_0->bus); ide_set_sector(VAR_0, sector_num + VAR_2); VAR_0->nsector -= VAR_2; } }