From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.71) id 1bWDKb-0006eR-FN for mharc-grub-devel@gnu.org; Sat, 06 Aug 2016 21:56:49 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44105) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bWDKX-0006dK-Cg for grub-devel@gnu.org; Sat, 06 Aug 2016 21:56:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bWDKS-0003gV-Q1 for grub-devel@gnu.org; Sat, 06 Aug 2016 21:56:42 -0400 Received: from mail-pa0-x241.google.com ([2607:f8b0:400e:c03::241]:36747) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bWDKS-0003gJ-F7 for grub-devel@gnu.org; Sat, 06 Aug 2016 21:56:40 -0400 Received: by mail-pa0-x241.google.com with SMTP id ez1so21595826pab.3 for ; Sat, 06 Aug 2016 18:56:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=tq/JsBkjq3Fzknbcsw8Iq3J/JRTcXjT0HnnSFnllZhI=; b=mDRYXs9VUq1z/ibz4RfHjFHA4Her6iEX0GPNmQPXsrHN/CuTw9W3hVOCWcR+592R9X BiPATjm6CDBVoLnEqaq2onDiAJGXpqaBlRUXroZilkFJQooicHGAlOia2PzRfzxce5wE mX/ebQL1SGWfzE7dPCjkeGLd4NRfHWm4AePBJ9dfxmbjV2ulLAJDfpV9w67LgLOKztXW tB/qHyUsG8hJhHlso223+aCv3fnwRDecpJcG5DHLcOoDjok4Xgd943JIVHH95xnBenae 1IH5jP4+deaAj6BcvzxCld25C5hZL3xlkRdvfolTXvQSw0wppiWyI6W3iCPmwEp4bl5/ Re8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=tq/JsBkjq3Fzknbcsw8Iq3J/JRTcXjT0HnnSFnllZhI=; b=eZhWGTsJP8UluyrjKgs6P4dE1USQ9wlK+xpAVjhZyYBtzeZoqsGFhKQzeQUPQtBVn1 A6vHo2IWNZEcUTLDfnxifiA9BTxiQckHGgctlm1Wbj6Wzj1m+RNMTTbxAzV+RPP55qFU nCGSJSmwDFXCtl6/6xJRkWo9qpLHNPzoQv1TLOAfizbttv7EMnoKlVGm57N81536mt73 8kKhwZJ1gR76oUWDiNnePwEdoFsDG5dFXUdwru0J8krhbQR7ZiMNgYye51/r+/+9Al6J YCQ7WcGu357KRNxdHAw9GynIajgB4PKRuR5v1uw7q4li3ZfazntbOdmmPvATn2IHFoSk IQBg== X-Gm-Message-State: AEkooutwDtsfQu2gZ2+1D3TbUheCI2BS0Ro72+Y3paErAP9+bsdHdLbzPJtNFr+1kL+f6Q== X-Received: by 10.66.90.34 with SMTP id bt2mr147878103pab.139.1470534999599; Sat, 06 Aug 2016 18:56:39 -0700 (PDT) Received: from localhost.localdomain ([2601:602:9c00:cf41:a15c:1ca:cdf1:57a3]) by smtp.googlemail.com with ESMTPSA id 15sm37802061pfz.36.2016.08.06.18.56.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 06 Aug 2016 18:56:39 -0700 (PDT) From: Nicholas Vinson To: grub-devel@gnu.org Cc: Nicholas Vinson Subject: [GRUB PARTUUID PATCH V2 1/2] Add PARTUUID detection support to grub-probe Date: Sat, 6 Aug 2016 18:56:31 -0700 Message-Id: <20160807015632.32562-2-nvinson234@gmail.com> X-Mailer: git-send-email 2.9.2 In-Reply-To: <20160807015632.32562-1-nvinson234@gmail.com> References: <20160807015632.32562-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:c03::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: Sun, 07 Aug 2016 01:56:48 -0000 Add PARTUUID detection to grub-probe. The grub-probe utility is used by grub-mkconfig to determine the filesystem [GU]UID, so updating it to be able to return partition [GU]UIDs seemed like the natural choice. The other obvious choice was to rely on Linux userland tools and /dev file structure which would added to the runtime dependencies of grub-probe. Signed-off-by: Nicholas Vinson --- util/grub-probe.c | 83 +++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 68 insertions(+), 15 deletions(-) diff --git a/util/grub-probe.c b/util/grub-probe.c index 8ac527d..97daac6 100644 --- a/util/grub-probe.c +++ b/util/grub-probe.c @@ -62,6 +62,7 @@ enum { PRINT_DRIVE, PRINT_DEVICE, PRINT_PARTMAP, + PRINT_PARTUUID, PRINT_ABSTRACTION, PRINT_CRYPTODISK_UUID, PRINT_HINT_STR, @@ -85,6 +86,7 @@ static const char *targets[] = [PRINT_DRIVE] = "drive", [PRINT_DEVICE] = "device", [PRINT_PARTMAP] = "partmap", + [PRINT_PARTUUID] = "partuuid", [PRINT_ABSTRACTION] = "abstraction", [PRINT_CRYPTODISK_UUID] = "cryptodisk_uuid", [PRINT_HINT_STR] = "hints_string", @@ -168,6 +170,65 @@ probe_partmap (grub_disk_t disk, char delim) } static void +print_gpt_guid(const struct grub_gpt_partentry gptdata) +{ + grub_gpt_part_type_t gpttype; + gpttype.data1 = grub_le_to_cpu32 (gptdata.type.data1); + gpttype.data2 = grub_le_to_cpu16 (gptdata.type.data2); + gpttype.data3 = grub_le_to_cpu16 (gptdata.type.data3); + grub_memcpy (gpttype.data4, gptdata.type.data4, 8); + + grub_printf ("%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x", + gpttype.data1, gpttype.data2, gpttype.data3, gpttype.data4[0], + gpttype.data4[1], gpttype.data4[2], gpttype.data4[3], + gpttype.data4[4], gpttype.data4[5], gpttype.data4[6], + gpttype.data4[7]); +} + +static void +probe_partuuid (grub_disk_t disk, char delim) +{ + if (disk->partition) + { + if (strcmp(disk->partition->partmap->name, "gpt") == 0) + { + const int guid_offset = 16; + + grub_partition_t p = disk->partition; + struct grub_gpt_partentry gptdata; + + disk->partition = p->parent; + + if (grub_disk_read (disk, p->offset, p->index + guid_offset, + sizeof(gptdata), &gptdata) == 0) + print_gpt_guid (gptdata); + + disk->partition = p; + } + else if (strcmp(disk->partition->partmap->name, "msdos") == 0) + { + /* + * The partition GUID for MSDOS is the partition number (starting + * with 1) prepended with the NT disk signature. + */ + const int nt_disk_sig_offset = 440; + grub_uint32_t nt_disk_sig; + grub_partition_t p = disk->partition; + + disk->partition = p->parent; + + if (grub_disk_read (disk, 0, nt_disk_sig_offset, sizeof(nt_disk_sig), + &nt_disk_sig) == 0) + { + nt_disk_sig = grub_le_to_cpu32(nt_disk_sig); + grub_printf ("%08x-%02x", nt_disk_sig, 1 + p->number); + } + disk->partition = p; + } + } +} + +static void probe_cryptodisk_uuid (grub_disk_t disk, char delim) { grub_disk_memberlist_t list = NULL, tmp; @@ -621,6 +682,12 @@ probe (const char *path, char **device_names, char delim) /* Check if dev->disk itself is contained in a partmap. */ probe_partmap (dev->disk, delim); + else if (print == PRINT_PARTUUID) + { + probe_partuuid (dev->disk, delim); + putchar (delim); + } + else if (print == PRINT_MSDOS_PARTTYPE) { if (dev->disk->partition @@ -641,21 +708,7 @@ probe (const char *path, char **device_names, char delim) if (grub_disk_read (dev->disk, p->offset, p->index, sizeof (gptdata), &gptdata) == 0) - { - grub_gpt_part_type_t gpttype; - gpttype.data1 = grub_le_to_cpu32 (gptdata.type.data1); - gpttype.data2 = grub_le_to_cpu16 (gptdata.type.data2); - gpttype.data3 = grub_le_to_cpu16 (gptdata.type.data3); - grub_memcpy (gpttype.data4, gptdata.type.data4, 8); - - grub_printf ("%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x", - gpttype.data1, gpttype.data2, - gpttype.data3, gpttype.data4[0], - gpttype.data4[1], gpttype.data4[2], - gpttype.data4[3], gpttype.data4[4], - gpttype.data4[5], gpttype.data4[6], - gpttype.data4[7]); - } + print_gpt_guid(gptdata); dev->disk->partition = p; } putchar (delim); -- 2.9.2