aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--misc-utils/Makefile.am1
-rw-r--r--misc-utils/lsblk.83
-rw-r--r--misc-utils/lsblk.c50
3 files changed, 15 insertions, 39 deletions
diff --git a/misc-utils/Makefile.am b/misc-utils/Makefile.am
index 80975cbf6b..51f20cab9c 100644
--- a/misc-utils/Makefile.am
+++ b/misc-utils/Makefile.am
@@ -60,6 +60,7 @@ lsblk_SOURCES = \
$(top_srcdir)/lib/at.c \
$(top_srcdir)/lib/canonicalize.c \
$(top_srcdir)/lib/mbsalign.c \
+ $(top_srcdir)/lib/mangle.c \
$(top_srcdir)/lib/strutils.c \
$(top_srcdir)/lib/sysfs.c \
$(top_srcdir)/lib/tt.c
diff --git a/misc-utils/lsblk.8 b/misc-utils/lsblk.8
index a525d2f572..21d58382ef 100644
--- a/misc-utils/lsblk.8
+++ b/misc-utils/lsblk.8
@@ -56,7 +56,8 @@ to get a list of all supported columns.
.IP "\fB\-P, \-\-pairs\fP"
Use key="value" output format. All potentially unsafe characters are hex-escaped (\\x<code>).
.IP "\fB\-r, \-\-raw\fP"
-Use the raw output format. All potentially unsafe characters are hex-escaped (\\x<code>).
+Use the raw output format. All potentially unsafe characters are hex-escaped
+(\\x<code>) in NAME, KNAME, LABEL, PARTLABEL and MOUNTPOINT columns.
.IP "\fB\-s, \-\-inverse\fP"
Print dependencies in inverse order.
.IP "\fB\-t, \-\-topology\fP"
diff --git a/misc-utils/lsblk.c b/misc-utils/lsblk.c
index bac4230e15..e3779ba0a4 100644
--- a/misc-utils/lsblk.c
+++ b/misc-utils/lsblk.c
@@ -59,6 +59,7 @@
#include "at.h"
#include "sysfs.h"
#include "closestream.h"
+#include "mangle.h"
/* column IDs */
enum {
@@ -367,16 +368,20 @@ static int probe_device_by_udev(struct blkdev_cxt *cxt)
if (dev) {
const char *data;
- if ((data = udev_device_get_property_value(dev, "ID_FS_LABEL")))
+ if ((data = udev_device_get_property_value(dev, "ID_FS_LABEL"))) {
cxt->label = xstrdup(data);
+ unhexmangle_string(cxt->label);
+ }
if ((data = udev_device_get_property_value(dev, "ID_FS_TYPE")))
cxt->fstype = xstrdup(data);
if ((data = udev_device_get_property_value(dev, "ID_FS_UUID")))
cxt->uuid = xstrdup(data);
if ((data = udev_device_get_property_value(dev, "ID_PART_ENTRY_UUID")))
cxt->partuuid = xstrdup(data);
- if ((data = udev_device_get_property_value(dev, "ID_PART_ENTRY_NAME")))
+ if ((data = udev_device_get_property_value(dev, "ID_PART_ENTRY_NAME"))) {
cxt->partlabel = xstrdup(data);
+ unhexmangle_string(cxt->partlabel);
+ }
udev_device_unref(dev);
}
@@ -535,26 +540,6 @@ static char *get_type(struct blkdev_cxt *cxt)
#define is_parsable(_l) (((_l)->tt->flags & TT_FL_RAW) || \
((_l)->tt->flags & TT_FL_EXPORT))
-static char *encode_str(const char *str)
-{
- size_t sz;
- char *enc = NULL;
-
- if (!str)
- goto err;
-
- sz = strlen(str) * 4 + 1;
- enc = xmalloc(sz);
-
- if (blkid_encode_string(str, enc, sz) != 0)
- goto err;
-
- return enc;
-err:
- free(enc);
- return xstrdup("");
-}
-
static void set_tt_data(struct blkdev_cxt *cxt, int col, int id, struct tt_line *ln)
{
char buf[1024];
@@ -569,8 +554,7 @@ static void set_tt_data(struct blkdev_cxt *cxt, int col, int id, struct tt_line
case COL_NAME:
if (cxt->dm_name) {
if (is_parsable(lsblk))
- tt_line_set_data(ln, col,
- encode_str(cxt->dm_name));
+ tt_line_set_data(ln, col, cxt->dm_name);
else {
snprintf(buf, sizeof(buf), "%s (%s)",
cxt->dm_name, cxt->name);
@@ -579,10 +563,7 @@ static void set_tt_data(struct blkdev_cxt *cxt, int col, int id, struct tt_line
break;
}
case COL_KNAME:
- if (is_parsable(lsblk))
- tt_line_set_data(ln, col, encode_str(cxt->name));
- else
- tt_line_set_data(ln, col, xstrdup(cxt->name));
+ tt_line_set_data(ln, col, xstrdup(cxt->name));
break;
case COL_OWNER:
{
@@ -622,8 +603,7 @@ static void set_tt_data(struct blkdev_cxt *cxt, int col, int id, struct tt_line
break;
case COL_TARGET:
if (!(cxt->nholders + cxt->npartitions)) {
- p = get_device_mountpoint(cxt);
- if (p)
+ if ((p = get_device_mountpoint(cxt)))
tt_line_set_data(ln, col, p);
}
break;
@@ -632,10 +612,7 @@ static void set_tt_data(struct blkdev_cxt *cxt, int col, int id, struct tt_line
if (!cxt->label)
break;
- if (is_parsable(lsblk))
- tt_line_set_data(ln, col, encode_str(cxt->label));
- else
- tt_line_set_data(ln, col, xstrdup(cxt->label));
+ tt_line_set_data(ln, col, xstrdup(cxt->label));
break;
case COL_UUID:
probe_device(cxt);
@@ -647,10 +624,7 @@ static void set_tt_data(struct blkdev_cxt *cxt, int col, int id, struct tt_line
if (!cxt->partlabel)
break;
- if (is_parsable(lsblk))
- tt_line_set_data(ln, col, encode_str(cxt->partlabel));
- else
- tt_line_set_data(ln, col, xstrdup(cxt->partlabel));
+ tt_line_set_data(ln, col, xstrdup(cxt->partlabel));
break;
case COL_PARTUUID:
probe_device(cxt);