diff options
author | Karel Zak | 2018-10-16 14:37:28 +0200 |
---|---|---|
committer | Karel Zak | 2018-12-07 12:32:57 +0100 |
commit | e15c9e3dc53e64508720634c0fe926d4230e229b (patch) | |
tree | d96be7248e0c0d1fa86648bbd94e3c44a3bfa3d6 /misc-utils | |
parent | lsblk: make process_partitions() more readable (diff) | |
download | kernel-qcow2-util-linux-e15c9e3dc53e64508720634c0fe926d4230e229b.tar.gz kernel-qcow2-util-linux-e15c9e3dc53e64508720634c0fe926d4230e229b.tar.xz kernel-qcow2-util-linux-e15c9e3dc53e64508720634c0fe926d4230e229b.zip |
lsblk: reorder functions
The goal is to call process_one_device() from process_all_devices(),
so let's it keep in code in the right order.
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'misc-utils')
-rw-r--r-- | misc-utils/lsblk.c | 113 |
1 files changed, 57 insertions, 56 deletions
diff --git a/misc-utils/lsblk.c b/misc-utils/lsblk.c index 119660532..d27c5b00d 100644 --- a/misc-utils/lsblk.c +++ b/misc-utils/lsblk.c @@ -1261,62 +1261,6 @@ static int process_dependencies( /* Iterate devices in sysfs */ -static int process_all_devices(struct lsblk_devtree *tr) -{ - DIR *dir; - struct dirent *d; - struct path_cxt *pc = ul_new_path(_PATH_SYS_BLOCK); - - if (!pc) - err(EXIT_FAILURE, _("failed to allocate /sys handler")); - - ul_path_set_prefix(pc, lsblk->sysroot); - - /* TODO: reuse @pc in set_device(), etc. */ - dir = ul_path_opendir(pc, NULL); - if (!dir) - goto done; - - DBG(DEV, ul_debug("iterate on " _PATH_SYS_BLOCK "%s", lsblk->inverse ? " [inverse]" : "")); - - while ((d = xreaddir(dir))) { - struct lsblk_device *dev; - - DBG(DEV, ul_debug(" %s dentry", d->d_name)); - - dev = devtree_get_device_or_new(tr, NULL, d->d_name); - if (!dev) - continue; - - /* remove unwanted devices */ - if (is_maj_excluded(dev->maj) || !is_maj_included(dev->maj)) { - DBG(DEV, ul_debug(" %s: ignore (by filter)", d->d_name)); - lsblk_devtree_remove_device(tr, dev); - continue; - } - - /* - * ignore devices in the midle of the tree - */ - if (!lsblk->inverse) { - if (dev->nslaves) { - DBG(DEV, ul_debug(" %s: ignore (in-middle)", d->d_name)); - continue; - } - lsblk_devtree_add_root(tr, dev); - process_dependencies(tr, dev, 1); - } else { - /* not implemented yet */ - ; - } - } - - closedir(dir); -done: - ul_unref_path(pc); - DBG(DEV, ul_debug("iterate on " _PATH_SYS_BLOCK " -- done")); - return 0; -} static int process_one_device(struct lsblk_devtree *tr, char *devname) { @@ -1398,6 +1342,63 @@ leave: return rc; } +static int process_all_devices(struct lsblk_devtree *tr) +{ + DIR *dir; + struct dirent *d; + struct path_cxt *pc = ul_new_path(_PATH_SYS_BLOCK); + + if (!pc) + err(EXIT_FAILURE, _("failed to allocate /sys handler")); + + ul_path_set_prefix(pc, lsblk->sysroot); + + /* TODO: reuse @pc in set_device(), etc. */ + dir = ul_path_opendir(pc, NULL); + if (!dir) + goto done; + + DBG(DEV, ul_debug("iterate on " _PATH_SYS_BLOCK "%s", lsblk->inverse ? " [inverse]" : "")); + + while ((d = xreaddir(dir))) { + struct lsblk_device *dev; + + DBG(DEV, ul_debug(" %s dentry", d->d_name)); + + dev = devtree_get_device_or_new(tr, NULL, d->d_name); + if (!dev) + continue; + + /* remove unwanted devices */ + if (is_maj_excluded(dev->maj) || !is_maj_included(dev->maj)) { + DBG(DEV, ul_debug(" %s: ignore (by filter)", d->d_name)); + lsblk_devtree_remove_device(tr, dev); + continue; + } + + /* + * ignore devices in the midle of the tree + */ + if (!lsblk->inverse) { + if (dev->nslaves) { + DBG(DEV, ul_debug(" %s: ignore (in-middle)", d->d_name)); + continue; + } + lsblk_devtree_add_root(tr, dev); + process_dependencies(tr, dev, 1); + } else { + /* not implemented yet */ + ; + } + } + + closedir(dir); +done: + ul_unref_path(pc); + DBG(DEV, ul_debug("iterate on " _PATH_SYS_BLOCK " -- done")); + return 0; +} + static void parse_excludes(const char *str0) { const char *str = str0; |