All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] More flexibility about IDE devices
@ 2005-02-23 23:58 Pascal Terjan
  0 siblings, 0 replies; only message in thread
From: Pascal Terjan @ 2005-02-23 23:58 UTC (permalink / raw)
  To: qemu-devel

[-- Attachment #1: Type: text/plain, Size: 940 bytes --]

Hi,
first, thanks for the great work of coding qemu. The result is really nice !
I currently found only 2 functionnalities missing for my various uses of qemu :
- having the cd-rom somewhere else than hdc as I need to have hda+hdc
as hard drives for a project I work on
- a PXE capable network card

For the first problem, I found that the problem is only in options
handling and that it works fine with CD-ROM somewhere else. I wrote a
small patch for my own use and I think it's not the best way to handle
this (especially 0/1 for ide drive type is not nice). However I post
it here as it could be usefull for some people.

I can now have for example primary slave and secondary slave to be
CD-ROM drives with only a media in the secondary slave by running :

qemu -hda hda.img -hdc hdc.img -hdd my_other.iso -hdbtype 1 -hddtype 1

For the second problem there is much more work so I use instead a
floppy image with a grub to netboot :-)

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: qemu-flex_cd.patch --]
[-- Type: text/x-patch; name="qemu-flex_cd.patch", Size: 6667 bytes --]

Index: vl.c
===================================================================
RCS file: /cvsroot/qemu/qemu/vl.c,v
retrieving revision 1.120
diff -a -u -r1.120 vl.c
--- vl.c	10 Feb 2005 22:00:06 -0000	1.120
+++ vl.c	23 Feb 2005 23:12:53 -0000
@@ -2709,9 +2709,9 @@
            "\n"
            "Standard options:\n"
            "-fda/-fdb file  use 'file' as floppy disk 0/1 image\n"
-           "-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"
+           "-hda/-hdb file  use 'file' as IDE device 0/1 image\n"
+           "-hdc/-hdd file  use 'file' as IDE device 2/3 image\n"
+           "-hdXtype [0|1]  hd[a|b|c|d] is a hard disk (default) or CD-ROM\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"
@@ -2809,7 +2809,10 @@
     QEMU_OPTION_hdb,
     QEMU_OPTION_hdc,
     QEMU_OPTION_hdd,
-    QEMU_OPTION_cdrom,
+    QEMU_OPTION_hdatype,
+    QEMU_OPTION_hdbtype,
+    QEMU_OPTION_hdctype,
+    QEMU_OPTION_hddtype,
     QEMU_OPTION_boot,
     QEMU_OPTION_snapshot,
     QEMU_OPTION_m,
@@ -2869,7 +2872,10 @@
     { "hdb", HAS_ARG, QEMU_OPTION_hdb },
     { "hdc", HAS_ARG, QEMU_OPTION_hdc },
     { "hdd", HAS_ARG, QEMU_OPTION_hdd },
-    { "cdrom", HAS_ARG, QEMU_OPTION_cdrom },
+    { "hdatype", HAS_ARG, QEMU_OPTION_hdatype },
+    { "hdbtype", HAS_ARG, QEMU_OPTION_hdbtype },
+    { "hdctype", HAS_ARG, QEMU_OPTION_hdctype },
+    { "hddtype", HAS_ARG, QEMU_OPTION_hddtype },
     { "boot", HAS_ARG, QEMU_OPTION_boot },
     { "snapshot", 0, QEMU_OPTION_snapshot },
     { "m", HAS_ARG, QEMU_OPTION_m },
@@ -2980,11 +2986,12 @@
 #ifdef CONFIG_GDBSTUB
     int use_gdbstub, gdbstub_port;
 #endif
-    int i, has_cdrom;
+    int i;
     int snapshot, linux_boot;
     CPUState *env;
     const char *initrd_filename;
     const char *hd_filename[MAX_DISKS], *fd_filename[MAX_FD];
+    int hd_type[MAX_DISKS];
     const char *kernel_filename, *kernel_cmdline;
     DisplayState *ds = &display_state;
     int cyls, heads, secs, translation;
@@ -3008,8 +3015,10 @@
     initrd_filename = NULL;
     for(i = 0; i < MAX_FD; i++)
         fd_filename[i] = NULL;
-    for(i = 0; i < MAX_DISKS; i++)
+    for(i = 0; i < MAX_DISKS; i++) {
         hd_filename[i] = NULL;
+        hd_type[i] = BDRV_TYPE_HD;
+    }
     ram_size = DEFAULT_RAM_SIZE * 1024 * 1024;
     vga_ram_size = VGA_RAM_SIZE;
     bios_size = BIOS_SIZE;
@@ -3022,7 +3031,6 @@
     nographic = 0;
     kernel_filename = NULL;
     kernel_cmdline = "";
-    has_cdrom = 1;
     cyls = heads = secs = 0;
     translation = BIOS_ATA_TRANSLATION_AUTO;
     pstrcpy(monitor_device, sizeof(monitor_device), "vc");
@@ -3091,6 +3099,24 @@
             case QEMU_OPTION_hdb:
                 hd_filename[1] = optarg;
                 break;
+            case QEMU_OPTION_hdc:
+                hd_filename[2] = optarg;
+                break;
+            case QEMU_OPTION_hdd:
+                hd_filename[3] = optarg;
+                break;
+            case QEMU_OPTION_hdatype:
+                hd_type[0] = atoi(optarg);
+                break;
+            case QEMU_OPTION_hdbtype:
+                hd_type[1] = atoi(optarg);
+                break;
+            case QEMU_OPTION_hdctype:
+                hd_type[2] = atoi(optarg);
+                break;
+            case QEMU_OPTION_hddtype:
+                hd_type[3] = atoi(optarg);
+                break;
             case QEMU_OPTION_snapshot:
                 snapshot = 1;
                 break;
@@ -3156,17 +3182,6 @@
                     }
                 }
 		break;
-            case QEMU_OPTION_hdc:
-                hd_filename[2] = optarg;
-                has_cdrom = 0;
-                break;
-            case QEMU_OPTION_hdd:
-                hd_filename[3] = optarg;
-                break;
-            case QEMU_OPTION_cdrom:
-                hd_filename[2] = optarg;
-                has_cdrom = 1;
-                break;
             case QEMU_OPTION_boot:
                 boot_device = optarg[0];
                 if (boot_device != 'a' && 
@@ -3379,6 +3394,14 @@
     if (!linux_boot && hd_filename[0] == '\0' && hd_filename[2] == '\0' &&
         fd_filename[0] == '\0')
         help();
+
+    for (i = 0; i < MAX_DISKS; i++) {
+	if ((hd_type[i]<BDRV_TYPE_MIN)||(hd_type[i]>BDRV_TYPE_MAX)) {
+            fprintf(stderr, "%s: invalid type for hd%c : %d\n", 
+                    argv[0], 'a'+i, hd_type[i]);
+            exit(1);
+        }
+    }
     
     /* boot to cd by default if no hard disk */
     if (hd_filename[0] == '\0' && boot_device == 'c') {
@@ -3484,20 +3507,20 @@
     }
 #endif
 
-    /* we always create the cdrom drive, even if no disk is there */
     bdrv_init();
-    if (has_cdrom) {
-        bs_table[2] = bdrv_new("cdrom");
-        bdrv_set_type_hint(bs_table[2], BDRV_TYPE_CDROM);
+    /* hdc is an empty cdrom if not specified */
+    if (hd_filename[2][0] == '\0') {
+	hd_type[2]=BDRV_TYPE_CDROM;
     }
 
     /* 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);
+            char buf[64];
+            snprintf(buf, sizeof(buf), "hd%c", i + 'a');
+            bs_table[i] = bdrv_new(buf);
+            if (hd_type[i]==BDRV_TYPE_CDROM) {
+                bdrv_set_type_hint(bs_table[i], BDRV_TYPE_CDROM);
             }
             if (bdrv_open(bs_table[i], hd_filename[i], snapshot) < 0) {
                 fprintf(stderr, "qemu: could not open hard disk image '%s'\n",
Index: vl.h
===================================================================
RCS file: /cvsroot/qemu/qemu/vl.h,v
retrieving revision 1.67
diff -a -u -r1.67 vl.h
--- vl.h	10 Feb 2005 22:00:06 -0000	1.67
+++ vl.h	23 Feb 2005 23:12:53 -0000
@@ -404,6 +404,9 @@
 #define BDRV_TYPE_HD     0
 #define BDRV_TYPE_CDROM  1
 #define BDRV_TYPE_FLOPPY 2
+/* Min and Max types for hd[abcd] */
+#define BDRV_TYPE_MIN 0
+#define BDRV_TYPE_MAX 1
 #define BIOS_ATA_TRANSLATION_AUTO 0
 #define BIOS_ATA_TRANSLATION_NONE 1
 #define BIOS_ATA_TRANSLATION_LBA  2

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2005-02-24  2:22 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-02-23 23:58 [Qemu-devel] More flexibility about IDE devices Pascal Terjan

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.