summaryrefslogtreecommitdiffstats
path: root/misc-utils/findmnt.c
diff options
context:
space:
mode:
authorKarel Zak2012-04-27 14:06:20 +0200
committerKarel Zak2012-04-27 14:06:20 +0200
commit4bfd4bffb7b2cb8c82d7046a5fd4b861ee5464d8 (patch)
treedbbee15fcde579598318cd6015e04c9b88d08d9b /misc-utils/findmnt.c
parentdocs: fix further typos found by misspellings (diff)
downloadkernel-qcow2-util-linux-4bfd4bffb7b2cb8c82d7046a5fd4b861ee5464d8.tar.gz
kernel-qcow2-util-linux-4bfd4bffb7b2cb8c82d7046a5fd4b861ee5464d8.tar.xz
kernel-qcow2-util-linux-4bfd4bffb7b2cb8c82d7046a5fd4b861ee5464d8.zip
findmnt: restrict within-device matching
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'misc-utils/findmnt.c')
-rw-r--r--misc-utils/findmnt.c61
1 files changed, 35 insertions, 26 deletions
diff --git a/misc-utils/findmnt.c b/misc-utils/findmnt.c
index e053873d6..dc01d94ad 100644
--- a/misc-utils/findmnt.c
+++ b/misc-utils/findmnt.c
@@ -192,6 +192,10 @@ static void set_match_data(int id, void *data)
infos[id].match_data = data;
}
+/*
+ * source match means COL_SOURCE *or* COL_MAJMIN, depends on
+ * data format.
+ */
static void set_source_match(const char *data)
{
int maj, min;
@@ -202,10 +206,31 @@ static void set_source_match(const char *data)
*devno = makedev(maj, min);
set_match(COL_MAJMIN, data);
set_match_data(COL_MAJMIN, (void *) devno);
+ flags |= FL_NOSWAPMATCH;
} else
set_match(COL_SOURCE, data);
}
+static void enable_extra_target_match(void)
+{
+ char *cn = NULL, *mnt = NULL;
+
+ /*
+ * Check if match pattern is mountpoint, if not use the
+ * real mountpoint.
+ */
+ cn = mnt_resolve_path(get_match(COL_TARGET), cache);
+ if (!cn)
+ return;
+
+ mnt = mnt_get_mountpoint(cn);
+ if (!mnt || strcmp(mnt, cn) == 0)
+ return;
+
+ /* replace the current setting with the real mountpoint */
+ set_match(COL_TARGET, mnt);
+}
+
static int is_tabdiff_column(int id)
{
@@ -661,29 +686,6 @@ 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,
@@ -694,11 +696,11 @@ static int match_func(struct libmnt_fs *fs,
void *md;
m = get_match(COL_TARGET);
- if (m && !match_by_file(m, fs, mnt_fs_match_target))
+ if (m && !mnt_fs_match_target(fs, m, cache))
return rc;
m = get_match(COL_SOURCE);
- if (m && !match_by_file(m, fs, mnt_fs_match_source))
+ if (m && !mnt_fs_match_source(fs, m, cache))
return rc;
m = get_match(COL_FSTYPE);
@@ -1221,7 +1223,6 @@ int main(int argc, char *argv[])
if (!tabtype)
tabtype = TABTYPE_KERNEL;
-
if (flags & FL_POLL) {
if (tabtype != TABTYPE_KERNEL)
errx_mutually_exclusive("--{poll,fstab,mtab}");
@@ -1279,6 +1280,14 @@ int main(int argc, char *argv[])
}
mnt_table_set_cache(tb, cache);
+ if (tabtype == TABTYPE_KERNEL
+ && (flags & FL_NOSWAPMATCH)
+ && get_match(COL_TARGET))
+ /*
+ * enable extra functionality for target match
+ */
+ enable_extra_target_match();
+
/*
* initialize output formatting (tt.h)
*/