From: Karel Zak Date: Thu, 12 Feb 2015 11:57:03 +0000 (+0100) Subject: findmnt: don't parse mountinfo twice X-Git-Tag: v2.26~32 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9c277ede65c45c1e5bc00a10c965bfaea8e2929d;p=thirdparty%2Futil-linux.git findmnt: don't parse mountinfo twice We parse /proc/self/mountinfo to initialize cache targets, this step is unnecessary if --mtab reads all from kernel. Signed-off-by: Karel Zak --- diff --git a/misc-utils/findmnt.c b/misc-utils/findmnt.c index 423d384221..9685123552 100644 --- a/misc-utils/findmnt.c +++ b/misc-utils/findmnt.c @@ -900,6 +900,26 @@ static int tab_is_tree(struct libmnt_table *tb) return rc; } +/* checks if all fs in @tb are from kernel */ +static int tab_is_kernel(struct libmnt_table *tb) +{ + struct libmnt_fs *fs = NULL; + struct libmnt_iter *itr = NULL; + + itr = mnt_new_iter(MNT_ITER_BACKWARD); + if (!itr) + return 0; + + while (mnt_table_next_fs(tb, itr, &fs) == 0) { + if (!mnt_fs_is_kernel(fs)) { + mnt_free_iter(itr); + return 0; + } + } + + mnt_free_iter(itr); + return 1; +} /* filter function for libmount (mnt_table_find_next_fs()) */ static int match_func(struct libmnt_fs *fs, @@ -1510,6 +1530,9 @@ int main(int argc, char *argv[]) if (!tb) goto leave; + if (tabtype == TABTYPE_MTAB && tab_is_kernel(tb)) + tabtype = TABTYPE_KERNEL; + if ((flags & FL_TREE) && (ntabfiles > 1 || !tab_is_tree(tb))) flags &= ~FL_TREE;