Skip to contentSkip to conversation

Add user-defined fstab location for findmnt

PATCH Applied Dave Reisner 2 participants 5 messages Dec 11, 2011 – Dec 16, 2011 Util-Linux package

lore
Share & tools
lore
#0 lore raw

cover Add user-defined fstab location for findmnt

This adds an optional argument to the --fstab parameter of findmnt to allow for a custom location of /etc/fstab. The first patch is a minor fixup for a bug I discovered while testing.

Dave Reisner (2):
findmnt: use warnx for libmnt error callback
findmnt: support alternative location of fstab

 misc-utils/findmnt.8 |    6 ++++--
 misc-utils/findmnt.c |    8 ++++----
 2 files changed, 8 insertions(+), 6 deletions(-)
Signature · 1 line
1.7.8
#1 lore raw

PATCH 1/2 findmnt: use warnx for libmnt error callback

libmount doesn't set errno appropriately here:

$ findmnt -s
findmnt: /etc/fstab: parse error at line 20: Success
---
 misc-utils/findmnt.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
misc-utils/findmnt.c +1 -1
index 9c2b9fc..4577dc6 100644
@@ -484,7 +484,7 @@ leave:
 static int parser_errcb(struct libmnt_table *tb __attribute__ ((__unused__)),
 			const char *filename, int line)
 {
-	warn(_("%s: parse error at line %d"), filename, line);
+	warnx(_("%s: parse error at line %d"), filename, line);
 	return 0;
 }
 
Signature · 1 line
1.7.8
maintainer
#2 lore raw

Re: [PATCH 1/2] findmnt: use warnx for libmnt error callback

misc-utils/findmnt.c leave: · line 487

Quoted 13 lines · Dave Reisner
 misc-utils/findmnt.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
misc-utils/findmnt.c +1 -1
index 9c2b9fc..4577dc6 100644
@@ -484,7 +484,7 @@ leave:
 static int parser_errcb(struct libmnt_table *tb __attribute__ ((__unused__)),
 			const char *filename, int line)
 {
-	warn(_("%s: parse error at line %d"), filename, line);
+	warnx(_("%s: parse error at line %d"), filename, line);

Oh.. yes, errno does not make sense here. Applied, thanks.

Karel

Signature · 2 lines
 Karel Zak  <[email protected]>
 http://karelzak.blogspot.com
#3 lore raw

PATCH 2/2 findmnt: support alternative location of fstab

In reply to Dave Reisner
---
 misc-utils/findmnt.8 |    6 ++++--
 misc-utils/findmnt.c |    6 +++---
 2 files changed, 7 insertions(+), 5 deletions(-)
misc-utils/findmnt.8 +4 -2
index 24e3a52..7f3dc6c 100644
@@ -36,12 +36,14 @@ The command prints all mounted filesystems in the tree-like format by default.
 .SH OPTIONS
 .IP "\fB\-h, \-\-help\fP"
 Print help and exit.
-.IP "\fB\-s, \-\-fstab\fP"
+.IP "\fB\-s, \-\-fstab\fR[\fI=fstab\fR]\fP"
 Search in
 .IR /etc/fstab
 and
 .IR /etc/fstab.d .
-The output is in the list format (see --list).
+The output is in the list format (see --list). Optionally, search the file
+specified by
+.IR fstab .
 .IP "\fB\-m, \-\-mtab\fP"
 Search in
 .IR /etc/mtab .
misc-utils/findmnt.c +3 -3
index 4577dc6..a23a432 100644
@@ -770,7 +770,7 @@ static void __attribute__((__noreturn__)) usage(FILE *out)
 
 	fprintf(out, _(
 	"\nOptions:\n"
-	" -s, --fstab            search in static table of filesystems\n"
+	" -s, --fstab[=<fstab>]  search in static table of filesystems\n"
 	" -m, --mtab             search in table of mounted filesystems\n"
 	" -k, --kernel           search in kernel table of mounted\n"
         "                          filesystems (default)\n\n"));
@@ -839,7 +839,7 @@ int main(int argc, char *argv[])
 	    { "direction",    1, 0, 'd' },
 	    { "evaluate",     0, 0, 'e' },
 	    { "first-only",   0, 0, 'f' },
-	    { "fstab",        0, 0, 's' },
+	    { "fstab",        2, 0, 's' },
 	    { "help",         0, 0, 'h' },
 	    { "invert",       0, 0, 'i' },
 	    { "kernel",       0, 0, 'k' },
@@ -938,7 +938,7 @@ int main(int argc, char *argv[])
 		case 's':		/* fstab */
 			if (tabfile)
 				errx_mutually_exclusive("--{fstab,mtab,kernel}");
-			tabfile = _PATH_MNTTAB;
+			tabfile = optarg ? optarg : _PATH_MNTTAB;
 			tt_flags &= ~TT_FL_TREE;
 			break;
 		case 'k':		/* kernel (mountinfo) */
Signature · 1 line
1.7.8
maintainer Applied
#4 lore raw

Re: [PATCH 2/2] findmnt: support alternative location of fstab

Quoted 3 lines · Dave Reisner
 misc-utils/findmnt.8 |    6 ++++--
 misc-utils/findmnt.c |    6 +++---
 2 files changed, 7 insertions(+), 5 deletions(-)

Applied, thanks. My plan is to support this feature in new mount(8) (libmount/src/sample/mount.c) too.

Karel

Signature · 2 lines
 Karel Zak  <[email protected]>
 http://karelzak.blogspot.com