static int guess_disk_lchs(IDEState *s,

                           int *pcylinders, int *pheads, int *psectors)

{

    uint8_t *buf;

    int ret, i, heads, sectors, cylinders;

    struct partition *p;

    uint32_t nr_sects;



    buf = qemu_memalign(512, 512);

    if (buf == NULL)

        return -1;

    ret = bdrv_read(s->bs, 0, buf, 1);

    if (ret < 0) {

        qemu_free(buf);

        return -1;

    }

    /* test msdos magic */

    if (buf[510] != 0x55 || buf[511] != 0xaa) {

        qemu_free(buf);

        return -1;

    }

    for(i = 0; i < 4; i++) {

        p = ((struct partition *)(buf + 0x1be)) + i;

        nr_sects = le32_to_cpu(p->nr_sects);

        if (nr_sects && p->end_head) {

            /* We make the assumption that the partition terminates on

               a cylinder boundary */

            heads = p->end_head + 1;

            sectors = p->end_sector & 63;

            if (sectors == 0)

                continue;

            cylinders = s->nb_sectors / (heads * sectors);

            if (cylinders < 1 || cylinders > 16383)

                continue;

            *pheads = heads;

            *psectors = sectors;

            *pcylinders = cylinders;

#if 0

            printf("guessed geometry: LCHS=%d %d %d\n",

                   cylinders, heads, sectors);

#endif

            qemu_free(buf);

            return 0;

        }

    }

    qemu_free(buf);

    return -1;

}

static int guess_disk_lchs(IDEState *s,

                           int *pcylinders, int *pheads, int *psectors)

{

    uint8_t *buf;

    int ret, i, heads, sectors, cylinders;

    struct partition *p;

    uint32_t nr_sects;



    buf = qemu_memalign(512, 512);

    if (buf == NULL)

        return -1;

    ret = bdrv_read(s->bs, 0, buf, 1);

    if (ret < 0) {

        qemu_free(buf);

        return -1;

    }

    

    if (buf[510] != 0x55 || buf[511] != 0xaa) {

        qemu_free(buf);

        return -1;

    }

    for(i = 0; i < 4; i++) {

        p = ((struct partition *)(buf + 0x1be)) + i;

        nr_sects = le32_to_cpu(p->nr_sects);

        if (nr_sects && p->end_head) {

            



            heads = p->end_head + 1;

            sectors = p->end_sector & 63;

            if (sectors == 0)

                continue;

            cylinders = s->nb_sectors / (heads * sectors);

            if (cylinders < 1 || cylinders > 16383)

                continue;

            *pheads = heads;

            *psectors = sectors;

            *pcylinders = cylinders;

#if 0

            printf("guessed geometry: LCHS=%d %d %d\n",

                   cylinders, heads, sectors);

#endif

            qemu_free(buf);

            return 0;

        }

    }

    qemu_free(buf);

    return -1;

}

    uint8_t *buf;     buf = qemu_memalign(512, 512);     if (buf == NULL)         return -1;         qemu_free(buf);         qemu_free(buf);             qemu_free(buf);     qemu_free(buf);
static int FUNC_0(IDEState *VAR_0,

                           int *VAR_1, int *VAR_2, int *VAR_3)

{

    uint8_t *buf;

    int VAR_4, VAR_5, VAR_6, VAR_7, VAR_8;

    struct partition *VAR_9;

    uint32_t nr_sects;



    buf = qemu_memalign(512, 512);

    if (buf == NULL)

        return -1;

    VAR_4 = bdrv_read(VAR_0->bs, 0, buf, 1);

    if (VAR_4 < 0) {

        qemu_free(buf);

        return -1;

    }

    

    if (buf[510] != 0x55 || buf[511] != 0xaa) {

        qemu_free(buf);

        return -1;

    }

    for(VAR_5 = 0; VAR_5 < 4; VAR_5++) {

        VAR_9 = ((struct partition *)(buf + 0x1be)) + VAR_5;

        nr_sects = le32_to_cpu(VAR_9->nr_sects);

        if (nr_sects && VAR_9->end_head) {

            



            VAR_6 = VAR_9->end_head + 1;

            VAR_7 = VAR_9->end_sector & 63;

            if (VAR_7 == 0)

                continue;

            VAR_8 = VAR_0->nb_sectors / (VAR_6 * VAR_7);

            if (VAR_8 < 1 || VAR_8 > 16383)

                continue;

            *VAR_2 = VAR_6;

            *VAR_3 = VAR_7;

            *VAR_1 = VAR_8;

#if 0

            printf("guessed geometry: LCHS=%d %d %d\n",

                   VAR_8, VAR_6, VAR_7);

#endif

            qemu_free(buf);

            return 0;

        }

    }

    qemu_free(buf);

    return -1;

}

static int FUNC_0(IDEState *VAR_0,
int *VAR_1, int *VAR_2, int *VAR_3)
{ uint8_t *buf; int VAR_4, VAR_5, VAR_6, VAR_7, VAR_8; struct partition *VAR_9; uint32_t nr_sects; buf = qemu_memalign(512, 512); if (buf == NULL)
return -1; VAR_4 = bdrv_read(VAR_0->bs, 0, buf, 1); if (VAR_4 < 0) { qemu_free(buf); return -1; } if (buf[510] != 0x55 || buf[511] != 0xaa) { qemu_free(buf); return -1; } for(VAR_5 = 0; VAR_5 < 4; VAR_5++) { VAR_9 = ((struct partition *)(buf + 0x1be)) + VAR_5; nr_sects = le32_to_cpu(VAR_9->nr_sects); if (nr_sects && VAR_9->end_head) { VAR_6 = VAR_9->end_head + 1; VAR_7 = VAR_9->end_sector & 63; if (VAR_7 == 0)
continue; VAR_8 = VAR_0->nb_sectors / (VAR_6 * VAR_7); if (VAR_8 < 1 || VAR_8 > 16383)
continue; *VAR_2 = VAR_6; *VAR_3 = VAR_7; *VAR_1 = VAR_8; #if 0
printf("guessed geometry: LCHS=%d %d %d\n",
VAR_8, VAR_6, VAR_7); #endif
qemu_free(buf); return 0; } } qemu_free(buf); return -1; }