From: Karel Zak Date: Wed, 25 Oct 2023 10:25:37 +0000 (+0200) Subject: lsblk: ignore duplicate lines for counters X-Git-Tag: v2.40-rc1~151^2~33 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=7de6a8a91448c9bffdd3370a9884d6c4771de4f3;p=thirdparty%2Futil-linux.git lsblk: ignore duplicate lines for counters Signed-off-by: Karel Zak --- diff --git a/misc-utils/lsblk.c b/misc-utils/lsblk.c index 164e38291c..1810df7714 100644 --- a/misc-utils/lsblk.c +++ b/misc-utils/lsblk.c @@ -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);