Received: from mailman by lists.gnu.org with archive (Exim 4.43) id 1KaYHv-0000E5-Ly for mharc-grub-devel@gnu.org; Tue, 02 Sep 2008 11:59:27 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1KaYHt-0000DG-QN for grub-devel@gnu.org; Tue, 02 Sep 2008 11:59:25 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1KaYHs-0000CW-9v for grub-devel@gnu.org; Tue, 02 Sep 2008 11:59:25 -0400 Received: from [199.232.76.173] (port=33350 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KaYHs-0000CK-09 for grub-devel@gnu.org; Tue, 02 Sep 2008 11:59:24 -0400 Received: from moutng.kundenserver.de ([212.227.126.177]:61578) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1KaYHr-0006Yj-8H for grub-devel@gnu.org; Tue, 02 Sep 2008 11:59:23 -0400 Received: from [85.180.13.152] (e180013152.adsl.alicedsl.de [85.180.13.152]) by mrelayeu.kundenserver.de (node=mrelayeu7) with ESMTP (Nemesis) id 0ML2xA-1KaYHp3JG6-0002sL; Tue, 02 Sep 2008 17:59:22 +0200 From: Felix Zielcke To: The development of GRUB 2 In-Reply-To: <48BD54CD.3000907@nic.fi> References: <20080808202337.3440.57502.reportbug@sylvester.jejik.com.jejik.com> <1218277583.9301.6.camel@fz.local> <489EEAC5.4080209@jejik.com> <1218471512.6939.19.camel@fz.local> <1218735245.8950.10.camel@fz.local> <20080814180353.GC5614@thorin> <1218742324.10393.8.camel@fz.local> <20080814203856.GA23307@thorin> <1218748505.10393.13.camel@fz.local> <1219071926.4569.57.camel@fz.local> <20080901221405.GA11511@thorin> <1220309171.4115.31.camel@fz.local> <1220344081.4101.2.camel@fz.local> <48BD54CD.3000907@nic.fi> Content-Type: multipart/mixed; boundary="=-x6Do3cmffA7QBrQI/xdm" Date: Tue, 02 Sep 2008 17:59:20 +0200 Message-Id: <1220371160.6359.37.camel@fz.local> Mime-Version: 1.0 X-Mailer: Evolution 2.22.3.1 X-Provags-ID: V01U2FsdGVkX1+lseMW9rUoEHi00XCg3JJIVRbTnxsj5IVyqR+ lcOQmZI91Nt4FytV0LcINOXTIDik9GL6CBsrDKbvig1cOZnh1B DYUslTaT3aCrQ4RQW3EkRBJ9rkhHiqS X-detected-kernel: by monty-python.gnu.org: Linux 2.6? (barebone, rare!) Subject: Re: [PATCH] Grub2 cannot find LVM volume groups with a dash (-) in the name X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: The development of GRUB 2 List-Id: The development of GRUB 2 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 02 Sep 2008 15:59:26 -0000 --=-x6Do3cmffA7QBrQI/xdm Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Am Dienstag, den 02.09.2008, 17:59 +0300 schrieb Vesa J=C3=A4=C3=A4skel=C3= =A4inen:=20 > Felix Zielcke wrote: >=20 > sizeof returns type of size_t so it would be good that char k uses that. > I am a bit surprised that this didn't generate compiler warning? Well somewhere hidden in a mail from me, I think I already wrote that I already got the idea to make these warnings more visible :) I didn't look yet further into it, maybe even a [RFC] topic should be made for this. I'm thinking about how linux kernel compiling works. Actually I haven't checked that code ;) > And there is no reason to define integers as constants unless you really > want to make sure they don't change :) This is just a thing left from my previous coding experience. As I started to code I personally just prefer that, but yeah gcc is so nice and optimizes (almost) everything for us and this code is so little anyway :) > > + p =3D strchr (os_dev, 'p'); > > + if (p) > > + *p =3D ','; >=20 > It is usually a bad idea to modify source string. Urm right this is util/ no need to save a few bytes :) Thanks for your suggestions Vesa. It really looks now better compared to the first code I sent about this problem and it only uses now 3 variables :) --=20 Felix Zielcke --=-x6Do3cmffA7QBrQI/xdm Content-Disposition: attachment; filename=getroot.diff.3 Content-Type: text/plain; name=getroot.diff.3; charset=UTF-8 Content-Transfer-Encoding: 7bit 2008-09-02 Felix Zielcke * util/getroot.c: Include . (grub_util_get_grub_dev): Rewritten to use asprintf for mdraid devices, add support for /dev/md/N devices and handle LVM double dash escaping. Index: util/getroot.c =================================================================== --- util/getroot.c (Revision 1845) +++ util/getroot.c (Arbeitskopie) @@ -17,6 +17,7 @@ * along with GRUB. If not, see . */ +#include #include #include #include @@ -417,62 +418,52 @@ grub_util_get_grub_dev (const char *os_d switch (grub_util_get_dev_abstraction (os_dev)) { case GRUB_DEV_ABSTRACTION_LVM: - grub_dev = xmalloc (strlen (os_dev) - 12 + 1); - - strcpy (grub_dev, os_dev + 12); + { + unsigned short i, len; + grub_size_t offset = sizeof ("/dev/mapper/") - 1; + + len = strlen (os_dev) - offset; + grub_dev = xmalloc (len); + + for (i = 0; i <= len; i++, offset++) + { + grub_dev[i] = os_dev[offset]; + if (os_dev[offset] == '-' && os_dev[offset + 1] == '-') + offset++; + } + } + break; case GRUB_DEV_ABSTRACTION_RAID: - grub_dev = xmalloc (20); if (os_dev[7] == '_' && os_dev[8] == 'd') { - const char *p; - /* This a partitionable RAID device of the form /dev/md_dNNpMM. */ - int i; - - grub_dev[0] = 'm'; - grub_dev[1] = 'd'; - i = 2; - p = os_dev + 9; - while (*p >= '0' && *p <= '9') - { - grub_dev[i] = *p; - i++; - p++; - } + char *p , *q; - if (*p == '\0') - grub_dev[i] = '\0'; - else if (*p == 'p') - { - p++; - grub_dev[i] = ','; - i++; - - while (*p >= '0' && *p <= '9') - { - grub_dev[i] = *p; - i++; - p++; - } + p = strdup (os_dev + sizeof ("/dev/md_d") - 1); - grub_dev[i] = '\0'; - } - else - grub_util_error ("Unknown kind of RAID device `%s'", os_dev); + q = strchr (p, 'p'); + if (q) + *q = ','; + + asprintf (&grub_dev, "md%s", p); + free (p); } else if (os_dev[7] >= '0' && os_dev[7] <= '9') { - memcpy (grub_dev, os_dev + 5, 7); - grub_dev[7] = '\0'; + asprintf (&grub_dev, "md%s", os_dev + sizeof ("/dev/md") - 1); + } + else if (os_dev[7] == '/' && os_dev[8] >= '0' && os_dev[8] <= '9') + { + asprintf (&grub_dev, "md%s", os_dev + sizeof ("/dev/md/") - 1); } else grub_util_error ("Unknown kind of RAID device `%s'", os_dev); - + break; default: /* GRUB_DEV_ABSTRACTION_NONE */ --=-x6Do3cmffA7QBrQI/xdm--