Subject: bin/28884: mount_mfs(8) doesn't set default fs size if "swap" is specified
To: None <gnats-admin@netbsd.org, netbsd-bugs@netbsd.org>
From: None <tsutsui@ceres.dti.ne.jp>
List: netbsd-bugs
Date: 01/06/2005 13:57:00
>Number:         28884
>Category:       bin
>Synopsis:       mount_mfs(8) doesn't set default fssize if "swap" is specified
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    bin-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Thu Jan 06 13:57:00 +0000 2005
>Originator:     Izumi Tsutsui
>Release:        NetBSD 2.99.11 and 2.0-release
>Organization:
>Environment:
System: NetBSD 2.99.11
Architecture: i386
Machine: i386
but maybe all arch
>Description:
Old mount_mfs prepared faked disklabel to set default fssize,
but it was removed from newfs.c rev 1.75. The new version uses
stat(2) to take fssize of filesystem specified as "special",
but it fails if "swap" (and other) keyword is used.

>How-To-Repeat:
Boot GENERIC_MD kernel for macppc or dreamcast, which use
"mount -t mfs swap /tmp" in md_root .profile .
It complains "Unable to determine file system size."

>Fix:
Set default fssize if stat(2) fails for mount_mfs case:

Index: newfs.c
===================================================================
RCS file: /cvsroot/src/sbin/newfs/newfs.c,v
retrieving revision 1.85
diff -u -r1.85 newfs.c
--- newfs.c	15 Nov 2004 12:21:29 -0000	1.85
+++ newfs.c	6 Jan 2005 13:45:00 -0000
@@ -170,6 +170,11 @@
 #define	DFL_SECSIZE	512
 
 /*
+ * Default file system size for "mount_mfs swap /dir" case.
+ */
+#define	DFL_FSSIZE	(8 * 1024 * 1024)
+
+/*
  * MAXBLKPG determines the maximum number of data blocks which are
  * placed in a single cylinder group. The default is one indirect
  * block worth of data blocks.
@@ -413,8 +418,10 @@
 
 		if (mfs) {
 			/* Default filesystem size to that of supplied device */
-			if (fssize == 0)
-				stat(special, &sb);
+			if (fssize == 0) {
+				if (stat(special, &sb) != 0)
+					fssize = DFL_FSSIZE / sectorsize;
+			}
 		} else {
 			/* creating image in a regular file */
 			int fl;

>Unformatted: