]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
findmnt: don't parse mountinfo twice
authorKarel Zak <kzak@redhat.com>
Thu, 12 Feb 2015 11:57:03 +0000 (12:57 +0100)
committerKarel Zak <kzak@redhat.com>
Thu, 12 Feb 2015 11:57:03 +0000 (12:57 +0100)
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>
misc-utils/findmnt.c

index 423d384221b32a71f071e721ef1a4eef922d6d05..9685123552410eada1ae5bd14eae0a8e2e0204c1 100644 (file)
@@ -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;