Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 27 Jul 2003 11:45:23 +0400 (MSD)
From:      Dmitry Morozovsky <marck@rinet.ru>
To:        FreeBSD-gnats-submit@FreeBSD.org
Subject:   bin/54897: [PATCH] -y flag for mount_mfs
Message-ID:  <200307270745.h6R7jNKF092707@woozle.rinet.ru>
Resent-Message-ID: <200307270750.h6R7oJ7e061494@freefall.freebsd.org>

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

>Number:         54897
>Category:       bin
>Synopsis:       [PATCH] -y flag for mount_mfs
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sun Jul 27 00:50:19 PDT 2003
>Closed-Date:
>Last-Modified:
>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:
>Unformatted:



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