From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.71) id 1VmHY2-0006iE-SY for mharc-grub-devel@gnu.org; Fri, 29 Nov 2013 01:27:30 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41167) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VmHXs-0006g1-Up for grub-devel@gnu.org; Fri, 29 Nov 2013 01:27:29 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VmHXi-0005Lc-A2 for grub-devel@gnu.org; Fri, 29 Nov 2013 01:27:20 -0500 Received: from mail-ea0-x236.google.com ([2a00:1450:4013:c01::236]:35263) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VmHXh-0005LX-Tx for grub-devel@gnu.org; Fri, 29 Nov 2013 01:27:10 -0500 Received: by mail-ea0-f182.google.com with SMTP id o10so8538701eaj.13 for ; Thu, 28 Nov 2013 22:27:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-type; bh=Xg8MWxNs7tGEOjDo9cq4f+dGz+uQUesTCHSIZjmcHJc=; b=q1VjpaSjcM6G00BLxEGuZXVo16vyL5K47SdXmZ+9rslHJ5+Vc2z+8KozArng8cOUS4 86IbPUiYzy+fXA1LFsn4ANADx4uliLUNJ2ScIX4WHyJy/WtIcbj1kiKTUkk7DyrTY+Lo gFhT2a/pKNG+1hocenumaKwsqWHP77bE8gNY9M4/kfdCq5RwOxLQlxaHjR7d1DU1l9mr GsSM/ZiP1TCC7DwQnLU8ASc8+zdj+M2i7YYWFzrWlLWF+ErGzGDFuj1hMfP0yz42oGzI C5/WPU0CF00giHhN8X3yDjKaZnRPmKTy2Iu/nB2DbZfGdAWjCzkJ2E+8jAQIwbxmetuK u5RQ== X-Received: by 10.14.93.197 with SMTP id l45mr1022657eef.53.1385706428679; Thu, 28 Nov 2013 22:27:08 -0800 (PST) Received: from [192.168.1.16] (31-249.1-85.cust.bluewin.ch. [85.1.249.31]) by mx.google.com with ESMTPSA id o1sm37252170eea.10.2013.11.28.22.27.07 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 28 Nov 2013 22:27:07 -0800 (PST) Message-ID: <529833BA.4030605@gmail.com> Date: Fri, 29 Nov 2013 07:27:06 +0100 From: =?UTF-8?B?VmxhZGltaXIgJ8+GLWNvZGVyL3BoY29kZXInIFNlcmJpbmVua28=?= User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20131005 Icedove/17.0.9 MIME-Version: 1.0 To: The development of GNU GRUB Subject: Re: [PATCH] fix using grub device name as install device References: <1385673108-13091-1-git-send-email-arvidjaar@gmail.com> In-Reply-To: <1385673108-13091-1-git-send-email-arvidjaar@gmail.com> X-Enigmail-Version: 1.5.1 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="----enig2IFVAPGVXPUTMWULORNGP" X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a00:1450:4013:c01::236 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: Fri, 29 Nov 2013 06:27:29 -0000 This is an OpenPGP/MIME signed message (RFC 4880 and 3156) ------enig2IFVAPGVXPUTMWULORNGP Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On 28.11.2013 22:11, Andrey Borzenkov wrote: > 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: >=20 Do you have a reason for continuing accepting such input? It was considered wrong way of doing things for quite some while. > grub2-install: info: grub-bios-setup --verbose --force --skip-fs-pro= be --directory=3D'/boot/grub2/i386-pc' --device-map=3D'/boot/grub2/device= =2Emap' '(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 =3D -1. > grub2-install: error: disk `(hd2)' not found. >=20 > Move resolving of destination device name into main setup routine > so it is done consistently in both cases. >=20 > --- > util/grub-setup.c | 41 +---------------------------------------- > util/setup.c | 26 +++++++++++++++++++++++++- > 2 files changed, 26 insertions(+), 41 deletions(-) >=20 > 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 > }; > =20 > -static char * > -get_device_name (char *dev) > -{ > - size_t len =3D strlen (dev); > - > - if (dev[0] !=3D '(' || dev[len - 1] !=3D ')') > - return 0; > - > - dev[len - 1] =3D '\0'; > - return dev + 1; > -} > - > int > main (int argc, char *argv[]) > { > - char *root_dev =3D NULL; > - char *dest_dev =3D NULL; > struct arguments arguments; > =20 > grub_util_host_init (&argc, &argv); > @@ -264,34 +250,11 @@ main (int argc, char *argv[]) > grub_mdraid1x_init (); > grub_lvm_init (); > =20 > - dest_dev =3D get_device_name (arguments.device); > - if (! dest_dev) > - { > - /* Possibly, the user specified an OS device file. */ > - dest_dev =3D grub_util_get_grub_dev (arguments.device); > - if (! dest_dev) > - { > - char *program =3D xstrdup(program_name); > - fprintf (stderr, _("Invalid device `%s'.\n"), arguments.devi= ce); > - 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 =3D 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); > =20 > /* 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); > =20 > 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 =3D 0; > + char *dest =3D 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 =3D 0; > =20 > + { > + size_t len =3D strlen (dev); > + > + if (len > 2 && dev[0] =3D=3D '(' && dev[len - 1] =3D=3D ')') > + { > + dest =3D xmalloc (len - 1); > + strncpy (dest, dev + 1, len - 2); > + dest[len - 2] =3D '\0'; > + } > + } > + > + if (! dest) > + { > + /* Possibly, the user specified an OS device file. */ > + dest =3D 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 =3D grub_util_get_path (dir, boot_file); > boot_size =3D grub_util_get_image_size (boot_path); > @@ -303,6 +326,7 @@ SETUP (const char *dir, > dest_dev =3D grub_device_open (dest); > if (! dest_dev) > grub_util_error ("%s", grub_errmsg); > + free (dest); > =20 > core_dev =3D dest_dev; > =20 >=20 ------enig2IFVAPGVXPUTMWULORNGP Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.15 (GNU/Linux) Comment: Using GnuPG with Icedove - http://www.enigmail.net/ iF4EAREKAAYFAlKYM7oACgkQmBXlbbo5nOukuAD+NQu6qWBS+/1GfCzCZfxGe97t WWo9y1S84IjobqGmD9IA/0Q0FTI4yAUysmKyhNsST7HEQ+3xFMvTB/EUMs+s4MQQ =dvEj -----END PGP SIGNATURE----- ------enig2IFVAPGVXPUTMWULORNGP--