diff options
author | Karel Zak | 2011-05-18 12:17:43 +0200 |
---|---|---|
committer | Karel Zak | 2011-05-18 12:17:43 +0200 |
commit | 9cfe1b9c6a8663263b1ff2ee45450cf38af707bd (patch) | |
tree | 0f34e61a7657c1545250c43a38b8bc5a5b28f3d9 /misc-utils/lsblk.c | |
parent | lib: [sysfs.c] make sysfs_read_* function more robust (diff) | |
download | kernel-qcow2-util-linux-9cfe1b9c6a8663263b1ff2ee45450cf38af707bd.tar.gz kernel-qcow2-util-linux-9cfe1b9c6a8663263b1ff2ee45450cf38af707bd.tar.xz kernel-qcow2-util-linux-9cfe1b9c6a8663263b1ff2ee45450cf38af707bd.zip |
lsblk: use sysfs_read_u64() rather than sysfs_strdup() + atol()
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'misc-utils/lsblk.c')
-rw-r--r-- | misc-utils/lsblk.c | 26 |
1 files 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; |