public inbox for util-linux@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3] libblkid: print PTUUID, the partition table uuid
@ 2013-06-07 17:27 Gabriel de Perthuis
  2013-06-13 13:30 ` PTUUID and PARTUUID (was: [PATCH v3] libblkid: print PTUUID, the partition table uuid) Karel Zak
  0 siblings, 1 reply; 3+ messages in thread
From: Gabriel de Perthuis @ 2013-06-07 17:27 UTC (permalink / raw)
  To: util-linux

Call it ID_PART_TABLE_UUID in udev rules.

Signed-off-by: Gabriel de Perthuis <g2p.code@gmail.com>
---
v3: Call it ID_PART_TABLE_UUID in udev rules

 libblkid/src/partitions/gpt.c        |  8 ++++----
 libblkid/src/partitions/partitions.c | 14 +++++++++++---
 misc-utils/blkid.c                   |  3 +++
 3 files changed, 18 insertions(+), 7 deletions(-)

diff --git a/libblkid/src/partitions/gpt.c b/libblkid/src/partitions/gpt.c
index 4441939..87b5ff6 100644
--- a/libblkid/src/partitions/gpt.c
+++ b/libblkid/src/partitions/gpt.c
@@ -320,14 +320,10 @@ static int probe_gpt_pt(blkid_probe pr,
 	if (blkid_probe_set_magic(pr, lba << 9,
 			      sizeof(GPT_HEADER_SIGNATURE_STR) - 1,
 			      (unsigned char *) GPT_HEADER_SIGNATURE_STR))
 		goto err;
 
-	if (blkid_partitions_need_typeonly(pr))
-		/* caller does not ask for details about partitions */
-		return 0;
-
 	ls = blkid_probe_get_partlist(pr);
 	if (!ls)
 		goto err;
 
 	tab = blkid_partlist_new_parttable(ls, "gpt", lba << 9);
@@ -336,10 +332,14 @@ static int probe_gpt_pt(blkid_probe pr,
 
 	guid = h->disk_guid;
 	swap_efi_guid(&guid);
 	blkid_parttable_set_id(tab, (const unsigned char *) &guid);
 
+	if (blkid_partitions_need_typeonly(pr))
+		/* caller does not ask for details about partitions */
+		return 0;
+
 	ssf = blkid_probe_get_sectorsize(pr) / 512;
 
 	fu = le64_to_cpu(h->first_usable_lba);
 	lu = le64_to_cpu(h->last_usable_lba);
 
diff --git a/libblkid/src/partitions/partitions.c b/libblkid/src/partitions/partitions.c
index 87ca0c1..f732527 100644
--- a/libblkid/src/partitions/partitions.c
+++ b/libblkid/src/partitions/partitions.c
@@ -35,10 +35,12 @@
  *
  * NAME=value interface, supported tags:
  *
  * @PTTYPE: partition table type (dos, gpt, etc.).
  *
+ * @PTUUID: partition table uuid (gpt only)
+ *
  * @PART_ENTRY_SCHEME: partition table type
  *
  * @PART_ENTRY_NAME: partition name (gpt and mac only)
  *
  * @PART_ENTRY_UUID: partition UUID (gpt only)
@@ -568,17 +570,18 @@ nothing:
  */
 static int partitions_probe(blkid_probe pr, struct blkid_chain *chn)
 {
 	int rc = 1;
 	size_t i;
+	blkid_partlist ls;
+	blkid_parttable pt;
 
 	if (!pr || chn->idx < -1)
 		return -1;
 	blkid_probe_chain_reset_vals(pr, chn);
 
-	if (chn->binary)
-		partitions_init_data(chn);
+	ls = partitions_init_data(chn);
 
 	if (!pr->wipe_size && (pr->prob_flags & BLKID_PROBE_FL_IGNORE_PT))
 		goto details_only;
 
 	DBG(LOWPROBE, blkid_debug("--> starting probing loop [PARTS idx=%d]",
@@ -600,14 +603,19 @@ static int partitions_probe(blkid_probe pr, struct blkid_chain *chn)
 			continue;
 
 		name = idinfos[i]->name;
 
 		/* all checks passed */
-		if (!chn->binary)
+		if (!chn->binary) {
 			blkid_probe_set_value(pr, "PTTYPE",
 						(unsigned char *) name,
 						strlen(name) + 1);
+			pt = blkid_partlist_get_table(ls);
+			if (pt && pt->id && strcmp(name, "gpt") == 0)
+				blkid_probe_set_value(pr, "PTUUID",
+						      pt->id, 37);
+		}
 		DBG(LOWPROBE, blkid_debug("<-- leaving probing loop (type=%s) [PARTS idx=%d]",
 			name, chn->idx));
 		rc = 0;
 		break;
 	}
diff --git a/misc-utils/blkid.c b/misc-utils/blkid.c
index f572a20..b032c85 100644
--- a/misc-utils/blkid.c
+++ b/misc-utils/blkid.c
@@ -251,10 +251,13 @@ static void print_udev_format(const char *name, const char *value)
 		printf("ID_FS_%s=%s\n", name, safe);
 
 		blkid_encode_string(value, enc, sizeof(enc));
 		printf("ID_FS_%s_ENC=%s\n", name, enc);
 
+	} else if (!strcmp(name, "PTUUID")) {
+		printf("ID_PART_TABLE_UUID=%s\n", value);
+
 	} else if (!strcmp(name, "PTTYPE")) {
 		printf("ID_PART_TABLE_TYPE=%s\n", value);
 
 	} else if (!strcmp(name, "PART_ENTRY_NAME") ||
 		  !strcmp(name, "PART_ENTRY_TYPE")) {
-- 
1.8.3.222.g430da9e


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* PTUUID and PARTUUID (was: [PATCH v3] libblkid: print PTUUID, the partition table uuid)
  2013-06-07 17:27 [PATCH v3] libblkid: print PTUUID, the partition table uuid Gabriel de Perthuis
@ 2013-06-13 13:30 ` Karel Zak
  2013-06-13 13:40   ` Gabriel de Perthuis
  0 siblings, 1 reply; 3+ messages in thread
From: Karel Zak @ 2013-06-13 13:30 UTC (permalink / raw)
  To: Gabriel de Perthuis; +Cc: util-linux, Kay Sievers

On Fri, Jun 07, 2013 at 07:27:00PM +0200, Gabriel de Perthuis wrote:
> ---
> v3: Call it ID_PART_TABLE_UUID in udev rules
> 
>  libblkid/src/partitions/gpt.c        |  8 ++++----
>  libblkid/src/partitions/partitions.c | 14 +++++++++++---
>  misc-utils/blkid.c                   |  3 +++
>  3 files changed, 18 insertions(+), 7 deletions(-)

I have applied a little bit different version. Anyway, you have to
modify udevd to make it usable with in built-in blkid. It also
exports MBR ID (so the change is not GPT specific) as partition
table pseudo UUID. Examples:

 # blkid -p -o udev /dev/sda
 ID_PART_TABLE_UUID=3549290f-417c-4941-8503-f7835109b821
 ID_PART_TABLE_TYPE=gpt

 # blkid -p -o udev /dev/sdb
 ID_PART_TABLE_UUID=54e743a7
 ID_PART_TABLE_TYPE=dos


Note that I have also add support for Dos partitions pseudo-uuids. The
implementation is compatible with Linux kernel root=PARTUUID= command
line option.

The PARTUUID for Dos partitions is based on MBR Id and partition number,
for example:

  # blkid /dev/sdb1
  /dev/sdb1: TYPE="ext2" PARTUUID="54e743a7-01" 

is the first partition on disk with PTUUID=54e743a7. So you can use

  # mount PARTUUID="54e743a7-01" /mnt/test

    Karel

-- 
 Karel Zak  <kzak@redhat.com>
 http://karelzak.blogspot.com

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: PTUUID and PARTUUID (was: [PATCH v3] libblkid: print PTUUID, the partition table uuid)
  2013-06-13 13:30 ` PTUUID and PARTUUID (was: [PATCH v3] libblkid: print PTUUID, the partition table uuid) Karel Zak
@ 2013-06-13 13:40   ` Gabriel de Perthuis
  0 siblings, 0 replies; 3+ messages in thread
From: Gabriel de Perthuis @ 2013-06-13 13:40 UTC (permalink / raw)
  To: Karel Zak; +Cc: util-linux, Kay Sievers

Le jeu. 13 juin 2013 15:30:35 CEST, Karel Zak a écrit :
> On Fri, Jun 07, 2013 at 07:27:00PM +0200, Gabriel de Perthuis wrote:
>> ---
>> v3: Call it ID_PART_TABLE_UUID in udev rules
>
> I have applied a little bit different version. Anyway, you have to
> modify udevd to make it usable with in built-in blkid. It also
> exports MBR ID (so the change is not GPT specific) as partition
> table pseudo UUID. Examples:
>
>  # blkid -p -o udev /dev/sda
>  ID_PART_TABLE_UUID=3549290f-417c-4941-8503-f7835109b821
>  ID_PART_TABLE_TYPE=gpt
>
>  # blkid -p -o udev /dev/sdb
>  ID_PART_TABLE_UUID=54e743a7
>  ID_PART_TABLE_TYPE=dos
>
>
> Note that I have also add support for Dos partitions pseudo-uuids. The
> implementation is compatible with Linux kernel root=PARTUUID= command
> line option.

v1 of the patch had those MBR ids, I deliberately removed them in v2
because they weren't unique on the disks I had.
Calling those UUIDs will create false expectations.

> The PARTUUID for Dos partitions is based on MBR Id and partition number,
> for example:
>
>   # blkid /dev/sdb1
>   /dev/sdb1: TYPE="ext2" PARTUUID="54e743a7-01" 
>
> is the first partition on disk with PTUUID=54e743a7. So you can use
>
>   # mount PARTUUID="54e743a7-01" /mnt/test
>
>     Karel

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2013-06-13 13:40 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-06-07 17:27 [PATCH v3] libblkid: print PTUUID, the partition table uuid Gabriel de Perthuis
2013-06-13 13:30 ` PTUUID and PARTUUID (was: [PATCH v3] libblkid: print PTUUID, the partition table uuid) Karel Zak
2013-06-13 13:40   ` Gabriel de Perthuis

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox