Subject: bin/1367: [dM] can't newfs non-disks
To: None <gnats-bugs@gnats.netbsd.org>
From: der Mouse <mouse@Collatz.McRCIM.McGill.EDU>
List: netbsd-bugs
Date: 08/17/1995 15:01:47
>Number:         1367
>Category:       bin
>Synopsis:       [dM] can't newfs non-disks
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    bin-bug-people (Utility Bug People)
>State:          open
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Thu Aug 17 15:05:01 1995
>Last-Modified:
>Originator:     der Mouse
>Organization:
	Dis-
>Release:        -current as of this morning's sup (17 Aug '95)
>Environment:
	SPARC IPC, but it's irrelevant
>Description:
	newfs absolutely refuses to create filesystems on things that
	don't support the DIOCGDINFO ioctl (unless built with COMPAT,
	and then it requires a disk type name).  However, if -s, -t,
	and -u are given, newfs does not need the label for anything.
	This problem makes it much more difficult to use vnd devices,
	since one can't create a filesystem on one de novo.
>How-To-Repeat:
	Try to newfs a vnd device.  Or a file (trying to make it
	contain a filesystem image).  Or anything else....
>Fix:
	Here's the patch I'm using.  There are other problems I haven't
	corrected; for example, the "can't figure out file system
	partition" error, which really shouldn't be a fatal error.

diff -b -c -r /sources/latest-usr-src/sbin/newfs/mkfs.c /usr/src/sbin/newfs/mkfs.c
*** /sources/latest-usr-src/sbin/newfs/mkfs.c	Tue Jun 20 06:37:44 1995
--- /usr/src/sbin/newfs/mkfs.c	Thu Aug 17 14:44:58 1995
***************
*** 627,636 ****
--- 627,638 ----
  	 * Update information about this partion in pack
  	 * label, to that it may be updated on disk.
  	 */
+ 	if (pp) {
  		pp->p_fstype = FS_BSDFFS;
  		pp->p_fsize = sblock.fs_fsize;
  		pp->p_frag = sblock.fs_frag;
  		pp->p_cpg = sblock.fs_cpg;
+ 	}
  	/*
  	 * Notify parent process of success.
  	 * Dissociate from session and tty.
diff -b -c -r /sources/latest-usr-src/sbin/newfs/newfs.c /usr/src/sbin/newfs/newfs.c
*** /sources/latest-usr-src/sbin/newfs/newfs.c	Wed Jun 28 03:04:24 1995
--- /usr/src/sbin/newfs/newfs.c	Thu Aug 17 14:49:22 1995
***************
*** 428,433 ****
--- 428,435 ----
  			disktype = argv[1];
  #endif
  		lp = getdisklabel(special, fsi);
+ 		pp = 0;
+ 		if (lp) {
  			if (isdigit(*cp))
  				pp = &lp->d_partitions[0];
  			else
***************
*** 439,448 ****
  			fatal("%s: `%c' partition overlaps boot program",
  			      argv[0], *cp);
  	}
  havelabel:
  	if (fssize == 0)
  		fssize = pp->p_size;
! 	if (fssize > pp->p_size && !mfs)
  	       fatal("%s: maximum file system size on the `%c' partition is %d",
  			argv[0], *cp, pp->p_size);
  	if (rpm == 0) {
--- 441,465 ----
  				fatal("%s: `%c' partition overlaps boot program",
  				      argv[0], *cp);
  		}
+ 	}
  havelabel:
+ 	if (! pp) {
+ 		if ( (fssize == 0) ||
+ 		     (ntracks == 0) ||
+ 		     (nsectors == 0) )
+ 			fatal("%s: no label; must specify -s, -t, and -u",argv[0]);
+ 		if (sectorsize == 0) sectorsize = 512;
+ 		if (rpm == 0) rpm = 3600;
+ 		if (trackskew < 0) trackskew = 0;
+ 		if (interleave == 0) interleave = 1;
+ 		if (fsize == 0) fsize = DFL_FRAGSIZE;
+ 		if (bsize == 0) bsize = DFL_BLKSIZE;
+ 		if (trackspares < 0) trackspares = 0;
+ 		if (cylspares < 0) cylspares = 0;
+ 	}
  	if (fssize == 0)
  		fssize = pp->p_size;
! 	if (pp && fssize > pp->p_size && !mfs)
  	       fatal("%s: maximum file system size on the `%c' partition is %d",
  			argv[0], *cp, pp->p_size);
  	if (rpm == 0) {
***************
*** 512,530 ****
  			cylspares = 0;
  	}
  	secpercyl = nsectors * ntracks - cylspares;
! 	if (secpercyl != lp->d_secpercyl)
  		fprintf(stderr, "%s (%d) %s (%lu)\n",
  			"Warning: calculated sectors per cylinder", secpercyl,
  			"disagrees with disk label", lp->d_secpercyl);
  	if (maxbpg == 0)
  		maxbpg = MAXBLKPG(bsize);
! 	headswitch = lp->d_headswitch;
! 	trackseek = lp->d_trkseek;
  #ifdef notdef /* label may be 0 if faked up by kernel */
  	bbsize = lp->d_bbsize;
  	sbsize = lp->d_sbsize;
  #endif
! 	oldpartition = *pp;
  #ifdef tahoe
  	realsectorsize = sectorsize;
  	if (sectorsize != DEV_BSIZE) {		/* XXX */
--- 529,547 ----
  			cylspares = 0;
  	}
  	secpercyl = nsectors * ntracks - cylspares;
! 	if (lp && (secpercyl != lp->d_secpercyl))
  		fprintf(stderr, "%s (%d) %s (%lu)\n",
  			"Warning: calculated sectors per cylinder", secpercyl,
  			"disagrees with disk label", lp->d_secpercyl);
  	if (maxbpg == 0)
  		maxbpg = MAXBLKPG(bsize);
! 	headswitch = lp ? lp->d_headswitch : 0; /* XXX should have flag */
! 	trackseek = lp ? lp->d_trkseek : 0; /* XXX should have flag */
  #ifdef notdef /* label may be 0 if faked up by kernel */
  	bbsize = lp->d_bbsize;
  	sbsize = lp->d_sbsize;
  #endif
! 	if (pp) oldpartition = *pp;
  #ifdef tahoe
  	realsectorsize = sectorsize;
  	if (sectorsize != DEV_BSIZE) {		/* XXX */
***************
*** 535,549 ****
  		nphyssectors /= secperblk;
  		secpercyl /= secperblk;
  		fssize /= secperblk;
! 		pp->p_size /= secperblk;
  	}
  #endif
  	mkfs(pp, special, fsi, fso);
  #ifdef tahoe
! 	if (realsectorsize != DEV_BSIZE)
  		pp->p_size *= DEV_BSIZE / realsectorsize;
  #endif
! 	if (!Nflag && memcmp(pp, &oldpartition, sizeof(oldpartition)))
  		rewritelabel(special, fso, lp);
  	if (!Nflag)
  		close(fso);
--- 552,566 ----
  		nphyssectors /= secperblk;
  		secpercyl /= secperblk;
  		fssize /= secperblk;
! 		if (pp) pp->p_size /= secperblk;
  	}
  #endif
  	mkfs(pp, special, fsi, fso);
  #ifdef tahoe
! 	if (pp && (realsectorsize != DEV_BSIZE))
  		pp->p_size *= DEV_BSIZE / realsectorsize;
  #endif
! 	if (!Nflag && pp && memcmp(pp, &oldpartition, sizeof(oldpartition)))
  		rewritelabel(special, fso, lp);
  	if (!Nflag)
  		close(fso);
***************
*** 594,600 ****
  		}
  #endif
  		warn("ioctl (GDINFO)");
! 		fatal(lmsg, s);
  	}
  	return (&lab);
  }
--- 611,617 ----
  		}
  #endif
  		warn("ioctl (GDINFO)");
! 		return(0);
  	}
  	return (&lab);
  }

					der Mouse

			    mouse@collatz.mcrcim.mcgill.edu
>Audit-Trail:
>Unformatted: