This allows to handle the default FAT size in a single place and make the
following part taking care only about size parameters. It will be later
moved away in a specific function.
Setting a floppy disk of 1MB is no longer possible as it was a side
effect of passing "fat-type=12". To be precise there were three cases:
- fat-type undefined (aka default): a fat12 2MB disk
- fat-type=16: a fat16 2Mb disk
- fat-type=12: a fat12 1Mb disk
Now, that fat-type undefined means fat-type=2, it's no longer possible
to make that size distinction. It will be added back a bit later,
through the size parameter.
Signed-off-by: Clément Chigot <chigot@adacore.com>
---
block/vvfat.c | 48 +++++++++++++++++++++++++++---------------------
1 file changed, 27 insertions(+), 21 deletions(-)
diff --git a/block/vvfat.c b/block/vvfat.c
index 0220dd828b..91e4ad3158 100644
--- a/block/vvfat.c
+++ b/block/vvfat.c
@@ -1190,45 +1190,51 @@ static int vvfat_open(BlockDriverState *bs, QDict *options, int flags,
memcpy(s->volume_label, "QEMU VVFAT", 10);
}
- if (floppy) {
- /* 1.44MB or 2.88MB floppy. 2.88MB can be FAT12 (default) or FAT16. */
- if (!s->fat_type) {
+ /* Verify FAT type */
+ switch (s->fat_type) {
+ case 32:
+ warn_report("FAT32 has not been tested. You are welcome to do so!");
+ break;
+ case 16:
+ case 12:
+ break;
+ case 0:
+ /* Set a default type */
+ if (floppy) {
s->fat_type = 12;
+ } else {
+ s->fat_type = 16;
+ }
+ break;
+ default:
+ error_setg(errp, "Valid FAT types are only 12, 16 and 32");
+ ret = -EINVAL;
+ goto fail;
+ }
+
+
+ if (floppy) {
+ /* 2.88MB floppy */
+ if (s->fat_type == 12) {
secs = 36;
s->sectors_per_cluster = 2;
} else {
- secs = s->fat_type == 12 ? 18 : 36;
+ secs = 36;
s->sectors_per_cluster = 1;
}
cyls = 80;
heads = 2;
} else {
- /* 32MB or 504MB disk*/
- if (!s->fat_type) {
- s->fat_type = 16;
- }
/* Reserver space for MBR */
if (!qemu_opt_get_bool(opts, "no-mbr", false)) {
s->offset_to_bootsector = 0x3f;
}
+ /* 32MB or 504MB disk*/
cyls = s->fat_type == 12 ? 64 : 1024;
heads = 16;
secs = 63;
}
- switch (s->fat_type) {
- case 32:
- warn_report("FAT32 has not been tested. You are welcome to do so!");
- break;
- case 16:
- case 12:
- break;
- default:
- error_setg(errp, "Valid FAT types are only 12, 16 and 32");
- ret = -EINVAL;
- goto fail;
- }
-
s->bs = bs;
--
2.34.1