Received: from list by lists.gnu.org with archive (Exim 4.71) id 1hMxaD-0004Mt-IU for mharc-grub-devel@gnu.org; Sat, 04 May 2019 12:32:17 -0400 Received: from eggs.gnu.org ([209.51.188.92]:46696) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hMxaB-0004Li-OC for grub-devel@gnu.org; Sat, 04 May 2019 12:32:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hMxa9-0001OL-Ra for grub-devel@gnu.org; Sat, 04 May 2019 12:32:15 -0400 Received: from mail-lj1-x241.google.com ([2a00:1450:4864:20::241]:35923) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hMxa8-0001IL-Gg for grub-devel@gnu.org; Sat, 04 May 2019 12:32:13 -0400 Received: by mail-lj1-x241.google.com with SMTP id y8so7490609ljd.3 for ; Sat, 04 May 2019 09:32:10 -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=FWQlaHg40YOb4SpNKRfh4ONl7f7ve8AprhRRqyJcbcY=; b=ZyGNlYNbnoZEjFEIygqfsKDhULLJ2daHNLgqLf2algaX3MEGzom+i4sMQliXwhdend eK94GlcGm5ObPGZI2/MVXteZFj+NTVtNBhplzGgA7aOy1C60IdbaAh6moDh91qqHN0bN BNW6I3cAmy+hQiweiD4QtASsvhvqNFSW7n64qcY7S0KCTJEkKxrOKJLBYZYjLneJF4Ic OV0kCAFY9rH/PXEzqLojU1hy0qFYzU2S5sbCdHXrpDgbBzPkfdZNzOUXpLwkmDU6nF/T 2Z3csn4RntKzypgzeJm5ZiYASi9lbTAorkHblhVoFud1dvbQDlMFG9xbj1sxxD1XhIg+ RDuQ== 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=FWQlaHg40YOb4SpNKRfh4ONl7f7ve8AprhRRqyJcbcY=; b=HUWDcacGcyB4XJ7nic4hhOh/JR8DkhbTLafU1t23OYO0rkf56qPh4RThnqc0CNUmrX NfssX1Asd2AlbGLhW9NRquWcgXmX3yxrU65q6WNaJagph/l/3d9Km8wV5NvQdg1TX1zm HN7i3sMRWCpO5iWBkj2Bq65hM5JjhXFtYZZJYZaGe7ScVUX1mHCxcdRUrRoSvFAQx/1v AJ7OESDAQVPXZ6tlvJIEa1kRaZwAVeIYyFMMNeh2n5Fygydx2f1iJUUSkM9pU01FsrNZ y/zuag51bblyISaLnHdcP+oO8CSgR4W575MUGOL1fV3hbRGflPhM0ix7Iz0NP/pupLh6 v/2w== X-Gm-Message-State: APjAAAWXVLMVffsthZiywGdt4S4tse4t96lBmxKB52i92E0bw1YwPhMF +so7IJHIQ2CrqS+gnDBEW+zFyLpv X-Google-Smtp-Source: APXvYqzeBnWKg20qke96agELk1C+hqJB0eWgdQ8IkWBIBvU0VqXfhLT0NAtPGyN0e4ll6TfoRpmK2g== X-Received: by 2002:a2e:1f02:: with SMTP id f2mr8502080ljf.86.1556987528491; Sat, 04 May 2019 09:32:08 -0700 (PDT) Received: from localhost.localdomain (37-247-29-68.customers.ownit.se. [37.247.29.68]) by smtp.gmail.com with ESMTPSA id r5sm1119769ljh.27.2019.05.04.09.32.07 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 04 May 2019 09:32:07 -0700 (PDT) From: Jacob Kroon To: grub-devel@gnu.org Subject: [RFC][PATCH] probe: Support probing for gpt partition uuid with -q Date: Sat, 4 May 2019 18:31:35 +0200 Message-Id: <20190504163135.18437-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::241 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: Sat, 04 May 2019 16:32:16 -0000 Signed-off-by: Jacob Kroon --- grub-core/commands/probe.c | 13 +++++++++++++ grub-core/partmap/gpt.c | 7 +++++++ include/grub/partition.h | 3 +++ 3 files changed, 23 insertions(+) diff --git a/grub-core/commands/probe.c b/grub-core/commands/probe.c index 95d272287..626ed705c 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", 'q', 0, N_("Determine partition PARTUUID."), 0, 0}, {0, 0, 0, 0, 0, 0} }; @@ -154,6 +155,18 @@ grub_cmd_probe (grub_extcmd_context_t ctxt, int argc, char **args) grub_device_close (dev); return GRUB_ERR_NONE; } + if (state[6].set) + { + const char *val = "none"; + if (dev->disk && dev->disk->partition) + val = dev->disk->partition->partuuid; + if (state[0].set) + grub_env_set (state[0].arg, val); + else + grub_printf ("%s", val); + grub_device_close (dev); + return GRUB_ERR_NONE; + } grub_device_close (dev); return grub_error (GRUB_ERR_BAD_ARGUMENT, "unrecognised target"); } diff --git a/grub-core/partmap/gpt.c b/grub-core/partmap/gpt.c index 103f6796f..66f4c23fb 100644 --- a/grub-core/partmap/gpt.c +++ b/grub-core/partmap/gpt.c @@ -108,6 +108,13 @@ grub_gpt_partition_map_iterate (grub_disk_t disk, part.index = last_offset; part.partmap = &grub_gpt_partition_map; part.parent = disk->partition; + grub_gpt_part_guid_t *guid = &entry.guid; + grub_snprintf(part.partuuid, sizeof(part.partuuid), + "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x", + guid->data1, guid->data2, 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]); grub_dprintf ("gpt", "GPT entry %d: start=%lld, length=%lld\n", i, (unsigned long long) part.start, diff --git a/include/grub/partition.h b/include/grub/partition.h index 7adb7ec6e..c4dc31d15 100644 --- a/include/grub/partition.h +++ b/include/grub/partition.h @@ -78,6 +78,9 @@ struct grub_partition /* The index of this partition in the partition table. */ int index; + /* The partition uuid. */ + char partuuid[37]; + /* Parent partition (physically contains this partition). */ struct grub_partition *parent; -- 2.20.1