Subject: bin/2404: newfs for disks other than 512bytes/sector
To: None <gnats-bugs@NetBSD.ORG>
From: None <yasufu-i@is.aist-nara.ac.jp>
List: netbsd-bugs
Date: 05/14/1996 02:17:11
>Number:         2404
>Category:       bin
>Synopsis:       newfs for disks other than 512bytes/sector
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    bin-bug-people (Utility Bug People)
>State:          open
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Mon May 13 13:35:01 1996
>Last-Modified:
>Originator:     ITOH, Yasufumi
>Organization:
	
Nara Institute of Schence and Technology, Nara, Japan
>Release:        1.1
>Environment:
	
System: NetBSD acha.my.domain 1.1 NetBSD 1.1 (ACHA) #1: Tue Apr 30 13:22:56 JST 1996 yasufu-i@wonder1:/mnt/src/sys/arch/x68k/compile/ACHA x68k


>Description:
	
/sbin/newfs doesn't work for disks whose sector size != 512bytes.
If it is used for floppies whose sector size = 1024byte,
it destroys the disklabel.

It is true that most disks are 512byte sector,
but I think it desiable to support such type of disks,
since /etc/disktab does have field for specifying sector size.

>How-To-Repeat:
	
1. Make an /etc/disktab entry like following:

floppy5j|5inj|2hd|5in1232|5.25 inch High Density Floppy (1024kbytes/sec, 77cyl):\
	:ty=floppy:se#1024:nt#2:rm#360:ns#8:nc#77:\
	:ts=1800:\
	:pa#1232:oa#0:ba#4096:fa#1024:\
	:pb#0:ob#0:\
	:pc#1232:oc#0:

2. Write disklabel to a floppy
	# disklabel -r -w fd0a floppy5j

3. Make filesystem
	# newfs fd0a

4. Then, the disklabel is corrupt (confirm by "disklabel -r fd0a")

>Fix:
	
newfs supports sector < 512byte disks with -Dtahoe compilation option,
so it is easy to fix this problem.

*** sbin/newfs/newfs.c.orig	Sat Oct 14 10:12:39 1995
--- sbin/newfs/newfs.c	Mon May 13 23:32:29 1996
***************
*** 157,163 ****
  int	trackspares = -1;	/* spare sectors per track */
  int	cylspares = -1;		/* spare sectors per cylinder */
  int	sectorsize;		/* bytes/sector */
! #ifdef tahoe
  int	realsectorsize;		/* bytes/sector in hardware */
  #endif
  int	rpm;			/* revolutions/minute of drive */
--- 157,163 ----
  int	trackspares = -1;	/* spare sectors per track */
  int	cylspares = -1;		/* spare sectors per cylinder */
  int	sectorsize;		/* bytes/sector */
! #ifndef FIXED_SECTOR_SIZE
  int	realsectorsize;		/* bytes/sector in hardware */
  #endif
  int	rpm;			/* revolutions/minute of drive */
***************
*** 525,533 ****
  	sbsize = lp->d_sbsize;
  #endif
  	oldpartition = *pp;
! #ifdef tahoe
  	realsectorsize = sectorsize;
! 	if (sectorsize != DEV_BSIZE) {		/* XXX */
  		int secperblk = DEV_BSIZE / sectorsize;
  
  		sectorsize = DEV_BSIZE;
--- 525,533 ----
  	sbsize = lp->d_sbsize;
  #endif
  	oldpartition = *pp;
! #ifndef FIXED_SECTOR_SIZE
  	realsectorsize = sectorsize;
! 	if (sectorsize < DEV_BSIZE) {		/* XXX */
  		int secperblk = DEV_BSIZE / sectorsize;
  
  		sectorsize = DEV_BSIZE;
***************
*** 536,547 ****
  		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);
--- 536,558 ----
  		secpercyl /= secperblk;
  		fssize /= secperblk;
  		pp->p_size /= secperblk;
+ 	} else if (sectorsize > DEV_BSIZE) {
+ 		int blkpersec = sectorsize / DEV_BSIZE;
+ 
+ 		sectorsize = DEV_BSIZE;
+ 		nsectors *= blkpersec;
+ 		nphyssectors *= blkpersec;
+ 		secpercyl *= blkpersec;
+ 		fssize *= blkpersec;
+ 		pp->p_size *= blkpersec;
  	}
  #endif
  	mkfs(pp, special, fsi, fso);
! #ifndef FIXED_SECTOR_SIZE
! 	if (realsectorsize < DEV_BSIZE)
  		pp->p_size *= DEV_BSIZE / realsectorsize;
+ 	else if (realsectorsize > DEV_BSIZE)
+ 		pp->p_size /= realsectorsize / DEV_BSIZE;
  #endif
  	if (!Nflag && memcmp(pp, &oldpartition, sizeof(oldpartition)))
  		rewritelabel(special, fso, lp);
>Audit-Trail:
>Unformatted: