]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lsblk: ignore duplicate lines for counters
authorKarel Zak <kzak@redhat.com>
Wed, 25 Oct 2023 10:25:37 +0000 (12:25 +0200)
committerKarel Zak <kzak@redhat.com>
Mon, 20 Nov 2023 21:25:47 +0000 (22:25 +0100)
Signed-off-by: Karel Zak <kzak@redhat.com>
misc-utils/lsblk.c

index 164e38291c22acae0b56488f7de564f3a742393c..1810df7714d77478d8ee81dc0b9f1ca8b5071219 100644 (file)
@@ -1303,7 +1303,7 @@ static void device_to_scols(
        struct libscols_line *ln;
        struct lsblk_iter itr;
        struct lsblk_device *child = NULL;
-       int link_group = 0;
+       int link_group = 0, nocount = 0;
 
 
        DBG(DEV, ul_debugobj(dev, "add '%s' to scols", dev->name));
@@ -1379,6 +1379,10 @@ static void device_to_scols(
                scols_line_link_group(ln, gr, 0);
        }
 
+       /* The same device could be printed more than once, don't use it in counter */
+       if (dev->scols_line)
+               nocount = 1;
+
        dev->scols_line = ln;
 
        if (dev->npartitions == 0)
@@ -1403,8 +1407,10 @@ static void device_to_scols(
        }
 
        /* apply counters */
-       for (i = 0; ln && i < lsblk->ncts; i++)
-               scols_line_apply_filter(ln, lsblk->ct_filters[i], NULL);
+       if (!nocount) {
+               for (i = 0; ln && i < lsblk->ncts; i++)
+                       scols_line_apply_filter(ln, lsblk->ct_filters[i], NULL);
+       }
 
        /* Let's be careful with number of open files */
        ul_path_close_dirfd(dev->sysfs);