From patchwork Mon Sep 3 02:56:11 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Ogilvie X-Patchwork-Id: 181280 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 912382C008D for ; Mon, 3 Sep 2012 12:57:19 +1000 (EST) Received: from localhost ([::1]:57595 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T8Mqj-0007hC-Gu for incoming@patchwork.ozlabs.org; Sun, 02 Sep 2012 22:57:17 -0400 Received: from eggs.gnu.org ([208.118.235.92]:42402) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T8MqU-0007Yq-FP for qemu-devel@nongnu.org; Sun, 02 Sep 2012 22:57:03 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1T8MqT-0008H0-B6 for qemu-devel@nongnu.org; Sun, 02 Sep 2012 22:57:02 -0400 Received: from qmta06.emeryville.ca.mail.comcast.net ([76.96.30.56]:36013) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T8MqT-0008Gp-1s for qemu-devel@nongnu.org; Sun, 02 Sep 2012 22:57:01 -0400 Received: from omta01.emeryville.ca.mail.comcast.net ([76.96.30.11]) by qmta06.emeryville.ca.mail.comcast.net with comcast id uSwC1j0020EPchoA6Sx0bE; Mon, 03 Sep 2012 02:57:00 +0000 Received: from mmogilvi.homeip.net ([24.9.53.136]) by omta01.emeryville.ca.mail.comcast.net with comcast id uSwy1j00U2wKXRC8MSwzTy; Mon, 03 Sep 2012 02:56:59 +0000 Received: by mmogilvi.homeip.net (Postfix, from userid 501) id AAEE81E9601B; Sun, 2 Sep 2012 20:56:58 -0600 (MDT) From: Matthew Ogilvie To: qemu-devel@nongnu.org Date: Sun, 2 Sep 2012 20:56:11 -0600 Message-Id: <1346640974-30974-3-git-send-email-mmogilvi_qemu@miniinfo.net> X-Mailer: git-send-email 1.7.10.2.484.gcd07cc5 In-Reply-To: <1346640974-30974-1-git-send-email-mmogilvi_qemu@miniinfo.net> References: <1346640974-30974-1-git-send-email-mmogilvi_qemu@miniinfo.net> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 76.96.30.56 Cc: Matthew Ogilvie Subject: [Qemu-devel] [PATCH v4 2/5] vl: fix -hdachs/-hda argument order parsing issues X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Without this patch, the -hdachs argument had to occur either BEFORE the corresponding "-hda" option, or AFTER the plain disk image name (if neither -hda nor -drive is used). Otherwise it would effectively be ignored. Option -hdachs still has no effect on -drive, but that seems best. Signed-off-by: Matthew Ogilvie --- vl.c | 39 ++++++++++++++++++--------------------- 1 file changed, 18 insertions(+), 21 deletions(-) diff --git a/vl.c b/vl.c index 7c577fa..febfd62 100644 --- a/vl.c +++ b/vl.c @@ -2352,8 +2352,9 @@ int main(int argc, char **argv, char **envp) char boot_devices[33] = "cad"; /* default to HD->floppy->CD-ROM */ DisplayState *ds; DisplayChangeListener *dcl; - int cyls, heads, secs, translation; - QemuOpts *hda_opts = NULL, *opts, *machine_opts; + char hdachs_params[512]; /* save -hdachs to apply to later -hda */ + QemuOpts *hda_opts = NULL; /* save -hda to be modified by later -hdachs */ + QemuOpts *opts, *machine_opts; QemuOptsList *olist; int optind; const char *optarg; @@ -2408,8 +2409,7 @@ int main(int argc, char **argv, char **envp) cpu_model = NULL; ram_size = 0; snapshot = 0; - cyls = heads = secs = 0; - translation = BIOS_ATA_TRANSLATION_AUTO; + snprintf(hdachs_params, sizeof(hdachs_params), "%s", HD_OPTS); for (i = 0; i < MAX_NODES; i++) { node_mem[i] = 0; @@ -2457,7 +2457,7 @@ int main(int argc, char **argv, char **envp) if (optind >= argc) break; if (argv[optind][0] != '-') { - hda_opts = drive_add(IF_DEFAULT, 0, argv[optind++], HD_OPTS); + hda_opts = drive_add(IF_DEFAULT, 0, argv[optind++], hdachs_params); } else { const QEMUOption *popt; @@ -2475,21 +2475,8 @@ int main(int argc, char **argv, char **envp) cpu_model = optarg; break; case QEMU_OPTION_hda: - { - char buf[256]; - if (cyls == 0) - snprintf(buf, sizeof(buf), "%s", HD_OPTS); - else - snprintf(buf, sizeof(buf), - "%s,cyls=%d,heads=%d,secs=%d%s", - HD_OPTS , cyls, heads, secs, - translation == BIOS_ATA_TRANSLATION_LBA ? - ",trans=lba" : - translation == BIOS_ATA_TRANSLATION_NONE ? - ",trans=none" : ""); - drive_add(IF_DEFAULT, 0, optarg, buf); - break; - } + hda_opts = drive_add(IF_DEFAULT, 0, optarg, hdachs_params); + break; case QEMU_OPTION_hdb: case QEMU_OPTION_hdc: case QEMU_OPTION_hdd: @@ -2523,7 +2510,10 @@ int main(int argc, char **argv, char **envp) break; case QEMU_OPTION_hdachs: { + int cyls, heads, secs, translation; const char *p; + cyls = heads = secs = 0; + translation = BIOS_ATA_TRANSLATION_AUTO; p = optarg; cyls = strtol(p, (char **)&p, 0); if (cyls < 1 || cyls > 16383) @@ -2555,7 +2545,14 @@ int main(int argc, char **argv, char **envp) fprintf(stderr, "qemu: invalid physical CHS format\n"); exit(1); } - if (hda_opts != NULL) { + snprintf(hdachs_params, sizeof(hdachs_params), + "%s,cyls=%d,heads=%d,secs=%d%s", + HD_OPTS , cyls, heads, secs, + translation == BIOS_ATA_TRANSLATION_LBA ? + ",trans=lba" : + translation == BIOS_ATA_TRANSLATION_NONE ? + ",trans=none" : ""); + if (hda_opts != NULL) { char num[16]; snprintf(num, sizeof(num), "%d", cyls); qemu_opt_set(hda_opts, "cyls", num);