Received: from list by lists.gnu.org with archive (Exim 4.71) id 1cfL8n-0002zw-Qn for mharc-grub-devel@gnu.org; Sun, 19 Feb 2017 01:38:37 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39181) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cfL8k-0002zo-JK for grub-devel@gnu.org; Sun, 19 Feb 2017 01:38:36 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cfL8h-0006Oj-Fn for grub-devel@gnu.org; Sun, 19 Feb 2017 01:38:34 -0500 Received: from mail-lf0-x243.google.com ([2a00:1450:4010:c07::243]:36225) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cfL8h-0006Ng-3o for grub-devel@gnu.org; Sun, 19 Feb 2017 01:38:31 -0500 Received: by mail-lf0-x243.google.com with SMTP id o140so156572lff.3 for ; Sat, 18 Feb 2017 22:38:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:cc:from:message-id:date:user-agent :mime-version:in-reply-to:content-transfer-encoding; bh=ErP5Mvz7uKxAZcSSocy/EZEVfICgJ2wwRISUv8iAdNk=; b=NNXycQkj0sn5rLDPrIMQrMaDKTtE/AK0AUn9lQ4gqZjJNnixcf7lKYOk1dYOOiwf9z +0W1kN4odFao96XvVu22PvrlZk6RzlKMOy93py+mjSrqLUkYDheJrMN/TF3CTnp6Z7Le /u+W2ZklYQUaq7A/JAQmnBNUIQcNVCb0X8c4XoBRSa7xdTp1T3zngm2ZZVZZxj+rlvVb z2n/f78A/TagrxgXYvDRUa/dNJMSCg3GD5P6i8GALUZDmpfdsZzJuY/X3sWeMuY0JkY8 g1OvO/TrkZbmAPilcQIs2QLpMKR3FzZqA01+/h96BOuKuqF3wcVZR5BXEcjU+DnLpbzW Fang== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:cc:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding; bh=ErP5Mvz7uKxAZcSSocy/EZEVfICgJ2wwRISUv8iAdNk=; b=p/gOQfE5qk9fzyMhSqawB6CzI+hrp3l6+kg8YQKn2Uo1Jrqepsme5nF7nH+A/AvRKh Iyy1MnBcGotXHhpxT5I0+SO35YGiry4OJ3wf9BDUFeUh5iI4tezIIm4T2lzGD5VhajoF eGToizbOU/T56fTBKEfMDOAl0mi9HuFiyySG/wbqEsvw0e/BHedciZ3Jdq/LgDZbCRkB c+iIWy2Z1URdWwjHhZfrcMHUZJf69NOAKo9/XQrFa7XUn81IiDPB+Gtt2i0b10zISfas G4YHR9GK4EM9Z/Qm10PvZ0cTOh3+TORDulRj3bp0VpqvVJxzumUBEq82uWJCCmLTlVxe yYSA== X-Gm-Message-State: AMke39kuEx8mqojurKIuDOiCYXdzxOIH+1ejYpSIZQoNqQyeIJDsgtRV9ymeyxxsxXIV0g== X-Received: by 10.46.83.15 with SMTP id h15mr4110972ljb.28.1487486309469; Sat, 18 Feb 2017 22:38:29 -0800 (PST) Received: from [192.168.1.6] (ppp109-252-90-129.pppoe.spdop.ru. [109.252.90.129]) by smtp.gmail.com with ESMTPSA id h13sm4181843ljh.5.2017.02.18.22.38.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 18 Feb 2017 22:38:28 -0800 (PST) Subject: Re: [PATCH 1/1 V2] add --partuuid to probe To: The development of GNU GRUB References: <20170218153129.6393-1-skenton@ou.edu> Cc: Steve Kenton From: Andrei Borzenkov Message-ID: <6c75abb9-0155-903d-aba1-d01c3bd6e94c@gmail.com> Date: Sun, 19 Feb 2017 09:38:28 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.7.0 MIME-Version: 1.0 In-Reply-To: <20170218153129.6393-1-skenton@ou.edu> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:4010:c07::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: Sun, 19 Feb 2017 06:38:36 -0000 18.02.2017 18:31, Steve Kenton пишет: > Signed-off-by: Steve Kenton > --- > V2 coding style changes as suggested in feedback > In V1 I was treating p->index as an offset into the partition table instead > of an index from 0-15 of the partition table slot needing to be multipled > by the size of a gtp partition table entry. Is this correct? There are two E-h-h ... either it returns the correct GUID or not, right? :) > temporary comments about the include files used to remove the magic numbers, > If you would prefer others just let me know. > > grub-core/commands/probe.c | 59 ++++++++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 59 insertions(+) > > diff --git a/grub-core/commands/probe.c b/grub-core/commands/probe.c > index cf2793e..662c0a3 100644 > --- a/grub-core/commands/probe.c > +++ b/grub-core/commands/probe.c > @@ -16,6 +16,7 @@ > * along with GRUB. If not, see . > */ > > +#include > #include > #include > #include > @@ -24,6 +25,8 @@ > #include > #include > #include > +#include > +#include > #include > #include > #include > @@ -45,6 +48,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" */ > {0, 0, 0, 0, 0, 0} > }; > > @@ -154,6 +158,61 @@ 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") == 0) As discussed in other thread, we probably need to skip nested partitions here. > + { > + /* 440 location of NT Volume Label in MBR ./include/grub/i386/pc/boot.h */ > + const int diskid_offset = GRUB_BOOT_MACHINE_WINDOWS_NT_MAGIC; > + dev->disk->partition = p->parent; > + /* little-endian 4-byte NT disk id */ > + 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 */ > + } > + else if (grub_strcmp (p->partmap->name, "gpt") == 0) > + { > + const int guid_offset = p->index * sizeof(struct grub_gpt_partentry) + p->index is absolute byte offset from the start of partition entries array. > + /* 16 location of GUID in entry ./include/grub/gpt_partition.h */ > + offsetof(struct grub_gpt_partentry, guid); I scratched my head how it compiled at all and then I noticed that in my case we have gcc -DHAVE_CONFIG_H -I. -I.. -Wall -W -DGRUB_MACHINE_PCBIOS=1 -DGRUB_MACHINE=I386_PC -m32 -nostdinc -isystem /usr/lib/gcc/x86_64-linux-gnu/5/include ... So we do pull in definitions from host even into kernel build (and of course offset() is defined in stddef.h in this directory). This looks like something to solve irrespectively; in your case I suggest you simply read the whole grub_gpt_partentry to avoid. Although having offsetof() is actually not that bad. > + dev->disk->partition = p->parent; > + /* little-endian 16-byte EFI partition GUID */ > + err = grub_disk_read (dev->disk, p->offset, 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"); > } >