diff options
author | Karel Zak | 2018-05-16 13:20:39 +0200 |
---|---|---|
committer | Karel Zak | 2018-06-21 13:07:46 +0200 |
commit | 708a58b665a2157c4d6f9057246a1531ae3ae33a (patch) | |
tree | dc0f36e29bdf9df025f5d97dc851845ec175cdd2 /libblkid | |
parent | lib/sysfs: add sysfs_blkdev_get_parent() (diff) | |
download | kernel-qcow2-util-linux-708a58b665a2157c4d6f9057246a1531ae3ae33a.tar.gz kernel-qcow2-util-linux-708a58b665a2157c4d6f9057246a1531ae3ae33a.tar.xz kernel-qcow2-util-linux-708a58b665a2157c4d6f9057246a1531ae3ae33a.zip |
libblkid: use new ul_path_* API
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'libblkid')
-rw-r--r-- | libblkid/src/devname.c | 13 | ||||
-rw-r--r-- | libblkid/src/partitions/partitions.c | 20 | ||||
-rw-r--r-- | libblkid/src/topology/sysfs.c | 60 |
3 files changed, 51 insertions, 42 deletions
diff --git a/libblkid/src/devname.c b/libblkid/src/devname.c index 59029ec06..986bcf241 100644 --- a/libblkid/src/devname.c +++ b/libblkid/src/devname.c @@ -565,6 +565,7 @@ static int probe_all(blkid_cache cache, int only_if_new) */ static int probe_all_removable(blkid_cache cache) { + struct path_cxt *pc; DIR *dir; struct dirent *d; @@ -575,8 +576,9 @@ static int probe_all_removable(blkid_cache cache) if (!dir) return -BLKID_ERR_PROC; + pc = ul_new_path(NULL); + while((d = readdir(dir))) { - struct sysfs_cxt sysfs = UL_SYSFSCXT_EMPTY; int removable = 0; dev_t devno; @@ -589,20 +591,19 @@ static int probe_all_removable(blkid_cache cache) ((d->d_name[1] == '.') && (d->d_name[2] == 0)))) continue; - devno = sysfs_devname_to_devno(d->d_name, NULL); + devno = sysfs_devname_to_devno(d->d_name); if (!devno) continue; - if (sysfs_init(&sysfs, devno, NULL) == 0) { - if (sysfs_read_int(&sysfs, "removable", &removable) != 0) + if (sysfs_blkdev_init_path(pc, devno, NULL) == 0 + && ul_path_read_s32(pc, &removable, "removable") != 0) removable = 0; - sysfs_deinit(&sysfs); - } if (removable) probe_one(cache, d->d_name, devno, 0, 0, 1); } + ul_unref_path(pc); closedir(dir); return 0; } diff --git a/libblkid/src/partitions/partitions.c b/libblkid/src/partitions/partitions.c index 83c3c4f1b..f60f3c653 100644 --- a/libblkid/src/partitions/partitions.c +++ b/libblkid/src/partitions/partitions.c @@ -1008,26 +1008,30 @@ blkid_partition blkid_partlist_get_partition_by_partno(blkid_partlist ls, int n) */ blkid_partition blkid_partlist_devno_to_partition(blkid_partlist ls, dev_t devno) { - struct sysfs_cxt sysfs; + struct path_cxt *pc; uint64_t start, size; int i, rc, partno = 0; DBG(LOWPROBE, ul_debug("trying to convert devno 0x%llx to partition", (long long) devno)); - if (sysfs_init(&sysfs, devno, NULL)) { + + pc = ul_new_sysfs_path(devno, NULL, NULL); + if (!pc) { DBG(LOWPROBE, ul_debug("failed t init sysfs context")); return NULL; } - rc = sysfs_read_u64(&sysfs, "size", &size); + rc = ul_path_read_u64(pc, &size, "size"); if (!rc) { - rc = sysfs_read_u64(&sysfs, "start", &start); + rc = ul_path_read_u64(pc, &start, "start"); if (rc) { /* try to get partition number from DM uuid. */ - char *uuid = sysfs_strdup(&sysfs, "dm/uuid"); - char *tmp = uuid; - char *prefix = uuid ? strsep(&tmp, "-") : NULL; + char *uuid = NULL, *tmp, *prefix; + + ul_path_read_string(pc, &uuid, "dm/uuid"); + tmp = uuid; + prefix = uuid ? strsep(&tmp, "-") : NULL; if (prefix && strncasecmp(prefix, "part", 4) == 0) { char *end = NULL; @@ -1042,7 +1046,7 @@ blkid_partition blkid_partlist_devno_to_partition(blkid_partlist ls, dev_t devno } } - sysfs_deinit(&sysfs); + ul_unref_path(pc); if (rc) return NULL; diff --git a/libblkid/src/topology/sysfs.c b/libblkid/src/topology/sysfs.c index 710e4b676..0605c3558 100644 --- a/libblkid/src/topology/sysfs.c +++ b/libblkid/src/topology/sysfs.c @@ -42,55 +42,61 @@ static struct topology_val { static int probe_sysfs_tp(blkid_probe pr, const struct blkid_idmag *mag __attribute__((__unused__))) { - dev_t dev, disk = 0; - int rc; - struct sysfs_cxt sysfs = UL_SYSFSCXT_EMPTY, - parent = UL_SYSFSCXT_EMPTY; + dev_t dev; + int rc, set_parent = 1; + struct path_cxt *pc; size_t i, count = 0; dev = blkid_probe_get_devno(pr); - if (!dev || sysfs_init(&sysfs, dev, NULL) != 0) + if (!dev) + return 1; + pc = ul_new_sysfs_path(dev, NULL, NULL); + if (!pc) return 1; rc = 1; /* nothing (default) */ for (i = 0; i < ARRAY_SIZE(topology_vals); i++) { struct topology_val *val = &topology_vals[i]; - int ok = sysfs_has_attribute(&sysfs, val->attr); + int ok = ul_path_access(pc, F_OK, val->attr) == 0; rc = 1; /* nothing */ - if (!ok) { - if (!disk) { - /* - * Read attributes from "disk" if the current - * device is a partition. - */ - disk = blkid_probe_get_wholedisk_devno(pr); - if (disk && disk != dev) { - if (sysfs_init(&parent, disk, NULL) != 0) - goto done; - - sysfs.parent = &parent; - ok = sysfs_has_attribute(&sysfs, - val->attr); - } + if (!ok && set_parent) { + dev_t disk = blkid_probe_get_wholedisk_devno(pr); + set_parent = 0; + + /* + * Read attributes from "disk" if the current device is + * a partition. Note that sysfs ul_path_* API is able + * to redirect requests to attributes if parent is set. + */ + if (disk && disk != dev) { + struct path_cxt *parent = ul_new_sysfs_path(disk, NULL, NULL); + if (!parent) + goto done; + + sysfs_blkdev_set_parent(pc, parent); + ul_unref_path(parent); + + /* try it again */ + ok = ul_path_access(pc, F_OK, val->attr) == 0; } - if (!ok) - continue; /* attribute does not exist */ } + if (!ok) + continue; /* attribute does not exist */ if (val->set_ulong) { uint64_t data; - if (sysfs_read_u64(&sysfs, val->attr, &data) != 0) + if (ul_path_read_u64(pc, &data, val->attr) != 0) continue; rc = val->set_ulong(pr, (unsigned long) data); } else if (val->set_int) { int64_t data; - if (sysfs_read_s64(&sysfs, val->attr, &data) != 0) + if (ul_path_read_s64(pc, &data, val->attr) != 0) continue; rc = val->set_int(pr, (int) data); } @@ -102,9 +108,7 @@ static int probe_sysfs_tp(blkid_probe pr, } done: - sysfs_deinit(&sysfs); - sysfs_deinit(&parent); - + ul_unref_path(pc); /* unref pc and parent */ if (count) return 0; /* success */ return rc; /* error or nothing */ |