]> git.ipfire.org Git - thirdparty/util-linux.git/blobdiff - misc-utils/lsblk-properties.c
docs: update year in libs docs
[thirdparty/util-linux.git] / misc-utils / lsblk-properties.c
index a4fdeb5bd9c4b52a0fef502bb832f2f04f52723e..a1c73bc7d0cd9d5cddbef47b0520597c9a068167 100644 (file)
@@ -9,6 +9,7 @@
 #include "xalloc.h"
 #include "mangle.h"
 #include "path.h"
+#include "nls.h"
 
 #include "lsblk.h"
 
@@ -22,6 +23,7 @@ void lsblk_device_free_properties(struct lsblk_devprop *p)
                return;
 
        free(p->fstype);
+       free(p->fsversion);
        free(p->uuid);
        free(p->ptuuid);
        free(p->pttype);
@@ -87,6 +89,8 @@ static struct lsblk_devprop *get_properties_by_udev(struct lsblk_device *ld)
                }
                if ((data = udev_device_get_property_value(dev, "ID_FS_TYPE")))
                        prop->fstype = xstrdup(data);
+               if ((data = udev_device_get_property_value(dev, "ID_FS_VERSION")))
+                       prop->fsversion = xstrdup(data);
                if ((data = udev_device_get_property_value(dev, "ID_PART_ENTRY_TYPE")))
                        prop->parttype = xstrdup(data);
                if ((data = udev_device_get_property_value(dev, "ID_PART_ENTRY_UUID")))
@@ -196,6 +200,7 @@ static struct lsblk_devprop *get_properties_by_file(struct lsblk_device *ld)
                else if (lookup(buf, "ID_PART_TABLE_UUID", &prop->ptuuid)) ;
                else if (lookup(buf, "ID_PART_TABLE_TYPE", &prop->pttype)) ;
                else if (lookup(buf, "ID_FS_TYPE", &prop->fstype)) ;
+               else if (lookup(buf, "ID_FS_VERSION", &prop->fsversion)) ;
                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)) ;
@@ -265,6 +270,8 @@ static struct lsblk_devprop *get_properties_by_blkid(struct lsblk_device *dev)
                        prop->pttype = xstrdup(data);
                if (!blkid_probe_lookup_value(pr, "LABEL", &data, NULL))
                        prop->label = xstrdup(data);
+               if (!blkid_probe_lookup_value(pr, "VERSION", &data, NULL))
+                       prop->fsversion = xstrdup(data);
                if (!blkid_probe_lookup_value(pr, "PART_ENTRY_TYPE", &data, NULL))
                        prop->parttype = xstrdup(data);
                if (!blkid_probe_lookup_value(pr, "PART_ENTRY_UUID", &data, NULL))
@@ -305,3 +312,66 @@ void lsblk_properties_deinit(void)
        udev_unref(udev);
 #endif
 }
+
+
+
+/*
+ * Partition types
+ */
+struct lsblk_parttype {
+       unsigned int    code;           /* type as number or zero */
+       char            *name;          /* description */
+       char            *typestr;       /* type as string or NULL */
+};
+
+static const struct lsblk_parttype mbr_types[] =
+{
+       #include "pt-mbr-partnames.h"
+};
+
+#define DEF_GUID(_u, _n) \
+       { \
+               .typestr = (_u), \
+               .name = (_n),    \
+       }
+static const struct lsblk_parttype gpt_types[] =
+{
+       #include "pt-gpt-partnames.h"
+};
+
+const char *lsblk_parttype_code_to_string(const char *code, const char *pttype)
+{
+       size_t i;
+
+       if (!code || !pttype)
+               return NULL;
+
+       if (strcmp(pttype, "dos") == 0 || strcmp(pttype, "mbr") == 0) {
+               char *end = NULL;
+               unsigned int xcode;
+
+               errno = 0;
+               xcode = strtol(code, &end, 16);
+
+               if (errno || *end != '\0')
+                       return NULL;
+
+               for (i = 0; i < ARRAY_SIZE(mbr_types); i++) {
+                       const struct lsblk_parttype *t = &mbr_types[i];
+
+                       if (t->name && t->code == xcode)
+                               return t->name;
+               }
+
+       } else if (strcmp(pttype, "gpt") == 0) {
+               for (i = 0; i < ARRAY_SIZE(gpt_types); i++) {
+                       const struct lsblk_parttype *t = &gpt_types[i];
+
+                       if (t->name && t->typestr &&
+                           strcasecmp(code, t->typestr) == 0)
+                               return t->name;
+               }
+       }
+
+       return NULL;
+}