diff options
author | bellard <bellard@c046a42c-6fe2-441c-8c8c-71466251a162> | 2004-11-16 01:45:27 +0000 |
---|---|---|
committer | bellard <bellard@c046a42c-6fe2-441c-8c8c-71466251a162> | 2004-11-16 01:45:27 +0000 |
commit | 46d4767d93bcb2e84869ba6d2344ebff4382be86 (patch) | |
tree | ec07dcd1af4aaab9db64547e0b4cf36558caf772 /hw/ide.c | |
parent | e35c55fe38faea68eb9356163f52a426e533d79b (diff) | |
download | qemu-46d4767d93bcb2e84869ba6d2344ebff4382be86.zip qemu-46d4767d93bcb2e84869ba6d2344ebff4382be86.tar.gz qemu-46d4767d93bcb2e84869ba6d2344ebff4382be86.tar.bz2 |
better BIOS ATA translation support
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@1153 c046a42c-6fe2-441c-8c8c-71466251a162
Diffstat (limited to 'hw/ide.c')
-rw-r--r-- | hw/ide.c | 21 |
1 files changed, 15 insertions, 6 deletions
@@ -1826,11 +1826,11 @@ struct partition { uint32_t nr_sects; /* nr of sectors in partition */ } __attribute__((packed)); -/* try to guess the IDE geometry from the MSDOS partition table */ +/* try to guess the IDE physical geometry from the MSDOS partition table */ static void ide_guess_geometry(IDEState *s) { uint8_t buf[512]; - int ret, i; + int ret, i, heads, sectors, cylinders; struct partition *p; uint32_t nr_sects; @@ -1848,9 +1848,18 @@ static void ide_guess_geometry(IDEState *s) if (nr_sects && p->end_head) { /* We make the assumption that the partition terminates on a cylinder boundary */ - s->heads = p->end_head + 1; - s->sectors = p->end_sector & 63; - s->cylinders = s->nb_sectors / (s->heads * s->sectors); + heads = p->end_head + 1; + if (heads < 1 || heads > 16) + continue; + sectors = p->end_sector & 63; + if (sectors == 0) + continue; + cylinders = s->nb_sectors / (heads * sectors); + if (cylinders < 1 || cylinders > 16383) + continue; + s->heads = heads; + s->sectors = sectors; + s->cylinders = cylinders; #if 0 printf("guessed partition: CHS=%d %d %d\n", s->cylinders, s->heads, s->sectors); @@ -1885,7 +1894,7 @@ static void ide_init2(IDEState *ide_state, int irq, } else { ide_guess_geometry(s); if (s->cylinders == 0) { - /* if no geometry, use a LBA compatible one */ + /* if no geometry, use a standard physical disk geometry */ cylinders = nb_sectors / (16 * 63); if (cylinders > 16383) cylinders = 16383; |