diff options
author | Karel Zak | 2011-05-18 11:57:17 +0200 |
---|---|---|
committer | Karel Zak | 2011-05-18 11:57:17 +0200 |
commit | 90e9fcda3bb3a215f027fc66c1182a18e0746972 (patch) | |
tree | cd10e1fd1fe586cf3d08287c82f30cd7e4edce72 /misc-utils/lsblk.c | |
parent | build-sys: disable lib/ at.c tests building (diff) | |
download | kernel-qcow2-util-linux-90e9fcda3bb3a215f027fc66c1182a18e0746972.tar.gz kernel-qcow2-util-linux-90e9fcda3bb3a215f027fc66c1182a18e0746972.tar.xz kernel-qcow2-util-linux-90e9fcda3bb3a215f027fc66c1182a18e0746972.zip |
lib: [sysfs.c] make sysfs_read_* function more robust
The functions does not modify result if the requested sysfs attribute
does not exist.
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'misc-utils/lsblk.c')
-rw-r--r-- | misc-utils/lsblk.c | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/misc-utils/lsblk.c b/misc-utils/lsblk.c index 02061629e..49be9fd11 100644 --- a/misc-utils/lsblk.c +++ b/misc-utils/lsblk.c @@ -391,8 +391,11 @@ static char *get_type(struct blkdev_cxt *cxt) } else { const char *type = cxt->partition ? "part" : "disk"; + int x = 0; - switch (sysfs_read_int(&cxt->sysfs, "device/type")) { + sysfs_read_int(&cxt->sysfs, "device/type", &x); + + switch (x) { case 0x0c: /* TYPE_RAID */ type = "raid"; break; case 0x01: /* TYPE_TAPE */ @@ -406,7 +409,7 @@ static char *get_type(struct blkdev_cxt *cxt) type = "rbc"; break; } - res = xstrdup(type); + res = xstrdup(type); } for (p = res; p && *p; p++) @@ -619,8 +622,10 @@ static int set_cxt(struct blkdev_cxt *cxt, cxt->maj = major(devno); cxt->min = minor(devno); - cxt->size = sysfs_read_u64(&cxt->sysfs, "size") << 9; - cxt->discard = sysfs_read_int(&cxt->sysfs, "queue/discard_granularity"); + sysfs_read_u64(&cxt->sysfs, "size", &cxt->size); /* in sectors */ + cxt->size <<= 9; /* in bytes */ + + sysfs_read_int(&cxt->sysfs, "queue/discard_granularity", &cxt->discard); /* Ignore devices of zero size */ if (!lsblk->all_devices && cxt->size == 0) |