Subject: bin/4384: boot floppies and fsck/mount: PR2975 not done right, 2974 still open
To: None <gnats-bugs@gnats.netbsd.org>
From: None <bgrayson@ece.utexas.edu>
List: netbsd-bugs
Date: 10/29/1997 08:51:43
>Number:         4384
>Category:       bin
>Synopsis:       The proposed fix in PR 2975 appears to have been applied, but it had a bug.
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    bin-bug-people (Utility Bug People)
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Wed Oct 29 07:05:00 1997
>Last-Modified:
>Originator:     Brian Grayson
>Organization:
	Parallel and Distributed Systems
	Electrical and Computer Engineering
	The University of Texas at Austin
>Release:        Oct 28, 1997
>Environment:
NetBSD marvin 1.3_ALPHA NetBSD 1.3_ALPHA (MARVIN) #14: Mon Oct 27 11:38:47 CST 1997     bgrayson@marvin:/a/c3p0/home/c3p0/src/sys/arch/i386/compile/MARVIN i386

>Description:
	PR 2974 and 2975 dealt with the fact that both mount and
	fsck, when passed the -t VFS switch, exec mount_VFS (or
	fsck_VFS).  However, they pass a bogus argv[0] of simply
	VFS, not mount_VFS.  This leads to problems on
	crunchgen'd things (such as boot floppies), because
	crunchgen'd programs look at argv[0] to determine what
	program to run.  Since both mount_VFS and fsck_VFS will
	cause a crunched binary to try to run VFS, one of the two
	programs will not be available.  (Someone added links for
	VFS->mount_VFS to all the appropriate crunchgen.conf
	files, so that at least mounting would work, but
	now one can't fsck -t VFS, only fsck_VFS, which defeats
	part of the point of having a single fsck that runs the
	appropriate fsck_VFS.)

	PR 2974 covered this and other problems, none of which appear to
	have been corrected?  PR 2975 covered simply the above
	problem for fsck, and was closed.  However, the patch was
	incorrect -- it sets argv[0] to vfstype, when it should
	be set to execbase.
>How-To-Repeat:
	Boot a boot floppy, and try to run fsck /dev/wd0a.  It
	will fail with:

	mount_ffs: illegal option -- y
	usage: mount_ffs [-o options] special node

	because the crunch'd binary is trying to execute ffs -y,
	which gets mapped to mount_ffs via the bogus link in the
	ramdiskbin.conf file:

	ln mount_cd9660 cd9660
	ln mount_ffs ffs
	ln mount_msdos msdos
	ln mount_nfs nfs
	ln mount_kernfs kernfs
>Fix:
	For fsck.c:
--- /usr/src/sbin/fsck/fsck.c   Mon Oct 13 06:53:06 1997
+++ fsck.c      Wed Oct 29 08:36:52 1997
@@ -239,7 +239,7 @@
 
        /* construct basename of executable and argv[0]
         * simultaneously */
        (void) snprintf(execbase, sizeof(execbase), "fsck_%s",
vfstype);
-       argv[0] = vfstype;
+       argv[0] = execbase;
 

	For mount, this can be cleaned up some, but I'm not sure
	what the implications are, so I left a comment and the
	original code commented out.  Also, resetting argv[0]
	before each exec attempt might not be the best thing
	stylistically.
--- /usr/src/sbin/mount/mount.c Wed Sep 17 06:13:53 1997
+++ mount.c     Wed Oct 29 08:41:45 1997
@@ -364,7 +364,13 @@
        }
 
        argc = 0;
+       /*  Skip assignment of argv[0] for now -- wait
+           until below when we try the execs.
+
        argv[argc++] = vfstype;
+
+       */
+       argc++;
        mangle(optbuf, &argc, argv);
        argv[argc++] = spec;
        argv[argc++] = name;
@@ -389,6 +395,7 @@
                do {
                        (void)snprintf(execname,
                            sizeof(execname), "%s/mount_%s", *edir, vfstype);
+                       argv[0] = execname;
                        execv(execname, (char * const *)argv);
                        if (errno != ENOENT)
                                warn("exec %s for %s", execname, name);

	When the above changes are made, all of the "ln" lines for
	mount_* from the following crunchgen conf files can be removed:

sun3/common/rd_bin.conf
vax/inst-common/instbin.conf
amiga/floppies/inst-common/instbin.conf
arm32/floppies/inst-common/instbin.conf
i386/floppies/ramdisk/ramdiskbin.conf
pc532/floppies/inst-common/instbin.conf
x68k/floppies/ramdisk/ramdiskbin.conf

	
>Audit-Trail:
>Unformatted: