From: Karel Zak Date: Mon, 5 Sep 2022 07:01:42 +0000 (+0200) Subject: lsblk: add PARTN column X-Git-Tag: v2.39-rc1~534 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=e4ed8665e159229f5ae79dc16a041ba18e9d9428;p=thirdparty%2Futil-linux.git lsblk: add PARTN column Add PARTN column, the source for this column is ID_PART_ENTRY_NUMBER from udev db, the original source of this information comes from libblkid. There is also another PARTN in udevdb, but it's based on data from kernel uevent. Fixes: https://github.com/util-linux/util-linux/issues/1787 Signed-off-by: Karel Zak --- diff --git a/misc-utils/lsblk-properties.c b/misc-utils/lsblk-properties.c index f1bbf9a583..8acaad7a81 100644 --- a/misc-utils/lsblk-properties.c +++ b/misc-utils/lsblk-properties.c @@ -32,6 +32,7 @@ void lsblk_device_free_properties(struct lsblk_devprop *p) free(p->parttype); free(p->partuuid); free(p->partlabel); + free(p->partn); free(p->wwn); free(p->serial); free(p->model); @@ -106,6 +107,8 @@ static struct lsblk_devprop *get_properties_by_udev(struct lsblk_device *ld) prop->parttype = xstrdup(data); if ((data = udev_device_get_property_value(dev, "ID_PART_ENTRY_UUID"))) prop->partuuid = xstrdup(data); + if ((data = udev_device_get_property_value(dev, "ID_PART_ENTRY_NUMBER"))) + prop->partn = xstrdup(data); if ((data = udev_device_get_property_value(dev, "ID_PART_ENTRY_FLAGS"))) prop->partflags = xstrdup(data); @@ -243,6 +246,7 @@ static struct lsblk_devprop *get_properties_by_file(struct lsblk_device *ld) else if (lookup(buf, "ID_PART_ENTRY_TYPE", &prop->parttype)) ; else if (lookup(buf, "ID_PART_ENTRY_UUID", &prop->partuuid)) ; else if (lookup(buf, "ID_PART_ENTRY_FLAGS", &prop->partflags)) ; + else if (lookup(buf, "ID_PART_ENTRY_NUMBER", &prop->partn)) ; else if (lookup(buf, "ID_MODEL", &prop->model)) ; else if (lookup(buf, "ID_WWN_WITH_EXTENSION", &prop->wwn)) ; else if (lookup(buf, "ID_WWN", &prop->wwn)) ; @@ -321,6 +325,8 @@ static struct lsblk_devprop *get_properties_by_blkid(struct lsblk_device *dev) prop->partlabel = xstrdup(data); if (!blkid_probe_lookup_value(pr, "PART_ENTRY_FLAGS", &data, NULL)) prop->partflags = xstrdup(data); + if (!blkid_probe_lookup_value(pr, "PART_ENTRY_NUMBER", &data, NULL)) + prop->partn = xstrdup(data); DBG(DEV, ul_debugobj(dev, "%s: found blkid properties", dev->name)); } diff --git a/misc-utils/lsblk.c b/misc-utils/lsblk.c index 9873922187..655463e418 100644 --- a/misc-utils/lsblk.c +++ b/misc-utils/lsblk.c @@ -97,6 +97,7 @@ enum { COL_OWNER, COL_PARTFLAGS, COL_PARTLABEL, + COL_PARTN, COL_PARTTYPE, COL_PARTTYPENAME, COL_PARTUUID, @@ -198,6 +199,7 @@ static struct colinfo infos[] = { [COL_OWNER] = { "OWNER", 0.1, SCOLS_FL_TRUNC, N_("user name"), }, [COL_PARTFLAGS] = { "PARTFLAGS", 36, 0, N_("partition flags") }, [COL_PARTLABEL] = { "PARTLABEL", 0.1, 0, N_("partition LABEL") }, + [COL_PARTN] = { "PARTN", 2, SCOLS_FL_RIGHT, N_("partition number as read from the partition table"), COLTYPE_NUM }, [COL_PARTTYPENAME] = { "PARTTYPENAME", 0.1, 0, N_("partition type name") }, [COL_PARTTYPE] = { "PARTTYPE", 36, 0, N_("partition type code or UUID") }, [COL_PARTUUID] = { "PARTUUID", 36, 0, N_("partition UUID") }, @@ -949,6 +951,11 @@ static char *device_get_data( if (prop && prop->partflags) str = xstrdup(prop->partflags); break; + case COL_PARTN: + prop = lsblk_device_get_properties(dev); + if (prop && prop->partn) + str = xstrdup(prop->partn); + break; case COL_WWN: prop = lsblk_device_get_properties(dev); if (prop && prop->wwn) diff --git a/misc-utils/lsblk.h b/misc-utils/lsblk.h index 31c9ecad5d..c00723f1ae 100644 --- a/misc-utils/lsblk.h +++ b/misc-utils/lsblk.h @@ -74,6 +74,7 @@ struct lsblk_devprop { char *partuuid; /* partition UUID */ char *partlabel; /* partition label */ char *partflags; /* partition flags */ + char *partn; /* partition number */ char *wwn; /* storage WWN */ char *serial; /* disk serial number */ char *model; /* disk model */