Received: from list by lists.gnu.org with archive (Exim 4.71) id 1ci93y-0005yJ-Sq for mharc-grub-devel@gnu.org; Sun, 26 Feb 2017 19:21:14 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48515) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ci93w-0005wY-EV for grub-devel@gnu.org; Sun, 26 Feb 2017 19:21:13 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ci93v-000820-6O for grub-devel@gnu.org; Sun, 26 Feb 2017 19:21:12 -0500 Received: from mail-pg0-x244.google.com ([2607:f8b0:400e:c05::244]:35016) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ci93v-000812-0C for grub-devel@gnu.org; Sun, 26 Feb 2017 19:21:11 -0500 Received: by mail-pg0-x244.google.com with SMTP id 1so10802923pgz.2 for ; Sun, 26 Feb 2017 16:21:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=xoVuC/kRJNAzZMH4GW38uLn/FSIYX8edJc2mwK3OilM=; b=kUyQASWadSQI1Ibi1m09hWlodnypzvPbt+Ve/s0OCmM9GsNg0scGH68Fx8twwL6cv1 jY1JdEx6bjKQY6YA94YclrQ0leV/+fwveCy2ZUmngQ8kq5xyEfQRCPeCxAhrdcznBL4i gIEAQhGtFjhZAo8scuaW2ghO3LdTsThIOMpeEWCT6QcGz2TlYS8mCwWuzhiGYXVx9cmB Uo6+Co/Uk0dRXqz3rRaaSm6s9vGHDck12zH3ydIrCjrMRUogK3aJxXmJW4Ae8mXurTGH JUJFuzUEv/eXSXI4T71EyToGZ1xqSE6D3/4dSM65fZGo3N/utN9EukE8Bf0BmGRYOKvZ +hyw== 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:in-reply-to :references; bh=xoVuC/kRJNAzZMH4GW38uLn/FSIYX8edJc2mwK3OilM=; b=TsqevMagkq1STuxKiRKCXQi4GC1KPkveGQwK7bzBmeBTjbksnXebgt6KqYE241FxsC vHxkHcoCYtYiorLjcSNlnMF+4m5Nn6a4zlZr1yzivugmrDlPNbMDxupoTASics4onOHj W/dfgniEJz0ABFvVxpKrc+HR8+ZpSDocwOu3av8imK1VKj0+jRcgtxsASCZgD8+j6uBW U8DWJj8IheU5u5G1Qwfb7mFjsh2ToziPike3X+X5n9DB0fbzh5disDVjJRJjI1WpRZzz cu8pAj21FIcW8lqMb/ztsozD1zSsEOtUVLeeyyBS5zRyrOR9ApECPCX1uTdKvhnynXmT aaLg== X-Gm-Message-State: AMke39mlpMFNN5pgAYBWkhq2mdjHNzUd8UwiecGYAFu97npJjkSOHFu6LBHXWv0pqI3vLQ== X-Received: by 10.99.121.195 with SMTP id u186mr17766081pgc.96.1488154870213; Sun, 26 Feb 2017 16:21:10 -0800 (PST) Received: from localhost.localdomain ([2601:602:9c01:e86a:1fb0:47b:8245:c067]) by smtp.googlemail.com with ESMTPSA id u82sm26523453pfd.7.2017.02.26.16.21.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 26 Feb 2017 16:21:09 -0800 (PST) From: Nicholas Vinson To: skenton@ou.edu, grub-devel@gnu.org Subject: [GRUB PARTUUID PATCH V3 4/5] Support both EFI and NT Disk Signature for passing to kernel as root=PARTUUID=$val Date: Sun, 26 Feb 2017 16:20:54 -0800 Message-Id: <20170227002055.5829-5-nvinson234@gmail.com> X-Mailer: git-send-email 2.12.0 In-Reply-To: <20170227002055.5829-1-nvinson234@gmail.com> References: <20170227002055.5829-1-nvinson234@gmail.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2607:f8b0:400e:c05::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: Mon, 27 Feb 2017 00:21:13 -0000 From: Steve Kenton --- 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 cf2793e1d..5dd1a6bc5 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 */ + /* Nested partitions are not supported for now. */ + /* Non-nested partitions must have dev->disk->partition->parent == NULL */ + if (dev->disk && dev->disk->partition && dev->disk->partition->parent == NULL) + { + grub_partition_t p = dev->disk->partition; + if (grub_strcmp (p->partmap->name, "msdos") == 0) + { + /* little-endian 4-byte NT disk id "GUID" in the MBR */ + grub_uint8_t diskid[4]; + dev->disk->partition = p->parent; + grub_uint32_t nt_disk_sig; + err = grub_disk_read (dev->disk, 0, GRUB_BOOT_MACHINE_WINDOWS_NT_MAGIC, sizeof(diskid), diskid); + dev->disk->partition = p; + if (err) + return grub_errno; + /* partition numbers are one-based */ + partuuid = grub_xasprintf ("%02x%02x%02x%02x-%02x", + diskid[3], diskid[2], diskid[1], disk[0], + p->number + 1); + } + else if (grub_strcmp (p->partmap->name, "gpt") == 0) + { + struct grub_gpt_partentry e; + dev->disk->partition = p->parent; + err = grub_disk_read (dev->disk, p->offset, p->index, sizeof e, &e); + 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", + e.guid[3], e.guid[2], e.guid[1], e.guid[0], + e.guid[5], e.guid[4], + e.guid[7], e.guid[6], + e.guid[8], e.guid[9], + e.guid[10], e.guid[11], e.guid[12], e.guid[13], e.guid[14], e.guid[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.12.0