[PATCH] lsblk: use Y/N instead of 0/1

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Davidlohr Bueso <dave@xxxxxxx>

This notation is a little more user friendly and applies to information about removable, readonly and rotational devices

Signed-off-by: Davidlohr Bueso <dave@xxxxxxx>
---
 misc-utils/lsblk.c |   47 ++++++++++++++++++++++++++++++++++++++---------
 1 files changed, 38 insertions(+), 9 deletions(-)

diff --git a/misc-utils/lsblk.c b/misc-utils/lsblk.c
index 6c5a205..a8c29a6 100644
--- a/misc-utils/lsblk.c
+++ b/misc-utils/lsblk.c
@@ -504,6 +504,24 @@ static void probe_device(struct blkdev_cxt *cxt)
 	return;
 }
 
+static int is_removable_device(struct blkdev_cxt *cxt)
+{
+	char *str = NULL;
+	int ret = 0;
+
+	str = sysfs_strdup(cxt, "removable");
+
+	if (!str && cxt->parent)
+		str = sysfs_strdup(cxt->parent, "removable");
+
+	if (str) {
+		ret = atoi(str);
+		free(str);
+	}
+
+	return ret;
+}
+
 static int is_readonly_device(struct blkdev_cxt *cxt)
 {
 	int fd, ro = 0;
@@ -520,6 +538,21 @@ static int is_readonly_device(struct blkdev_cxt *cxt)
 	return ro;
 }
 
+static int is_rotational_device(struct blkdev_cxt *cxt)
+{
+	char *str = NULL;
+	int ret = 0;
+
+	str = sysfs_strdup(cxt, "queue/rotational");
+	if (str) {
+		ret = atoi(str);
+		free(str);
+	}
+
+	return ret;
+}
+
+
 static char *get_scheduler(struct blkdev_cxt *cxt)
 {
 	char *str = sysfs_strdup(cxt, "queue/scheduler");
@@ -613,19 +646,15 @@ static void set_tt_data(struct blkdev_cxt *cxt, int col, int id, struct tt_line
 		break;
 	case COL_RO:
 		tt_line_set_data(ln, col, is_readonly_device(cxt) ?
-					xstrdup("1") : xstrdup("0"));
+					xstrdup("Y") : xstrdup("N"));
 		break;
 	case COL_RA:
-		p = sysfs_strdup(cxt, "removable");
-		if (!p && cxt->parent)
-			p = sysfs_strdup(cxt->parent, "removable");
-		if (p)
-			tt_line_set_data(ln, col, p);
+		tt_line_set_data(ln, col, is_removable_device(cxt) ?
+					xstrdup("Y") : xstrdup("N"));	
 		break;
 	case COL_ROTA:
-		p = sysfs_strdup(cxt, "queue/rotational");
-		if (p)
-			tt_line_set_data(ln, col, p);
+		tt_line_set_data(ln, col, is_rotational_device(cxt) ?
+					xstrdup("Y") : xstrdup("N"));	
 		break;
 	case COL_MODEL:
 		if (!cxt->partition && cxt->nslaves == 0) {
-- 
1.7.1



--
To unsubscribe from this list: send the line "unsubscribe util-linux-ng" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux