From 9cfe1b9c6a8663263b1ff2ee45450cf38af707bd Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Wed, 18 May 2011 12:17:43 +0200 Subject: lsblk: use sysfs_read_u64() rather than sysfs_strdup() + atol() Signed-off-by: Karel Zak --- misc-utils/lsblk.c | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/misc-utils/lsblk.c b/misc-utils/lsblk.c index 49be9fd11..271999fa4 100644 --- a/misc-utils/lsblk.c +++ b/misc-utils/lsblk.c @@ -420,7 +420,7 @@ static char *get_type(struct blkdev_cxt *cxt) static void set_tt_data(struct blkdev_cxt *cxt, int col, int id, struct tt_line *ln) { char buf[1024]; - char *p; + char *p = NULL; if (!cxt->st.st_rdev && (id == COL_OWNER || id == COL_GROUP || id == COL_MODE)) @@ -565,16 +565,28 @@ static void set_tt_data(struct blkdev_cxt *cxt, int col, int id, struct tt_line tt_line_set_data(ln, col, "0"); break; case COL_DGRAN: - p = sysfs_strdup(&cxt->sysfs, "queue/discard_granularity"); - if (!lsblk->bytes) - p = size_to_human_string(atoi(p)); + if (lsblk->bytes) + p = sysfs_strdup(&cxt->sysfs, "queue/discard_granularity"); + else { + uint64_t x; + + if (sysfs_read_u64(&cxt->sysfs, + "queue/discard_granularity", &x) == 0) + p = size_to_human_string(x); + } if (p) tt_line_set_data(ln, col, p); break; case COL_DMAX: - p = sysfs_strdup(&cxt->sysfs, "queue/discard_max_bytes"); - if (!lsblk->bytes) - p = size_to_human_string(atol(p)); + if (lsblk->bytes) + p = sysfs_strdup(&cxt->sysfs, "queue/discard_max_bytes"); + else { + uint64_t x; + + if (sysfs_read_u64(&cxt->sysfs, + "queue/discard_max_bytes", &x) == 0) + p = size_to_human_string(x); + } if (p) tt_line_set_data(ln, col, p); break; -- cgit v1.2.3-55-g7522