diff options
author | Karel Zak <kzak@redhat.com> | 2015-02-12 12:57:03 +0100 |
---|---|---|
committer | Karel Zak <kzak@redhat.com> | 2015-02-12 12:57:03 +0100 |
commit | 9c277ede65c45c1e5bc00a10c965bfaea8e2929d (patch) | |
tree | 126a05ce57702802017275bdc303b9f45a8361b0 | |
parent | 4597b69249be90c248de0f4a3270901c4762f4a9 (diff) | |
download | util-linux-playground-9c277ede65c45c1e5bc00a10c965bfaea8e2929d.tar.gz |
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 <kzak@redhat.com>
-rw-r--r-- | misc-utils/findmnt.c | 23 |
1 files changed, 23 insertions, 0 deletions
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; |