From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.71) id 1cdxG9-000687-N1 for mharc-grub-devel@gnu.org; Wed, 15 Feb 2017 05:56:29 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36974) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cdxG7-000662-LF for grub-devel@gnu.org; Wed, 15 Feb 2017 05:56:29 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cdxG6-0005O9-5I for grub-devel@gnu.org; Wed, 15 Feb 2017 05:56:27 -0500 Received: from mail-ua0-x243.google.com ([2607:f8b0:400c:c08::243]:33911) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cdxG5-0005N5-Va for grub-devel@gnu.org; Wed, 15 Feb 2017 05:56:26 -0500 Received: by mail-ua0-x243.google.com with SMTP id i68so13226196uad.1 for ; Wed, 15 Feb 2017 02:56:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=DTHtZfxrXh/U52iVogEh5Nju4s11k8AoPEFilBZftwc=; b=boMZV3bW+F7sbMq40KFzRv8U9+45QAujmlqVPSDz1HGZFq3EcfdSMvo4fqDL+JbmGI fEUg16V+n1aR3vBuEZGfXZJO9dVvheqlbR1+ersm04Gb7G43918f23xbBuyKE6ZCrret OZxXwvnslBRGzC3aoTtU9LDlxhhoeJ4Lmt6kbr/7ZHsvgtvL0CXI8T2ZcNAAEI3gvsSo WH6dQ5qas6sSSHjudye2OyuZyAVKcxo2VKi8GwYhXUN+Hn2ppvHBLhGVwvsep/EcEeMm 1+DUkkeQ1hoIczvJebNEvaNe7QOmYQvaaFS052ULIQNmGZ0Lg20zYxLVJfbOguRZA/fE Egmw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=DTHtZfxrXh/U52iVogEh5Nju4s11k8AoPEFilBZftwc=; b=FrKJW5GZvE7LjNVVE/YC23vnMi4hXHqYHT9AOP/nQBrjsjSZ5VsHhrdfa4na0YO1+0 MXDneGTzZBRa4Q9U0Wbr8ERnxxlIIVGOPV6CgERPebFEaUyWHIPAhf1LtcCpDa12R6SS VgiZiQVdjjR207KqG2nrHgO3Zuus8J1LWzHtihdkWKa7i0R2vLkTN3KeNmkysJdcVrKB Y6qYjAKw3PSCGW57jya8oFnxDWAAiVZxuKdBaFk+YIcK+IN1pag5SMpfIzFCJHbm+nFR rf+Y1MWKUQZKhu7xL7+LKgtIsnwE5AWWEd2My5gLTtqDutS9vQ8NFWSTwVD4KFhUqlVh SFcg== X-Gm-Message-State: AMke39llzFlFT52556Nk8NzLXT4IvkoYxvXJkcczeOIhOQ2fhYBatlElxIdFE2OrPd8hpHoFv/V6FWyAKA0EtA== X-Received: by 10.176.1.1 with SMTP id 1mr1743675uak.170.1487156183739; Wed, 15 Feb 2017 02:56:23 -0800 (PST) MIME-Version: 1.0 References: <20170214180035.3461-1-skenton@ou.edu> In-Reply-To: <20170214180035.3461-1-skenton@ou.edu> From: "Vladimir 'phcoder' Serbinenko" Date: Wed, 15 Feb 2017 10:56:12 +0000 Message-ID: Subject: Re: [PATCH 1/1] add --partuuid to probe To: The development of GNU GRUB Cc: Steve Kenton Content-Type: multipart/alternative; boundary=001a113d06b40eb27705488f88e5 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2607:f8b0:400c:c08::243 X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 15 Feb 2017 10:56:29 -0000 --001a113d06b40eb27705488f88e5 Content-Type: text/plain; charset=UTF-8 On Tue, Feb 14, 2017, 19:01 Steve Kenton wrote: > Support both EFI and NT Disk Signature for passing to kernel as > root=PARTUUID=$val > > Signed-off-by: Steve Kenton > --- > It's been six months so I thought I'd resend this so it does not get lost > in case I get hit by a meteor or something before the next release > > grub-core/commands/probe.c | 53 > ++++++++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 53 insertions(+) > > diff --git a/grub-core/commands/probe.c b/grub-core/commands/probe.c > index cf2793e..3afc8b8 100644 > --- a/grub-core/commands/probe.c > +++ b/grub-core/commands/probe.c > @@ -45,6 +45,7 @@ static const struct grub_arg_option options[] = > {"fs", 'f', 0, N_("Determine filesystem type."), 0, 0}, > {"fs-uuid", 'u', 0, N_("Determine filesystem UUID."), > 0, 0}, > {"label", 'l', 0, N_("Determine filesystem label."), 0, 0}, > + {"partuuid", 'g', 0, N_("Determine partition GUID/UUID."), 0, > 0}, /* GUID but Linux kernel calls it "PARTUUID" */ > I like how it generalizes. > {0, 0, 0, 0, 0, 0} > }; > > @@ -154,6 +155,58 @@ grub_cmd_probe (grub_extcmd_context_t ctxt, int argc, > char **args) > grub_device_close (dev); > return GRUB_ERR_NONE; > } > + if (state[6].set) > + { > + char *partuuid = NULL; /* NULL to silence a spurious GCC warning */ > + grub_uint8_t diskbuf[16]; > + if (dev->disk && dev->disk->partition) > + { > + grub_partition_t p = dev->disk->partition; > + if (!grub_strcmp (p->partmap->name, "msdos")) > Please use == 0 rather than ! > + { > + const int diskid_offset = 440; /* location in MBR */ > Please get this from a common header rather than hard coding. I think we have it in msdos.h > + dev->disk->partition = p->parent; > + /* little-endian 4-byte NT disk signature */ > + err = grub_disk_read (dev->disk, 0, diskid_offset, 4, > diskbuf); > + dev->disk->partition = p; > + if (err) > + return grub_errno; > + partuuid = grub_xasprintf ("%02x%02x%02x%02x-%02x", > + diskbuf[3], diskbuf[2], > diskbuf[1], diskbuf[0], > + p->number + 1); /* one based > partition number */ > This is not NT-style. NT uses partition offset. Who uses this format? Are you sure that partition numbers are synced with user? Even in presence of Solaris and bsd partitions. > + } > + else if (!grub_strcmp (p->partmap->name, "gpt")) > Ditto. > + { > + const int guid_offset = 16; /* location in entry */ > Ditto. > + dev->disk->partition = p->parent; > + /* little-endian 16-byte EFI partition GUID */ > + err = grub_disk_read (dev->disk, p->offset, p->index + > guid_offset, 16, diskbuf); > + dev->disk->partition = p; > + if (err) > + return grub_errno; > + partuuid = grub_xasprintf > ("%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x", > + diskbuf[3], diskbuf[2], > diskbuf[1], diskbuf[0], > + diskbuf[5], diskbuf[4], > + diskbuf[7], diskbuf[6], > + diskbuf[8], diskbuf[9], > + diskbuf[10], diskbuf[11], > diskbuf[12], diskbuf[13], diskbuf[14], diskbuf[15]); > + } > + else > + return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, > + N_("partition map %s does not support > partition UUIDs"), > + dev->disk->partition->partmap->name); > + } > + else > + partuuid = grub_strdup (""); /* a freeable empty string */ > + > + if (state[0].set) > + grub_env_set (state[0].arg, partuuid); > + else > + grub_printf ("%s", partuuid); > + grub_free (partuuid); > + grub_device_close (dev); > + return GRUB_ERR_NONE; > + } > grub_device_close (dev); > return grub_error (GRUB_ERR_BAD_ARGUMENT, "unrecognised target"); > } > -- > 2.9.0.137.gcf4c2cf > > > _______________________________________________ > Grub-devel mailing list > Grub-devel@gnu.org > https://lists.gnu.org/mailman/listinfo/grub-devel > --001a113d06b40eb27705488f88e5 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable

On Tue, Feb 14, 2017, 1= 9:01 Steve Kenton <skenton@ou.edu&= gt; wrote:
Support both EFI and NT = Disk Signature for passing to kernel as root=3DPARTUUID=3D$val

Signed-off-by: Steve Kenton <skenton@ou.edu>
---
It's been six months so I thought I'd resend this so it does not ge= t lost
in case I get hit by a meteor or something before the next release

=C2=A0grub-core/commands/probe.c | 53 +++++++++++++++++++++++++++++++++++++= +++++++++
=C2=A01 file changed, 53 insertions(+)

diff --git a/grub-core/commands/probe.c b/grub-core/commands/probe.c
index cf2793e..3afc8b8 100644
--- a/grub-core/commands/probe.c
+++ b/grub-core/commands/probe.c
@@ -45,6 +45,7 @@ static const struct grub_arg_option options[] =3D
=C2=A0 =C2=A0 =C2=A0{"fs",=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0'f', 0, N_("Determine filesystem type."), 0, 0}= ,
=C2=A0 =C2=A0 =C2=A0{"fs-uuid",=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0 'u', 0, N_("Determine filesystem UUID.&q= uot;), 0, 0},
=C2=A0 =C2=A0 =C2=A0{"label",=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 &= #39;l', 0, N_("Determine filesystem label."), 0, 0},
+=C2=A0 =C2=A0 {"partuuid",=C2=A0 =C2=A0 =C2=A0 =C2=A0'g'= , 0, N_("Determine partition GUID/UUID."), 0, 0}, /* GUID but Lin= ux kernel calls it "PARTUUID" */
I like how it generalizes.
<= blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px= #ccc solid;padding-left:1ex"> =C2=A0 =C2=A0 =C2=A0{0, 0, 0, 0, 0, 0}
=C2=A0 =C2=A0};

@@ -154,6 +155,58 @@ grub_cmd_probe (grub_extcmd_context_t ctxt, int argc, = char **args)
=C2=A0 =C2=A0 =C2=A0 =C2=A0grub_device_close (dev);
=C2=A0 =C2=A0 =C2=A0 =C2=A0return GRUB_ERR_NONE;
=C2=A0 =C2=A0 =C2=A0}
+=C2=A0 if (state[6].set)
+=C2=A0 =C2=A0 {
+=C2=A0 =C2=A0 =C2=A0 char *partuuid =3D NULL; /* NULL to silence a spuriou= s GCC warning */
+=C2=A0 =C2=A0 =C2=A0 grub_uint8_t diskbuf[16];
+=C2=A0 =C2=A0 =C2=A0 if (dev->disk && dev->disk->partitio= n)
+=C2=A0 =C2=A0 =C2=A0 =C2=A0{
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0grub_partition_t p =3D dev->disk->= partition;
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0if (!grub_strcmp (p->partmap->name= , "msdos"))
Please= use =3D=3D 0 rather than !
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0{
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0const int diskid_offset = =3D 440; /* location in MBR */
Please get this from a common header rather than hard coding. I think we= have it in msdos.h
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0dev->disk->partition= =3D p->parent;
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0/* little-endian 4-byte NT= disk signature */
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0err =3D grub_disk_read (de= v->disk, 0, diskid_offset, 4, diskbuf);
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0dev->disk->partition= =3D p;
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0if (err)
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0return grub_errno;<= br class=3D"gmail_msg"> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0partuuid =3D grub_xasprint= f ("%02x%02x%02x%02x-%02x",
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 diskbuf[= 3], diskbuf[2], diskbuf[1], diskbuf[0],
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 p->nu= mber + 1); /* one based partition number */
This is not NT-style. NT uses partition offset. Who uses th= is format? Are you sure that partition numbers are synced with user? Even i= n presence of Solaris and bsd partitions.
<= blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px= #ccc solid;padding-left:1ex"> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0}
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0else if (!grub_strcmp (p->partmap->= ;name, "gpt"))
Dit= to.
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0{
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0const int guid_offset =3D = 16; /* location in entry */
= Ditto.
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0dev->disk->partition= =3D p->parent;
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0/* little-endian 16-byte E= FI partition GUID */
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0err =3D grub_disk_read (de= v->disk, p->offset, p->index + guid_offset, 16, diskbuf);
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0dev->disk->partition= =3D p;
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0if (err)
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0return grub_errno;<= br class=3D"gmail_msg"> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0partuuid =3D grub_xasprint= f ("%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%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ED_YET,
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 N_("partition map %s does not support = partition UUIDs"),
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 dev->disk->partition->partmap->= name);
+=C2=A0 =C2=A0 =C2=A0 =C2=A0}
+=C2=A0 =C2=A0 =C2=A0 else
+=C2=A0 =C2=A0 =C2=A0 =C2=A0partuuid =3D grub_strdup (""); /* a f= reeable empty string */
+
+=C2=A0 =C2=A0 =C2=A0 if (state[0].set)
+=C2=A0 =C2=A0 =C2=A0 =C2=A0grub_env_set (state[0].arg, partuuid);
+=C2=A0 =C2=A0 =C2=A0 else
+=C2=A0 =C2=A0 =C2=A0 =C2=A0grub_printf ("%s", partuuid);
+=C2=A0 =C2=A0 =C2=A0 grub_free (partuuid);
+=C2=A0 =C2=A0 =C2=A0 grub_device_close (dev);
+=C2=A0 =C2=A0 =C2=A0 return GRUB_ERR_NONE;
+=C2=A0 =C2=A0 }
=C2=A0 =C2=A0grub_device_close (dev);
=C2=A0 =C2=A0return grub_error (GRUB_ERR_BAD_ARGUMENT, "unrecognised t= arget");
=C2=A0}
--
2.9.0.137.gcf4c2cf


_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/l= istinfo/grub-devel
--001a113d06b40eb27705488f88e5--