Revision 46d4767d hw/ide.c

b/hw/ide.c
1826 1826
	uint32_t nr_sects;		/* nr of sectors in partition */
1827 1827
} __attribute__((packed));
1828 1828

  
1829
/* try to guess the IDE geometry from the MSDOS partition table */
1829
/* try to guess the IDE physical geometry from the MSDOS partition table */
1830 1830
static void ide_guess_geometry(IDEState *s)
1831 1831
{
1832 1832
    uint8_t buf[512];
1833
    int ret, i;
1833
    int ret, i, heads, sectors, cylinders;
1834 1834
    struct partition *p;
1835 1835
    uint32_t nr_sects;
1836 1836

  
......
1848 1848
        if (nr_sects && p->end_head) {
1849 1849
            /* We make the assumption that the partition terminates on
1850 1850
               a cylinder boundary */
1851
            s->heads = p->end_head + 1;
1852
            s->sectors = p->end_sector & 63;
1853
            s->cylinders = s->nb_sectors / (s->heads * s->sectors);
1851
            heads = p->end_head + 1;
1852
            if (heads < 1 || heads > 16)
1853
                continue;
1854
            sectors = p->end_sector & 63;
1855
            if (sectors == 0)
1856
                continue;
1857
            cylinders = s->nb_sectors / (heads * sectors);
1858
            if (cylinders < 1 || cylinders > 16383)
1859
                continue;
1860
            s->heads = heads;
1861
            s->sectors = sectors;
1862
            s->cylinders = cylinders;
1854 1863
#if 0
1855 1864
            printf("guessed partition: CHS=%d %d %d\n", 
1856 1865
                   s->cylinders, s->heads, s->sectors);
......
1885 1894
            } else {
1886 1895
                ide_guess_geometry(s);
1887 1896
                if (s->cylinders == 0) {
1888
                    /* if no geometry, use a LBA compatible one */
1897
                    /* if no geometry, use a standard physical disk geometry */
1889 1898
                    cylinders = nb_sectors / (16 * 63);
1890 1899
                    if (cylinders > 16383)
1891 1900
                        cylinders = 16383;

Also available in: Unified diff