diff options
author | Karel Zak | 2012-03-07 14:28:52 +0100 |
---|---|---|
committer | Karel Zak | 2012-03-07 14:28:52 +0100 |
commit | 540d506f717bc340b243c0baaa4e785688e8300f (patch) | |
tree | 2d7cad30496d714723db2f9a073bcf5f565b264a /misc-utils/lsblk.c | |
parent | lsblk: add inverse tree support (-s) (diff) | |
download | kernel-qcow2-util-linux-540d506f717bc340b243c0baaa4e785688e8300f.tar.gz kernel-qcow2-util-linux-540d506f717bc340b243c0baaa4e785688e8300f.tar.xz kernel-qcow2-util-linux-540d506f717bc340b243c0baaa4e785688e8300f.zip |
lsblk: use readlink_at from at.c
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'misc-utils/lsblk.c')
-rw-r--r-- | misc-utils/lsblk.c | 33 |
1 files changed, 24 insertions, 9 deletions
diff --git a/misc-utils/lsblk.c b/misc-utils/lsblk.c index 10627d3c7..2eacc10d2 100644 --- a/misc-utils/lsblk.c +++ b/misc-utils/lsblk.c @@ -47,6 +47,7 @@ #include <assert.h> +#include "c.h" #include "pathnames.h" #include "blkdev.h" #include "canonicalize.h" @@ -55,7 +56,7 @@ #include "tt.h" #include "xalloc.h" #include "strutils.h" -#include "c.h" +#include "at.h" #include "sysfs.h" /* column IDs */ @@ -826,20 +827,29 @@ static int list_partitions(struct blkdev_cxt *wholedisk_cxt, struct blkdev_cxt * return r; } -static int get_wholedisk_from_partition_dirent(DIR *dir, struct dirent *d, - struct blkdev_cxt *cxt) +static int get_wholedisk_from_partition_dirent(DIR *dir, const char *dirname, + struct dirent *d, struct blkdev_cxt *cxt) { char path[PATH_MAX]; char *p; int len; - if ((len = readlinkat(dirfd(dir), d->d_name, path, sizeof(path))) < 0) + if ((len = readlink_at(dirfd(dir), dirname, + d->d_name, path, sizeof(path))) < 0) return 0; - path[len]='\0'; + + path[len] = '\0'; /* The path ends with ".../<device>/<partition>" */ - p = strrchr(path, '/'); *p = '\0'; - p = strrchr(path, '/'); p++; + p = strrchr(path, '/'); + if (!p) + return 0; + *p = '\0'; + + p = strrchr(path, '/'); + if (!p) + return 0; + p++; return set_cxt(cxt, NULL, NULL, p); } @@ -852,6 +862,8 @@ static int list_deps(struct blkdev_cxt *cxt) DIR *dir; struct dirent *d; struct blkdev_cxt dep = {}; + char dirname[PATH_MAX]; + const char *depname; assert(cxt); @@ -861,14 +873,17 @@ static int list_deps(struct blkdev_cxt *cxt) if (!(lsblk->inverse ? cxt->nslaves : cxt->nholders)) return 0; - dir = sysfs_opendir(&cxt->sysfs, lsblk->inverse ? "slaves" : "holders"); + depname = lsblk->inverse ? "slaves" : "holders"; + dir = sysfs_opendir(&cxt->sysfs, depname); if (!dir) return 0; + snprintf(dirname, sizeof(dirname), "%s/%s", cxt->sysfs.dir_path, depname); + while ((d = xreaddir(dir))) { /* Is the dependency a partition? */ if (sysfs_is_partition_dirent(dir, d, NULL)) { - if (!get_wholedisk_from_partition_dirent(dir, d, &dep)) + if (!get_wholedisk_from_partition_dirent(dir, dirname, d, &dep)) process_blkdev(&dep, cxt, 1, d->d_name); } /* The dependency is a whole device. */ |