From: Karel Zak Date: Thu, 18 Nov 2021 13:31:38 +0000 (+0100) Subject: findmnt: make sure all entries are in tree output X-Git-Tag: v2.38-rc1~159 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=2a83759765aeedf41d6a053150bf6c3873491b80;p=thirdparty%2Futil-linux.git findmnt: make sure all entries are in tree output For example /proc/self/mountinfo when mounted in chroot environment does not contain all nodes and parent-child relation is not always possible to create. Signed-off-by: Karel Zak --- diff --git a/misc-utils/findmnt.c b/misc-utils/findmnt.c index eebe95e834..d4fdd6de84 100644 --- a/misc-utils/findmnt.c +++ b/misc-utils/findmnt.c @@ -759,13 +759,14 @@ static int create_treenode(struct libscols_table *table, struct libmnt_table *tb struct libmnt_fs *chld = NULL; struct libmnt_iter *itr = NULL; struct libscols_line *line; - int rc = -1; + int rc = -1, first = 0; if (!fs) { /* first call, get root FS */ if (mnt_table_get_root_fs(tb, &fs)) goto leave; parent_line = NULL; + first = 1; } else if ((flags & FL_SUBMOUNTS) && has_line(table, fs)) return 0; @@ -784,11 +785,23 @@ static int create_treenode(struct libscols_table *table, struct libmnt_table *tb /* * add all children to the output table */ - while(mnt_table_next_child_fs(tb, itr, fs, &chld) == 0) { + while (mnt_table_next_child_fs(tb, itr, fs, &chld) == 0) { if (create_treenode(table, tb, chld, line)) goto leave; } rc = 0; + + /* make sure all entries are in the tree */ + if (first && (size_t) mnt_table_get_nents(tb) > + (size_t) scols_table_get_nlines(table)) { + mnt_reset_iter(itr, MNT_ITER_FORWARD); + fs = NULL; + + while (mnt_table_next_fs(tb, itr, &fs) == 0) { + if (!has_line(table, fs)) + create_treenode(table, tb, fs, NULL); + } + } leave: mnt_free_iter(itr); return rc;