From marck@woozle.rinet.ru  Sun Jul 27 00:45:26 2003
Return-Path: <marck@woozle.rinet.ru>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id B6C6037B401
	for <FreeBSD-gnats-submit@freebsd.org>; Sun, 27 Jul 2003 00:45:26 -0700 (PDT)
Received: from woozle.rinet.ru (woozle.rinet.ru [195.54.192.68])
	by mx1.FreeBSD.org (Postfix) with ESMTP id D89F643FAF
	for <FreeBSD-gnats-submit@freebsd.org>; Sun, 27 Jul 2003 00:45:25 -0700 (PDT)
	(envelope-from marck@woozle.rinet.ru)
Received: from woozle.rinet.ru (localhost [127.0.0.1])
	by woozle.rinet.ru (8.12.9/8.12.9) with ESMTP id h6R7jO4C092708
	for <FreeBSD-gnats-submit@freebsd.org>; Sun, 27 Jul 2003 11:45:24 +0400 (MSD)
	(envelope-from marck@woozle.rinet.ru)
Received: (from marck@localhost)
	by woozle.rinet.ru (8.12.9/8.12.9/Submit) id h6R7jNKF092707;
	Sun, 27 Jul 2003 11:45:23 +0400 (MSD)
Message-Id: <200307270745.h6R7jNKF092707@woozle.rinet.ru>
Date: Sun, 27 Jul 2003 11:45:23 +0400 (MSD)
From: Dmitry Morozovsky <marck@rinet.ru>
Reply-To: Dmitry Morozovsky <marck@rinet.ru>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: [PATCH] -y flag for mount_mfs
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         54897
>Category:       bin
>Synopsis:       [PATCH] -y flag for mount_mfs
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    matteo
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sun Jul 27 00:50:19 PDT 2003
>Closed-Date:    Tue Feb 13 09:26:59 GMT 2007
>Last-Modified:  Tue Feb 13 09:26:59 GMT 2007
>Originator:     Dmitry Morozovsky
>Release:        FreeBSD 4-STABLE i386
>Organization:
Cronyx Plus LLC (RiNet ISP)
>Environment:
System: FreeBSD 4-STABLE 

>Description:

mount_mfs makes file system root inode world writable and sticky, which is
great for temporary file places; however, there are number of occasions where
this behaviour better be avoided, and mounting leads to race. Workararounds like 

	mount_mfs ... /mnt
	chmod 755 /mnt
	rm -rf /mnt

do not seem elegant to me. On the other hand, changing default directory mode
violates POLA. Hence, the following patch, which adds -y option to mount_mfs.


This behaviour is not applicable to -current, as mdconfig does not make
fs root-dir 1777

>How-To-Repeat:

mount_mfs -s 65536 swap /mnt
ls -ld /mnt

>Fix:


Index: sbin/newfs/mkfs.c
===================================================================
RCS file: /home/ncvs/src/sbin/newfs/mkfs.c,v
retrieving revision 1.29.2.6
diff -u -r1.29.2.6 mkfs.c
--- sbin/newfs/mkfs.c	21 Sep 2001 19:15:21 -0000	1.29.2.6
+++ sbin/newfs/mkfs.c	27 Jul 2003 07:33:00 -0000
@@ -96,6 +96,7 @@
 extern int	Nflag;		/* run mkfs without writing file system */
 extern int	Oflag;		/* format as an 4.3BSD file system */
 extern int	Uflag;		/* enable soft updates for file system */
+extern int	yflag;		/* do not make root inode with mode 1777 */
 extern int	fssize;		/* file system size */
 extern int	ntracks;	/* # tracks/cylinder */
 extern int	nsectors;	/* # sectors/track */
@@ -1008,7 +1009,7 @@
 	/*
 	 * create the root directory
 	 */
-	if (mfs)
+	if (mfs && !yflag)
 		node.di_mode = IFDIR | 01777;
 	else
 		node.di_mode = IFDIR | UMASK;
Index: sbin/newfs/newfs.8
===================================================================
RCS file: /home/ncvs/src/sbin/newfs/newfs.8,v
retrieving revision 1.26.2.15
diff -u -r1.26.2.15 newfs.8
--- sbin/newfs/newfs.8	13 May 2003 12:16:08 -0000	1.26.2.15
+++ sbin/newfs/newfs.8	27 Jul 2003 07:33:00 -0000
@@ -82,6 +82,7 @@
 .Op Fl o Ar options
 .Op Fl s Ar size
 .Op Fl v
+.Op Fl y
 .Ar special node
 .Sh DESCRIPTION
 .Nm Newfs
@@ -333,9 +334,11 @@
 .Nm
 command, except for the
 .Fl o
-option.
+and
+.Fl y
+options.
 .Pp
-That option is as follows:
+That options are as follows:
 .Bl -tag -width indent
 .It Fl o
 Options are specified with a
@@ -344,6 +347,13 @@
 See the
 .Xr mount 8
 man page for possible options and their meanings.
+.It Fl y
+By default, 
+.Nm mount_mfs
+command makes file system with world writable sticky (mode 1777)
+root directory which is useful for temporary file systems.
+.Fl y
+option disables this behaviour.
 .El
 .Sh EXAMPLES
 .Dl newfs /dev/ad3s1a
Index: sbin/newfs/newfs.c
===================================================================
RCS file: /home/ncvs/src/sbin/newfs/newfs.c,v
retrieving revision 1.30.2.9
diff -u -r1.30.2.9 newfs.c
--- sbin/newfs/newfs.c	13 May 2003 12:03:55 -0000	1.30.2.9
+++ sbin/newfs/newfs.c	27 Jul 2003 07:33:00 -0000
@@ -171,6 +171,7 @@
 int	Nflag;			/* run without writing file system */
 int	Oflag;			/* format as an 4.3BSD file system */
 int	Uflag;			/* enable soft updates for file system */
+int	yflag;			/* do not make root inode with mode 1777 */
 int	fssize;			/* file system size */
 int	ntracks = NTRACKS;	/* # tracks/cylinder */
 int	nsectors = NSECTORS;	/* # sectors/track */
@@ -249,7 +250,7 @@
 	}
 
 	opstring = mfs ?
-	    "NF:T:Ua:b:c:d:e:f:g:h:i:m:o:s:v" :
+	    "NF:T:Ua:b:c:d:e:f:g:h:i:m:o:s:vy" :
 	    "NOS:T:Ua:b:c:d:e:f:g:h:i:k:l:m:n:o:p:r:s:t:u:vx:";
 	while ((ch = getopt(argc, argv, opstring)) != -1)
 		switch (ch) {
@@ -375,6 +376,9 @@
 				fatal("%s: bad spare sectors per cylinder",
 				    optarg);
 			break;
+		case 'y':
+			yflag = 1;
+			break;
 		case '?':
 		default:
 			usage();
@@ -785,5 +789,7 @@
 	fprintf(stderr,
         "\t-v do not attempt to determine partition name from device name\n");
 	fprintf(stderr, "\t-x spare sectors per cylinder\n");
+	if (mfs)
+		fprintf(stderr, "\t-y make normal (non-writable) root dir\n");
 	exit(1);
 }
>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->matteo 
Responsible-Changed-By: matteo 
Responsible-Changed-When: Sun Nov 12 11:01:29 UTC 2006 
Responsible-Changed-Why:  
Take this PR, as I'm interested in md(4)'s use in fstab 

http://www.freebsd.org/cgi/query-pr.cgi?pr=54897 
State-Changed-From-To: open->closed 
State-Changed-By: matteo 
State-Changed-When: Tue Feb 13 09:26:34 UTC 2007 
State-Changed-Why:  
The "-p" option is available to accomplish this task. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=54897 
>Unformatted:
