Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 27 Oct 2003 13:26:23 -0800
From:      Wes Peters <wes@softweyr.com>
To:        current@freebsd.org
Subject:   newfs by fstab directory name?
Message-ID:  <200310271326.23562.wes@softweyr.com>

next in thread | raw e-mail | index | archive | help

--Boundary-00=_/1Yn/kpBvKRGMaD
Content-Type: text/plain;
  charset="us-ascii"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

At work we do a lot of dynamic filesystem creation, so we added the 
ability to specify the 'special file' argument to newfs via the fstab 
mount point directory.  Please see the attached patch.  If nobody 
objects, I'll commit this in a couple of days.

-- 

        Where am I, and what am I doing in this handbasket?

Wes Peters                                               wes@softweyr.com

--Boundary-00=_/1Yn/kpBvKRGMaD
Content-Type: text/x-diff;
  charset="us-ascii";
  name="foo"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
	filename="foo"

Index: newfs.c
===================================================================
RCS file: /big/ncvs/src/sbin/newfs/newfs.c,v
retrieving revision 1.73
diff -u -r1.73 newfs.c
--- newfs.c	3 May 2003 18:41:58 -0000	1.73
+++ newfs.c	27 Oct 2003 21:23:45 -0000
@@ -72,6 +72,7 @@
 #include <ctype.h>
 #include <err.h>
 #include <errno.h>
+#include <fstab.h>
 #include <paths.h>
 #include <stdarg.h>
 #include <stdio.h>
@@ -151,6 +152,7 @@
 	struct disklabel *lp;
 	struct partition oldpartition;
 	struct stat st;
+	struct fstab *fst;
 	char *cp, *special;
 	int ch, i;
 	off_t mediasize;
@@ -264,15 +266,19 @@
 		usage();
 
 	special = argv[0];
-	cp = strrchr(special, '/');
-	if (cp == 0) {
-		/*
-		 * No path prefix; try prefixing _PATH_DEV.
-		 */
-		snprintf(device, sizeof(device), "%s%s", _PATH_DEV, special);
-		special = device;
+	if ((fst = getfsfile(special)) != NULL)
+		special = strdup(fst->fs_spec);
+	else {
+		cp = strrchr(special, '/');
+		if (cp == 0) {
+			/*
+			 * No path prefix; try prefixing _PATH_DEV.
+			 */
+			snprintf(device, sizeof(device), "%s%s", _PATH_DEV,
+			    special);
+			special = device;
+		}
 	}
-
 	if (ufs_disk_fillout_blank(&disk, special) == -1 ||
 	    (!Nflag && ufs_disk_write(&disk) == -1)) {
 		if (disk.d_error != NULL)
Index: newfs.8
===================================================================
RCS file: /big/ncvs/src/sbin/newfs/newfs.8,v
retrieving revision 1.64
diff -u -r1.64 newfs.8
--- newfs.8	11 Oct 2003 08:24:07 -0000	1.64
+++ newfs.8	27 Oct 2003 21:17:17 -0000
@@ -74,7 +74,11 @@
 as the
 .Dq disk ,
 although the special file need not be a physical disk.
-In fact, it need not even be special.)
+In fact, it need not even be special.)  The special file argument
+may also reference a directory the filesystem is normally mounted
+on, as configured in
+.Pa /etc/fstab .
+.Pp
 Typically the defaults are reasonable, however
 .Nm
 has numerous options to allow the defaults to be selectively overridden.

--Boundary-00=_/1Yn/kpBvKRGMaD--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200310271326.23562.wes>