This patch allows to define floppy using the "-disk" syntax. It adds an interface type "floppy".
"-fda file" is an alias for "-disk file,index=0,if=floppy" "-fdb file" is an alias for "-disk file,index=1,if=floppy" -- vl.c | 86 +++++++++++++++++++++++++++++++++++-------------------------------- vl.h | 2 - 2 files changed, 46 insertions(+), 42 deletions(-) Index: qemu/vl.c =================================================================== --- qemu.orig/vl.c 2007-10-31 15:48:54.000000000 +0100 +++ qemu/vl.c 2007-10-31 15:49:17.000000000 +0100 @@ -4711,6 +4711,7 @@ } } +#define FD_ALIAS ",index=%d,if=floppy" #define HD_ALIAS ",index=%d,media=disk" #ifdef TARGET_PPC @@ -4722,7 +4723,7 @@ static int disk_init(const char *str, int snapshot, QEMUMachine *machine) { char buf[16]; - enum { IF_IDE, IF_SCSI } interface; + enum { IF_IDE, IF_SCSI, IF_FLOPPY } interface; enum { MEDIA_DISK, MEDIA_CDROM } media; int bus_id, unit_id; int cyls, heads, secs, translation; @@ -4811,6 +4812,8 @@ interface = IF_IDE; else if (!strcmp(buf, "scsi")) interface = IF_SCSI; + else if (!strcmp(buf, "floppy")) + interface = IF_FLOPPY; else { fprintf(stderr, "unsupported bus type '%s'\n", buf); return -1; @@ -4966,6 +4969,30 @@ } } break; + case IF_FLOPPY: + if (disk_index == -1) { + disk_index = 0; + while (fd_table[disk_index] && disk_index < MAX_FD) + disk_index++; + } + if (disk_index >= MAX_FD) { + fprintf(stderr, "qemu: too many floppy\n"); + return -1; + } + + if (!fd_table[disk_index]) { + snprintf(buf, sizeof(buf), "fd%c", disk_index + 'a'); + fd_table[disk_index] = bdrv_new(buf); + bdrv_set_type_hint(fd_table[disk_index], BDRV_TYPE_FLOPPY); + + if ( file[0] && (bdrv_open(fd_table[disk_index], file, + snapshot ? BDRV_O_SNAPSHOT : 0) < 0)) { + fprintf(stderr, "qemu: could not open floppy disk image '%s'\n", + file); + return -1; + } + } + break; } return 0; } @@ -7848,7 +7875,6 @@ int i, pflash_index; int snapshot, linux_boot; const char *initrd_filename; - const char *fd_filename[MAX_FD]; const char *pflash_filename[MAX_PFLASH]; const char *sd_filename; const char *mtd_filename; @@ -7912,8 +7938,6 @@ machine = first_machine; cpu_model = NULL; initrd_filename = NULL; - for(i = 0; i < MAX_FD; i++) - fd_filename[i] = NULL; for(i = 0; i < MAX_PFLASH; i++) pflash_filename[i] = NULL; pflash_index = 0; @@ -8169,10 +8193,14 @@ } break; case QEMU_OPTION_fda: - fd_filename[0] = optarg; - break; case QEMU_OPTION_fdb: - fd_filename[1] = optarg; + if (nb_disks >= MAX_DISKS) { + fprintf(stderr, "qemu: too many disks\n"); + exit(1); + } + snprintf(disks[nb_disks], sizeof(disks[0]), + "%s" FD_ALIAS, optarg, popt->index - QEMU_OPTION_fda); + nb_disks++; break; #ifdef TARGET_I386 case QEMU_OPTION_no_fd_bootchk: @@ -8516,19 +8544,11 @@ if (!linux_boot && (!strchr(boot_device, 'n')) && - nb_disks == 0 && - fd_filename[0] == '\0') + nb_disks == 0) help(1); - /* boot to floppy or the default cd if no hard disk defined yet */ if (!boot_device[0]) { - if (nb_disks) - boot_device[0] = 'c'; - else if (fd_filename[0] != '\0') - boot_device[0] = 'a'; - else - boot_device[0] = 'd'; - boot_device[1] = 0; + pstrcpy(boot_device, sizeof(boot_device), BOOTCHARS); } setvbuf(stdout, NULL, _IOLBF, 0); @@ -8606,35 +8626,19 @@ nb_disks++; } + /* we always create at least on floppy */ + + if (nb_disks < MAX_DISKS) { + snprintf(disks[nb_disks], sizeof(disks[0]), FD_ALIAS, 0); + nb_disks++; + } + /* open the virtual block devices */ for(i = 0; i < nb_disks; i++) if (disk_init(disks[i], snapshot, machine) == -1) exit(1); - /* we always create at least one floppy disk */ - fd_table[0] = bdrv_new("fda"); - bdrv_set_type_hint(fd_table[0], BDRV_TYPE_FLOPPY); - - for(i = 0; i < MAX_FD; i++) { - if (fd_filename[i]) { - if (!fd_table[i]) { - char buf[64]; - snprintf(buf, sizeof(buf), "fd%c", i + 'a'); - fd_table[i] = bdrv_new(buf); - bdrv_set_type_hint(fd_table[i], BDRV_TYPE_FLOPPY); - } - if (fd_filename[i][0] != '\0') { - if (bdrv_open(fd_table[i], fd_filename[i], - snapshot ? BDRV_O_SNAPSHOT : 0) < 0) { - fprintf(stderr, "qemu: could not open floppy disk image '%s'\n", - fd_filename[i]); - exit(1); - } - } - } - } - /* Open the virtual parallel flash block devices */ for(i = 0; i < MAX_PFLASH; i++) { if (pflash_filename[i]) { @@ -8750,7 +8754,7 @@ } machine->init(ram_size, vga_ram_size, boot_device, - ds, fd_filename, snapshot, + ds, NULL, snapshot, kernel_filename, kernel_cmdline, initrd_filename, cpu_model); /* init USB devices */ Index: qemu/vl.h =================================================================== --- qemu.orig/vl.h 2007-10-31 15:49:23.000000000 +0100 +++ qemu/vl.h 2007-10-31 15:49:40.000000000 +0100 @@ -994,7 +994,7 @@ #define MAX_IDE_DEVS 2 #define MAX_IDE_DISKS (MAX_IDE_BUS * MAX_IDE_DEVS) -#define MAX_DISKS (MAX_IDE_DISKS + MAX_SCSI_DISKS) +#define MAX_DISKS (MAX_IDE_DISKS + MAX_SCSI_DISKS + MAX_FD) extern BlockDriverState *bs_table[MAX_IDE_DISKS + 1]; extern BlockDriverState *sd_table[MAX_SCSI_DISKS + 1];