Received: from list by lists.gnu.org with archive (Exim 4.71) id 1hQmLs-0002Vz-U6 for mharc-grub-devel@gnu.org; Wed, 15 May 2019 01:21:16 -0400 Received: from eggs.gnu.org ([209.51.188.92]:40663) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hQmLq-0002Vq-VX for grub-devel@gnu.org; Wed, 15 May 2019 01:21:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hQmLp-0004wW-TK for grub-devel@gnu.org; Wed, 15 May 2019 01:21:14 -0400 Received: from mail-lj1-x244.google.com ([2a00:1450:4864:20::244]:39598) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hQmLp-0004rS-IY for grub-devel@gnu.org; Wed, 15 May 2019 01:21:13 -0400 Received: by mail-lj1-x244.google.com with SMTP id a10so1286933ljf.6 for ; Tue, 14 May 2019 22:21:12 -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=HS3BTZG387iFwQ4U5hgXBfaeIKkA4YtCiEi3qkB6UOY=; b=LhPg3Ff6FD046taBxz2tOHx2eJAvKupKqJXvdBDtaMdaVTOa4ou48rghYKcrKohJEe CxeF6/pt4mOLwqS32o0+vS/4s01rdJQU0IaPqu+WZxblj79L1oXdLB9jDtrMIWjzpsbx tgbEoqh8Cm9fsESkkaUCKBdpsmAHwG57UYSaWPUCNXx+Bz4unpbdJFhVwWa9WIT9QWSF sXL2S7IBP57X6LM4biKu8q3dpZ/xgEWZ5DHZcvxkbsAKZhw4aMDjM+zHx2bCgMKJkcwn dtzRqbtsjVcp62QOeTtDprEvPtPWt9B+JrXYn2mtqr+tO+19YOzv9MuwGhW9TJ+JnQaD 3rUg== 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=HS3BTZG387iFwQ4U5hgXBfaeIKkA4YtCiEi3qkB6UOY=; b=IpVybrojZrmjQjydshCWIeKCQKiahS30c/uwxaGFSijY9VOVrhlpTHvbHtRuciK5b8 bSSS/WpR1UhGDtFaadtSv1OdoJMSQjegyO0i506c/RYgvTfsTGzVLL8za1+JHS86AgaU o/9Wf+qvW3sdksvLG7lciPhp4qOeabFRCYy6YoVEZCASYNzFrJjSE+C8A88HER+oTtRx 1DChOdiPIX8HqFSOUzrrfY0+Cilpzeyh+RwONT4XNDJL4kij3KCKtULhg2aJROFU6ky3 m339dEEupG4t1+sbCM60cndP39IPevUfGYXIZn2jyJY+tNGS/DkhhAP+9ACnWLLiXNqF eqnw== X-Gm-Message-State: APjAAAXEAEqp81vQJ4f+k4bfMLAI0bZj0NhW3zeWDiXVOqCWJIvPd+dj +KuHof7oy9RJ7s4PhRtOaQpQXc18 X-Google-Smtp-Source: APXvYqw1l3PGXTTlAyyvW/f6a92ihe1AdOJxg+BKGLNUpgeyimTMt2uuFzjB+9sCMQo+M4PxFkNp9A== X-Received: by 2002:a2e:89cc:: with SMTP id c12mr14899670ljk.90.1557897670780; Tue, 14 May 2019 22:21:10 -0700 (PDT) Received: from localhost.localdomain (37-247-29-68.customers.ownit.se. [37.247.29.68]) by smtp.gmail.com with ESMTPSA id p14sm182231lfk.24.2019.05.14.22.21.09 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 14 May 2019 22:21:09 -0700 (PDT) From: Jacob Kroon To: grub-devel@gnu.org Subject: [PATCH v6] probe: Support probing for partition UUID with --part-uuid Date: Wed, 15 May 2019 07:20:56 +0200 Message-Id: <20190515052056.19992-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 05:21:16 -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 | 2 +- grub-core/commands/probe.c | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) Changes since v5: * Remove short option * partition UUID is not necessarily restricted to GPT, so clarify that in the help text and commit message diff --git a/docs/grub.texi b/docs/grub.texi index 308b25074..d85818744 100644 --- a/docs/grub.texi +++ b/docs/grub.texi @@ -4771,7 +4771,7 @@ 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. @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