summaryrefslogtreecommitdiffstats
path: root/misc-utils/findmnt.c
diff options
context:
space:
mode:
authorKarel Zak2015-03-19 12:08:30 +0100
committerKarel Zak2015-03-19 12:12:21 +0100
commit0009f510cb4bafabbec0d26acd7385436c3e7c8b (patch)
treeef70e8fab20dc7fa0deb44cc5926481c88d6f6e7 /misc-utils/findmnt.c
parenttests: start script/race test only when --force specified (diff)
downloadkernel-qcow2-util-linux-0009f510cb4bafabbec0d26acd7385436c3e7c8b.tar.gz
kernel-qcow2-util-linux-0009f510cb4bafabbec0d26acd7385436c3e7c8b.tar.xz
kernel-qcow2-util-linux-0009f510cb4bafabbec0d26acd7385436c3e7c8b.zip
findmnt: add --mountpoint command line option
The current --target <path> implementation check the <path> elements in reverse order to get the mountpoint. The feature may be inwanted in some cases when we really want to check for mountpoint specified by the <path>. The new option "--mountpoint <path>" allows to be strict. Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'misc-utils/findmnt.c')
-rw-r--r--misc-utils/findmnt.c21
1 files changed, 17 insertions, 4 deletions
diff --git a/misc-utils/findmnt.c b/misc-utils/findmnt.c
index 1adc23124..f76ac2e04 100644
--- a/misc-utils/findmnt.c
+++ b/misc-utils/findmnt.c
@@ -62,6 +62,7 @@ enum {
FL_UNIQ = (1 << 12),
FL_BYTES = (1 << 13),
FL_NOCACHE = (1 << 14),
+ FL_STRICTTARGET = (1 << 15),
/* basic table settings */
FL_ASCII = (1 << 20),
@@ -259,7 +260,12 @@ static void set_source_match(const char *data)
set_match(COL_SOURCE, data);
}
-/* @tb has to be from kernel (so no fstab or so)! */
+/*
+ * Extra functionality for --target <path>. The function mnt_table_find_mountpoint()
+ * also checks parents (path elements in reverse order) to get mountpoint.
+ *
+ * @tb has to be from kernel (so no fstab or so)!
+ */
static void enable_extra_target_match(struct libmnt_table *tb)
{
char *cn = NULL;
@@ -1201,7 +1207,7 @@ static void __attribute__((__noreturn__)) usage(FILE *out)
" %1$s [options]\n"
" %1$s [options] <device> | <mountpoint>\n"
" %1$s [options] <device> <mountpoint>\n"
- " %1$s [options] [--source <device>] [--target <mountpoint>]\n"),
+ " %1$s [options] [--source <device>] [--target <path> | --mountpoint <dir>]\n"),
program_invocation_short_name);
fputs(USAGE_SEPARATOR, out);
@@ -1239,7 +1245,8 @@ static void __attribute__((__noreturn__)) usage(FILE *out)
fputs(_(" -r, --raw use raw output format\n"), out);
fputs(_(" -S, --source <string> the device to mount (by name, maj:min, \n"
" LABEL=, UUID=, PARTUUID=, PARTLABEL=)\n"), out);
- fputs(_(" -T, --target <string> the mountpoint to use\n"), out);
+ fputs(_(" -T, --target <path> the path to the filesystem to use\n"), out);
+ fputs(_(" -M, --mountpoint <dir> the mountpoint directory\n"), out);
fputs(_(" -t, --types <list> limit the set of filesystems by FS types\n"), out);
fputs(_(" -U, --uniq ignore filesystems with duplicate target\n"), out);
fputs(_(" -u, --notruncate don't truncate text in columns\n"), out);
@@ -1284,6 +1291,7 @@ int main(int argc, char *argv[])
{ "invert", 0, 0, 'i' },
{ "kernel", 0, 0, 'k' },
{ "list", 0, 0, 'l' },
+ { "mountpoint", 1, 0, 'M' },
{ "mtab", 0, 0, 'm' },
{ "noheadings", 0, 0, 'n' },
{ "notruncate", 0, 0, 'u' },
@@ -1310,6 +1318,7 @@ int main(int argc, char *argv[])
static const ul_excl_t excl[] = { /* rows and cols in in ASCII order */
{ 'C', 'c'}, /* [no]canonicalize */
{ 'C', 'e' }, /* nocanonicalize, evaluate */
+ { 'M', 'T' }, /* mountpoint, target */
{ 'N','k','m','s' }, /* task,kernel,mtab,fstab */
{ 'P','l','r' }, /* pairs,list,raw */
{ 'm','p','s' }, /* mtab,poll,fstab */
@@ -1326,7 +1335,7 @@ int main(int argc, char *argv[])
flags |= FL_TREE;
while ((c = getopt_long(argc, argv,
- "AabCcDd:ehifF:o:O:p::PklmnN:rst:uvRS:T:Uw:V",
+ "AabCcDd:ehifF:o:O:p::PklmM:nN:rst:uvRS:T:Uw:V",
longopts, NULL)) != -1) {
err_exclusive_options(c, longopts, excl, excl_st);
@@ -1439,6 +1448,9 @@ int main(int argc, char *argv[])
set_source_match(optarg);
flags |= FL_NOSWAPMATCH;
break;
+ case 'M':
+ flags |= FL_STRICTTARGET;
+ /* fallthrough */
case 'T':
set_match(COL_TARGET, optarg);
flags |= FL_NOSWAPMATCH;
@@ -1602,6 +1614,7 @@ int main(int argc, char *argv[])
if (rc != 0
&& tabtype == TABTYPE_KERNEL
&& (flags & FL_NOSWAPMATCH)
+ && !(flags & FL_STRICTTARGET)
&& get_match(COL_TARGET)) {
/*
* Found nothing, maybe the --target is regular file,