Skip to contentSkip to conversation

Add -disk interface

PATCH New Laurent Vivier 1 participant 8 messages Oct 31, 2007

lore
Share & tools
lore
#3 lore raw

PATCH 3/7 Add floppy support by -disk

In reply to Laurent Vivier

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(-)
vl.c +45 -41
Index: qemu/vl.c
===================================================================
@@ -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 */
vl.h +1 -1
Index: qemu/vl.h
===================================================================
@@ -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];
#4 lore raw

PATCH 4/7 remove fd_filename from the machine init interface

As the parameter fd_filename seems unused and as we can't provide it anymore using the "-disk" interface, this patch removes it.

--

 hw/an5206.c        |    2 +-
 hw/etraxfs.c       |    2 +-
 hw/integratorcp.c  |    2 +-
 hw/mcf5208.c       |    2 +-
 hw/mips_malta.c    |    2 +-
 hw/mips_mipssim.c  |    2 +-
 hw/mips_pica61.c   |    2 +-
 hw/mips_r4k.c      |    2 +-
 hw/palm.c          |    2 +-
 hw/pc.c            |   12 +++++-------
 hw/ppc405_boards.c |    4 ++--
 hw/ppc_chrp.c      |    2 +-
 hw/ppc_oldworld.c  |    2 +-
 hw/ppc_prep.c      |    2 +-
 hw/r2d.c           |    2 +-
 hw/realview.c      |    2 +-
 hw/shix.c          |    2 +-
 hw/spitz.c         |    8 ++++----
 hw/sun4m.c         |    4 ++--
 hw/sun4u.c         |    2 +-
 hw/versatilepb.c   |   10 +++++-----
 vl.c               |    2 +-
 vl.h               |    2 +-
 23 files changed, 36 insertions(+), 38 deletions(-)
vl.h +1 -1
Index: qemu/vl.h
===================================================================
@@ -732,7 +732,7 @@
 
 typedef void QEMUMachineInitFunc(int ram_size, int vga_ram_size,
                                  const char *boot_device,
-             DisplayState *ds, const char **fd_filename, int snapshot,
+             DisplayState *ds, int snapshot,
              const char *kernel_filename, const char *kernel_cmdline,
              const char *initrd_filename, const char *cpu_model);
 
hw/an5206.c +1 -1
Index: qemu/hw/an5206.c
===================================================================
@@ -28,7 +28,7 @@
 /* Board init.  */
 
 static void an5206_init(int ram_size, int vga_ram_size, const char *boot_device,
-                     DisplayState *ds, const char **fd_filename, int snapshot,
+                     DisplayState *ds, int snapshot,
                      const char *kernel_filename, const char *kernel_cmdline,
                      const char *initrd_filename, const char *cpu_model)
 {
hw/etraxfs.c +1 -1
Index: qemu/hw/etraxfs.c
===================================================================
@@ -108,7 +108,7 @@
 
 static
 void bareetraxfs_init (int ram_size, int vga_ram_size, const char *boot_device,
-                       DisplayState *ds, const char **fd_filename, int snapshot,
+                       DisplayState *ds, int snapshot,
                        const char *kernel_filename, const char *kernel_cmdline,
                        const char *initrd_filename, const char *cpu_model)
 {
hw/integratorcp.c +1 -1
Index: qemu/hw/integratorcp.c
===================================================================
@@ -464,7 +464,7 @@
 
 static void integratorcp_init(int ram_size, int vga_ram_size,
                      const char *boot_device, DisplayState *ds,
-                     const char **fd_filename, int snapshot,
+                     int snapshot,
                      const char *kernel_filename, const char *kernel_cmdline,
                      const char *initrd_filename, const char *cpu_model)
 {
hw/mcf5208.c +1 -1
Index: qemu/hw/mcf5208.c
===================================================================
@@ -199,7 +199,7 @@
 
 static void mcf5208evb_init(int ram_size, int vga_ram_size,
                      const char *boot_device, DisplayState *ds,
-                     const char **fd_filename, int snapshot,
+                     int snapshot,
                      const char *kernel_filename, const char *kernel_cmdline,
                      const char *initrd_filename, const char *cpu_model)
 {
hw/mips_malta.c +1 -1
Index: qemu/hw/mips_malta.c
===================================================================
@@ -741,7 +741,7 @@
 
 static
 void mips_malta_init (int ram_size, int vga_ram_size, const char *boot_device,
-                      DisplayState *ds, const char **fd_filename, int snapshot,
+                      DisplayState *ds, int snapshot,
                       const char *kernel_filename, const char *kernel_cmdline,
                       const char *initrd_filename, const char *cpu_model)
 {
hw/mips_mipssim.c +1 -1
Index: qemu/hw/mips_mipssim.c
===================================================================
@@ -75,7 +75,7 @@
 
 static void
 mips_mipssim_init (int ram_size, int vga_ram_size, const char *boot_device,
-                   DisplayState *ds, const char **fd_filename, int snapshot,
+                   DisplayState *ds, int snapshot,
                    const char *kernel_filename, const char *kernel_cmdline,
                    const char *initrd_filename, const char *cpu_model)
 {
hw/palm.c +1 -1
Index: qemu/hw/palm.c
===================================================================
@@ -117,7 +117,7 @@
 
 static void palmte_init(int ram_size, int vga_ram_size,
                 const char *boot_device, DisplayState *ds,
-                const char **fd_filename, int snapshot,
+                int snapshot,
                 const char *kernel_filename, const char *kernel_cmdline,
                 const char *initrd_filename, const char *cpu_model)
 {
hw/ppc405_boards.c +2 -2
Index: qemu/hw/ppc405_boards.c
===================================================================
@@ -173,7 +173,7 @@
 
 static void ref405ep_init (int ram_size, int vga_ram_size,
                            const char *boot_device, DisplayState *ds,
-                           const char **fd_filename, int snapshot,
+                           int snapshot,
                            const char *kernel_filename,
                            const char *kernel_cmdline,
                            const char *initrd_filename,
@@ -499,7 +499,7 @@
 
 static void taihu_405ep_init(int ram_size, int vga_ram_size,
                              const char *boot_device, DisplayState *ds,
-                             const char **fd_filename, int snapshot,
+                             int snapshot,
                              const char *kernel_filename,
                              const char *kernel_cmdline,
                              const char *initrd_filename,
hw/ppc_chrp.c +1 -1
Index: qemu/hw/ppc_chrp.c
===================================================================
@@ -50,7 +50,7 @@
 /* PowerPC Mac99 hardware initialisation */
 static void ppc_core99_init (int ram_size, int vga_ram_size,
                              const char *boot_device, DisplayState *ds,
-                             const char **fd_filename, int snapshot,
+                             int snapshot,
                              const char *kernel_filename,
                              const char *kernel_cmdline,
                              const char *initrd_filename,
hw/ppc_oldworld.c +1 -1
Index: qemu/hw/ppc_oldworld.c
===================================================================
@@ -94,7 +94,7 @@
 
 static void ppc_heathrow_init (int ram_size, int vga_ram_size,
                                const char *boot_device, DisplayState *ds,
-                               const char **fd_filename, int snapshot,
+                               int snapshot,
                                const char *kernel_filename,
                                const char *kernel_cmdline,
                                const char *initrd_filename,
hw/r2d.c +1 -1
Index: qemu/hw/r2d.c
===================================================================
@@ -28,7 +28,7 @@
 #define SDRAM_SIZE 0x04000000
 
 static void r2d_init(int ram_size, int vga_ram_size, const char *boot_device,
-	      DisplayState * ds, const char **fd_filename, int snapshot,
+	      DisplayState * ds, int snapshot,
 	      const char *kernel_filename, const char *kernel_cmdline,
 	      const char *initrd_filename, const char *cpu_model)
 {
hw/shix.c +1 -1
Index: qemu/hw/shix.c
===================================================================
@@ -63,7 +63,7 @@
 }
 
 static void shix_init(int ram_size, int vga_ram_size, const char *boot_device,
-	       DisplayState * ds, const char **fd_filename, int snapshot,
+	       DisplayState * ds, int snapshot,
 	       const char *kernel_filename, const char *kernel_cmdline,
 	       const char *initrd_filename, const char *cpu_model)
 {
hw/spitz.c +4 -4
Index: qemu/hw/spitz.c
===================================================================
@@ -1230,7 +1230,7 @@
 
 static void spitz_init(int ram_size, int vga_ram_size,
                 const char *boot_device, DisplayState *ds,
-                const char **fd_filename, int snapshot,
+                int snapshot,
                 const char *kernel_filename, const char *kernel_cmdline,
                 const char *initrd_filename, const char *cpu_model)
 {
@@ -1240,7 +1240,7 @@
 
 static void borzoi_init(int ram_size, int vga_ram_size,
                 const char *boot_device, DisplayState *ds,
-                const char **fd_filename, int snapshot,
+                int snapshot,
                 const char *kernel_filename, const char *kernel_cmdline,
                 const char *initrd_filename, const char *cpu_model)
 {
@@ -1250,7 +1250,7 @@
 
 static void akita_init(int ram_size, int vga_ram_size,
                 const char *boot_device, DisplayState *ds,
-                const char **fd_filename, int snapshot,
+                int snapshot,
                 const char *kernel_filename, const char *kernel_cmdline,
                 const char *initrd_filename, const char *cpu_model)
 {
@@ -1260,7 +1260,7 @@
 
 static void terrier_init(int ram_size, int vga_ram_size,
                 const char *boot_device, DisplayState *ds,
-                const char **fd_filename, int snapshot,
+                int snapshot,
                 const char *kernel_filename, const char *kernel_cmdline,
                 const char *initrd_filename, const char *cpu_model)
 {
hw/sun4u.c +1 -1
Index: qemu/hw/sun4u.c
===================================================================
@@ -332,7 +332,7 @@
 
 /* Sun4u hardware initialisation */
 static void sun4u_init(int ram_size, int vga_ram_size, const char *boot_device,
-             DisplayState *ds, const char **fd_filename, int snapshot,
+             DisplayState *ds, int snapshot,
              const char *kernel_filename, const char *kernel_cmdline,
              const char *initrd_filename, const char *cpu_model)
 {
hw/mips_pica61.c +1 -1
Index: qemu/hw/mips_pica61.c
===================================================================
@@ -56,7 +56,7 @@
 
 static
 void mips_pica61_init (int ram_size, int vga_ram_size, const char *boot_device,
-                    DisplayState *ds, const char **fd_filename, int snapshot,
+                    DisplayState *ds, int snapshot,
                     const char *kernel_filename, const char *kernel_cmdline,
                     const char *initrd_filename, const char *cpu_model)
 {
hw/mips_r4k.c +1 -1
Index: qemu/hw/mips_r4k.c
===================================================================
@@ -138,7 +138,7 @@
 
 static
 void mips_r4k_init (int ram_size, int vga_ram_size, const char *boot_device,
-                    DisplayState *ds, const char **fd_filename, int snapshot,
+                    DisplayState *ds, int snapshot,
                     const char *kernel_filename, const char *kernel_cmdline,
                     const char *initrd_filename, const char *cpu_model)
 {
hw/pc.c +5 -7
Index: qemu/hw/pc.c
===================================================================
@@ -669,7 +669,7 @@
 
 /* PC hardware initialisation */
 static void pc_init1(int ram_size, int vga_ram_size, const char *boot_device,
-                     DisplayState *ds, const char **fd_filename, int snapshot,
+                     DisplayState *ds, int snapshot,
                      const char *kernel_filename, const char *kernel_cmdline,
                      const char *initrd_filename,
                      int pci_enabled)
@@ -949,29 +949,27 @@
 }
 
 static void pc_init_pci(int ram_size, int vga_ram_size, const char *boot_device,
-                        DisplayState *ds, const char **fd_filename,
-                        int snapshot,
+                        DisplayState *ds, int snapshot,
                         const char *kernel_filename,
                         const char *kernel_cmdline,
                         const char *initrd_filename,
                         const char *cpu_model)
 {
     pc_init1(ram_size, vga_ram_size, boot_device,
-             ds, fd_filename, snapshot,
+             ds, snapshot,
              kernel_filename, kernel_cmdline,
              initrd_filename, 1);
 }
 
 static void pc_init_isa(int ram_size, int vga_ram_size, const char *boot_device,
-                        DisplayState *ds, const char **fd_filename,
-                        int snapshot,
+                        DisplayState *ds, int snapshot,
                         const char *kernel_filename,
                         const char *kernel_cmdline,
                         const char *initrd_filename,
                         const char *cpu_model)
 {
     pc_init1(ram_size, vga_ram_size, boot_device,
-             ds, fd_filename, snapshot,
+             ds, snapshot,
              kernel_filename, kernel_cmdline,
              initrd_filename, 0);
 }
hw/ppc_prep.c +1 -1
Index: qemu/hw/ppc_prep.c
===================================================================
@@ -522,7 +522,7 @@
 
 /* PowerPC PREP hardware initialisation */
 static void ppc_prep_init (int ram_size, int vga_ram_size, const char *boot_device,
-                           DisplayState *ds, const char **fd_filename,
+                           DisplayState *ds,
                            int snapshot, const char *kernel_filename,
                            const char *kernel_cmdline,
                            const char *initrd_filename,
hw/realview.c +1 -1
Index: qemu/hw/realview.c
===================================================================
@@ -14,7 +14,7 @@
 
 static void realview_init(int ram_size, int vga_ram_size,
                      const char *boot_device, DisplayState *ds,
-                     const char **fd_filename, int snapshot,
+                     int snapshot,
                      const char *kernel_filename, const char *kernel_cmdline,
                      const char *initrd_filename, const char *cpu_model)
 {
hw/sun4m.c +2 -2
Index: qemu/hw/sun4m.c
===================================================================
@@ -571,7 +571,7 @@
 
 /* SPARCstation 5 hardware initialisation */
 static void ss5_init(int RAM_size, int vga_ram_size, const char *boot_device,
-                       DisplayState *ds, const char **fd_filename, int snapshot,
+                       DisplayState *ds, int snapshot,
                        const char *kernel_filename, const char *kernel_cmdline,
                        const char *initrd_filename, const char *cpu_model)
 {
@@ -584,7 +584,7 @@
 
 /* SPARCstation 10 hardware initialisation */
 static void ss10_init(int RAM_size, int vga_ram_size, const char *boot_device,
-                            DisplayState *ds, const char **fd_filename, int snapshot,
+                            DisplayState *ds, int snapshot,
                             const char *kernel_filename, const char *kernel_cmdline,
                             const char *initrd_filename, const char *cpu_model)
 {
hw/versatilepb.c +5 -5
Index: qemu/hw/versatilepb.c
===================================================================
@@ -153,7 +153,7 @@
 
 static void versatile_init(int ram_size, int vga_ram_size,
                      const char *boot_device, DisplayState *ds,
-                     const char **fd_filename, int snapshot,
+                     int snapshot,
                      const char *kernel_filename, const char *kernel_cmdline,
                      const char *initrd_filename, const char *cpu_model,
                      int board_id)
@@ -268,23 +268,23 @@
 }
 
 static void vpb_init(int ram_size, int vga_ram_size, const char *boot_device,
-                     DisplayState *ds, const char **fd_filename, int snapshot,
+                     DisplayState *ds, int snapshot,
                      const char *kernel_filename, const char *kernel_cmdline,
                      const char *initrd_filename, const char *cpu_model)
 {
     versatile_init(ram_size, vga_ram_size, boot_device,
-                   ds, fd_filename, snapshot,
+                   ds, snapshot,
                    kernel_filename, kernel_cmdline,
                    initrd_filename, cpu_model, 0x183);
 }
 
 static void vab_init(int ram_size, int vga_ram_size, const char *boot_device,
-                     DisplayState *ds, const char **fd_filename, int snapshot,
+                     DisplayState *ds, int snapshot,
                      const char *kernel_filename, const char *kernel_cmdline,
                      const char *initrd_filename, const char *cpu_model)
 {
     versatile_init(ram_size, vga_ram_size, boot_device,
-                   ds, fd_filename, snapshot,
+                   ds, snapshot,
                    kernel_filename, kernel_cmdline,
                    initrd_filename, cpu_model, 0x25e);
 }
vl.c +1 -1
Index: qemu/vl.c
===================================================================
@@ -8754,7 +8754,7 @@
     }
 
     machine->init(ram_size, vga_ram_size, boot_device,
-                  ds, NULL, snapshot,
+                  ds, snapshot,
                   kernel_filename, kernel_cmdline, initrd_filename, cpu_model);
 
     /* init USB devices */
#5 lore raw

PATCH 5/7 Add parallel flash support by -disk

This patch allows to define a parallel flash using -disk syntax. It adds an interface type "pflash".

"-pflash file" is an alias for "-disk file,if=pflash"

--

 vl.c |   59 +++++++++++++++++++++++++++++++++--------------------------
 vl.h |    2 +-
 2 files changed, 34 insertions(+), 27 deletions(-)
vl.c +33 -26
Index: qemu/vl.c
===================================================================
@@ -4712,6 +4712,7 @@
 }
 
 #define FD_ALIAS ",index=%d,if=floppy"
+#define PFLASH_ALIAS ",if=pflash"
 #define HD_ALIAS ",index=%d,media=disk"
 
 #ifdef TARGET_PPC
@@ -4723,7 +4724,7 @@
 static int disk_init(const char *str, int snapshot, QEMUMachine *machine)
 {
     char buf[16];
-    enum { IF_IDE, IF_SCSI, IF_FLOPPY } interface;
+    enum { IF_IDE, IF_SCSI, IF_FLOPPY, IF_PFLASH } interface;
     enum { MEDIA_DISK, MEDIA_CDROM } media;
     int bus_id, unit_id;
     int cyls, heads, secs, translation;
@@ -4814,6 +4815,8 @@
 	    interface = IF_SCSI;
 	else if (!strcmp(buf, "floppy"))
 	    interface = IF_FLOPPY;
+	else if (!strcmp(buf, "pflash"))
+	    interface = IF_PFLASH;
 	else {
             fprintf(stderr, "unsupported bus type '%s'\n", buf);
             return -1;
@@ -4993,6 +4996,29 @@
             }
 	}
         break;
+    case IF_PFLASH:
+        if (disk_index == -1) {
+	    disk_index = 0;
+	    while (pflash_table[disk_index] && disk_index < MAX_PFLASH)
+	        disk_index++;
+	}
+	if (disk_index >= MAX_PFLASH) {
+	    fprintf(stderr, "qemu: too many parallel flash images\n");
+	    return -1;
+	}
+
+        if (!pflash_table[disk_index]) {
+            snprintf(buf, sizeof(buf), "fl%c", disk_index + 'a');
+            pflash_table[disk_index] = bdrv_new(buf);
+
+            if (file[0] && bdrv_open(pflash_table[disk_index], file,
+                          snapshot ? BDRV_O_SNAPSHOT : 0) < 0) {
+                fprintf(stderr, "qemu: could not open flash image '%s'\n",
+                        file);
+                return -1;
+            }
+        }
+	break;
     }
    return 0;
 }
@@ -7872,10 +7898,9 @@
     int use_gdbstub;
     const char *gdbstub_port;
 #endif
-    int i, pflash_index;
+    int i;
     int snapshot, linux_boot;
     const char *initrd_filename;
-    const char *pflash_filename[MAX_PFLASH];
     const char *sd_filename;
     const char *mtd_filename;
     const char *kernel_filename, *kernel_cmdline;
@@ -7938,9 +7963,6 @@
     machine = first_machine;
     cpu_model = NULL;
     initrd_filename = NULL;
-    for(i = 0; i < MAX_PFLASH; i++)
-        pflash_filename[i] = NULL;
-    pflash_index = 0;
     sd_filename = NULL;
     mtd_filename = NULL;
     ram_size = DEFAULT_RAM_SIZE * 1024 * 1024;
@@ -8097,11 +8119,13 @@
                 sd_filename = optarg;
                 break;
             case QEMU_OPTION_pflash:
-                if (pflash_index >= MAX_PFLASH) {
-                    fprintf(stderr, "qemu: too many parallel flash images\n");
+                if (nb_disks >= MAX_DISKS) {
+                    fprintf(stderr, "qemu: too many disks\n");
                     exit(1);
                 }
-                pflash_filename[pflash_index++] = optarg;
+		snprintf(disks[nb_disks], sizeof(disks[0]),
+		         "%s" PFLASH_ALIAS, optarg);
+	        nb_disks++;
                 break;
             case QEMU_OPTION_snapshot:
                 snapshot = 1;
@@ -8639,23 +8663,6 @@
         if (disk_init(disks[i], snapshot, machine) == -1)
 	    exit(1);
 
-    /* Open the virtual parallel flash block devices */
-    for(i = 0; i < MAX_PFLASH; i++) {
-        if (pflash_filename[i]) {
-            if (!pflash_table[i]) {
-                char buf[64];
-                snprintf(buf, sizeof(buf), "fl%c", i + 'a');
-                pflash_table[i] = bdrv_new(buf);
-            }
-            if (bdrv_open(pflash_table[i], pflash_filename[i],
-                          snapshot ? BDRV_O_SNAPSHOT : 0) < 0) {
-                fprintf(stderr, "qemu: could not open flash image '%s'\n",
-                        pflash_filename[i]);
-                exit(1);
-            }
-        }
-    }
-
     sd_bdrv = bdrv_new ("sd");
     /* FIXME: This isn't really a floppy, but it's a reasonable
        approximation.  */
vl.h +1 -1
Index: qemu/vl.h
===================================================================
@@ -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 + MAX_FD)
+#define MAX_DISKS (MAX_IDE_DISKS + MAX_SCSI_DISKS + MAX_FD + MAX_PFLASH)
 
 extern BlockDriverState *bs_table[MAX_IDE_DISKS + 1];
 extern BlockDriverState *sd_table[MAX_SCSI_DISKS + 1];
#6 lore raw

PATCH 6/7 Add flash support by -disk

This patch allows to define a flash (mtd) using the "-disk" syntax. It adds an interface type "mtd"

"-mtdblock file" is an alias for "-disk file,if=mtd"

--

 vl.c |   39 +++++++++++++++++++++++----------------
 vl.h |    5 ++++-
 2 files changed, 27 insertions(+), 17 deletions(-)
vl.c +23 -16
Index: qemu/vl.c
===================================================================
@@ -4713,6 +4713,7 @@
 
 #define FD_ALIAS ",index=%d,if=floppy"
 #define PFLASH_ALIAS ",if=pflash"
+#define MTD_ALIAS ",if=mtd"
 #define HD_ALIAS ",index=%d,media=disk"
 
 #ifdef TARGET_PPC
@@ -4724,7 +4725,7 @@
 static int disk_init(const char *str, int snapshot, QEMUMachine *machine)
 {
     char buf[16];
-    enum { IF_IDE, IF_SCSI, IF_FLOPPY, IF_PFLASH } interface;
+    enum { IF_IDE, IF_SCSI, IF_FLOPPY, IF_PFLASH, IF_MTD } interface;
     enum { MEDIA_DISK, MEDIA_CDROM } media;
     int bus_id, unit_id;
     int cyls, heads, secs, translation;
@@ -4817,6 +4818,8 @@
 	    interface = IF_FLOPPY;
 	else if (!strcmp(buf, "pflash"))
 	    interface = IF_PFLASH;
+	else if (!strcmp(buf, "mtd"))
+	    interface = IF_MTD;
 	else {
             fprintf(stderr, "unsupported bus type '%s'\n", buf);
             return -1;
@@ -5019,6 +5022,18 @@
             }
         }
 	break;
+    case IF_MTD:
+	if (!mtd_bdrv) {
+            mtd_bdrv = bdrv_new ("mtd");
+            if (file[0] && bdrv_open(mtd_bdrv, file,
+                                     snapshot ? BDRV_O_SNAPSHOT : 0) < 0
+                        || qemu_key_check(mtd_bdrv, file)) {
+                fprintf(stderr, "qemu: could not open Flash image %s\n",
+                                file);
+		return -1;
+            }
+	}
+        break;
     }
    return 0;
 }
@@ -7902,7 +7917,6 @@
     int snapshot, linux_boot;
     const char *initrd_filename;
     const char *sd_filename;
-    const char *mtd_filename;
     const char *kernel_filename, *kernel_cmdline;
     DisplayState *ds = &display_state;
     int cyls, heads, secs, translation;
@@ -7964,7 +7978,6 @@
     cpu_model = NULL;
     initrd_filename = NULL;
     sd_filename = NULL;
-    mtd_filename = NULL;
     ram_size = DEFAULT_RAM_SIZE * 1024 * 1024;
     vga_ram_size = VGA_RAM_SIZE;
 #ifdef CONFIG_GDBSTUB
@@ -8113,7 +8126,13 @@
 	        nb_disks++;
 	        break;
             case QEMU_OPTION_mtdblock:
-                mtd_filename = optarg;
+                if (nb_disks >= MAX_DISKS) {
+                    fprintf(stderr, "qemu: too many disks\n");
+                    exit(1);
+                }
+		snprintf(disks[nb_disks], sizeof(disks[0]),
+		         "%s" MTD_ALIAS, optarg);
+	        nb_disks++;
                 break;
             case QEMU_OPTION_sd:
                 sd_filename = optarg;
@@ -8676,18 +8695,6 @@
             qemu_key_check(sd_bdrv, sd_filename);
     }
 
-    if (mtd_filename) {
-        mtd_bdrv = bdrv_new ("mtd");
-        if (bdrv_open(mtd_bdrv, mtd_filename,
-                      snapshot ? BDRV_O_SNAPSHOT : 0) < 0 ||
-            qemu_key_check(mtd_bdrv, mtd_filename)) {
-            fprintf(stderr, "qemu: could not open Flash image %s\n",
-                    mtd_filename);
-            bdrv_delete(mtd_bdrv);
-            mtd_bdrv = 0;
-        }
-    }
-
     register_savevm("timer", 0, 2, timer_save, timer_load, NULL);
     register_savevm("ram", 0, 2, ram_save, ram_load, NULL);
 
vl.h +4 -1
Index: qemu/vl.h
===================================================================
@@ -994,7 +994,10 @@
 #define MAX_IDE_DEVS 2
 #define MAX_IDE_DISKS (MAX_IDE_BUS * MAX_IDE_DEVS)
 
-#define MAX_DISKS (MAX_IDE_DISKS + MAX_SCSI_DISKS + MAX_FD + MAX_PFLASH)
+#define MAX_MTD 1
+
+#define MAX_DISKS (MAX_IDE_DISKS + MAX_SCSI_DISKS + MAX_FD + MAX_PFLASH + \
+                   MAX_MTD)
 
 extern BlockDriverState *bs_table[MAX_IDE_DISKS + 1];
 extern BlockDriverState *sd_table[MAX_SCSI_DISKS + 1];
#7 lore raw

PATCH 7/7 Add SecureDigital support by -disk

This patch allows to define SecureDigital disk using "-disk" syntax" It adds an interface type "sd"

"-sd file" becomes the alias of "-disk file,if=sd"

--

 vl.c |   43 ++++++++++++++++++++++++++-----------------
 vl.h |    3 ++-
 2 files changed, 28 insertions(+), 18 deletions(-)
vl.c +26 -17
Index: qemu/vl.c
===================================================================
@@ -4714,6 +4714,7 @@
 #define FD_ALIAS ",index=%d,if=floppy"
 #define PFLASH_ALIAS ",if=pflash"
 #define MTD_ALIAS ",if=mtd"
+#define SD_ALIAS ",if=sd"
 #define HD_ALIAS ",index=%d,media=disk"
 
 #ifdef TARGET_PPC
@@ -4725,7 +4726,7 @@
 static int disk_init(const char *str, int snapshot, QEMUMachine *machine)
 {
     char buf[16];
-    enum { IF_IDE, IF_SCSI, IF_FLOPPY, IF_PFLASH, IF_MTD } interface;
+    enum { IF_IDE, IF_SCSI, IF_FLOPPY, IF_PFLASH, IF_MTD, IF_SD } interface;
     enum { MEDIA_DISK, MEDIA_CDROM } media;
     int bus_id, unit_id;
     int cyls, heads, secs, translation;
@@ -4820,6 +4821,8 @@
 	    interface = IF_PFLASH;
 	else if (!strcmp(buf, "mtd"))
 	    interface = IF_MTD;
+	else if (!strcmp(buf, "sd"))
+	    interface = IF_SD;
 	else {
             fprintf(stderr, "unsupported bus type '%s'\n", buf);
             return -1;
@@ -5034,6 +5037,21 @@
             }
 	}
         break;
+    case IF_SD:
+	if (!sd_bdrv) {
+            sd_bdrv = bdrv_new ("sd");
+            /* FIXME: This isn't really a floppy, but it's a reasonable
+               approximation.  */
+            bdrv_set_type_hint(sd_bdrv, BDRV_TYPE_FLOPPY);
+            if (file[0] && bdrv_open(sd_bdrv, file,
+                                     snapshot ? BDRV_O_SNAPSHOT : 0) < 0
+                        || qemu_key_check(sd_bdrv, file)) {
+                fprintf(stderr, "qemu: could not open SD card image %s\n",
+                        file);
+                return -1;
+	    }
+	}
+        break;
     }
    return 0;
 }
@@ -7916,7 +7934,6 @@
     int i;
     int snapshot, linux_boot;
     const char *initrd_filename;
-    const char *sd_filename;
     const char *kernel_filename, *kernel_cmdline;
     DisplayState *ds = &display_state;
     int cyls, heads, secs, translation;
@@ -7977,7 +7994,6 @@
     machine = first_machine;
     cpu_model = NULL;
     initrd_filename = NULL;
-    sd_filename = NULL;
     ram_size = DEFAULT_RAM_SIZE * 1024 * 1024;
     vga_ram_size = VGA_RAM_SIZE;
 #ifdef CONFIG_GDBSTUB
@@ -8135,7 +8151,13 @@
 	        nb_disks++;
                 break;
             case QEMU_OPTION_sd:
-                sd_filename = optarg;
+                if (nb_disks >= MAX_DISKS) {
+                    fprintf(stderr, "qemu: too many disks\n");
+                    exit(1);
+                }
+		snprintf(disks[nb_disks], sizeof(disks[0]),
+		         "%s" SD_ALIAS, optarg);
+	        nb_disks++;
                 break;
             case QEMU_OPTION_pflash:
                 if (nb_disks >= MAX_DISKS) {
@@ -8682,19 +8704,6 @@
         if (disk_init(disks[i], snapshot, machine) == -1)
 	    exit(1);
 
-    sd_bdrv = bdrv_new ("sd");
-    /* FIXME: This isn't really a floppy, but it's a reasonable
-       approximation.  */
-    bdrv_set_type_hint(sd_bdrv, BDRV_TYPE_FLOPPY);
-    if (sd_filename) {
-        if (bdrv_open(sd_bdrv, sd_filename,
-                      snapshot ? BDRV_O_SNAPSHOT : 0) < 0) {
-            fprintf(stderr, "qemu: could not open SD card image %s\n",
-                    sd_filename);
-        } else
-            qemu_key_check(sd_bdrv, sd_filename);
-    }
-
     register_savevm("timer", 0, 2, timer_save, timer_load, NULL);
     register_savevm("ram", 0, 2, ram_save, ram_load, NULL);
 
vl.h +2 -1
Index: qemu/vl.h
===================================================================
@@ -995,9 +995,10 @@
 #define MAX_IDE_DISKS (MAX_IDE_BUS * MAX_IDE_DEVS)
 
 #define MAX_MTD 1
+#define MAX_SD 1
 
 #define MAX_DISKS (MAX_IDE_DISKS + MAX_SCSI_DISKS + MAX_FD + MAX_PFLASH + \
-                   MAX_MTD)
+                   MAX_MTD + MAX_SD)
 
 extern BlockDriverState *bs_table[MAX_IDE_DISKS + 1];
 extern BlockDriverState *sd_table[MAX_SCSI_DISKS + 1];
#1 lore raw

PATCH 1/7 Add arg -disk to define new disk with more features

In reply to Laurent Vivier

This patch introduces a new parameter allowing to define disks.

The new parameter is "-disk":

    -disk file[,if=type][,index=i][,bus=n][,unit=m][,media=d][,cyls=c,heads=h,secs=s[,trans=t]][snapshot=on|off]

where:

file is the disk image
type is the interface type (ide)
i is the index of the disk on the interface (0, 1, 2, ...) n is the bus number of the given type
m is the unit number on the the given bus
d is the type of the media (disk, cdrom)
c,h,s,t are the parameters usually given by -hdachs snapshot allows to enable or not the snapshot for this disk

"-cdrom file" is an alias for "-disk file,index=2,media=cdrom" "-hda file" is an alias for "-disk file,index=0,media=disk" "-hdb file" is an alias for "-disk file,index=1,media=disk" "-hdc file" is an alias for "-disk file,index=2,media=disk" "-hdd file" is an alias for "-disk file,index=3,media=disk" "-hda file -hdachs a,b,c" is an alias for

                 "-disk file,index=0,cyls=a,heads=b,secs=c"

You can also define a cdrom on the slave of ide0 with:
"-disk file,if=ide,bus=0,unit=1,media=cdrom"

--

 hw/mips_pica61.c |    5
 hw/mips_r4k.c    |    5
 hw/pc.c          |    5
 hw/ppc_prep.c    |    5
 monitor.c        |    2
 vl.c             |  346 ++++++++++++++++++++++++++++++++++++++++++++++--------- vl.h             |    8 -
 7 files changed, 311 insertions(+), 65 deletions(-)
vl.c +292 -54
Index: qemu/vl.c
===================================================================
@@ -149,9 +149,9 @@
 void *ioport_opaque[MAX_IOPORTS];
 IOPortReadFunc *ioport_read_table[3][MAX_IOPORTS];
 IOPortWriteFunc *ioport_write_table[3][MAX_IOPORTS];
-/* Note: bs_table[MAX_DISKS] is a dummy block driver if none available
+/* Note: bs_table[MAX_IDE_DISKS] is a dummy block driver if none available
    to store the VM snapshots */
-BlockDriverState *bs_table[MAX_DISKS + 1], *fd_table[MAX_FD];
+BlockDriverState *bs_table[MAX_IDE_DISKS + 1], *fd_table[MAX_FD];
 BlockDriverState *pflash_table[MAX_PFLASH];
 BlockDriverState *sd_bdrv;
 BlockDriverState *mtd_bdrv;
@@ -1748,7 +1748,7 @@
         case 's':
             {
                 int i;
-                for (i = 0; i < MAX_DISKS; i++) {
+                for (i = 0; i < MAX_IDE_DISKS; i++) {
                     if (bs_table[i])
                         bdrv_commit(bs_table[i]);
                 }
@@ -4706,6 +4706,205 @@
     }
 }
 
+#define HD_ALIAS ",index=%d,media=disk"
+
+#ifdef TARGET_PPC
+#define CDROM_ALIAS ",index=1,media=cdrom"
+#else
+#define CDROM_ALIAS ",index=2,media=cdrom"
+#endif
+
+static int disk_init(const char *str, int snapshot)
+{
+    char buf[16];
+    enum { IF_IDE, IF_SCSI } interface;
+    enum { MEDIA_DISK, MEDIA_CDROM } media;
+    int bus_id, unit_id;
+    int cyls, heads, secs, translation;
+    char *p;
+    char *file;
+    int disk_index;
+
+    file = str;
+    p = str;
+    while (*p != '\0' && *p != ',')
+        p++;
+    if (*p == ',') {
+        *p = '\0';
+        p++;
+    }
+
+    cyls = heads = secs = 0;
+    bus_id = -1;
+    unit_id = -1;
+    disk_index = -1;
+    translation = BIOS_ATA_TRANSLATION_AUTO;
+    interface = IF_IDE;
+    media = MEDIA_DISK;
+
+    /* extract parameters */
+
+    if (get_param_value(buf, sizeof(buf), "bus", p)) {
+        bus_id = strtol(buf, NULL, 0);
+	if (bus_id < 0) {
+	    fprintf(stderr, "qemu: invalid bus id\n");
+	    return -1;
+	}
+    }
+
+    if (get_param_value(buf, sizeof(buf), "unit", p)) {
+        unit_id = strtol(buf, NULL, 0);
+	if (unit_id < 0) {
+	    fprintf(stderr, "qemu: invalid unit id\n");
+	    return -1;
+	}
+    }
+
+    if (get_param_value(buf, sizeof(buf), "index", p)) {
+        disk_index = strtol(buf, NULL, 0);
+	if (disk_index < 0) {
+	    fprintf(stderr, "qemu: invalid disk index\n");
+	    return -1;
+	}
+    }
+
+    if (get_param_value(buf, sizeof(buf), "cyls", p)) {
+        cyls = strtol(buf, NULL, 0);
+        if (cyls < 1 || cyls > 16383) {
+            fprintf(stderr, "qemu: invalid physical cyls number\n");
+	    return -1;
+	}
+    }
+
+    if (get_param_value(buf, sizeof(buf), "heads", p)) {
+        heads = strtol(buf, NULL, 0);
+        if (heads < 1 || heads > 16) {
+            fprintf(stderr, "qemu: invalid physical heads number\n");
+	    return -1;
+	}
+    }
+
+    if (get_param_value(buf, sizeof(buf), "secs", p)) {
+        secs = strtol(buf, NULL, 0);
+            if (secs < 1 || secs > 63) {
+            fprintf(stderr, "qemu: invalid physical secs number\n");
+	    return -1;
+	}
+    }
+
+    if (get_param_value(buf, sizeof(buf), "if", p)) {
+        if (!strcmp(buf, "ide"))
+	    interface = IF_IDE;
+	else if (!strcmp(buf, "scsi"))
+	    interface = IF_SCSI;
+	else {
+            fprintf(stderr, "unsupported bus type '%s'\n", buf);
+            return -1;
+	}
+    }
+
+    if (get_param_value(buf, sizeof(buf), "trans", p)) {
+        if (!strcmp(buf, "none"))
+            translation = BIOS_ATA_TRANSLATION_NONE;
+        else if (!strcmp(buf, "lba"))
+            translation = BIOS_ATA_TRANSLATION_LBA;
+        else if (!strcmp(buf, "auto"))
+            translation = BIOS_ATA_TRANSLATION_AUTO;
+	else {
+            fprintf(stderr, "qemu: invalid translation type\n");
+	    return -1;
+	}
+    }
+
+    if (get_param_value(buf, sizeof(buf), "media", p)) {
+        if (!(strcmp(buf, "disk"))) {
+	    media = MEDIA_DISK;
+	} else if (!strcmp(buf, "cdrom")) {
+            if (cyls || secs || heads) {
+                fprintf(stderr, "qemu: invalid physical CHS format\n");
+	        return -1;
+            }
+	    media = MEDIA_CDROM;
+	} else {
+	    fprintf(stderr, "qemu: invalid media\n");
+	    return -1;
+	}
+    }
+
+    if (get_param_value(buf, sizeof(buf), "snapshot", p)) {
+        if (!(strcmp(buf, "on")))
+	    snapshot = 1;
+        else if (!(strcmp(buf, "off")))
+	    snapshot = 0;
+	else {
+	    fprintf(stderr, "qemu: invalid snapshot option\n");
+	    return -1;
+	}
+    }
+
+    switch(interface) {
+    case IF_IDE:
+	if (bus_id >= MAX_IDE_BUS) {
+	    fprintf(stderr, "qemu: bus number too big\n");
+	    return -1;
+	}
+	if (unit_id >= MAX_IDE_DEVS) {
+	    fprintf(stderr, "qemu: unit number too big\n");
+	    return -1;
+	}
+
+        if (disk_index == -1) {
+	    if (bus_id != -1 && unit_id != -1) {
+	        disk_index = bus_id * MAX_IDE_DEVS + unit_id;
+	    } else {
+	        if (bus_id != -1)
+	            disk_index = bus_id * MAX_IDE_DEVS;
+	        else
+	            disk_index = 0;
+	         while (bs_table[disk_index] &&  disk_index < MAX_IDE_DISKS)
+	             disk_index++;
+	    }
+	}
+
+	if (disk_index >= MAX_IDE_DISKS) {
+	    fprintf(stderr, "qemu: too many disks\n");
+	    return -1;
+	}
+
+        if (!bs_table[disk_index]) {
+            switch(media) {
+	    case MEDIA_DISK:
+                snprintf(buf, sizeof(buf), "hd%c", disk_index + 'a');
+                bs_table[disk_index] = bdrv_new(buf);
+	        break;
+	    case MEDIA_CDROM:
+                snprintf(buf, sizeof(buf), "cdrom%c", disk_index + '0');
+                bs_table[disk_index] = bdrv_new(buf);
+                bdrv_set_type_hint(bs_table[disk_index], BDRV_TYPE_CDROM);
+	        break;
+	    }
+
+            if (file[0] && bdrv_open(bs_table[disk_index], file,
+                          snapshot ? BDRV_O_SNAPSHOT : 0) < 0) {
+                fprintf(stderr, "qemu: could not open hard disk image '%s'\n",
+                        file);
+                      return -1;
+            }
+
+            if (cyls != 0) {
+                bdrv_set_geometry_hint(bs_table[disk_index],
+	                               cyls, heads, secs);
+                bdrv_set_translation_hint(bs_table[disk_index], translation);
+            }
+	}
+        break;
+    case IF_SCSI:
+        /* TODO */
+	break;
+    }
+   return 0;
+}
+
 /***********************************************************/
 /* USB devices */
 
@@ -5489,7 +5688,7 @@
 
     if (bs_snapshots)
         return bs_snapshots;
-    for(i = 0; i <= MAX_DISKS; i++) {
+    for(i = 0; i <= MAX_IDE_DISKS; i++) {
         bs = bs_table[i];
         if (bdrv_can_snapshot(bs))
             goto ok;
@@ -5598,7 +5797,7 @@
 
     /* create the snapshots */
 
-    for(i = 0; i < MAX_DISKS; i++) {
+    for(i = 0; i < MAX_IDE_DISKS; i++) {
         bs1 = bs_table[i];
         if (bdrv_has_snapshot(bs1)) {
             if (must_delete) {
@@ -5641,7 +5840,7 @@
     saved_vm_running = vm_running;
     vm_stop(0);
 
-    for(i = 0; i <= MAX_DISKS; i++) {
+    for(i = 0; i <= MAX_IDE_DISKS; i++) {
         bs1 = bs_table[i];
         if (bdrv_has_snapshot(bs1)) {
             ret = bdrv_snapshot_goto(bs1, name);
@@ -5702,7 +5901,7 @@
         return;
     }
 
-    for(i = 0; i <= MAX_DISKS; i++) {
+    for(i = 0; i <= MAX_IDE_DISKS; i++) {
         bs1 = bs_table[i];
         if (bdrv_has_snapshot(bs1)) {
             ret = bdrv_snapshot_delete(bs1, name);
@@ -5731,7 +5930,7 @@
         return;
     }
     term_printf("Snapshot devices:");
-    for(i = 0; i <= MAX_DISKS; i++) {
+    for(i = 0; i <= MAX_IDE_DISKS; i++) {
         bs1 = bs_table[i];
         if (bdrv_has_snapshot(bs1)) {
             if (bs == bs1)
@@ -6436,7 +6635,7 @@
             /* find if the memory block is available on a virtual
                block device */
             sector_num = -1;
-            for(j = 0; j < MAX_DISKS; j++) {
+            for(j = 0; j < MAX_IDE_DISKS; j++) {
                 if (bs_table[j]) {
                     sector_num = bdrv_hash_find(bs_table[j],
                                                 phys_ram_base + i, BDRV_HASH_BLOCK_SIZE);
@@ -6444,7 +6643,7 @@
                         break;
                 }
             }
-            if (j == MAX_DISKS)
+            if (j == MAX_IDE_DISKS)
                 goto normal_compress;
             buf[0] = 1;
             buf[1] = j;
@@ -6495,7 +6694,7 @@
             ram_decompress_buf(s, buf + 1, 9);
             bs_index = buf[1];
             sector_num = be64_to_cpupu((const uint64_t *)(buf + 2));
-            if (bs_index >= MAX_DISKS || bs_table[bs_index] == NULL) {
+            if (bs_index >= MAX_IDE_DISKS || bs_table[bs_index] == NULL) {
                 fprintf(stderr, "Invalid block device index %d\n", bs_index);
                 goto error;
             }
@@ -6996,6 +7195,8 @@
            "-hda/-hdb file  use 'file' as IDE hard disk 0/1 image\n"
            "-hdc/-hdd file  use 'file' as IDE hard disk 2/3 image\n"
            "-cdrom file     use 'file' as IDE cdrom image (cdrom is ide1 master)\n"
+	   "-disk file[,if=type][,index=i][,bus=n][,unit=m][,media=d][,cyls=c,heads=h,secs=s[,trans=t]][snapshot=on|off]\n"
+	   "                use 'file' as a disk image\n"
            "-mtdblock file  use 'file' as on-board Flash memory image\n"
            "-sd file        use 'file' as SecureDigital card image\n"
            "-pflash file    use 'file' as a parallel flash image\n"
@@ -7144,6 +7345,7 @@
     QEMU_OPTION_hdb,
     QEMU_OPTION_hdc,
     QEMU_OPTION_hdd,
+    QEMU_OPTION_disk,
     QEMU_OPTION_cdrom,
     QEMU_OPTION_mtdblock,
     QEMU_OPTION_sd,
@@ -7232,6 +7434,7 @@
     { "hdb", HAS_ARG, QEMU_OPTION_hdb },
     { "hdc", HAS_ARG, QEMU_OPTION_hdc },
     { "hdd", HAS_ARG, QEMU_OPTION_hdd },
+    { "disk", HAS_ARG, QEMU_OPTION_disk },
     { "cdrom", HAS_ARG, QEMU_OPTION_cdrom },
     { "mtdblock", HAS_ARG, QEMU_OPTION_mtdblock },
     { "sd", HAS_ARG, QEMU_OPTION_sd },
@@ -7354,10 +7557,10 @@
 {
     BlockDriverState *bs;
 
-    if (index < 4) {
+    if (index < MAX_IDE_DISKS) {
         bs = bs_table[index];
-    } else if (index < 6) {
-        bs = fd_table[index - 4];
+    } else if (index < MAX_IDE_DISKS + MAX_FD) {
+        bs = fd_table[index - MAX_IDE_DISKS];
     } else {
         bs = NULL;
     }
@@ -7556,10 +7759,10 @@
     int use_gdbstub;
     const char *gdbstub_port;
 #endif
-    int i, cdrom_index, pflash_index;
+    int i, pflash_index;
     int snapshot, linux_boot;
     const char *initrd_filename;
-    const char *hd_filename[MAX_DISKS], *fd_filename[MAX_FD];
+    const char *fd_filename[MAX_FD];
     const char *pflash_filename[MAX_PFLASH];
     const char *sd_filename;
     const char *mtd_filename;
@@ -7567,7 +7770,10 @@
     DisplayState *ds = &display_state;
     int cyls, heads, secs, translation;
     char net_clients[MAX_NET_CLIENTS][256];
+    char disks[MAX_DISKS][256];
     int nb_net_clients;
+    int nb_disks;
+    int hda_index;
     int optind;
     const char *r, *optarg;
     CharDriverState *monitor_hd;
@@ -7622,8 +7828,6 @@
     initrd_filename = NULL;
     for(i = 0; i < MAX_FD; i++)
         fd_filename[i] = NULL;
-    for(i = 0; i < MAX_DISKS; i++)
-        hd_filename[i] = NULL;
     for(i = 0; i < MAX_PFLASH; i++)
         pflash_filename[i] = NULL;
     pflash_index = 0;
@@ -7639,11 +7843,6 @@
     nographic = 0;
     kernel_filename = NULL;
     kernel_cmdline = "";
-#ifdef TARGET_PPC
-    cdrom_index = 1;
-#else
-    cdrom_index = 2;
-#endif
     cyls = heads = secs = 0;
     translation = BIOS_ATA_TRANSLATION_AUTO;
     pstrcpy(monitor_device, sizeof(monitor_device), "vc");
@@ -7661,6 +7860,8 @@
     usb_devices_index = 0;
 
     nb_net_clients = 0;
+    nb_disks = 0;
+    hda_index = -1;
 
     nb_nics = 0;
     /* default mac address of the first network interface */
@@ -7671,7 +7872,10 @@
             break;
         r = argv[optind];
         if (r[0] != '-') {
-            hd_filename[0] = argv[optind++];
+	    hda_index = nb_disks;
+            snprintf(disks[nb_disks], sizeof(disks[0]),
+                     "%s" HD_ALIAS, argv[optind++], 0);
+            nb_disks++;
         } else {
             const QEMUOption *popt;
 
@@ -7731,17 +7935,51 @@
                 initrd_filename = optarg;
                 break;
             case QEMU_OPTION_hda:
+                if (nb_disks >= MAX_DISKS) {
+                    fprintf(stderr, "qemu: too many disks\n");
+                    exit(1);
+                }
+                hda_index = nb_disks;
+                if (cyls == 0)
+                    snprintf(disks[nb_disks], sizeof(disks[0]),
+                             "%s" HD_ALIAS, optarg, 0);
+                else {
+                    snprintf(disks[nb_disks], sizeof(disks[0]),
+                             "%s" HD_ALIAS
+			     ",cyls=%d,heads=%d,secs=%d%s",
+                             optarg, 0, cyls, heads, secs,
+                             translation == BIOS_ATA_TRANSLATION_LBA ?
+                                 ",trans=lba" :
+                             translation == BIOS_ATA_TRANSLATION_NONE ?
+                                 ",trans=none" : "");
+                }
+            nb_disks++;
+            break;
             case QEMU_OPTION_hdb:
             case QEMU_OPTION_hdc:
             case QEMU_OPTION_hdd:
                 {
                     int hd_index;
+                    if (nb_disks >= MAX_DISKS) {
+                        fprintf(stderr, "qemu: too many disks\n");
+                        exit(1);
+                    }
                     hd_index = popt->index - QEMU_OPTION_hda;
-                    hd_filename[hd_index] = optarg;
-                    if (hd_index == cdrom_index)
-                        cdrom_index = -1;
+		    snprintf(disks[nb_disks], sizeof(disks[0]),
+		             "%s" HD_ALIAS, optarg, hd_index);
+	            nb_disks++;
                 }
                 break;
+            case QEMU_OPTION_disk:
+                if (nb_disks >= MAX_DISKS) {
+                    fprintf(stderr, "qemu: too many disks\n");
+                    exit(1);
+                }
+		pstrcpy(disks[nb_disks],
+                        sizeof(disks[0]),
+			optarg);
+	        nb_disks++;
+	        break;
             case QEMU_OPTION_mtdblock:
                 mtd_filename = optarg;
                 break;
@@ -7792,6 +8030,15 @@
                         fprintf(stderr, "qemu: invalid physical CHS format\n");
                         exit(1);
                     }
+		    if (hda_index != -1)
+		        snprintf(disks[hda_index] + strlen(disks[hda_index]),
+			         sizeof(disks[0]) - strlen(disks[hda_index]),
+		                 ",cyls=%d,heads=%d,secs=%d%s",
+			         cyls, heads, secs,
+			         translation == BIOS_ATA_TRANSLATION_LBA ?
+			     	    ",trans=lba" :
+			         translation == BIOS_ATA_TRANSLATION_NONE ?
+			             ",trans=none" : "");
                 }
                 break;
             case QEMU_OPTION_nographic:
@@ -7810,9 +8057,13 @@
                 kernel_cmdline = optarg;
                 break;
             case QEMU_OPTION_cdrom:
-                if (cdrom_index >= 0) {
-                    hd_filename[cdrom_index] = optarg;
+                if (nb_disks >= MAX_DISKS) {
+                    fprintf(stderr, "qemu: too many disks\n");
+                    exit(1);
                 }
+		snprintf(disks[nb_disks], sizeof(disks[0]),
+		         "%s" CDROM_ALIAS, optarg);
+	        nb_disks++;
                 break;
             case QEMU_OPTION_boot:
                 if (strlen(optarg) > MAX_BOOT_DEVICES) {
@@ -8179,14 +8430,13 @@
 
     if (!linux_boot &&
         (!strchr(boot_device, 'n')) &&
-        hd_filename[0] == '\0' &&
-        (cdrom_index >= 0 && hd_filename[cdrom_index] == '\0') &&
+        nb_disks == 0 &&
         fd_filename[0] == '\0')
         help(1);
 
     /* boot to floppy or the default cd if no hard disk defined yet */
     if (!boot_device[0]) {
-        if (hd_filename[0] != '\0')
+        if (nb_disks)
             boot_device[0] = 'c';
         else if (fd_filename[0] != '\0')
             boot_device[0] = 'a';
@@ -8261,32 +8511,20 @@
         exit(1);
     }
 
-    /* we always create the cdrom drive, even if no disk is there */
     bdrv_init();
-    if (cdrom_index >= 0) {
-        bs_table[cdrom_index] = bdrv_new("cdrom");
-        bdrv_set_type_hint(bs_table[cdrom_index], BDRV_TYPE_CDROM);
+
+    /* we always create the cdrom drive, even if no disk is there */
+
+    if (nb_disks < MAX_DISKS) {
+        pstrcpy(disks[nb_disks], sizeof(disks[0]), CDROM_ALIAS);
+        nb_disks++;
     }
 
     /* open the virtual block devices */
-    for(i = 0; i < MAX_DISKS; i++) {
-        if (hd_filename[i]) {
-            if (!bs_table[i]) {
-                char buf[64];
-                snprintf(buf, sizeof(buf), "hd%c", i + 'a');
-                bs_table[i] = bdrv_new(buf);
-            }
-            if (bdrv_open(bs_table[i], hd_filename[i], snapshot ? BDRV_O_SNAPSHOT : 0) < 0) {
-                fprintf(stderr, "qemu: could not open hard disk image '%s'\n",
-                        hd_filename[i]);
-                exit(1);
-            }
-            if (i == 0 && cyls != 0) {
-                bdrv_set_geometry_hint(bs_table[i], cyls, heads, secs);
-                bdrv_set_translation_hint(bs_table[i], translation);
-            }
-        }
-    }
+
+    for(i = 0; i < nb_disks; i++)
+        if (disk_init(disks[i], snapshot) == -1)
+	    exit(1);
 
     /* we always create at least one floppy disk */
     fd_table[0] = bdrv_new("fda");
vl.h +6 -2
Index: qemu/vl.h
===================================================================
@@ -984,9 +984,13 @@
 extern uint8_t _translate_keycode(const int key);
 
 /* ide.c */
-#define MAX_DISKS 4
+#define MAX_IDE_BUS 2
+#define MAX_IDE_DEVS 2
+#define MAX_IDE_DISKS (MAX_IDE_BUS * MAX_IDE_DEVS)
 
-extern BlockDriverState *bs_table[MAX_DISKS + 1];
+#define MAX_DISKS (MAX_IDE_DISKS)
+
+extern BlockDriverState *bs_table[MAX_IDE_DISKS + 1];
 extern BlockDriverState *sd_bdrv;
 extern BlockDriverState *mtd_bdrv;
 
monitor.c +1 -1
Index: qemu/monitor.c
===================================================================
@@ -204,7 +204,7 @@
     int i, all_devices;
 
     all_devices = !strcmp(device, "all");
-    for (i = 0; i < MAX_DISKS; i++) {
+    for (i = 0; i < MAX_IDE_DISKS; i++) {
         if (bs_table[i]) {
             if (all_devices ||
                 !strcmp(bdrv_get_device_name(bs_table[i]), device))
hw/mips_pica61.c +3 -2
Index: qemu/hw/mips_pica61.c
===================================================================
@@ -136,9 +136,10 @@
     i8042_mm_init(i8259[6], i8259[7], 0x80005060, 0);
 
     /* IDE controller */
-    for(i = 0; i < 2; i++)
+    for(i = 0; i < MAX_IDE_BUS; i++)
         isa_ide_init(ide_iobase[i], ide_iobase2[i], i8259[ide_irq[i]],
-                     bs_table[2 * i], bs_table[2 * i + 1]);
+                     bs_table[MAX_IDE_DEVS * i],
+		     bs_table[MAX_IDE_DEVS * i + 1]);
 
     /* Network controller */
     /* FIXME: missing NS SONIC DP83932 */
hw/mips_r4k.c +3 -2
Index: qemu/hw/mips_r4k.c
===================================================================
@@ -240,9 +240,10 @@
         }
     }
 
-    for(i = 0; i < 2; i++)
+    for(i = 0; i < MAX_IDE_BUS; i++)
         isa_ide_init(ide_iobase[i], ide_iobase2[i], i8259[ide_irq[i]],
-                     bs_table[2 * i], bs_table[2 * i + 1]);
+                     bs_table[MAX_IDE_DEVS * i],
+		     bs_table[MAX_IDE_DEVS * i + 1]);
 
     i8042_init(i8259[1], i8259[12], 0x60);
     ds1225y_init(0x9000, "nvram");
hw/pc.c +3 -2
Index: qemu/hw/pc.c
===================================================================
@@ -892,9 +892,10 @@
     if (pci_enabled) {
         pci_piix3_ide_init(pci_bus, bs_table, piix3_devfn + 1, i8259);
     } else {
-        for(i = 0; i < 2; i++) {
+        for(i = 0; i < MAX_IDE_BUS; i++) {
             isa_ide_init(ide_iobase[i], ide_iobase2[i], i8259[ide_irq[i]],
-                         bs_table[2 * i], bs_table[2 * i + 1]);
+                         bs_table[MAX_IDE_DEVS * i],
+			 bs_table[MAX_IDE_DEVS * i + 1]);
         }
     }
 
hw/ppc_prep.c +3 -2
Index: qemu/hw/ppc_prep.c
===================================================================
@@ -649,9 +649,10 @@
         }
     }
 
-    for(i = 0; i < 2; i++) {
+    for(i = 0; i < MAX_IDE_BUS; i++) {
         isa_ide_init(ide_iobase[i], ide_iobase2[i], i8259[ide_irq[i]],
-                     bs_table[2 * i], bs_table[2 * i + 1]);
+                     bs_table[MAX_IDE_DEVS * i],
+		     bs_table[MAX_IDE_DEVS * i + 1]);
     }
     i8042_init(i8259[1], i8259[12], 0x60);
     DMA_init(1);
#0 lore raw

cover Add -disk interface

This series of patches add a new interface to qemu to define storages.

The new parameter is "-disk":

    -disk file[,if=type][,index=i][,bus=n][,unit=m][,media=d][,cyls=c,heads=h,secs=s[,trans=t]][snapshot=on|off]

where:

file is the disk image
type is the interface type (ide, scsi, floppy, pflash, mtd, sd) i is the index of the disk on the interface (0, 1, 2, ...) n is the bus number of the given type
m is the unit number on the the given bus
d is the type of the media (disk, cdrom)
c,h,s,t are the parameters usually given by -hdachs snapshot allows to enable or not the snapshot for this disk

"-cdrom file" is an alias for "-disk file,index=2,media=cdrom" "-hda file" is an alias for "-disk file,index=0,media=disk" "-hdb file" is an alias for "-disk file,index=1,media=disk" "-hdc file" is an alias for "-disk file,index=2,media=disk" "-hdd file" is an alias for "-disk file,index=3,media=disk" "-hda file -hdachs a,b,c" is an alias for

                 "-disk file,index=0,cyls=a,heads=b,secs=c"

"-fda file" is an alias for "-disk file,index=0,if=floppy" "-fdb file" is an alias for "-disk file,index=1,if=floppy" "-pflash file" is an alias for "-disk file,if=pflash" "-mtdblock file" is an alias for "-disk file,if=mtd" "-sd file" becomes the alias of "-disk file,if=sd"

You can also define a cdrom on the slave of ide0 with:
"-disk file,if=ide,bus=0,unit=1,media=cdrom" You can define a cdrom on the scsi bus 0 with unit id 3:
"-disk file,if=scsi,bus=0,unit=3,media=cdrom"

You can define a scsi disk on bus 0 with unit id 6 with:

"-disk file,if=scsi,bus=0,unit=6"

You can define disks with default ordering:

"-disk a.img -disk b.img -disk c.img" is equal to "-hda a.img -hdb b.img -hdc c.img"

[PATCH 1/7] Add arg -disk to define new disk with more features

Define -disk, support interface type "ide"

[PATCH 2/7] Add scsi support for the target PC

support interface type "scsi"

[PATCH 3/7] Add floppy support by -disk

support interface type "floppy"

[PATCH 4/7] remove fd_filename from the machine init interface

change machine init interface to remove fd_filename

[PATCH 5/7] Add parallel flash support by -disk

support interface type "pflash"

[PATCH 6/7] Add flash support by -disk

support interface type "mtd"

[PATCH 7/7] Add SecureDigital support by -disk

support interface type "sd"

#2 lore raw

PATCH 2/7 Add scsi support for the target PC

In reply to Laurent Vivier

This patch adds the SCSI support for the target PC. It allows to initalize SCSI interface in the PC init machine.

it adds a new interface type "scsi" to "-disk" interface.

"-disk file,if=scsi,bus=0,unit=6" allows to connect the disk image file to the bus 0 with the unit id 6.

if there is no SCSI disk, the SCSI interface is not created.

It also defines the default interface type to "scsi" for targets "realview", "SS-5", "SS-10", "versatilepb", "versatileab" to keep old behavior, where "-hda" is a SCSI disk.

--

 hw/esp.c         |    4 +-
 hw/pc.c          |   30 ++++++++-------
 hw/realview.c    |    6 +--
 hw/sun4m.c       |    6 +--
 hw/versatilepb.c |    6 +--
 monitor.c        |    7 +++
 vl.c             |  108 +++++++++++++++++++++++++++++++++++++++++++++++++------
 vl.h             |    9 ++++
 8 files changed, 139 insertions(+), 37 deletions(-)
hw/pc.c +16 -14
Index: qemu/hw/pc.c
===================================================================
@@ -927,23 +927,25 @@
     if (i440fx_state) {
         i440fx_init_memory_mappings(i440fx_state);
     }
-#if 0
-    /* ??? Need to figure out some way for the user to
-       specify SCSI devices.  */
+
     if (pci_enabled) {
-        void *scsi;
-        BlockDriverState *bdrv;
+        void *scsi[SCSI_MAX_BUS];
+	int max_bus = -1;
+
+	for (i = 0; i < MAX_SCSI_DISKS; i++)
+	    if (sd_table[i])
+	        max_bus = i / SCSI_MAX_DEVS + 1;
+
+	for (i = 0; i < max_bus; i++)
+            scsi[i] = lsi_scsi_init(pci_bus, -1);
 
-        scsi = lsi_scsi_init(pci_bus, -1);
-        bdrv = bdrv_new("scsidisk");
-        bdrv_open(bdrv, "scsi_disk.img", 0);
-        lsi_scsi_attach(scsi, bdrv, -1);
-        bdrv = bdrv_new("scsicd");
-        bdrv_open(bdrv, "scsi_cd.iso", 0);
-        bdrv_set_type_hint(bdrv, BDRV_TYPE_CDROM);
-        lsi_scsi_attach(scsi, bdrv, -1);
+	for (i = 0; i < MAX_SCSI_DISKS; i++) {
+	    if (sd_table[i]) {
+                lsi_scsi_attach(scsi[i / SCSI_MAX_DEVS],
+		                sd_table[i], i % SCSI_MAX_DEVS);
+	    }
+        }
     }
-#endif
 }
 
 static void pc_init_pci(int ram_size, int vga_ram_size, const char *boot_device,
hw/realview.c +3 -3
Index: qemu/hw/realview.c
===================================================================
@@ -65,9 +65,9 @@
         usb_ohci_init_pci(pci_bus, 3, -1);
     }
     scsi_hba = lsi_scsi_init(pci_bus, -1);
-    for (n = 0; n < MAX_DISKS; n++) {
-        if (bs_table[n]) {
-            lsi_scsi_attach(scsi_hba, bs_table[n], n);
+    for (n = 0; n < SCSI_MAX_DEVS; n++) {
+        if (sd_table[n]) {
+            lsi_scsi_attach(scsi_hba, sd_table[n], n);
         }
     }
     for(n = 0; n < nb_nics; n++) {
hw/versatilepb.c +3 -3
Index: qemu/hw/versatilepb.c
===================================================================
@@ -199,9 +199,9 @@
         usb_ohci_init_pci(pci_bus, 3, -1);
     }
     scsi_hba = lsi_scsi_init(pci_bus, -1);
-    for (n = 0; n < MAX_DISKS; n++) {
-        if (bs_table[n]) {
-            lsi_scsi_attach(scsi_hba, bs_table[n], n);
+    for (n = 0; n < SCSI_MAX_DEVS; n++) {
+        if (sd_table[n]) {
+            lsi_scsi_attach(scsi_hba, sd_table[n], n);
         }
     }
 
vl.c +97 -11

174 lines not on this page · raw message

vl.h +8 -1
Index: qemu/vl.h
===================================================================
@@ -983,14 +983,21 @@
 /* x_keymap.c */
 extern uint8_t _translate_keycode(const int key);
 
+/* lsi53c895a.c */
+
+#define SCSI_MAX_DEVS 7
+#define SCSI_MAX_BUS 4
+#define MAX_SCSI_DISKS (SCSI_MAX_BUS * SCSI_MAX_DEVS)
+
 /* ide.c */
 #define MAX_IDE_BUS 2
 #define MAX_IDE_DEVS 2
 #define MAX_IDE_DISKS (MAX_IDE_BUS * MAX_IDE_DEVS)
 
-#define MAX_DISKS (MAX_IDE_DISKS)
+#define MAX_DISKS (MAX_IDE_DISKS + MAX_SCSI_DISKS)
 
 extern BlockDriverState *bs_table[MAX_IDE_DISKS + 1];
+extern BlockDriverState *sd_table[MAX_SCSI_DISKS + 1];
 extern BlockDriverState *sd_bdrv;
 extern BlockDriverState *mtd_bdrv;
 
hw/sun4m.c +3 -3
Index: qemu/hw/sun4m.c
===================================================================
@@ -394,9 +394,9 @@
     main_esp = esp_init(bs_table, hwdef->esp_base, espdma, *espdma_irq,
                         esp_reset);
 
-    for (i = 0; i < MAX_DISKS; i++) {
-        if (bs_table[i]) {
-            esp_scsi_attach(main_esp, bs_table[i], i);
+    for (i = 0; i < MAX_SCSI_DISKS; i++) {
+        if (sd_table[i]) {
+            esp_scsi_attach(main_esp, sd_table[i], i);
         }
     }
 
monitor.c +7 -0
Index: qemu/monitor.c
===================================================================
@@ -211,6 +211,13 @@
                 bdrv_commit(bs_table[i]);
         }
     }
+    for (i = 0; i < MAX_SCSI_DISKS; i++) {
+        if (sd_table[i]) {
+            if (all_devices ||
+                !strcmp(bdrv_get_device_name(sd_table[i]), device))
+                bdrv_commit(sd_table[i]);
+        }
+    }
     if (mtd_bdrv)
         if (all_devices || !strcmp(bdrv_get_device_name(mtd_bdrv), device))
             bdrv_commit(mtd_bdrv);
hw/esp.c +2 -2
Index: qemu/hw/esp.c
===================================================================
@@ -60,7 +60,7 @@
     uint8_t ti_buf[TI_BUFSZ];
     int sense;
     int dma;
-    SCSIDevice *scsi_dev[MAX_DISKS];
+    SCSIDevice *scsi_dev[SCSI_MAX_DEVS];
     SCSIDevice *current_dev;
     uint8_t cmdbuf[TI_BUFSZ];
     int cmdlen;
@@ -122,7 +122,7 @@
         s->async_len = 0;
     }
 
-    if (target >= MAX_DISKS || !s->scsi_dev[target]) {
+    if (target >= SCSI_MAX_DEVS || !s->scsi_dev[target]) {
         // No such drive
         s->rregs[4] = STAT_IN;
         s->rregs[5] = INTR_DC;