From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.71) id 1Vm8sk-0003r1-4l for mharc-grub-devel@gnu.org; Thu, 28 Nov 2013 16:12:18 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47894) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vm8sY-0003op-QG for grub-devel@gnu.org; Thu, 28 Nov 2013 16:12:15 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Vm8sQ-0008H4-Ba for grub-devel@gnu.org; Thu, 28 Nov 2013 16:12:06 -0500 Received: from mail-lb0-x235.google.com ([2a00:1450:4010:c04::235]:44234) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vm8sP-0008Gw-VN for grub-devel@gnu.org; Thu, 28 Nov 2013 16:11:58 -0500 Received: by mail-lb0-f181.google.com with SMTP id q8so6401221lbi.40 for ; Thu, 28 Nov 2013 13:11:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:subject:date:message-id; bh=My4x/Ii6bvIVv9JUGwOWXjCT4x3CjxHJ2dlb+rUJ+3E=; b=ZBuoW0Mo+lIrFWSl0KRkD2p47YOY8IIz4i7Sb4RzykuEAQDsrmArRiWe9k/YL/V+dA i0LjfrlHYcgslPyfFxfkhWDbN6s9Q8j/VcW9LNsRRNSdMV51AKyf1zOHkgmv2UOaYaAs zEDgxY7tvZzv5SQszoE9CF1zA+NEdLAzPKNgnP90tYJeHAH0BMKFidlVRp3IlV5zGtdx 6n0AuHaGGzoH6xanQ1xESHqrMEI6aoZ/HaGQ/i1r3hvHTWnbbmyAcKGos436969JlO9E jlu0qP8gMtJ9CyRZKJnkB+4z40nTgHWgrKjaEk2Bq8nMM1G3iKWb5ttCjVmKWzMouFNy 5AQw== X-Received: by 10.152.10.99 with SMTP id h3mr34626802lab.13.1385673116535; Thu, 28 Nov 2013 13:11:56 -0800 (PST) Received: from localhost.localdomain (ppp91-76-134-134.pppoe.mtu-net.ru. [91.76.134.134]) by mx.google.com with ESMTPSA id dm10sm50816626lbc.14.2013.11.28.13.11.55 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 28 Nov 2013 13:11:55 -0800 (PST) From: Andrey Borzenkov To: grub-devel@gnu.org Subject: [PATCH] fix using grub device name as install device Date: Fri, 29 Nov 2013 01:11:48 +0400 Message-Id: <1385673108-13091-1-git-send-email-arvidjaar@gmail.com> X-Mailer: git-send-email 1.8.1.4 X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a00:1450:4010:c04::235 X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list Reply-To: The development of GNU GRUB List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 28 Nov 2013 21:12:15 -0000 Shell version of grub-install called grub-setup which resolved install device name and called main setup routine. C version of grub-install calls main setup routine directly, which leads to the error: grub2-install: info: grub-bios-setup --verbose --force --skip-fs-probe --directory='/boot/grub2/i386-pc' --device-map='/boot/grub2/device.map' '(hd2)'. grub2-install: info: reading /boot/grub2/i386-pc/boot.img. grub2-install: info: reading /boot/grub2/i386-pc/core.img. grub2-install: info: root is `(null)', dest is `(hd2)'. grub2-install: info: Opening dest. grub2-install: info: drive = -1. grub2-install: error: disk `(hd2)' not found. Move resolving of destination device name into main setup routine so it is done consistently in both cases. --- util/grub-setup.c | 41 +---------------------------------------- util/setup.c | 26 +++++++++++++++++++++++++- 2 files changed, 26 insertions(+), 41 deletions(-) diff --git a/util/grub-setup.c b/util/grub-setup.c index 90b9de0..cc3af5d 100644 --- a/util/grub-setup.c +++ b/util/grub-setup.c @@ -209,23 +209,9 @@ DEVICE must be an OS device (e.g. /dev/sda)."), NULL, help_filter, NULL }; -static char * -get_device_name (char *dev) -{ - size_t len = strlen (dev); - - if (dev[0] != '(' || dev[len - 1] != ')') - return 0; - - dev[len - 1] = '\0'; - return dev + 1; -} - int main (int argc, char *argv[]) { - char *root_dev = NULL; - char *dest_dev = NULL; struct arguments arguments; grub_util_host_init (&argc, &argv); @@ -264,34 +250,11 @@ main (int argc, char *argv[]) grub_mdraid1x_init (); grub_lvm_init (); - dest_dev = get_device_name (arguments.device); - if (! dest_dev) - { - /* Possibly, the user specified an OS device file. */ - dest_dev = grub_util_get_grub_dev (arguments.device); - if (! dest_dev) - { - char *program = xstrdup(program_name); - fprintf (stderr, _("Invalid device `%s'.\n"), arguments.device); - argp_help (&argp, stderr, ARGP_HELP_STD_USAGE, program); - free(program); - exit(1); - } - grub_util_info ("transformed OS device `%s' into GRUB device `%s'", - arguments.device, dest_dev); - } - else - { - /* For simplicity. */ - dest_dev = xstrdup (dest_dev); - grub_util_info ("Using `%s' as GRUB device", dest_dev); - } - /* Do the real work. */ GRUB_SETUP_FUNC (arguments.dir ? : DEFAULT_DIRECTORY, arguments.boot_file ? : DEFAULT_BOOT_FILE, arguments.core_file ? : DEFAULT_CORE_FILE, - dest_dev, arguments.force, + arguments.device, arguments.force, arguments.fs_probe, arguments.allow_floppy); /* Free resources. */ @@ -303,8 +266,6 @@ main (int argc, char *argv[]) free (arguments.dir); free (arguments.dev_map); free (arguments.device); - free (root_dev); - free (dest_dev); return 0; } diff --git a/util/setup.c b/util/setup.c index 337c304..c1de3d2 100644 --- a/util/setup.c +++ b/util/setup.c @@ -247,12 +247,13 @@ identify_partmap (grub_disk_t disk __attribute__ ((unused)), void SETUP (const char *dir, const char *boot_file, const char *core_file, - const char *dest, int force, + const char *dev, int force, int fs_probe, int allow_floppy) { char *core_path; char *boot_img, *core_img, *boot_path; char *root = 0; + char *dest = 0; size_t boot_size, core_size; #ifdef GRUB_SETUP_BIOS grub_uint16_t core_sectors; @@ -269,6 +270,28 @@ SETUP (const char *dir, #endif bl.last_length = 0; + { + size_t len = strlen (dev); + + if (len > 2 && dev[0] == '(' && dev[len - 1] == ')') + { + dest = xmalloc (len - 1); + strncpy (dest, dev + 1, len - 2); + dest[len - 2] = '\0'; + } + } + + if (! dest) + { + /* Possibly, the user specified an OS device file. */ + dest = grub_util_get_grub_dev (dev); + if (! dest) + grub_util_error (_("Invalid device `%s'.\n"), dev); + grub_util_info ("transformed OS device `%s' into GRUB device `%s'", + dev, dest); + } + + /* Read the boot image by the OS service. */ boot_path = grub_util_get_path (dir, boot_file); boot_size = grub_util_get_image_size (boot_path); @@ -303,6 +326,7 @@ SETUP (const char *dir, dest_dev = grub_device_open (dest); if (! dest_dev) grub_util_error ("%s", grub_errmsg); + free (dest); core_dev = dest_dev; -- tg: (b67422d..) u/grub-setup-device (depends on: master)