Skip to contentSkip to conversation

enh req: Allow ATAPI CD-ROM to be attached other than sec/master

Qemu-devel Toby Thain 5 participants 9 messages Apr 14, 2006 – Sep 25, 2006

lore
Share & tools
lore

Toby Thain

author
#0 lore raw

Per version 0.8.0, the ATAPI CD-ROM is always attached to IDE secondary/master (address 2). (See assignment to cdrom_index around vl.c line 4433.)

Bochs allows the CD-ROM to be attached to any of four addresses, my suggestion is perhaps adding a QEMU runtime option for this.

E.g. NEXTSTEP 3.3 installation has a quirk in that it expects an ATAPI CD-ROM to be primary/slave (address 1). Changing the ATAPI address helps with NS 3.3 installation (although mine goes on to fail for other reasons, after successfully detecting ATAPI drive patched to attach at address 1). I hope to soon be able to add NS 3.3 to the QEMU supported guest O/S list.

--Toby

#1 lore raw
Quoted 8 lines · Toby Thain

Per version 0.8.0, the ATAPI CD-ROM is always attached to IDE secondary/master (address 2). (See assignment to cdrom_index around vl.c line 4433.)

Bochs allows the CD-ROM to be attached to any of four addresses, my suggestion is perhaps adding a QEMU runtime option for this.

--Toby

Attached is a patch that does just that.

The default -cdrom still works, but you can also use -cdrom-a, -cdrom-b, -cdrom-c, and -cdrom-d to specify if the cdrom should be plugged in place over hda, hdb, hdc, or hdd respectively.

Also includes a few tests to make sure you don't clobber a hard disk with a cdrom, or use the same -hdX or -cdrom-X option multiple times.

Signature · 2 lines
Infinite complexity begets infinite beauty.
Infinite precision begets infinite perfection.
vl.c renamed from vl.c.nocdrom +37 -9
@@ -4730,6 +4730,10 @@
     QEMU_OPTION_hdc,
     QEMU_OPTION_hdd,
     QEMU_OPTION_cdrom,
+    QEMU_OPTION_cdrom_a,
+    QEMU_OPTION_cdrom_b,
+    QEMU_OPTION_cdrom_c,
+    QEMU_OPTION_cdrom_d,
     QEMU_OPTION_boot,
     QEMU_OPTION_snapshot,
     QEMU_OPTION_m,
@@ -4795,6 +4799,10 @@
     { "hdc", HAS_ARG, QEMU_OPTION_hdc },
     { "hdd", HAS_ARG, QEMU_OPTION_hdd },
     { "cdrom", HAS_ARG, QEMU_OPTION_cdrom },
+    { "cdrom-a", HAS_ARG, QEMU_OPTION_cdrom_a },
+    { "cdrom-b", HAS_ARG, QEMU_OPTION_cdrom_b },
+    { "cdrom-c", HAS_ARG, QEMU_OPTION_cdrom_c },
+    { "cdrom-d", HAS_ARG, QEMU_OPTION_cdrom_d },
     { "boot", HAS_ARG, QEMU_OPTION_boot },
     { "snapshot", 0, QEMU_OPTION_snapshot },
     { "m", HAS_ARG, QEMU_OPTION_m },
@@ -5091,11 +5099,7 @@
     nographic = 0;
     kernel_filename = NULL;
     kernel_cmdline = "";
-#ifdef TARGET_PPC
-    cdrom_index = 1;
-#else
-    cdrom_index = 2;
-#endif
+    cdrom_index = -1; //disable by default
     cyls = heads = secs = 0;
     translation = BIOS_ATA_TRANSLATION_AUTO;
 #ifdef _WIN32
@@ -5127,7 +5131,7 @@
             break;
         r = argv[optind];
         if (r[0] != '-') {
-            hd_filename[0] = argv[optind++];
+            //hd_filename[0] = argv[optind++];
         } else {
             const QEMUOption *popt;
 
@@ -5178,9 +5182,12 @@
                 {
                     int hd_index;
                     hd_index = popt->index - QEMU_OPTION_hda;
+                    if (hd_filename[hd_index] != NULL) {
+printf("%d %s\n", hd_index, hd_filename[hd_index]);
+                        fprintf(stderr, "qemu: can't share multiple disks\n");
+                        exit(1);
+                    }
                     hd_filename[hd_index] = optarg;
-                    if (hd_index == cdrom_index)
-                        cdrom_index = -1;
                 }
                 break;
             case QEMU_OPTION_snapshot:
@@ -5235,9 +5242,30 @@
                 kernel_cmdline = optarg;
                 break;
             case QEMU_OPTION_cdrom:
+            case QEMU_OPTION_cdrom_a:
+            case QEMU_OPTION_cdrom_b:
+            case QEMU_OPTION_cdrom_c:
+            case QEMU_OPTION_cdrom_d:
                 if (cdrom_index >= 0) {
-                    hd_filename[cdrom_index] = optarg;
+                    fprintf(stderr, "qemu: too many cdroms\n");
+                    exit(1);
+                }
+
+		if (popt->index == QEMU_OPTION_cdrom)
+/* use a sensible default */
+#ifdef TARGET_PPC
+                cdrom_index = 1;
+#else
+                cdrom_index = 2;
+#endif
+		else
+                    cdrom_index = popt->index - QEMU_OPTION_cdrom_a;
+
+                if (hd_filename[cdrom_index] != NULL) {
+                    fprintf(stderr, "qemu: can't share multiple disks\n");
+                    exit(1);
                 }
+                hd_filename[cdrom_index] = optarg;
                 break;
             case QEMU_OPTION_boot:
                 boot_device = optarg[0];
#2 lore raw
Quoted 6 lines · Jim C. Brown

Attached is a patch that does just that.

The default -cdrom still works, but you can also use -cdrom-a, -cdrom-b, -cdrom-c, and -cdrom-d to specify if the cdrom should be plugged in place over hda, hdb, hdc, or hdd respectively.

Also includes a few tests to make sure you don't clobber a hard disk with a cdrom, or use the same -hdX or -cdrom-X option multiple times.

Here is a slightly modified version that enables you to have multiple cdrom drives at once.

It is not heavily tested so there may be some bugs.

Signature · 2 lines
Infinite complexity begets infinite beauty.
Infinite precision begets infinite perfection.
vl.c renamed from vl.c.nocdrom +52 -12
@@ -4730,6 +4730,10 @@
     QEMU_OPTION_hdc,
     QEMU_OPTION_hdd,
     QEMU_OPTION_cdrom,
+    QEMU_OPTION_cdrom_a,
+    QEMU_OPTION_cdrom_b,
+    QEMU_OPTION_cdrom_c,
+    QEMU_OPTION_cdrom_d,
     QEMU_OPTION_boot,
     QEMU_OPTION_snapshot,
     QEMU_OPTION_m,
@@ -4795,6 +4799,10 @@
     { "hdc", HAS_ARG, QEMU_OPTION_hdc },
     { "hdd", HAS_ARG, QEMU_OPTION_hdd },
     { "cdrom", HAS_ARG, QEMU_OPTION_cdrom },
+    { "cdrom-a", HAS_ARG, QEMU_OPTION_cdrom_a },
+    { "cdrom-b", HAS_ARG, QEMU_OPTION_cdrom_b },
+    { "cdrom-c", HAS_ARG, QEMU_OPTION_cdrom_c },
+    { "cdrom-d", HAS_ARG, QEMU_OPTION_cdrom_d },
     { "boot", HAS_ARG, QEMU_OPTION_boot },
     { "snapshot", 0, QEMU_OPTION_snapshot },
     { "m", HAS_ARG, QEMU_OPTION_m },
@@ -5042,6 +5050,7 @@
     int snapshot, linux_boot;
     const char *initrd_filename;
     const char *hd_filename[MAX_DISKS], *fd_filename[MAX_FD];
+    int hd_is_cdrom[MAX_DISKS];
     const char *kernel_filename, *kernel_cmdline;
     DisplayState *ds = &display_state;
     int cyls, heads, secs, translation;
@@ -5079,7 +5088,10 @@
     for(i = 0; i < MAX_FD; i++)
         fd_filename[i] = NULL;
     for(i = 0; i < MAX_DISKS; i++)
+    {
         hd_filename[i] = NULL;
+        hd_is_cdrom[i] = 0;
+    }
     ram_size = DEFAULT_RAM_SIZE * 1024 * 1024;
     vga_ram_size = VGA_RAM_SIZE;
     bios_size = BIOS_SIZE;
@@ -5091,11 +5103,7 @@
     nographic = 0;
     kernel_filename = NULL;
     kernel_cmdline = "";
-#ifdef TARGET_PPC
-    cdrom_index = 1;
-#else
-    cdrom_index = 2;
-#endif
+    cdrom_index = -1; //disable by default
     cyls = heads = secs = 0;
     translation = BIOS_ATA_TRANSLATION_AUTO;
 #ifdef _WIN32
@@ -5127,7 +5135,7 @@
             break;
         r = argv[optind];
         if (r[0] != '-') {
-            hd_filename[0] = argv[optind++];
+            //hd_filename[0] = argv[optind++];
         } else {
             const QEMUOption *popt;
 
@@ -5178,9 +5186,12 @@
                 {
                     int hd_index;
                     hd_index = popt->index - QEMU_OPTION_hda;
+                    if (hd_filename[hd_index] != NULL) {
+                        fprintf(stderr, "qemu: can't share multiple disks\n");
+                        exit(1);
+                    }
                     hd_filename[hd_index] = optarg;
-                    if (hd_index == cdrom_index)
-                        cdrom_index = -1;
+                    hd_is_cdrom[hd_index] = 0;
                 }
                 break;
             case QEMU_OPTION_snapshot:
@@ -5235,9 +5246,26 @@
                 kernel_cmdline = optarg;
                 break;
             case QEMU_OPTION_cdrom:
-                if (cdrom_index >= 0) {
-                    hd_filename[cdrom_index] = optarg;
+            case QEMU_OPTION_cdrom_a:
+            case QEMU_OPTION_cdrom_b:
+            case QEMU_OPTION_cdrom_c:
+            case QEMU_OPTION_cdrom_d:
+              if (popt->index == QEMU_OPTION_cdrom)
+/* use a sensible default */
+#ifdef TARGET_PPC
+                cdrom_index = 1;
+#else
+                cdrom_index = 2;
+#endif
+                else
+                    cdrom_index = popt->index - QEMU_OPTION_cdrom_a;
+
+                if (hd_filename[cdrom_index] != NULL) {
+                    fprintf(stderr, "qemu: can't share multiple disks\n");
+                    exit(1);
                 }
+                hd_filename[cdrom_index] = optarg;
+                hd_is_cdrom[cdrom_index] = 1;
                 break;
             case QEMU_OPTION_boot:
                 boot_device = optarg[0];
@@ -5555,9 +5583,21 @@
 
     /* we always create the cdrom drive, even if no disk is there */
     bdrv_init();
+    int ci = 0;
+    char cdrom_name[7];
+    strcpy(cdrom_name, "cdrom");
+    cdrom_name[6] = '\0';
     if (cdrom_index >= 0) {
-        bs_table[cdrom_index] = bdrv_new("cdrom");
-        bdrv_set_type_hint(bs_table[cdrom_index], BDRV_TYPE_CDROM);
+        for (i = 0; i < MAX_DISKS; i++)
+        {
+            if (hd_is_cdrom[i])
+            {
+                bs_table[i] = bdrv_new(cdrom_name);
+                ci++;
+                cdrom_name[5] = '0' + (char)ci;
+                bdrv_set_type_hint(bs_table[i], BDRV_TYPE_CDROM);
+            }
+        }
     }
 
     /* open the virtual block devices */
#3 lore raw

Shouldnt the behaviour of -boot option be changed to match this change ? e.g. qemu -cdrom-a disk1.iso -cdrom-b myos.iso -boot cdrom-b

allowing multiple cdrom drives renders "-boot d" a bit strange imo.

Quoted 152 lines · --- "Jim C. Brown
Quoted 3 lines · Jim C. Brown

Attached is a patch that does just that.

The default -cdrom still works, but you can also use -cdrom-a, -cdrom-b, -cdrom-c, and

-cdrom-d to specify if the cdrom should be plugged in place over hda, hdb, hdc, or hdd respectively.

Quoted 2 lines

Also includes a few tests to make sure you don't clobber a hard disk with a cdrom, or use the

same -hdX or -cdrom-X option multiple times.

Quoted 1 line

Here is a slightly modified version that enables you to have multiple cdrom drives at once.

It is not heavily tested so there may be some bugs.

Signature · 2 lines
Infinite complexity begets infinite beauty.
Infinite precision begets infinite perfection.
Quoted 1 line

--- vl.c.nocdrom Fri Apr 14 15:12:35 2006

+++ vl.c Fri Apr 14 15:21:08 2006

vl.c renamed from vl.c.nocdrom +52 -12
@@ -4730,6 +4730,10 @@
     QEMU_OPTION_hdc,
     QEMU_OPTION_hdd,
     QEMU_OPTION_cdrom,
+    QEMU_OPTION_cdrom_a,
+    QEMU_OPTION_cdrom_b,
+    QEMU_OPTION_cdrom_c,
+    QEMU_OPTION_cdrom_d,
     QEMU_OPTION_boot,
     QEMU_OPTION_snapshot,
     QEMU_OPTION_m,
@@ -4795,6 +4799,10 @@
     { "hdc", HAS_ARG, QEMU_OPTION_hdc },
     { "hdd", HAS_ARG, QEMU_OPTION_hdd },
     { "cdrom", HAS_ARG, QEMU_OPTION_cdrom },
+    { "cdrom-a", HAS_ARG, QEMU_OPTION_cdrom_a },
+    { "cdrom-b", HAS_ARG, QEMU_OPTION_cdrom_b },
+    { "cdrom-c", HAS_ARG, QEMU_OPTION_cdrom_c },
+    { "cdrom-d", HAS_ARG, QEMU_OPTION_cdrom_d },
     { "boot", HAS_ARG, QEMU_OPTION_boot },
     { "snapshot", 0, QEMU_OPTION_snapshot },
     { "m", HAS_ARG, QEMU_OPTION_m },
@@ -5042,6 +5050,7 @@
     int snapshot, linux_boot;
     const char *initrd_filename;
     const char *hd_filename[MAX_DISKS], *fd_filename[MAX_FD];
+    int hd_is_cdrom[MAX_DISKS];
     const char *kernel_filename, *kernel_cmdline;
     DisplayState *ds = &display_state;
     int cyls, heads, secs, translation;
@@ -5079,7 +5088,10 @@
     for(i = 0; i < MAX_FD; i++)
         fd_filename[i] = NULL;
     for(i = 0; i < MAX_DISKS; i++)
+    {
         hd_filename[i] = NULL;
+        hd_is_cdrom[i] = 0;
+    }
     ram_size = DEFAULT_RAM_SIZE * 1024 * 1024;
     vga_ram_size = VGA_RAM_SIZE;
     bios_size = BIOS_SIZE;
@@ -5091,11 +5103,7 @@
     nographic = 0;
     kernel_filename = NULL;
     kernel_cmdline = "";
-#ifdef TARGET_PPC
-    cdrom_index = 1;
-#else
-    cdrom_index = 2;
-#endif
+    cdrom_index = -1; //disable by default
     cyls = heads = secs = 0;
     translation = BIOS_ATA_TRANSLATION_AUTO;
 #ifdef _WIN32
@@ -5127,7 +5135,7 @@
             break;
         r = argv[optind];
         if (r[0] != '-') {
-            hd_filename[0] = argv[optind++];
+            //hd_filename[0] = argv[optind++];
         } else {
             const QEMUOption *popt;
 
@@ -5178,9 +5186,12 @@
                 {
                     int hd_index;
                     hd_index = popt->index - QEMU_OPTION_hda;
+                    if (hd_filename[hd_index] != NULL) {
+                        fprintf(stderr, "qemu: can't share multiple disks\n");
+                        exit(1);
+                    }
                     hd_filename[hd_index] = optarg;
-                    if (hd_index == cdrom_index)
-                        cdrom_index = -1;
+                    hd_is_cdrom[hd_index] = 0;
                 }
                 break;
             case QEMU_OPTION_snapshot:
@@ -5235,9 +5246,26 @@
                 kernel_cmdline = optarg;
                 break;
             case QEMU_OPTION_cdrom:
-                if (cdrom_index >= 0) {
-                    hd_filename[cdrom_index] = optarg;
+            case QEMU_OPTION_cdrom_a:
+            case QEMU_OPTION_cdrom_b:
+            case QEMU_OPTION_cdrom_c:
+            case QEMU_OPTION_cdrom_d:
+              if (popt->index == QEMU_OPTION_cdrom)
+/* use a sensible default */
+#ifdef TARGET_PPC
+                cdrom_index = 1;
+#else
+                cdrom_index = 2;
+#endif
+                else
+                    cdrom_index = popt->index - QEMU_OPTION_cdrom_a;
+
+                if (hd_filename[cdrom_index] != NULL) {
+                    fprintf(stderr, "qemu: can't share multiple disks\n");
+                    exit(1);
                 }
+                hd_filename[cdrom_index] = optarg;
+                hd_is_cdrom[cdrom_index] = 1;
                 break;
             case QEMU_OPTION_boot:
                 boot_device = optarg[0];
@@ -5555,9 +5583,21 @@
 
     /* we always create the cdrom drive, even if no disk is there */
     bdrv_init();
+    int ci = 0;
+    char cdrom_name[7];
+    strcpy(cdrom_name, "cdrom");
+    cdrom_name[6] = '\0';
     if (cdrom_index >= 0) {
-        bs_table[cdrom_index] = bdrv_new("cdrom");
-        bdrv_set_type_hint(bs_table[cdrom_index], BDRV_TYPE_CDROM);
+        for (i = 0; i < MAX_DISKS; i++)
+        {
+            if (hd_is_cdrom[i])
+            {
+                bs_table[i] = bdrv_new(cdrom_name);
+                ci++;
+                cdrom_name[5] = '0' + (char)ci;
+                bdrv_set_type_hint(bs_table[i], BDRV_TYPE_CDROM);
+            }
+        }
     }
 
     /* open the virtual block devices */
Quoted 1 line

_______________________________________________

Quoted 4 lines

Qemu-devel mailing list
[email protected]
http://lists.nongnu.org/mailman/listinfo/qemu-devel

Kind regards,
Sylvain Petreolle (aka Usurp)
--- --- --- --- --- --- --- --- --- --- --- --- ---
Listen to free Music: http://www.jamendo.com
Windows is proprietary, use free ReactOS instead : http://www.reactos.org

#4 lore raw
Quoted 5 lines · Sylvain Petreolle

Shouldnt the behaviour of -boot option be changed to match this change ? e.g. qemu -cdrom-a disk1.iso -cdrom-b myos.iso -boot cdrom-b

allowing multiple cdrom drives renders "-boot d" a bit strange imo.

Probably.

Right now the bios seems to pick the first cdrom drive that it finds (in order of cdrom-a, cdrom-b, ..). This is done in the bios, so it is a little bit harder to change. (Hopefully fixing this would also make it trivial to be able to tell the bios to boot from hdb/hdc/hdd instead of only supporting hda).

Quoted 2 lines

Listen to free Music: http://www.jamendo.com
Windows is proprietary, use free ReactOS instead : http://www.reactos.org

Signature · 2 lines
Infinite complexity begets infinite beauty.
Infinite precision begets infinite perfection.
#5 lore raw

Hi Jim,

After updating to today's CVS,
qemu now segfaults if your patch is applied to the source.

Its too bad, since its really useful for some apps/OS install.

Could you have a look on it ?

Crash happens even if no cdrom is specified on the command line. (tried the qemu test linux.img and got the crash)

Running on Fedora 5/ compiled with gcc 3.2.3.

Kind regards,
Sylvain Petreolle (aka Usurp)
--- --- --- --- --- --- --- --- --- --- --- --- ---
Run your favorite Windows apps with free ReactOS : http://www.reactos.org
Listen to non-DRMised Music: http://www.jamendo.com

#6 lore raw
In reply to Jim C. Brown

Jim,

thanks for the patch, it seems to work great. However, I'm attaching an updated version that fixes the following [minor] problems:

1. qemu was not correctly aborting [with help] if no arguments/disk images were specified
2. using the method "qemu [options] <disk-image>" no longer worked... you had to specify -hda explicitly.

1 and 2 are fixed in this patch that I attached. It's also diff'ed against today's CVS, so it applies without fuzz or hunks.

Like I said, these fixes are minor more than anything else - otherwise the patch works great for me so far. I've been able to do a Windows XP install with 2 CDROM images attached. That's the extent of my testing so far, but I don't see any reason why there would be any problems otherwise.

Regards,

Leo Reiter

Quoted 8 lines · Jim C. Brown
Quoted 5 lines · Jim C. Brown

Attached is a patch that does just that.

The default -cdrom still works, but you can also use -cdrom-a, -cdrom-b, -cdrom-c, and -cdrom-d to specify if the cdrom should be plugged in place over hda, hdb, hdc, or hdd respectively.

Also includes a few tests to make sure you don't clobber a hard disk with a cdrom, or use the same -hdX or -cdrom-X option multiple times.

Signature · 8 lines
Leonardo E. Reiter
Vice President of Product Development, CTO

Win4Lin, Inc.
Virtual Computing from Desktop to Data Center
Main: +1 512 339 7979
Fax: +1 512 532 6501
http://www.win4lin.com

Index: vl.c
===================================================================
RCS file: /cvsroot/qemu/qemu/vl.c,v
retrieving revision 1.171

vl.c +54 -12
diff -a -u -r1.171 vl.c
@@ -4572,6 +4572,7 @@
            "-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"
+           "-cdrom-[n] file use 'file' as IDE cdrom image (n is a, b, c, or d)\n"
            "-boot [a|c|d]   boot on floppy (a), hard disk (c) or CD-ROM (d)\n"
 	   "-snapshot       write to temporary files instead of disk image files\n"
            "-m megs         set virtual RAM size to megs MB [default=%d]\n"
@@ -4700,6 +4701,10 @@
     QEMU_OPTION_hdc,
     QEMU_OPTION_hdd,
     QEMU_OPTION_cdrom,
+    QEMU_OPTION_cdrom_a,
+    QEMU_OPTION_cdrom_b,
+    QEMU_OPTION_cdrom_c,
+    QEMU_OPTION_cdrom_d,
     QEMU_OPTION_boot,
     QEMU_OPTION_snapshot,
     QEMU_OPTION_m,
@@ -4761,6 +4766,10 @@
     { "hdc", HAS_ARG, QEMU_OPTION_hdc },
     { "hdd", HAS_ARG, QEMU_OPTION_hdd },
     { "cdrom", HAS_ARG, QEMU_OPTION_cdrom },
+    { "cdrom-a", HAS_ARG, QEMU_OPTION_cdrom_a },
+    { "cdrom-b", HAS_ARG, QEMU_OPTION_cdrom_b },
+    { "cdrom-c", HAS_ARG, QEMU_OPTION_cdrom_c },
+    { "cdrom-d", HAS_ARG, QEMU_OPTION_cdrom_d },
     { "boot", HAS_ARG, QEMU_OPTION_boot },
     { "snapshot", 0, QEMU_OPTION_snapshot },
     { "m", HAS_ARG, QEMU_OPTION_m },
@@ -5004,6 +5013,7 @@
     int snapshot, linux_boot;
     const char *initrd_filename;
     const char *hd_filename[MAX_DISKS], *fd_filename[MAX_FD];
+    int hd_is_cdrom[MAX_DISKS];
     const char *kernel_filename, *kernel_cmdline;
     DisplayState *ds = &display_state;
     int cyls, heads, secs, translation;
@@ -5034,7 +5044,10 @@
     for(i = 0; i < MAX_FD; i++)
         fd_filename[i] = NULL;
     for(i = 0; i < MAX_DISKS; i++)
+    {
         hd_filename[i] = NULL;
+        hd_is_cdrom[i] = 0;
+    }
     ram_size = DEFAULT_RAM_SIZE * 1024 * 1024;
     vga_ram_size = VGA_RAM_SIZE;
     bios_size = BIOS_SIZE;
@@ -5046,11 +5059,7 @@
     nographic = 0;
     kernel_filename = NULL;
     kernel_cmdline = "";
-#ifdef TARGET_PPC
-    cdrom_index = 1;
-#else
-    cdrom_index = 2;
-#endif
+    cdrom_index = -1; //disable by default
     cyls = heads = secs = 0;
     translation = BIOS_ATA_TRANSLATION_AUTO;
     pstrcpy(monitor_device, sizeof(monitor_device), "vc");
@@ -5129,9 +5138,12 @@
                 {
                     int hd_index;
                     hd_index = popt->index - QEMU_OPTION_hda;
+                    if (hd_filename[hd_index] != NULL) {
+                        fprintf(stderr, "qemu: can't share multiple disks\n");
+                        exit(1);
+                    }
                     hd_filename[hd_index] = optarg;
-                    if (hd_index == cdrom_index)
-                        cdrom_index = -1;
+                    hd_is_cdrom[hd_index] = 0;
                 }
                 break;
             case QEMU_OPTION_snapshot:
@@ -5185,9 +5197,26 @@
                 kernel_cmdline = optarg;
                 break;
             case QEMU_OPTION_cdrom:
-                if (cdrom_index >= 0) {
-                    hd_filename[cdrom_index] = optarg;
+            case QEMU_OPTION_cdrom_a:
+            case QEMU_OPTION_cdrom_b:
+            case QEMU_OPTION_cdrom_c:
+            case QEMU_OPTION_cdrom_d:
+              if (popt->index == QEMU_OPTION_cdrom)
+/* use a sensible default */
+#ifdef TARGET_PPC
+                cdrom_index = 1;
+#else
+                cdrom_index = 2;
+#endif
+                else
+                    cdrom_index = popt->index - QEMU_OPTION_cdrom_a;
+
+                if (hd_filename[cdrom_index] != NULL) {
+                    fprintf(stderr, "qemu: can't share multiple disks\n");
+                    exit(1);
                 }
+                hd_filename[cdrom_index] = optarg;
+                hd_is_cdrom[cdrom_index] = 1;
                 break;
             case QEMU_OPTION_boot:
                 boot_device = optarg[0];
@@ -5407,7 +5436,8 @@
         
     if (!linux_boot && 
         hd_filename[0] == '\0' && 
-        (cdrom_index >= 0 && hd_filename[cdrom_index] == '\0') &&
+        ((cdrom_index >= 0 && hd_filename[cdrom_index] == '\0') || 
+	 (cdrom_index < 0)) &&
         fd_filename[0] == '\0')
         help();
     
@@ -5493,9 +5523,21 @@
 
     /* we always create the cdrom drive, even if no disk is there */
     bdrv_init();
+    int ci = 0;
+    char cdrom_name[7];
+    strcpy(cdrom_name, "cdrom");
+    cdrom_name[6] = '\0';
     if (cdrom_index >= 0) {
-        bs_table[cdrom_index] = bdrv_new("cdrom");
-        bdrv_set_type_hint(bs_table[cdrom_index], BDRV_TYPE_CDROM);
+        for (i = 0; i < MAX_DISKS; i++)
+        {
+            if (hd_is_cdrom[i])
+            {
+                bs_table[i] = bdrv_new(cdrom_name);
+                ci++;
+                cdrom_name[5] = '0' + (char)ci;
+                bdrv_set_type_hint(bs_table[i], BDRV_TYPE_CDROM);
+            }
+        }
     }
 
     /* open the virtual block devices */
#7 lore raw

Sorry, I should add that my patch also adds a simple help line for the new options. Again, minor stuff ;)

Regards,

Leo Reiter

Quoted 8 lines · Leonardo E. Reiter

Jim,

thanks for the patch, it seems to work great. However, I'm attaching an updated version that fixes the following [minor] problems:

1. qemu was not correctly aborting [with help] if no arguments/disk images were specified
2. using the method "qemu [options] <disk-image>" no longer worked... you had to specify -hda explicitly.

1 and 2 are fixed in this patch that I attached. It's also diff'ed against today's CVS, so it applies without fuzz or hunks.

Signature · 8 lines
Leonardo E. Reiter
Vice President of Product Development, CTO

Win4Lin, Inc.
Virtual Computing from Desktop to Data Center
Main: +1 512 339 7979
Fax: +1 512 532 6501
http://www.win4lin.com
#8 lore raw
In reply to Toby Thain
Quoted 8 lines · Toby Thain

Per version 0.8.0, the ATAPI CD-ROM is always attached to IDE secondary/master (address 2). (See assignment to cdrom_index around vl.c line 4433.)

Bochs allows the CD-ROM to be attached to any of four addresses, my suggestion is perhaps adding a QEMU runtime option for this.

I had sent a patch regarding this one year ago but got no feedback :

http://lists.gnu.org/archive/html/qemu-devel/2005-02/msg00427.html

Looks like some people are now interested in this :)