From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1InFrm-0003yP-3Y for qemu-devel@nongnu.org; Wed, 31 Oct 2007 11:52:26 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1InFrk-0003xS-Bj for qemu-devel@nongnu.org; Wed, 31 Oct 2007 11:52:25 -0400 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1InFrk-0003xN-7A for qemu-devel@nongnu.org; Wed, 31 Oct 2007 11:52:24 -0400 Received: from ecfrec.frec.bull.fr ([129.183.4.8]) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1InFrj-00043w-AQ for qemu-devel@nongnu.org; Wed, 31 Oct 2007 11:52:23 -0400 Received: from localhost (localhost [127.0.0.1]) by ecfrec.frec.bull.fr (Postfix) with ESMTP id 2640119D994 for ; Wed, 31 Oct 2007 16:52:16 +0100 (CET) Received: from ecfrec.frec.bull.fr ([127.0.0.1]) by localhost (ecfrec.frec.bull.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 25561-01 for ; Wed, 31 Oct 2007 16:52:12 +0100 (CET) Received: from ecn002.frec.bull.fr (ecn002.frec.bull.fr [129.183.4.6]) by ecfrec.frec.bull.fr (Postfix) with ESMTP id E999019D97B for ; Wed, 31 Oct 2007 16:52:10 +0100 (CET) In-Reply-To: <11938459121657@bull.net> Date: Wed, 31 Oct 2007 16:51:54 +0100 Message-Id: <11938459144026@bull.net> Mime-Version: 1.0 From: Laurent Vivier Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="iso-8859-1" Subject: [Qemu-devel] [PATCH 3/7] Add floppy support by -disk Reply-To: Laurent Vivier , qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Laurent.Vivier@bull.net 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=3D0,if=3Dfloppy" "-fdb file" is an alias for "-disk file,index=3D1,if=3Dfloppy" -- vl.c | 86 +++++++++++++++++++++++++++++++++++---------------------------= ----- vl.h | 2 - 2 files changed, 46 insertions(+), 42 deletions(-) Index: qemu/vl.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- 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 @@ } } =20 +#define FD_ALIAS ",index=3D%d,if=3Dfloppy" #define HD_ALIAS ",index=3D%d,media=3Ddisk" =20 #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 =3D IF_IDE; else if (!strcmp(buf, "scsi")) interface =3D IF_SCSI; + else if (!strcmp(buf, "floppy")) + interface =3D IF_FLOPPY; else { fprintf(stderr, "unsupported bus type '%s'\n", buf); return -1; @@ -4966,6 +4969,30 @@ } } break; + case IF_FLOPPY: + if (disk_index =3D=3D -1) { + disk_index =3D 0; + while (fd_table[disk_index] && disk_index < MAX_FD) + disk_index++; + } + if (disk_index >=3D 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] =3D 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 =3D first_machine; cpu_model =3D NULL; initrd_filename =3D NULL; - for(i =3D 0; i < MAX_FD; i++) - fd_filename[i] =3D NULL; for(i =3D 0; i < MAX_PFLASH; i++) pflash_filename[i] =3D NULL; pflash_index =3D 0; @@ -8169,10 +8193,14 @@ } break; case QEMU_OPTION_fda: - fd_filename[0] =3D optarg; - break; case QEMU_OPTION_fdb: - fd_filename[1] =3D optarg; + if (nb_disks >=3D 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 @@ =20 if (!linux_boot && (!strchr(boot_device, 'n')) && - nb_disks =3D=3D 0 && - fd_filename[0] =3D=3D '\0') + nb_disks =3D=3D 0) help(1); =20 - /* boot to floppy or the default cd if no hard disk defined yet */ if (!boot_device[0]) { - if (nb_disks) - boot_device[0] =3D 'c'; - else if (fd_filename[0] !=3D '\0') - boot_device[0] =3D 'a'; - else - boot_device[0] =3D 'd'; - boot_device[1] =3D 0; + pstrcpy(boot_device, sizeof(boot_device), BOOTCHARS); } setvbuf(stdout, NULL, _IOLBF, 0); =20 @@ -8606,35 +8626,19 @@ nb_disks++; } =20 + /* 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 */ =20 for(i =3D 0; i < nb_disks; i++) if (disk_init(disks[i], snapshot, machine) =3D=3D -1) exit(1); =20 - /* we always create at least one floppy disk */ - fd_table[0] =3D bdrv_new("fda"); - bdrv_set_type_hint(fd_table[0], BDRV_TYPE_FLOPPY); - - for(i =3D 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] =3D bdrv_new(buf); - bdrv_set_type_hint(fd_table[i], BDRV_TYPE_FLOPPY); - } - if (fd_filename[i][0] !=3D '\0') { - if (bdrv_open(fd_table[i], fd_filename[i], - snapshot ? BDRV_O_SNAPSHOT : 0) < 0) { - fprintf(stderr, "qemu: could not open floppy disk imag= e '%s'\n", - fd_filename[i]); - exit(1); - } - } - } - } - /* Open the virtual parallel flash block devices */ for(i =3D 0; i < MAX_PFLASH; i++) { if (pflash_filename[i]) { @@ -8750,7 +8754,7 @@ } =20 machine->init(ram_size, vga_ram_size, boot_device, - ds, fd_filename, snapshot, + ds, NULL, snapshot, kernel_filename, kernel_cmdline, initrd_filename, cpu_mo= del); =20 /* init USB devices */ Index: qemu/vl.h =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- 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) =20 -#define MAX_DISKS (MAX_IDE_DISKS + MAX_SCSI_DISKS) +#define MAX_DISKS (MAX_IDE_DISKS + MAX_SCSI_DISKS + MAX_FD) =20 extern BlockDriverState *bs_table[MAX_IDE_DISKS + 1]; extern BlockDriverState *sd_table[MAX_SCSI_DISKS + 1];