]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lsblk: reorder functions
authorKarel Zak <kzak@redhat.com>
Tue, 16 Oct 2018 12:37:28 +0000 (14:37 +0200)
committerKarel Zak <kzak@redhat.com>
Fri, 7 Dec 2018 11:32:57 +0000 (12:32 +0100)
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>
misc-utils/lsblk.c

index 1196605325497fe688d88cfb913bea2900bcb5f0..d27c5b00d50e29f91bc7a19d106dc9d049937b63 100644 (file)
@@ -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;