[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 1/3] Add args to -cdrom to define where is connected
From: |
Laurent . Vivier |
Subject: |
[Qemu-devel] [PATCH 1/3] Add args to -cdrom to define where is connected the cdrom |
Date: |
Sun, 28 Oct 2007 23:43:33 +0100 |
From: Laurent Vivier <address@hidden(none)>
This patch allows to define where is connected the CDROM device (bus,
unit).
It extends the "-cdrom" syntax to add these paramaters:
-cdrom file[,if=type][,bus=n][,unit=m]
where "type" defines the interface (by default, "ide")
"n" defines the bus number (by default 1)
"m" defines the unit number (by default 0)
---
vl.c | 123 ++++++++++++++++++++++++++++++++++++++++++++++++++++++------------
1 files changed, 101 insertions(+), 22 deletions(-)
diff --git a/vl.c b/vl.c
index f9500a9..a8c4a81 100644
--- a/vl.c
+++ b/vl.c
@@ -4701,6 +4701,79 @@ void do_info_network(void)
}
}
+#define MAX_CDROMS 4
+#ifdef TARGET_PPC
+#define DEFAULT_CDROM_BUS 0
+#define DEFAULT_CDROM_UNIT 1
+#define DEFAULT_CDROM_IF "ide"
+#else
+#define DEFAULT_CDROM_BUS 1
+#define DEFAULT_CDROM_UNIT 0
+#define DEFAULT_CDROM_IF "ide"
+#endif
+
+static int cdrom_init(const char *str)
+{
+ char *p;
+ char *file;
+ char buf[16];
+ char interface[16];
+ int bus_id, unit_id;
+
+ bus_id = DEFAULT_CDROM_BUS;
+ unit_id = DEFAULT_CDROM_UNIT;
+ pstrcpy(interface, sizeof(interface), DEFAULT_CDROM_IF);
+ file = str;
+
+ if (str) {
+ p = str;
+ while (*p != '\0' && *p != ',')
+ p++;
+ if (*p == ',') {
+ *p = '\0';
+ p++;
+ }
+
+ if (get_param_value(buf, sizeof(buf), "bus", p)) {
+ bus_id = strtol(buf, NULL, 0);
+ }
+
+ if (get_param_value(buf, sizeof(buf), "unit", p)) {
+ unit_id = strtol(buf, NULL, 0);
+ }
+
+ if (get_param_value(buf, sizeof(buf), "if", p)) {
+ pstrcpy(interface, sizeof(interface), buf);
+ }
+ }
+
+ if (strcmp(interface, "ide") == 0) {
+ int cdrom_index = bus_id * 2 + unit_id;
+
+ if (cdrom_index > MAX_DISKS) {
+ fprintf(stderr, "Invalid cdrom address bus=%d,unit=%d\n",
+ bus_id, unit_id);
+ return -1;
+ }
+
+ bs_table[cdrom_index] = bdrv_new("cdrom");
+ bdrv_set_type_hint(bs_table[cdrom_index], BDRV_TYPE_CDROM);
+
+ if (file && bdrv_open(bs_table[cdrom_index], file, 0) < 0) {
+ fprintf(stderr, "qemu: could not open cdrom image '%s'\n",
+ file);
+ return -1;
+ }
+ return 0;
+ } else if (strcmp(interface, "scsi") == 0) {
+ /* TODO */
+ }
+
+ fprintf(stderr, "unsupported bus type '%s' for cdrom '%s'\n",
+ interface, file);
+ return -1;
+}
+
/***********************************************************/
/* USB devices */
@@ -6990,7 +7063,9 @@ static void help(int exitcode)
"-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"
+ "-cdrom file[,if=type][,bus=n][,unit=m]\n"
+ " use 'file' as cdrom image\n"
+ " (by default cdrom is ide1 master
(if=ide,bus=1,unit=0))\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"
@@ -7551,7 +7626,7 @@ int main(int argc, char **argv)
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];
@@ -7562,7 +7637,9 @@ int main(int argc, char **argv)
DisplayState *ds = &display_state;
int cyls, heads, secs, translation;
char net_clients[MAX_NET_CLIENTS][256];
+ char cdroms[MAX_CDROMS][256];
int nb_net_clients;
+ int nb_cdroms;
int optind;
const char *r, *optarg;
CharDriverState *monitor_hd;
@@ -7634,11 +7711,6 @@ int main(int argc, char **argv)
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");
@@ -7656,6 +7728,7 @@ int main(int argc, char **argv)
usb_devices_index = 0;
nb_net_clients = 0;
+ nb_cdroms = 0;
nb_nics = 0;
/* default mac address of the first network interface */
@@ -7733,8 +7806,6 @@ int main(int argc, char **argv)
int hd_index;
hd_index = popt->index - QEMU_OPTION_hda;
hd_filename[hd_index] = optarg;
- if (hd_index == cdrom_index)
- cdrom_index = -1;
}
break;
case QEMU_OPTION_mtdblock:
@@ -7805,9 +7876,14 @@ int main(int argc, char **argv)
kernel_cmdline = optarg;
break;
case QEMU_OPTION_cdrom:
- if (cdrom_index >= 0) {
- hd_filename[cdrom_index] = optarg;
+ if (nb_cdroms >= MAX_CDROMS) {
+ fprintf(stderr, "qemu: too many cdroms\n");
+ exit(1);
}
+ pstrcpy(cdroms[nb_cdroms],
+ sizeof(cdroms[0]),
+ optarg);
+ nb_cdroms++;
break;
case QEMU_OPTION_boot:
boot_device = optarg[0];
@@ -8170,7 +8246,7 @@ int main(int argc, char **argv)
if (!linux_boot &&
boot_device != 'n' &&
hd_filename[0] == '\0' &&
- (cdrom_index >= 0 && hd_filename[cdrom_index] == '\0') &&
+ (nb_cdroms >= 0 && cdroms[0] == '\0') &&
fd_filename[0] == '\0')
help(1);
@@ -8249,21 +8325,24 @@ int main(int argc, char **argv)
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_cdroms == 0) && (cdrom_init(NULL) == -1))
+ exit(1);
+
+ for (i = 0; i < nb_cdroms; i++)
+ if (cdrom_init(cdroms[i]) == -1)
+ exit(1);
/* 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 (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]);
--
1.4.4.4
- [Qemu-devel] [PATCH 0/3] Add SCSI support for PC target, Laurent . Vivier, 2007/10/28
- [Qemu-devel] [PATCH 1/3] Add args to -cdrom to define where is connected the cdrom,
Laurent . Vivier <=
- [Qemu-devel] [PATCH 2/3] Add arg -disk to define new disk with more features, Laurent . Vivier, 2007/10/28
- Re: [Qemu-devel] [PATCH 1/3] Add args to -cdrom to define where is connected the cdrom, Johannes Schindelin, 2007/10/29
- Re: [Qemu-devel] [PATCH 1/3] Add args to -cdrom to define where is connected the cdrom, Daniel P. Berrange, 2007/10/29
- Re: [Qemu-devel] [PATCH 1/3] Add args to -cdrom to define where is connected the cdrom, Laurent Vivier, 2007/10/29
- Re: [Qemu-devel] [PATCH 1/3] Add args to -cdrom to define where is connected the cdrom, risc, 2007/10/29
- Re: [Qemu-devel] [PATCH 1/3] Add args to -cdrom to define where is connected the cdrom, Markus Hitter, 2007/10/29
- Re: [Qemu-devel] [PATCH 1/3] Add args to -cdrom to define where is connected the cdrom, Laurent Vivier, 2007/10/29
- Re: [Qemu-devel] [PATCH 1/3] Add args to -cdrom to define where is connected the cdrom, Blue Swirl, 2007/10/29