Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 16 Jan 2002 17:20:03 -0800 (PST)
From:      Adrian Filipi-Martin <adrian@ubergeeks.com>
To:        freebsd-bugs@FreeBSD.org
Subject:   Re: bin/16422: newfs always make root's / directory
Message-ID:  <200201170120.g0H1K3G79441@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help
The following reply was made to PR bin/16422; it has been noted by GNATS.

From: Adrian Filipi-Martin <adrian@ubergeeks.com>
To: freebsd-gnats-submit@FreeBSD.org,
	<ichimura@shimada.nuee.nagoya-u.ac.jp>
Cc:  
Subject: Re: bin/16422: newfs always make root's / directory
Date: Wed, 16 Jan 2002 20:18:44 -0500 (EST)

 Hi folks,
 
 	I know this PR is closed, but the fundamental need is real.
 Having newfs always produce a root:wheel owned directory is contrary to
 user mounts (sysctl vfs.usermount=1) facility.
 
 	We use user mounts to provide desktop users access to the local
 devices (floppy and cd-rom).  The users presently either need root
 privileges to chown a newfs'd floppy or then need to get one of our admins
 to do it.  This need is required by the default ownership of the filesystem
 root after newfs fnishes.
 
 	The attached diffs make newfs's behavior more compatible with user
 mounts.  To defeat this new behavior, the -R flag is provided.  If people
 do not like this being the default, I'd still like to see the -R flag, but
 with its logic reversed to enable the behavior.
 
 	Adrian
 --
 [ adrian@ubergeeks.com ]
 
 
 --- mkfs.c.orig	Fri Dec 21 23:33:36 2001
 +++ mkfs.c	Wed Jan 16 19:16:01 2002
 @@ -95,6 +95,7 @@
  extern struct stat mfs_mtstat;	/* stat prior to mount          */
  extern int	Nflag;		/* run mkfs without writing file system */
  extern int	Oflag;		/* format as an 4.3BSD file system */
 +extern int	Rflag;		/* Always set the root directory root:wheel */
  extern int	Uflag;		/* enable soft updates for file system */
  extern int	fssize;		/* file system size */
  extern int	ntracks;	/* # tracks/cylinder */
 @@ -1010,8 +1011,17 @@
  	 */
  	if (mfs)
  		node.di_mode = IFDIR | 01777;
 -	else
 -		node.di_mode = IFDIR | UMASK;
 +	else {
 +		if (Rflag || (getuid() == 0) ) {
 +			node.di_mode = IFDIR | UMASK;
 +		} else {
 +			mode_t mask = umask(0);
 +			umask(mask);
 +			node.di_mode = IFDIR | (0777 & ~mask);
 +			node.di_uid = getuid();
 +			node.di_gid = getgid();
 +		}
 +	}
  	node.di_nlink = PREDEFDIR;
  	if (Oflag)
  		node.di_size = makedir((struct direct *)oroot_dir, PREDEFDIR);
 --- newfs.8.orig	Fri Dec 21 23:33:36 2001
 +++ newfs.8	Wed Jan 16 20:00:04 2002
 @@ -41,7 +41,7 @@
  .Nd construct a new file system
  .Sh SYNOPSIS
  .Nm
 -.Op Fl NOU
 +.Op Fl NORU
  .Op Fl S Ar sector-size
  .Op Fl T Ar disktype
  .Op Fl a Ar maxcontig
 @@ -101,7 +101,16 @@
  In fact, it need not even be special.)
  Typically the defaults are reasonable, however
  .Nm
 -has numerous options to allow the defaults to be selectively overridden.
 +has numerous options to allow the defaults to be selectively
 +overridden.  The default owner and group of the root directory of
 +the formatted device is the same as that of the user issuing the
 +.Nm newfs
 +command, and the default mode is modified by the user's umask
 +setting, unless
 +.Nm newfs
 +is run by root, in which case
 +.Fl R
 +flag is assumed.
  .Pp
  .Nm Mount_mfs
  is used to build a file system in virtual memory and then mount it
 @@ -148,6 +157,12 @@
  format filesystem.
  This options is primarily used to build root filesystems
  that can be understood by older boot ROMs.
 +.It Fl R
 +Use the traditional behavior when setting the owner, group and mode
 +for the root directory on the newly formated device.  i.e. Set it
 +to root and wheel with the mode u=rwx,go=rx, rather than using the
 +current user's UID, GID and umask, if not running as root.  This
 +option is enabled implicitly if the user is root.
  .It Fl T
  Use information for the specified disk from
  .Pa /etc/disktab
 --- newfs.c.orig	Fri Dec 21 23:33:36 2001
 +++ newfs.c	Wed Jan 16 18:35:46 2002
 @@ -170,6 +170,7 @@
  struct stat mfs_mtstat;		/* stat prior to mount		*/
  int	Nflag;			/* run without writing file system */
  int	Oflag;			/* format as an 4.3BSD file system */
 +int	Rflag;			/* Always set the root directory root:wheel */
  int	Uflag;			/* enable soft updates for file system */
  int	fssize;			/* file system size */
  int	ntracks = NTRACKS;	/* # tracks/cylinder */
 @@ -250,7 +251,7 @@
 
  	opstring = mfs ?
  	    "NF:T:Ua:b:c:d:e:f:g:h:i:m:o:s:" :
 -	    "NOS:T:Ua:b:c:d:e:f:g:h:i:k:l:m:n:o:p:r:s:t:u:vx:";
 +	    "NORS: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) {
  		case 'N':
 @@ -258,6 +259,9 @@
  			break;
  		case 'O':
  			Oflag = 1;
 +			break;
 +		case 'R':
 +			Rflag = 1;
  			break;
  		case 'S':
  			if ((sectorsize = atoi(optarg)) <= 0)
 

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-bugs" in the body of the message




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