static int ide_write_dma_cb(IDEState *s, 

                            target_phys_addr_t phys_addr, 

                            int transfer_size1)

{

    int len, transfer_size, n;

    int64_t sector_num;



    transfer_size = transfer_size1;

    for(;;) {

        len = s->io_buffer_size - s->io_buffer_index;

        if (len == 0) {

            n = s->io_buffer_size >> 9;

            sector_num = ide_get_sector(s);

            bdrv_write(s->bs, sector_num, s->io_buffer, 

                       s->io_buffer_size >> 9);

            sector_num += n;

            ide_set_sector(s, sector_num);

            s->nsector -= n;

            n = s->nsector;

            if (n == 0) {

                /* end of transfer */

                s->status = READY_STAT | SEEK_STAT;

                ide_set_irq(s);

                return 0;

            }

            if (n > MAX_MULT_SECTORS)

                n = MAX_MULT_SECTORS;

            s->io_buffer_index = 0;

            s->io_buffer_size = n * 512;

            len = s->io_buffer_size;

        }

        if (transfer_size <= 0)

            break;

        if (len > transfer_size)

            len = transfer_size;

        cpu_physical_memory_read(phys_addr, 

                                 s->io_buffer + s->io_buffer_index, len);

        s->io_buffer_index += len;

        transfer_size -= len;

        phys_addr += len;

    }

    return transfer_size1 - transfer_size;

}

static int ide_write_dma_cb(IDEState *s, 

                            target_phys_addr_t phys_addr, 

                            int transfer_size1)

{

    int len, transfer_size, n;

    int64_t sector_num;



    transfer_size = transfer_size1;

    for(;;) {

        len = s->io_buffer_size - s->io_buffer_index;

        if (len == 0) {

            n = s->io_buffer_size >> 9;

            sector_num = ide_get_sector(s);

            bdrv_write(s->bs, sector_num, s->io_buffer, 

                       s->io_buffer_size >> 9);

            sector_num += n;

            ide_set_sector(s, sector_num);

            s->nsector -= n;

            n = s->nsector;

            if (n == 0) {

                

                s->status = READY_STAT | SEEK_STAT;

                ide_set_irq(s);

                return 0;

            }

            if (n > MAX_MULT_SECTORS)

                n = MAX_MULT_SECTORS;

            s->io_buffer_index = 0;

            s->io_buffer_size = n * 512;

            len = s->io_buffer_size;

        }

        if (transfer_size <= 0)

            break;

        if (len > transfer_size)

            len = transfer_size;

        cpu_physical_memory_read(phys_addr, 

                                 s->io_buffer + s->io_buffer_index, len);

        s->io_buffer_index += len;

        transfer_size -= len;

        phys_addr += len;

    }

    return transfer_size1 - transfer_size;

}

static int FUNC_0(IDEState *VAR_0, 

                            target_phys_addr_t VAR_1, 

                            int VAR_2)

{

    int VAR_3, VAR_4, VAR_5;

    int64_t sector_num;



    VAR_4 = VAR_2;

    for(;;) {

        VAR_3 = VAR_0->io_buffer_size - VAR_0->io_buffer_index;

        if (VAR_3 == 0) {

            VAR_5 = VAR_0->io_buffer_size >> 9;

            sector_num = ide_get_sector(VAR_0);

            bdrv_write(VAR_0->bs, sector_num, VAR_0->io_buffer, 

                       VAR_0->io_buffer_size >> 9);

            sector_num += VAR_5;

            ide_set_sector(VAR_0, sector_num);

            VAR_0->nsector -= VAR_5;

            VAR_5 = VAR_0->nsector;

            if (VAR_5 == 0) {

                

                VAR_0->status = READY_STAT | SEEK_STAT;

                ide_set_irq(VAR_0);

                return 0;

            }

            if (VAR_5 > MAX_MULT_SECTORS)

                VAR_5 = MAX_MULT_SECTORS;

            VAR_0->io_buffer_index = 0;

            VAR_0->io_buffer_size = VAR_5 * 512;

            VAR_3 = VAR_0->io_buffer_size;

        }

        if (VAR_4 <= 0)

            break;

        if (VAR_3 > VAR_4)

            VAR_3 = VAR_4;

        cpu_physical_memory_read(VAR_1, 

                                 VAR_0->io_buffer + VAR_0->io_buffer_index, VAR_3);

        VAR_0->io_buffer_index += VAR_3;

        VAR_4 -= VAR_3;

        VAR_1 += VAR_3;

    }

    return VAR_2 - VAR_4;

}

static int FUNC_0(IDEState *VAR_0,
target_phys_addr_t VAR_1,
int VAR_2)
{ int VAR_3, VAR_4, VAR_5; int64_t sector_num; VAR_4 = VAR_2; for(;;) { VAR_3 = VAR_0->io_buffer_size - VAR_0->io_buffer_index; if (VAR_3 == 0) { VAR_5 = VAR_0->io_buffer_size >> 9; sector_num = ide_get_sector(VAR_0); bdrv_write(VAR_0->bs, sector_num, VAR_0->io_buffer,
VAR_0->io_buffer_size >> 9); sector_num += VAR_5; ide_set_sector(VAR_0, sector_num); VAR_0->nsector -= VAR_5; VAR_5 = VAR_0->nsector; if (VAR_5 == 0) { VAR_0->status = READY_STAT | SEEK_STAT; ide_set_irq(VAR_0); return 0; } if (VAR_5 > MAX_MULT_SECTORS)
VAR_5 = MAX_MULT_SECTORS; VAR_0->io_buffer_index = 0; VAR_0->io_buffer_size = VAR_5 * 512; VAR_3 = VAR_0->io_buffer_size; } if (VAR_4 <= 0)
break; if (VAR_3 > VAR_4)
VAR_3 = VAR_4; cpu_physical_memory_read(VAR_1,
VAR_0->io_buffer + VAR_0->io_buffer_index, VAR_3); VAR_0->io_buffer_index += VAR_3; VAR_4 -= VAR_3; VAR_1 += VAR_3; } return VAR_2 - VAR_4; }