Skip to contentSkip to conversation

lsblk: add partition table UUID and type fields.

PATCH Applied Milan Broz 2 participants 2 messages Jun 19, 2018 Util-Linux package

lore
Share & tools
lore

Milan Broz

author
#0 lore raw

PATCH 1/1 lsblk: add partition table UUID and type fields.

This patch adds PTUUID and PTTYPE fields to lsblk, that are corresponding fields to ID_PART_TABLE_UUID and ID_PART_TABLE_TYPE in udev database.

---
 misc-utils/lsblk.c | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)
misc-utils/lsblk.c +27 -0
index fadef65c4..8586ea35c 100644
@@ -92,6 +92,8 @@ enum {
 	COL_TARGET,
 	COL_LABEL,
 	COL_UUID,
+	COL_PTUUID,
+	COL_PTTYPE,
 	COL_PARTTYPE,
 	COL_PARTLABEL,
 	COL_PARTUUID,
@@ -172,6 +174,9 @@ static struct colinfo infos[] = {
 	[COL_LABEL]  = { "LABEL",   0.1, 0, N_("filesystem LABEL") },
 	[COL_UUID]   = { "UUID",    36,  0, N_("filesystem UUID") },
 
+	[COL_PTUUID] = { "PTUUID",  36,  0, N_("partition table UUID") },
+	[COL_PTTYPE] = { "PTTYPE",  0.1, 0, N_("partition table type") },
+
 	[COL_PARTTYPE]  = { "PARTTYPE",  36,  0, N_("partition type UUID") },
 	[COL_PARTLABEL] = { "PARTLABEL", 0.1, 0, N_("partition LABEL") },
 	[COL_PARTUUID]  = { "PARTUUID",  36,  0, N_("partition UUID") },
@@ -285,6 +290,8 @@ struct blkdev_cxt {
 	int probed;		/* already probed */
 	char *fstype;		/* detected fs, NULL or "?" if cannot detect */
 	char *uuid;		/* filesystem UUID (or stack uuid) */
+	char *ptuuid;		/* partition table UUID */
+	char *pttype;		/* partition table type */
 	char *label;		/* filesystem label */
 	char *parttype;		/* partition type UUID */
 	char *partuuid;		/* partition UUID */
@@ -394,6 +401,8 @@ static void reset_blkdev_cxt(struct blkdev_cxt *cxt)
 	free(cxt->filename);
 	free(cxt->fstype);
 	free(cxt->uuid);
+	free(cxt->ptuuid);
+	free(cxt->pttype);
 	free(cxt->label);
 	free(cxt->parttype);
 	free(cxt->partuuid);
@@ -552,6 +561,10 @@ static int get_udev_properties(struct blkdev_cxt *cxt)
 			cxt->uuid = xstrdup(data);
 			unhexmangle_string(cxt->uuid);
 		}
+		if ((data = udev_device_get_property_value(dev, "ID_PART_TABLE_UUID")))
+			cxt->ptuuid = xstrdup(data);
+		if ((data = udev_device_get_property_value(dev, "ID_PART_TABLE_TYPE")))
+			cxt->pttype = xstrdup(data);
 		if ((data = udev_device_get_property_value(dev, "ID_PART_ENTRY_NAME"))) {
 			cxt->partlabel = xstrdup(data);
 			unhexmangle_string(cxt->partlabel);
@@ -621,6 +634,10 @@ static void probe_device(struct blkdev_cxt *cxt)
 			cxt->fstype = xstrdup(data);
 		if (!blkid_probe_lookup_value(pr, "UUID", &data, NULL))
 			cxt->uuid = xstrdup(data);
+		if (!blkid_probe_lookup_value(pr, "PTUUID", &data, NULL))
+			cxt->ptuuid = xstrdup(data);
+		if (!blkid_probe_lookup_value(pr, "PTTYPE", &data, NULL))
+			cxt->pttype = xstrdup(data);
 		if (!blkid_probe_lookup_value(pr, "LABEL", &data, NULL))
 			cxt->label = xstrdup(data);
 		if (!blkid_probe_lookup_value(pr, "PART_ENTRY_TYPE", &data, NULL))
@@ -964,6 +981,16 @@ static void set_scols_data(struct blkdev_cxt *cxt, int col, int id, struct libsc
 		if (cxt->uuid)
 			str = xstrdup(cxt->uuid);
 		break;
+	case COL_PTUUID:
+		probe_device(cxt);
+		if (cxt->ptuuid)
+			str = xstrdup(cxt->ptuuid);
+		break;
+	case COL_PTTYPE:
+		probe_device(cxt);
+		if (cxt->pttype)
+			str = xstrdup(cxt->pttype);
+		break;
 	case COL_PARTTYPE:
 		probe_device(cxt);
 		if (cxt->parttype)
Signature · 1 line
2.17.1
maintainer Applied
#1 lore raw
Quoted 2 lines · Milan Broz

This patch adds PTUUID and PTTYPE fields to lsblk, that are corresponding fields to ID_PART_TABLE_UUID and ID_PART_TABLE_TYPE in udev database.

Applied, thanks!

misc-utils/lsblk.c static struct colinfo infos[] = { · line 177

Quoted 1 line
misc-utils/lsblk.c +1 -0
+	[COL_PTUUID] = { "PTUUID",  36,  0, N_("partition table UUID") },

description change to "partition table identifier (usually UUID)" because for MBR it is not regular UUID

 # lsblk -s -o +PTTYPE,PTUUID /dev/sdb
 NAME MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT PTTYPE PTUUID
 sdb    8:16   0 74.5G  0 disk            dos    83e7bd0f

Karel

Signature · 2 lines
 Karel Zak  <[email protected]>
 http://karelzak.blogspot.com