summaryrefslogtreecommitdiffstats
path: root/misc-utils/findmnt.c
diff options
context:
space:
mode:
authorKarel Zak2011-05-10 11:16:41 +0200
committerKarel Zak2011-05-10 11:16:41 +0200
commit49e9fd3a0d5b514ca7f4fa107c66ec443ebee7a4 (patch)
tree074ac9b7f07efa642f9267c4831da120eafa7900 /misc-utils/findmnt.c
parentfindmnt: fix leak (diff)
downloadkernel-qcow2-util-linux-49e9fd3a0d5b514ca7f4fa107c66ec443ebee7a4.tar.gz
kernel-qcow2-util-linux-49e9fd3a0d5b514ca7f4fa107c66ec443ebee7a4.tar.xz
kernel-qcow2-util-linux-49e9fd3a0d5b514ca7f4fa107c66ec443ebee7a4.zip
findmnt: add --pairs to output in key="value" format
... usable in scripts, for example: findmnt --pairs -o "SOURCE,TARGET,FSTYPE" $1 | while read line; do eval $line echo "$SOURCE is mounted on $TARGET [$FSTYPE]" done Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'misc-utils/findmnt.c')
-rw-r--r--misc-utils/findmnt.c16
1 files changed, 11 insertions, 5 deletions
diff --git a/misc-utils/findmnt.c b/misc-utils/findmnt.c
index 338da112d..4b5e47d60 100644
--- a/misc-utils/findmnt.c
+++ b/misc-utils/findmnt.c
@@ -331,7 +331,7 @@ static const char *get_data(struct libmnt_fs *fs, int num)
if (devno) {
char *tmp;
int rc = 0;
- if (tt_flags & TT_FL_RAW)
+ if ((tt_flags & TT_FL_RAW) || (tt_flags & TT_FL_EXPORT))
rc = asprintf(&tmp, "%u:%u",
major(devno), minor(devno));
else
@@ -787,7 +787,8 @@ static void __attribute__((__noreturn__)) usage(FILE *out)
" -u, --notruncate don't truncate text in columns\n"
" -O, --options <list> limit the set of filesystems by mount options\n"
" -o, --output <list> output columns\n"
- " -r, --raw use raw format output\n"
+ " -P, --pairs use key=\"value\" output format\n"
+ " -r, --raw use raw output format\n"
" -a, --ascii use ascii chars for tree formatting\n"
" -t, --types <list> limit the set of filesystem by FS types\n"
" -v, --nofsroot don't print [/dir] for bind or btrfs mounts\n"
@@ -845,6 +846,7 @@ int main(int argc, char *argv[])
{ "options", 1, 0, 'O' },
{ "output", 1, 0, 'o' },
{ "poll", 2, 0, 'p' },
+ { "pairs", 0, 0, 'P' },
{ "raw", 0, 0, 'r' },
{ "types", 1, 0, 't' },
{ "fsroot", 0, 0, 'v' },
@@ -866,7 +868,7 @@ int main(int argc, char *argv[])
tt_flags |= TT_FL_TREE;
while ((c = getopt_long(argc, argv,
- "acd:ehifo:O:p::klmnrst:uvRS:T:w:", longopts, NULL)) != -1) {
+ "acd:ehifo:O:p::Pklmnrst:uvRS:T:w:", longopts, NULL)) != -1) {
switch(c) {
case 'a':
tt_flags |= TT_FL_ASCII;
@@ -915,6 +917,10 @@ int main(int argc, char *argv[])
flags |= FL_POLL;
tt_flags &= ~TT_FL_TREE;
break;
+ case 'P':
+ tt_flags |= TT_FL_EXPORT;
+ tt_flags &= ~TT_FL_TREE;
+ break;
case 'm': /* mtab */
if (tabfile)
errx_mutually_exclusive("--{fstab,mtab,kernel}");
@@ -940,8 +946,8 @@ int main(int argc, char *argv[])
tt_flags |= TT_FL_RAW; /* enable raw */
break;
case 'l':
- if (tt_flags & TT_FL_RAW)
- errx_mutually_exclusive("--{raw,list}");
+ if ((tt_flags & TT_FL_RAW) && (tt_flags & TT_FL_EXPORT))
+ errx_mutually_exclusive("--{raw,list,pairs}");
tt_flags &= ~TT_FL_TREE; /* disable the default */
break;