Received: from list by lists.gnu.org with archive (Exim 4.71) id 1hQzGZ-0005dy-Of for mharc-grub-devel@gnu.org; Wed, 15 May 2019 15:08:39 -0400 Received: from eggs.gnu.org ([209.51.188.92]:33799) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hQzGX-0005a6-0i for grub-devel@gnu.org; Wed, 15 May 2019 15:08:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hQzCx-0005Xc-Ce for grub-devel@gnu.org; Wed, 15 May 2019 15:04:56 -0400 Received: from mail-lj1-x244.google.com ([2a00:1450:4864:20::244]:36645) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hQzCx-0005XB-57 for grub-devel@gnu.org; Wed, 15 May 2019 15:04:55 -0400 Received: by mail-lj1-x244.google.com with SMTP id z1so787549ljb.3 for ; Wed, 15 May 2019 12:04:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=e84ifRfJK+ulX6WKA/ibmLELRB0kH0INZi3xZAMFM5o=; b=ZWP8p/aGNEdp5DHeJeIiQHqQ1nr6UE8mUu1wJhD9lZYNwjbyNETF2Kmb9ynwgL0pkR G2l+8D7bS8NRcZBQwZGcuzJM+UGwopcOoy8OOIOqCqKBSOLF7ipaqFJ57jU5j73xL4gE MdO0pckFcZ4ThEFJJ6wIsV0pFqL5vHrREzNI1OcqXaPBQm26J3VikLeIGQwb91wUl1U/ NJGA2/ohhwi+Q6F6tE8Cjkv0Sq2X3JFzCmc7I8t6EhJt4suhtpHmVE68/NX+mKuQN+0f uWa6P467dv4GiTKnAHPPCe5Enz5wrizbZ8drhhTRa2EKE/ur2RctGv2A2rX3J246TMem AWZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=e84ifRfJK+ulX6WKA/ibmLELRB0kH0INZi3xZAMFM5o=; b=MenF27pSCh35pop3BJfaLrppVUhHYmff5E6mmHWnzr+HGXFGlsC8t++mH04rwVZ41D TkESY01Pkn61DiZfAOXDUG2dVTr1B+tBfCNah6UqTzEygrxBZKopGmUJiOtC2vNRiP9M zIH7q3AKydbw9tJqWmEV14z9YcLJb9tLTjKpK3FanKHrhLdiAFR1Lv12YkxjwRsxUT5g R9coJKVf9cDfrVl0owLiMjTTMwdZGQwPfi+YJPd0LsmWnBG0Fg41J6lanLJqB18hc78c DU0Mx5D8ERzSRA9Kk+gc/eCuZj+Oc0xBDuxinlVHqteTC0H8H6xvv/oFKRsKfmPYtDbI R1lg== X-Gm-Message-State: APjAAAVzYIWFot2C3eenFrJMg1sJhInbFkkGMvSPJ6g1c7uLzCPhHC0m Jj6xcJaChrO8gpAGaZTyjphqENrZ X-Google-Smtp-Source: APXvYqwq5sPK+g3gboTZ0koEFFRwrG6gGncbiElVLcRevH10QMBPWS2kni2/BabyTnDL7IpU6+BuNg== X-Received: by 2002:a2e:9a4f:: with SMTP id k15mr16934678ljj.159.1557947093110; Wed, 15 May 2019 12:04:53 -0700 (PDT) Received: from localhost.localdomain (37-247-29-68.customers.ownit.se. [37.247.29.68]) by smtp.gmail.com with ESMTPSA id q29sm483210ljc.8.2019.05.15.12.04.51 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 15 May 2019 12:04:52 -0700 (PDT) From: Jacob Kroon To: grub-devel@gnu.org Subject: [PATCH v7] probe: Support probing for partition UUID with --part-uuid Date: Wed, 15 May 2019 21:04:43 +0200 Message-Id: <20190515190443.15702-1-jacob.kroon@gmail.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::244 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 May 2019 19:08:38 -0000 Linux supports root=PARTUUID= boot argument, so add support for probing it. Compared to the fs UUID, the partition UUID does not change when reformatting a partition. For now, only disks using a GPT partition table are supported. Signed-off-by: Jacob Kroon --- docs/grub.texi | 4 +++- grub-core/commands/probe.c | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) Changes since v6: * Mention GPT restriction in manual diff --git a/docs/grub.texi b/docs/grub.texi index 308b25074..fc12fc775 100644 --- a/docs/grub.texi +++ b/docs/grub.texi @@ -4771,9 +4771,11 @@ a rest. @node probe @subsection probe -@deffn Command probe [@option{--set} var] @option{--driver}|@option{--partmap}|@option{--fs}|@option{--fs-uuid}|@option{--label} device +@deffn Command probe [@option{--set} var] @option{--driver}|@option{--partmap}|@option{--fs}|@option{--fs-uuid}|@option{--label}|@option{--part-uuid} device Retrieve device information. If option @option{--set} is given, assign result to variable @var{var}, otherwise print information on the screen. + +The option @option{--part-uuid} is currently only implemented for GPT-formatted disks. @end deffn diff --git a/grub-core/commands/probe.c b/grub-core/commands/probe.c index 95d272287..d2e7f662e 100644 --- a/grub-core/commands/probe.c +++ b/grub-core/commands/probe.c @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -45,6 +46,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}, + {"part-uuid", 0, 0, N_("Determine partition UUID."), 0, 0}, {0, 0, 0, 0, 0, 0} }; @@ -98,6 +100,38 @@ grub_cmd_probe (grub_extcmd_context_t ctxt, int argc, char **args) grub_device_close (dev); return GRUB_ERR_NONE; } + if (state[6].set) + { + /* AAAABBBB-CCCC-DDDD-EEEE-FFFFFFFFFFFF + null terminator */ + char val[37] = "none"; + if (dev->disk && dev->disk->partition && + grub_strcmp(dev->disk->partition->partmap->name, "gpt") == 0) + { + struct grub_gpt_partentry entry; + struct grub_partition *p = dev->disk->partition; + grub_disk_t disk = grub_disk_open(dev->disk->name); + if (!disk) + return grub_errno; + if (grub_disk_read(disk, p->offset, p->index, sizeof(entry), &entry)) + return grub_errno; + grub_disk_close(disk); + grub_gpt_part_guid_t *guid = &entry.guid; + grub_snprintf (val, sizeof(val), + "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x", + grub_le_to_cpu32 (guid->data1), + grub_le_to_cpu16 (guid->data2), + grub_le_to_cpu16 (guid->data3), + guid->data4[0], guid->data4[1], guid->data4[2], + guid->data4[3], guid->data4[4], guid->data4[5], + guid->data4[6], guid->data4[7]); + } + if (state[0].set) + grub_env_set (state[0].arg, val); + else + grub_printf ("%s", val); + grub_device_close (dev); + return GRUB_ERR_NONE; + } fs = grub_fs_probe (dev); if (! fs) return grub_errno; -- 2.20.1