]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
findmnt: add match_by_file to do within-device matching
authorDave Reisner <dreisner@archlinux.org>
Thu, 26 Apr 2012 00:30:52 +0000 (20:30 -0400)
committerKarel Zak <kzak@redhat.com>
Thu, 26 Apr 2012 07:38:07 +0000 (09:38 +0200)
Use the newly exported mnt_get_mountpoint to determine the device that a
given file resides on, in case the supplied source or target is not
explicitly a mount point.

http://www.spinics.net/lists/util-linux-ng/msg06081.html

Signed-off-by: Dave Reisner <dreisner@archlinux.org>
misc-utils/findmnt.c

index cc71a6028e8d6090e67a3d3d16ddf915d457e887..9db167f511de8f7edefe4d13ffd7e2caa265c568 100644 (file)
@@ -661,6 +661,30 @@ static int tab_is_tree(struct libmnt_table *tb)
        return rc;
 }
 
+static int match_by_file(const char *name, struct libmnt_fs *fs,
+               int (*match_fn)(struct libmnt_fs*, const char*, struct libmnt_cache*))
+{
+       char *resolved, *mountpoint;
+       int match;
+
+       /* match exactly by name */
+       if (match_fn(fs, name, cache))
+               return 1;
+
+       /* maybe its a file within a mountpoint */
+       resolved = mnt_resolve_path(name, cache);
+       if (resolved) {
+               mountpoint = mnt_get_mountpoint(resolved);
+               if (mountpoint) {
+                       match = match_fn(fs, mountpoint, cache);
+                       free(mountpoint);
+                       return match;
+               }
+       }
+
+       return 0;
+}
+
 /* filter function for libmount (mnt_table_find_next_fs()) */
 static int match_func(struct libmnt_fs *fs,
                      void *data __attribute__ ((__unused__)))
@@ -670,11 +694,11 @@ static int match_func(struct libmnt_fs *fs,
        void *md;
 
        m = get_match(COL_TARGET);
-       if (m && !mnt_fs_match_target(fs, m, cache))
+       if (m && !match_by_file(m, fs, mnt_fs_match_target))
                return rc;
 
        m = get_match(COL_SOURCE);
-       if (m && !mnt_fs_match_source(fs, m, cache))
+       if (m && !match_by_file(m, fs, mnt_fs_match_source))
                return rc;
 
        m = get_match(COL_FSTYPE);