#include "xalloc.h"
#include "mangle.h"
#include "path.h"
+#include "nls.h"
#include "lsblk.h"
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;
+}
COL_PTUUID,
COL_PTTYPE,
COL_PARTTYPE,
+ COL_PARTTYPENAME,
COL_PARTLABEL,
COL_PARTUUID,
COL_PARTFLAGS,
[COL_PTUUID] = { "PTUUID", 36, 0, N_("partition table identifier (usually UUID)") },
[COL_PTTYPE] = { "PTTYPE", 0.1, 0, N_("partition table type") },
- [COL_PARTTYPE] = { "PARTTYPE", 36, 0, N_("partition type UUID") },
+ [COL_PARTTYPE] = { "PARTTYPE", 36, 0, N_("partition type code or UUID") },
+ [COL_PARTTYPENAME] = { "PARTTYPENAME", 0.1, 0, N_("partition type name") },
[COL_PARTLABEL] = { "PARTLABEL", 0.1, 0, N_("partition LABEL") },
[COL_PARTUUID] = { "PARTUUID", 36, 0, N_("partition UUID") },
[COL_PARTFLAGS] = { "PARTFLAGS", 36, 0, N_("partition flags") },
if (prop && prop->parttype)
str = xstrdup(prop->parttype);
break;
+ case COL_PARTTYPENAME:
+ prop = lsblk_device_get_properties(dev);
+ if (prop && prop->parttype && prop->pttype) {
+ const char *x = lsblk_parttype_code_to_string(
+ prop->parttype, prop->pttype);
+ if (x)
+ str = xstrdup(x);
+ }
+ break;
case COL_PARTLABEL:
prop = lsblk_device_get_properties(dev);
if (prop && prop->partlabel)
extern struct lsblk_devprop *lsblk_device_get_properties(struct lsblk_device *dev);
extern void lsblk_properties_deinit(void);
+extern const char *lsblk_parttype_code_to_string(const char *code, const char *pttype);
+
/* lsblk-devtree.c */
void lsblk_reset_iter(struct lsblk_iter *itr, int direction);
struct lsblk_device *lsblk_new_device(void);