Received: from list by lists.gnu.org with archive (Exim 4.71) id 1hQ9gt-0000ic-Ts for mharc-grub-devel@gnu.org; Mon, 13 May 2019 08:04:23 -0400 Received: from eggs.gnu.org ([209.51.188.92]:41586) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hQ9gr-0000gV-Nl for grub-devel@gnu.org; Mon, 13 May 2019 08:04:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hQ9gq-0005Bo-IB for grub-devel@gnu.org; Mon, 13 May 2019 08:04:21 -0400 Received: from mail-lf1-x142.google.com ([2a00:1450:4864:20::142]:41548) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hQ9gq-0005An-9p for grub-devel@gnu.org; Mon, 13 May 2019 08:04:20 -0400 Received: by mail-lf1-x142.google.com with SMTP id d8so8825436lfb.8 for ; Mon, 13 May 2019 05:04:19 -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=z3BJT8KeFaDTPhnuAGjAXCc7AQtqwT9XKb9w9b4vV5o=; b=eqYWd1NRpYFK3d25SkUjqtyziAi0HCpHCjasz/6v1lXUm2IwG0EZYy19Uaa5vdGw9Y EpcaMKE29zxb0Wo+R19pCL2a2LqAyP0DV+g0nqP6te4u3PexeedPv7AZi1qd93cTVWG8 KByUGOsksxkcUgO6vDe6NGR/InZf0aI3SbM1fMm80mGr7TcbuM7ilv1dqoETWvA7z9/n /iU7nQ3VLx64VZGlOV/odkD/Nn+R49Hro5MJt4CqVpTdzNuEH5u2ZQVWUNKNt+Y/0p9v Whl74k2/cgVtHyl+LLzoyQTLEinGRTe+r4M93Xz/lD3JEYIhoi8wilow9YU263ahcWu1 iIgg== 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=z3BJT8KeFaDTPhnuAGjAXCc7AQtqwT9XKb9w9b4vV5o=; b=OgCC2nX+NVKamgl5L94isz/IsGgzi95SdfXaoa5aM8DYez6pAuXoj61bgQVHrG4r3H /fRd+MEXRMoBQ/bNVlZPC5Bz0zuKzm1icXBPp0KtZM8oZoch7wJARx2MwYkM3xfwYcZF +rP/WPp1i+3hvXjpY0d/yCUx80OBKvEXfH0VfbA2qFBa8F2oyK4Es9sW9CEIOQ5IVlRc eK+nVdisfXCS1gyO3LaU2j1RtBJqBYxxVJux5cHZi9DIO59Ky8nNTZKh2dhn8lbuTEFj 9gXxXPthLyKwNZuSCmaAnrWnFV3sks4pvUYlUYtsfthAwCu6orb3cgcZFX+R4qQxdj71 /YKQ== X-Gm-Message-State: APjAAAVjtgMn0pqddL/VFCl81a9LZbWFXxTJ267zA/DBQFiVClwPWktF 60pEbjOFDpPjJTkBmoqYcQn0+O94 X-Google-Smtp-Source: APXvYqxpOMqSSCLNRS5IMMw7qBfE63eVgDKaqBExkmyCqkBKjdfamQYOL5Te8Sca9IHvmqIHGtkhsA== X-Received: by 2002:a19:750b:: with SMTP id y11mr14335936lfe.6.1557749057753; Mon, 13 May 2019 05:04:17 -0700 (PDT) Received: from localhost.localdomain ([213.185.29.22]) by smtp.gmail.com with ESMTPSA id n26sm2812634lfi.90.2019.05.13.05.04.16 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 13 May 2019 05:04:16 -0700 (PDT) From: Jacob Kroon To: grub-devel@gnu.org Subject: [PATCH v4] probe: Support probing for GPT partition UUID with -g Date: Mon, 13 May 2019 14:04:09 +0200 Message-Id: <20190513120409.10485-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::142 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, 13 May 2019 12:04:23 -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. Signed-off-by: Jacob Kroon --- docs/grub.texi | 2 +- grub-core/commands/probe.c | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) Changes since v3: * Change from '-q'/'--partuuid' to '-g'/'--part-uuid' * Capitalize 'UUID' in help text * Document new flag --part-uuid in docs/grub.texi 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..3c2412567 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", 'g', 0, N_("Determine GPT partition UUID."), 0, 0}, {0, 0, 0, 0, 0, 0} }; @@ -98,6 +100,39 @@ 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; + guid->data1 = grub_le_to_cpu32 (guid->data1); + guid->data2 = grub_le_to_cpu16 (guid->data2); + guid->data3 = grub_le_to_cpu16 (guid->data3); + grub_snprintf (val, sizeof(val), + "%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]); + } + 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