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 /shlibs/blkid/src | |
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 'shlibs/blkid/src')
-rw-r--r-- | shlibs/blkid/src/devname.c | 4 | ||||
-rw-r--r-- | shlibs/blkid/src/partitions/partitions.c | 10 | ||||
-rw-r--r-- | shlibs/blkid/src/topology/sysfs.c | 10 |
3 files changed, 17 insertions, 7 deletions
diff --git a/shlibs/blkid/src/devname.c b/shlibs/blkid/src/devname.c index 81eac9aa3..2ed85cdbd 100644 --- a/shlibs/blkid/src/devname.c +++ b/shlibs/blkid/src/devname.c @@ -555,7 +555,7 @@ static int probe_all_removable(blkid_cache cache) while((d = readdir(dir))) { struct sysfs_cxt sysfs; - int removable; + int removable = 0; dev_t devno; #ifdef _DIRENT_HAVE_D_TYPE @@ -572,7 +572,7 @@ static int probe_all_removable(blkid_cache cache) continue; sysfs_init(&sysfs, devno, NULL); - removable = sysfs_read_int(&sysfs, "removable"); + sysfs_read_int(&sysfs, "removable", &removable); sysfs_deinit(&sysfs); if (removable) diff --git a/shlibs/blkid/src/partitions/partitions.c b/shlibs/blkid/src/partitions/partitions.c index 2ac297a1c..060461d27 100644 --- a/shlibs/blkid/src/partitions/partitions.c +++ b/shlibs/blkid/src/partitions/partitions.c @@ -892,16 +892,20 @@ blkid_partition blkid_partlist_devno_to_partition(blkid_partlist ls, dev_t devno { struct sysfs_cxt sysfs; uint64_t start, size; - int i; + int i, rc; if (sysfs_init(&sysfs, devno, NULL)) return NULL; - start = sysfs_read_u64(&sysfs, "start"); - size = sysfs_read_u64(&sysfs, "size"); + rc = sysfs_read_u64(&sysfs, "start", &start); + if (!rc) + rc = sysfs_read_u64(&sysfs, "size", &size); sysfs_deinit(&sysfs); + if (rc) + return NULL; + for (i = 0; i < ls->nparts; i++) { blkid_partition par = &ls->parts[i]; diff --git a/shlibs/blkid/src/topology/sysfs.c b/shlibs/blkid/src/topology/sysfs.c index d5169d02a..fccd58f4d 100644 --- a/shlibs/blkid/src/topology/sysfs.c +++ b/shlibs/blkid/src/topology/sysfs.c @@ -78,11 +78,17 @@ static int probe_sysfs_tp(blkid_probe pr, const struct blkid_idmag *mag) } if (val->set_ulong) { - uint64_t data = sysfs_read_u64(&sysfs, val->attr); + uint64_t data; + + if (sysfs_read_u64(&sysfs, val->attr, &data) != 0) + continue; rc = val->set_ulong(pr, (unsigned long) data); } else if (val->set_int) { - int64_t data = sysfs_read_s64(&sysfs, val->attr); + int64_t data; + + if (sysfs_read_s64(&sysfs, val->attr, &data) != 0) + continue; rc = val->set_int(pr, (int) data); } |