grub-devel.gnu.org archive mirror
 help / color / mirror / Atom feed
From: "Vladimir 'phcoder' Serbinenko" <phcoder@gmail.com>
To: The development of GNU GRUB <grub-devel@gnu.org>
Cc: Steve Kenton <skenton@ou.edu>
Subject: Re: [PATCH 1/1] add --partuuid to probe
Date: Wed, 15 Feb 2017 10:56:12 +0000	[thread overview]
Message-ID: <CAEaD8JOz3M_6iFog5XD21xG4eaB6G8qVeUpMf_XRitWmADP+zA@mail.gmail.com> (raw)
In-Reply-To: <20170214180035.3461-1-skenton@ou.edu>

[-- Attachment #1: Type: text/plain, Size: 4489 bytes --]

On Tue, Feb 14, 2017, 19:01 Steve Kenton <skenton@ou.edu> wrote:

> Support both EFI and NT Disk Signature for passing to kernel as
> root=PARTUUID=$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 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
>

[-- Attachment #2: Type: text/html, Size: 8486 bytes --]

  parent reply	other threads:[~2017-02-15 10:56 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-14 18:00 [PATCH 1/1] add --partuuid to probe Steve Kenton
2017-02-14 19:12 ` Andrei Borzenkov
2017-02-14 19:39   ` Steve Kenton
2017-02-15  3:36     ` Nick Vinson
2017-02-15 10:56 ` Vladimir 'phcoder' Serbinenko [this message]
2017-02-15 16:26   ` Andrei Borzenkov
2017-02-15 17:25     ` Vladimir 'phcoder' Serbinenko
2017-02-19  6:12       ` Andrei Borzenkov
2017-02-27  0:37         ` Vladimir 'phcoder' Serbinenko
2017-02-27 17:53           ` Andrei Borzenkov
2017-02-27 18:20             ` Vladimir 'phcoder' Serbinenko
2017-02-28  4:11               ` Andrei Borzenkov
2017-02-28 14:08                 ` Vladimir 'phcoder' Serbinenko
2017-02-28 17:13                   ` grub-probe for nested BSD partition on Linux (was: [PATCH 1/1] add --partuuid to probe) Andrei Borzenkov
2017-02-28 18:31                     ` Lennart Sorensen
2017-02-28 18:50                       ` grub-probe for nested BSD partition on Linux Andrei Borzenkov
2017-02-28 22:05                         ` Lennart Sorensen
2017-03-01  3:39                           ` Andrei Borzenkov
  -- strict thread matches above, loose matches on Subject: below --
2016-08-16 14:56 [PATCH 1/1] add --partuuid to probe Steve Kenton

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAEaD8JOz3M_6iFog5XD21xG4eaB6G8qVeUpMf_XRitWmADP+zA@mail.gmail.com \
    --to=phcoder@gmail.com \
    --cc=grub-devel@gnu.org \
    --cc=skenton@ou.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).