From: Karel Zak Date: Tue, 10 May 2011 09:16:41 +0000 (+0200) Subject: findmnt: add --pairs to output in key="value" format X-Git-Tag: v2.20-rc1~289 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=49e9fd3a0d5b514ca7f4fa107c66ec443ebee7a4;p=thirdparty%2Futil-linux.git 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 --- diff --git a/misc-utils/findmnt.c b/misc-utils/findmnt.c index 338da112dc..4b5e47d604 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 limit the set of filesystems by mount options\n" " -o, --output 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 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;