Skip to contentSkip to conversation

exportfs: Add -s option.

PATCH In review Tony Asleson 3 participants 7 messages Oct 2, 2013 – Oct 21, 2013

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 exportfs: Add -s option.

Adds '-s' option which outputs the current exports in a format suitable for /etc/exports.

---
 utils/exportfs/exportfs.c   | 23 ++++++++++++++---------
 utils/exportfs/exportfs.man |  5 ++++-
 2 files changed, 18 insertions(+), 10 deletions(-)
utils/exportfs/exportfs.c +14 -9
index 4331697..52fc03d 100644
@@ -38,7 +38,7 @@ static void	export_all(int verbose);
 static void	exportfs(char *arg, char *options, int verbose);
 static void	unexportfs(char *arg, int verbose);
 static void	exports_update(int verbose);
-static void	dump(int verbose);
+static void	dump(int verbose, int export_format);
 static void	error(nfs_export *exp, int err);
 static void	usage(const char *progname, int n);
 static void	validate_export(nfs_export *exp);
@@ -88,6 +88,7 @@ main(int argc, char **argv)
 	int	f_export = 1;
 	int	f_all = 0;
 	int	f_verbose = 0;
+	int	f_export_format = 0;
 	int	f_reexport = 0;
 	int	f_ignore = 0;
 	int	i, c;
@@ -105,7 +106,7 @@ main(int argc, char **argv)
 
 	export_errno = 0;
 
-	while ((c = getopt(argc, argv, "afhio:ruv")) != EOF) {
+	while ((c = getopt(argc, argv, "afhio:ruvs")) != EOF) {
 		switch(c) {
 		case 'a':
 			f_all = 1;
@@ -132,6 +133,9 @@ main(int argc, char **argv)
 		case 'v':
 			f_verbose = 1;
 			break;
+		case 's':
+			f_export_format = 1;
+			break;
 		default:
 			usage(progname, 1);
 			break;
@@ -164,7 +168,7 @@ main(int argc, char **argv)
 			return 0;
 		} else {
 			xtab_export_read();
-			dump(f_verbose);
+			dump(f_verbose, f_export_format);
 			return 0;
 		}
 	}
@@ -634,7 +638,7 @@ dumpopt(char c, char *fmt, ...)
 }
 
 static void
-dump(int verbose)
+dump(int verbose, int export_format)
 {
 	nfs_export	*exp;
 	struct exportent *ep;
@@ -647,14 +651,15 @@ dump(int verbose)
 			if (!exp->m_xtabent)
 			    continue; /* neilb */
 			if (htype == MCL_ANONYMOUS)
-				hname = "<world>";
+				hname = (export_format) ? "*" : "<world>";
 			else
 				hname = ep->e_hostname;
-			if (strlen(ep->e_path) > 14)
+			if (strlen(ep->e_path) > 14 && !export_format)
 				printf("%-14s\n\t\t%s", ep->e_path, hname);
 			else
-				printf("%-14s\t%s", ep->e_path, hname);
-			if (!verbose) {
+				printf(((export_format)? "%s %s" : "%-14s\t%s"), ep->e_path, hname);
+
+			if (!verbose && !export_format) {
 				printf("\n");
 				continue;
 			}
@@ -728,6 +733,6 @@ error(nfs_export *exp, int err)
 static void
 usage(const char *progname, int n)
 {
-	fprintf(stderr, "usage: %s [-afhioruv] [host:/path]\n", progname);
+	fprintf(stderr, "usage: %s [-afhioruvs] [host:/path]\n", progname);
 	exit(n);
 }
utils/exportfs/exportfs.man +4 -1
index 8853486..590f9cf 100644
@@ -3,7 +3,7 @@
 .\" Copyright (C) 1995 Olaf Kirch <[email protected]>
 .\" Modifications 1999-2003 Neil Brown <[email protected]>
 .\"
-.TH exportfs 8 "31 December 2009"
+.TH exportfs 8 "30 September 2013"
 .SH NAME
 exportfs \- maintain table of exported NFS file systems
 .SH SYNOPSIS
@@ -133,6 +133,9 @@ when they make their next NFS mount request.
 Be verbose. When exporting or unexporting, show what's going on. When
 displaying the current export list, also display the list of export
 options.
+.TP
+.B -s
+Display the current export list suitable for /etc/exports.
 .SH DISCUSSION
 .SS Exporting Directories
 The first synopsis shows how to invoke
Signature · 1 line
1.8.2.1
#1 lore raw
Quoted 2 lines · Tony Asleson

Adds '-s' option which outputs the current exports in a format suitable for /etc/exports.

Sounds like a good idea....

Is there any difference between this and what's written to /var/lib/nfs/etab?

OK looks like the latter is more verbose--it doesn't skip default options.

Still can't help thinking there must be some needlessly duplicated code here.

--b.

Quoted 123 lines
---
 utils/exportfs/exportfs.c   | 23 ++++++++++++++---------
 utils/exportfs/exportfs.man |  5 ++++-
 2 files changed, 18 insertions(+), 10 deletions(-)
utils/exportfs/exportfs.c +14 -9
index 4331697..52fc03d 100644
@@ -38,7 +38,7 @@ static void	export_all(int verbose);
 static void	exportfs(char *arg, char *options, int verbose);
 static void	unexportfs(char *arg, int verbose);
 static void	exports_update(int verbose);
-static void	dump(int verbose);
+static void	dump(int verbose, int export_format);
 static void	error(nfs_export *exp, int err);
 static void	usage(const char *progname, int n);
 static void	validate_export(nfs_export *exp);
@@ -88,6 +88,7 @@ main(int argc, char **argv)
 	int	f_export = 1;
 	int	f_all = 0;
 	int	f_verbose = 0;
+	int	f_export_format = 0;
 	int	f_reexport = 0;
 	int	f_ignore = 0;
 	int	i, c;
@@ -105,7 +106,7 @@ main(int argc, char **argv)
 
 	export_errno = 0;
 
-	while ((c = getopt(argc, argv, "afhio:ruv")) != EOF) {
+	while ((c = getopt(argc, argv, "afhio:ruvs")) != EOF) {
 		switch(c) {
 		case 'a':
 			f_all = 1;
@@ -132,6 +133,9 @@ main(int argc, char **argv)
 		case 'v':
 			f_verbose = 1;
 			break;
+		case 's':
+			f_export_format = 1;
+			break;
 		default:
 			usage(progname, 1);
 			break;
@@ -164,7 +168,7 @@ main(int argc, char **argv)
 			return 0;
 		} else {
 			xtab_export_read();
-			dump(f_verbose);
+			dump(f_verbose, f_export_format);
 			return 0;
 		}
 	}
@@ -634,7 +638,7 @@ dumpopt(char c, char *fmt, ...)
 }
 
 static void
-dump(int verbose)
+dump(int verbose, int export_format)
 {
 	nfs_export	*exp;
 	struct exportent *ep;
@@ -647,14 +651,15 @@ dump(int verbose)
 			if (!exp->m_xtabent)
 			    continue; /* neilb */
 			if (htype == MCL_ANONYMOUS)
-				hname = "<world>";
+				hname = (export_format) ? "*" : "<world>";
 			else
 				hname = ep->e_hostname;
-			if (strlen(ep->e_path) > 14)
+			if (strlen(ep->e_path) > 14 && !export_format)
 				printf("%-14s\n\t\t%s", ep->e_path, hname);
 			else
-				printf("%-14s\t%s", ep->e_path, hname);
-			if (!verbose) {
+				printf(((export_format)? "%s %s" : "%-14s\t%s"), ep->e_path, hname);
+
+			if (!verbose && !export_format) {
 				printf("\n");
 				continue;
 			}
@@ -728,6 +733,6 @@ error(nfs_export *exp, int err)
 static void
 usage(const char *progname, int n)
 {
-	fprintf(stderr, "usage: %s [-afhioruv] [host:/path]\n", progname);
+	fprintf(stderr, "usage: %s [-afhioruvs] [host:/path]\n", progname);
 	exit(n);
 }
utils/exportfs/exportfs.man +4 -1
index 8853486..590f9cf 100644
@@ -3,7 +3,7 @@
 .\" Copyright (C) 1995 Olaf Kirch <[email protected]>
 .\" Modifications 1999-2003 Neil Brown <[email protected]>
 .\"
-.TH exportfs 8 "31 December 2009"
+.TH exportfs 8 "30 September 2013"
 .SH NAME
 exportfs \- maintain table of exported NFS file systems
 .SH SYNOPSIS
@@ -133,6 +133,9 @@ when they make their next NFS mount request.
 Be verbose. When exporting or unexporting, show what's going on. When
 displaying the current export list, also display the list of export
 options.
+.TP
+.B -s
+Display the current export list suitable for /etc/exports.
 .SH DISCUSSION
 .SS Exporting Directories
 The first synopsis shows how to invoke
Signature · 6 lines
1.8.2.1

--
To unsubscribe from this list: send the line "unsubscribe linux-nfs" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#2 lore raw
Quoted 8 lines · J. Bruce Fields
Quoted 2 lines · Tony Asleson

Adds '-s' option which outputs the current exports in a format suitable for /etc/exports.

Sounds like a good idea....

Is there any difference between this and what's written to /var/lib/nfs/etab?

Yes... The following options are in the etab but not in the -s output...

sync,hide,nocrossmnt,secure,no_all_squash,secure_locks,acl,anonuid=65534,anongid=65534

Quoted 3 lines

OK looks like the latter is more verbose--it doesn't skip default options.

The only real difference between -v and -s is -v uses the string "<world>" in for MCL_ANONYMOUS and -s uses "*"

I guess we could change -v to used what the -s is proposing, but that could break someone's existing configuration...

Quoted 3 lines

Still can't help thinking there must be some needlessly duplicated code here.

There is... but I stilling adding the -s makes sense....

steved.

Quoted 131 lines

--b.

Quoted 123 lines
---
 utils/exportfs/exportfs.c   | 23 ++++++++++++++---------
 utils/exportfs/exportfs.man |  5 ++++-
 2 files changed, 18 insertions(+), 10 deletions(-)
utils/exportfs/exportfs.c +14 -9
index 4331697..52fc03d 100644
@@ -38,7 +38,7 @@ static void	export_all(int verbose);
 static void	exportfs(char *arg, char *options, int verbose);
 static void	unexportfs(char *arg, int verbose);
 static void	exports_update(int verbose);
-static void	dump(int verbose);
+static void	dump(int verbose, int export_format);
 static void	error(nfs_export *exp, int err);
 static void	usage(const char *progname, int n);
 static void	validate_export(nfs_export *exp);
@@ -88,6 +88,7 @@ main(int argc, char **argv)
 	int	f_export = 1;
 	int	f_all = 0;
 	int	f_verbose = 0;
+	int	f_export_format = 0;
 	int	f_reexport = 0;
 	int	f_ignore = 0;
 	int	i, c;
@@ -105,7 +106,7 @@ main(int argc, char **argv)
 
 	export_errno = 0;
 
-	while ((c = getopt(argc, argv, "afhio:ruv")) != EOF) {
+	while ((c = getopt(argc, argv, "afhio:ruvs")) != EOF) {
 		switch(c) {
 		case 'a':
 			f_all = 1;
@@ -132,6 +133,9 @@ main(int argc, char **argv)
 		case 'v':
 			f_verbose = 1;
 			break;
+		case 's':
+			f_export_format = 1;
+			break;
 		default:
 			usage(progname, 1);
 			break;
@@ -164,7 +168,7 @@ main(int argc, char **argv)
 			return 0;
 		} else {
 			xtab_export_read();
-			dump(f_verbose);
+			dump(f_verbose, f_export_format);
 			return 0;
 		}
 	}
@@ -634,7 +638,7 @@ dumpopt(char c, char *fmt, ...)
 }
 
 static void
-dump(int verbose)
+dump(int verbose, int export_format)
 {
 	nfs_export	*exp;
 	struct exportent *ep;
@@ -647,14 +651,15 @@ dump(int verbose)
 			if (!exp->m_xtabent)
 			    continue; /* neilb */
 			if (htype == MCL_ANONYMOUS)
-				hname = "<world>";
+				hname = (export_format) ? "*" : "<world>";
 			else
 				hname = ep->e_hostname;
-			if (strlen(ep->e_path) > 14)
+			if (strlen(ep->e_path) > 14 && !export_format)
 				printf("%-14s\n\t\t%s", ep->e_path, hname);
 			else
-				printf("%-14s\t%s", ep->e_path, hname);
-			if (!verbose) {
+				printf(((export_format)? "%s %s" : "%-14s\t%s"), ep->e_path, hname);
+
+			if (!verbose && !export_format) {
 				printf("\n");
 				continue;
 			}
@@ -728,6 +733,6 @@ error(nfs_export *exp, int err)
 static void
 usage(const char *progname, int n)
 {
-	fprintf(stderr, "usage: %s [-afhioruv] [host:/path]\n", progname);
+	fprintf(stderr, "usage: %s [-afhioruvs] [host:/path]\n", progname);
 	exit(n);
 }
utils/exportfs/exportfs.man +4 -1
index 8853486..590f9cf 100644
@@ -3,7 +3,7 @@
 .\" Copyright (C) 1995 Olaf Kirch <[email protected]>
 .\" Modifications 1999-2003 Neil Brown <[email protected]>
 .\"
-.TH exportfs 8 "31 December 2009"
+.TH exportfs 8 "30 September 2013"
 .SH NAME
 exportfs \- maintain table of exported NFS file systems
 .SH SYNOPSIS
@@ -133,6 +133,9 @@ when they make their next NFS mount request.
 Be verbose. When exporting or unexporting, show what's going on. When
 displaying the current export list, also display the list of export
 options.
+.TP
+.B -s
+Display the current export list suitable for /etc/exports.
 .SH DISCUSSION
 .SS Exporting Directories
 The first synopsis shows how to invoke
Signature · 6 lines
1.8.2.1

--
To unsubscribe from this list: send the line "unsubscribe linux-nfs" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

--
To unsubscribe from this list: send the line "unsubscribe linux-nfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#3 lore raw
Quoted 15 lines · Steve Dickson
Quoted 8 lines · J. Bruce Fields
Quoted 2 lines · Tony Asleson

Adds '-s' option which outputs the current exports in a format suitable for /etc/exports.

Sounds like a good idea....

Is there any difference between this and what's written to /var/lib/nfs/etab?

Yes... The following options are in the etab but not in the -s output...

sync,hide,nocrossmnt,secure,no_all_squash,secure_locks,acl,anonuid=65534,anongid=65534

Quoted 1 line
Quoted 7 lines
Quoted 2 lines

OK looks like the latter is more verbose--it doesn't skip default options.

The only real difference between -v and -s is -v uses the string "<world>" in for MCL_ANONYMOUS and -s uses "*"

I guess we could change -v to used what the -s is proposing, but that could break someone's existing configuration...

Also, looking at my home server.... It would be annoying to get:

/export *(rw,sync,wdelay,hide,nocrossmnt,insecure,no_root_squash,no_all_squash,no_subtree_check,secure_locks,acl,anonuid=65534,anongid=65534)

when all you need is:

/export <world>(rw,wdelay,insecure,no_root_squash,no_subtree_check)

(Actually I wonder why it's even showing wdelay and no_subtree_check when those are both defaults? But this is on F16, maybe it's different now. I should really update that machine.)

Quoted 3 lines
Quoted 2 lines

Still can't help thinking there must be some needlessly duplicated code here.

There is... but I stilling adding the -s makes sense....

Fine by me.

--b.

Quoted 134 lines

steved.

Quoted 131 lines

--b.

Quoted 123 lines
---
 utils/exportfs/exportfs.c   | 23 ++++++++++++++---------
 utils/exportfs/exportfs.man |  5 ++++-
 2 files changed, 18 insertions(+), 10 deletions(-)
utils/exportfs/exportfs.c +14 -9
index 4331697..52fc03d 100644
@@ -38,7 +38,7 @@ static void	export_all(int verbose);
 static void	exportfs(char *arg, char *options, int verbose);
 static void	unexportfs(char *arg, int verbose);
 static void	exports_update(int verbose);
-static void	dump(int verbose);
+static void	dump(int verbose, int export_format);
 static void	error(nfs_export *exp, int err);
 static void	usage(const char *progname, int n);
 static void	validate_export(nfs_export *exp);
@@ -88,6 +88,7 @@ main(int argc, char **argv)
 	int	f_export = 1;
 	int	f_all = 0;
 	int	f_verbose = 0;
+	int	f_export_format = 0;
 	int	f_reexport = 0;
 	int	f_ignore = 0;
 	int	i, c;
@@ -105,7 +106,7 @@ main(int argc, char **argv)
 
 	export_errno = 0;
 
-	while ((c = getopt(argc, argv, "afhio:ruv")) != EOF) {
+	while ((c = getopt(argc, argv, "afhio:ruvs")) != EOF) {
 		switch(c) {
 		case 'a':
 			f_all = 1;
@@ -132,6 +133,9 @@ main(int argc, char **argv)
 		case 'v':
 			f_verbose = 1;
 			break;
+		case 's':
+			f_export_format = 1;
+			break;
 		default:
 			usage(progname, 1);
 			break;
@@ -164,7 +168,7 @@ main(int argc, char **argv)
 			return 0;
 		} else {
 			xtab_export_read();
-			dump(f_verbose);
+			dump(f_verbose, f_export_format);
 			return 0;
 		}
 	}
@@ -634,7 +638,7 @@ dumpopt(char c, char *fmt, ...)
 }
 
 static void
-dump(int verbose)
+dump(int verbose, int export_format)
 {
 	nfs_export	*exp;
 	struct exportent *ep;
@@ -647,14 +651,15 @@ dump(int verbose)
 			if (!exp->m_xtabent)
 			    continue; /* neilb */
 			if (htype == MCL_ANONYMOUS)
-				hname = "<world>";
+				hname = (export_format) ? "*" : "<world>";
 			else
 				hname = ep->e_hostname;
-			if (strlen(ep->e_path) > 14)
+			if (strlen(ep->e_path) > 14 && !export_format)
 				printf("%-14s\n\t\t%s", ep->e_path, hname);
 			else
-				printf("%-14s\t%s", ep->e_path, hname);
-			if (!verbose) {
+				printf(((export_format)? "%s %s" : "%-14s\t%s"), ep->e_path, hname);
+
+			if (!verbose && !export_format) {
 				printf("\n");
 				continue;
 			}
@@ -728,6 +733,6 @@ error(nfs_export *exp, int err)
 static void
 usage(const char *progname, int n)
 {
-	fprintf(stderr, "usage: %s [-afhioruv] [host:/path]\n", progname);
+	fprintf(stderr, "usage: %s [-afhioruvs] [host:/path]\n", progname);
 	exit(n);
 }
utils/exportfs/exportfs.man +4 -1
index 8853486..590f9cf 100644
@@ -3,7 +3,7 @@
 .\" Copyright (C) 1995 Olaf Kirch <[email protected]>
 .\" Modifications 1999-2003 Neil Brown <[email protected]>
 .\"
-.TH exportfs 8 "31 December 2009"
+.TH exportfs 8 "30 September 2013"
 .SH NAME
 exportfs \- maintain table of exported NFS file systems
 .SH SYNOPSIS
@@ -133,6 +133,9 @@ when they make their next NFS mount request.
 Be verbose. When exporting or unexporting, show what's going on. When
 displaying the current export list, also display the list of export
 options.
+.TP
+.B -s
+Display the current export list suitable for /etc/exports.
 .SH DISCUSSION
 .SS Exporting Directories
 The first synopsis shows how to invoke
Signature · 6 lines
1.8.2.1

--
To unsubscribe from this list: send the line "unsubscribe linux-nfs" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

--
To unsubscribe from this list: send the line "unsubscribe linux-nfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#4 lore raw
Quoted 8 lines · J. Bruce Fields
Quoted 2 lines · Steve Dickson

I guess we could change -v to used what the -s is proposing, but that could break someone's existing configuration...

Also, looking at my home server.... It would be annoying to get:

/export *(rw,sync,wdelay,hide,nocrossmnt,insecure,no_root_squash,no_all_squash,no_subtree_check,secure_locks,acl,anonuid=65534,anongid=65534)

Quoted 7 lines

when all you need is:

/export <world>(rw,wdelay,insecure,no_root_squash,no_subtree_check)

(Actually I wonder why it's even showing wdelay and no_subtree_check when those are both defaults? But this is on F16, maybe it's different now. I should really update that machine.)

No, the defaults have not changed for (quite) a while... The defaults are:
ro, root_squash, wdelay, no_subtree_check

Now it turns out wdelay (aka NFSEXP_GATHERED_WRITES) is a v2 only thing... So do we really need to have that on by default, now that we are slowly moving away from v2 support?

steved.

#5 lore raw
Quoted 18 lines · Steve Dickson
Quoted 8 lines · J. Bruce Fields
Quoted 2 lines · Steve Dickson

I guess we could change -v to used what the -s is proposing, but that could break someone's existing configuration...

Also, looking at my home server.... It would be annoying to get:

/export *(rw,sync,wdelay,hide,nocrossmnt,insecure,no_root_squash,no_all_squash,no_subtree_check,secure_locks,acl,anonuid=65534,anongid=65534)

Quoted 7 lines

when all you need is:

/export <world>(rw,wdelay,insecure,no_root_squash,no_subtree_check)

(Actually I wonder why it's even showing wdelay and no_subtree_check when those are both defaults? But this is on F16, maybe it's different now. I should really update that machine.)

Quoted 7 lines

No, the defaults have not changed for (quite) a while... The defaults are:
ro, root_squash, wdelay, no_subtree_check

Now it turns out wdelay (aka NFSEXP_GATHERED_WRITES) is a v2 only thing... So do we really need to have that on by default, now that we are slowly moving away from v2 support?

Yeah, it should stay on by default.

Anyway it wasn't the defaults I was wondering about so much as why exportfs -v was printing out some options that were already set at their defaults.

I guess that stuff is just hardwired into utils/exportfs/exportfs.c:dump(). So we may want the following.

(Anyway, ACK to the -s patch.)

--b.

utils/exportfs/exportfs.c +2 -2
index 4331697..0cde3e9 100644
@@ -665,7 +665,7 @@ dump(int verbose)
 				c = dumpopt(c, "rw");
 			if (ep->e_flags & NFSEXP_ASYNC)
 				c = dumpopt(c, "async");
-			if (ep->e_flags & NFSEXP_GATHERED_WRITES)
+			if (!(ep->e_flags & NFSEXP_GATHERED_WRITES))
 				c = dumpopt(c, "wdelay");
 			if (ep->e_flags & NFSEXP_NOHIDE)
 				c = dumpopt(c, "nohide");
@@ -679,7 +679,7 @@ dump(int verbose)
 				c = dumpopt(c, "no_root_squash");
 			if (ep->e_flags & NFSEXP_ALLSQUASH)
 				c = dumpopt(c, "all_squash");
-			if (ep->e_flags & NFSEXP_NOSUBTREECHECK)
+			if (!(ep->e_flags & NFSEXP_NOSUBTREECHECK))
 				c = dumpopt(c, "no_subtree_check");
 			if (ep->e_flags & NFSEXP_NOAUTHNLM)
 				c = dumpopt(c, "insecure_locks");
#6 lore raw
In reply to Tony Asleson
Quoted 8 lines · Tony Asleson

Adds '-s' option which outputs the current exports in a format suitable for /etc/exports.

---
 utils/exportfs/exportfs.c   | 23 ++++++++++++++---------
 utils/exportfs/exportfs.man |  5 ++++-
 2 files changed, 18 insertions(+), 10 deletions(-)

Committed...

steved.

Quoted 111 lines
utils/exportfs/exportfs.c +14 -9
index 4331697..52fc03d 100644
@@ -38,7 +38,7 @@ static void	export_all(int verbose);
 static void	exportfs(char *arg, char *options, int verbose);
 static void	unexportfs(char *arg, int verbose);
 static void	exports_update(int verbose);
-static void	dump(int verbose);
+static void	dump(int verbose, int export_format);
 static void	error(nfs_export *exp, int err);
 static void	usage(const char *progname, int n);
 static void	validate_export(nfs_export *exp);
@@ -88,6 +88,7 @@ main(int argc, char **argv)
 	int	f_export = 1;
 	int	f_all = 0;
 	int	f_verbose = 0;
+	int	f_export_format = 0;
 	int	f_reexport = 0;
 	int	f_ignore = 0;
 	int	i, c;
@@ -105,7 +106,7 @@ main(int argc, char **argv)
 
 	export_errno = 0;
 
-	while ((c = getopt(argc, argv, "afhio:ruv")) != EOF) {
+	while ((c = getopt(argc, argv, "afhio:ruvs")) != EOF) {
 		switch(c) {
 		case 'a':
 			f_all = 1;
@@ -132,6 +133,9 @@ main(int argc, char **argv)
 		case 'v':
 			f_verbose = 1;
 			break;
+		case 's':
+			f_export_format = 1;
+			break;
 		default:
 			usage(progname, 1);
 			break;
@@ -164,7 +168,7 @@ main(int argc, char **argv)
 			return 0;
 		} else {
 			xtab_export_read();
-			dump(f_verbose);
+			dump(f_verbose, f_export_format);
 			return 0;
 		}
 	}
@@ -634,7 +638,7 @@ dumpopt(char c, char *fmt, ...)
 }
 
 static void
-dump(int verbose)
+dump(int verbose, int export_format)
 {
 	nfs_export	*exp;
 	struct exportent *ep;
@@ -647,14 +651,15 @@ dump(int verbose)
 			if (!exp->m_xtabent)
 			    continue; /* neilb */
 			if (htype == MCL_ANONYMOUS)
-				hname = "<world>";
+				hname = (export_format) ? "*" : "<world>";
 			else
 				hname = ep->e_hostname;
-			if (strlen(ep->e_path) > 14)
+			if (strlen(ep->e_path) > 14 && !export_format)
 				printf("%-14s\n\t\t%s", ep->e_path, hname);
 			else
-				printf("%-14s\t%s", ep->e_path, hname);
-			if (!verbose) {
+				printf(((export_format)? "%s %s" : "%-14s\t%s"), ep->e_path, hname);
+
+			if (!verbose && !export_format) {
 				printf("\n");
 				continue;
 			}
@@ -728,6 +733,6 @@ error(nfs_export *exp, int err)
 static void
 usage(const char *progname, int n)
 {
-	fprintf(stderr, "usage: %s [-afhioruv] [host:/path]\n", progname);
+	fprintf(stderr, "usage: %s [-afhioruvs] [host:/path]\n", progname);
 	exit(n);
 }
utils/exportfs/exportfs.man +4 -1
index 8853486..590f9cf 100644
@@ -3,7 +3,7 @@
 .\" Copyright (C) 1995 Olaf Kirch <[email protected]>
 .\" Modifications 1999-2003 Neil Brown <[email protected]>
 .\"
-.TH exportfs 8 "31 December 2009"
+.TH exportfs 8 "30 September 2013"
 .SH NAME
 exportfs \- maintain table of exported NFS file systems
 .SH SYNOPSIS
@@ -133,6 +133,9 @@ when they make their next NFS mount request.
 Be verbose. When exporting or unexporting, show what's going on. When
 displaying the current export list, also display the list of export
 options.
+.TP
+.B -s
+Display the current export list suitable for /etc/exports.
 .SH DISCUSSION
 .SS Exporting Directories
 The first synopsis shows how to invoke