Subject: kern/18482: Supporting sector size != DEV_BSIZE
To: None <gnats-bugs@gnats.netbsd.org>
From: None <trevin@xmission.com>
List: netbsd-bugs
Date: 09/30/2002 16:40:54
>Number:         18482
>Category:       kern
>Synopsis:       Supporting sector size != DEV_BSIZE
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    kern-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Mon Sep 30 16:42:01 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator:     Trevin Beattie
>Release:        NetBSD-1.6I (-current 09/28/2002)
>Organization:
>Environment:
NetBSD clyde.wh.ca.us 1.6I NetBSD 1.6I (CLYDE) #1: Sun Sep 29 20:55:39 UTC 2002     trevin@clyde.wh.ca.us:/home/trevin/src/sys/arch/i386/compile/CLYDE i386

>Description:
This problem has been a part of NetBSD for years (see PR #'s bin/2404, kern/2896, kern/3790) and was recently the subject of a long discussion and test patches in the tech-kern mailing list in June/July 2002.  In summary, when the disk media's sector size != DEV_BSIZE,

* the port-specific disk subroutine gets the logical sector boundary wrong

* the kernel and disk utilities have trouble reading the partition table and/or super block

* mkfs computes some of the super block fields incorrectly

* installboot yields conflicting values for the block number / block count table

* file block counts are incorrect

>How-To-Repeat:
1) Create a blank virtual disk image:
   dd if=/dev/zero of=test-disk bs=1024 count=1024
   (Makes a 1MB blank file; you can make it whatever size you want)
2) Configure a virtual disk device with large sectors:
   vnconfig -v vnd0 test-disk 2048/64/1/8
   (or 1024/64/2/8, 4096/16/4/8, or whatever you want,
    so long as the first number != DEV_BSIZE)
3) (optional) Partition the virtual disk with /sbin/fdisk
4) Label the virtual disk with /sbin/disklabel
   and assign NetBSD partitions
5) Create a file system:
   newfs /dev/rvnd0a
6) Mount the file system:
   mount /dev/vnd0a /mnt
7) Copy some files and/or directories to /mnt/.
8) Check the file inode details for consistency (ls -l);
   in particular compare block count to file size.
9) Check file contents to see whether they have been corrupted
   (i.e., skipping or repeating blocks).

>Fix:
I've taken my last set of patches (posted to tech-kern on Jul 24, 2002) and pulled them up to NetBSD-1.6I (-current as of Sep 28, 2002).  The patches have been tested on the i386 port using both ffs and lfs.  There are a separate set of patches for the msdos file system; see PR# kern/17398.  I also have cursory patches for the mvme68k and x68k ports, but someone else needs to add port-specific patches for the non-i386 ports, since I don't have access to such machines for testing.

Index: sys/lib/libsa/ufs.c
===================================================================
RCS file: /cvsroot/syssrc/sys/lib/libsa/ufs.c,v
retrieving revision 1.30
diff -u -r1.30 ufs.c
--- sys/lib/libsa/ufs.c	2000/03/30 12:19:49	1.30
+++ sys/lib/libsa/ufs.c	2002/09/30 22:40:18
@@ -149,7 +149,7 @@
 	twiddle();
 #endif
 	rc = DEV_STRATEGY(f->f_dev)(f->f_devdata, F_READ,
-		fsbtodb(fs, ino_to_fsba(fs, inumber)), fs->fs_bsize,
+		fsbtoDB(fs, ino_to_fsba(fs, inumber)), fs->fs_bsize,
 		buf, &rsize);
 	if (rc)
 		goto out;
@@ -261,7 +261,7 @@
 			twiddle();
 #endif
 			rc = DEV_STRATEGY(f->f_dev)(f->f_devdata, F_READ,
-				fsbtodb(fp->f_fs, ind_block_num),
+				fsbtoDB(fp->f_fs, ind_block_num),
 				fs->fs_bsize,
 				fp->f_blk[level],
 				&fp->f_blksize[level]);
@@ -326,7 +326,7 @@
 			twiddle();
 #endif
 			rc = DEV_STRATEGY(f->f_dev)(f->f_devdata, F_READ,
-				fsbtodb(fs, disk_block),
+				fsbtoDB(fs, disk_block),
 				block_size, fp->f_buf, &fp->f_buf_size);
 			if (rc)
 				return (rc);
@@ -565,7 +565,7 @@
 				twiddle();
 #endif
 				rc = DEV_STRATEGY(f->f_dev)(f->f_devdata,
-					F_READ, fsbtodb(fs, disk_block),
+					F_READ, fsbtoDB(fs, disk_block),
 					fs->fs_bsize, buf, &buf_size);
 				if (rc)
 					goto out;
Index: sys/arch/i386/i386/disksubr.c
===================================================================
RCS file: /cvsroot/syssrc/sys/arch/i386/i386/disksubr.c,v
retrieving revision 1.46
diff -u -r1.46 disksubr.c
--- sys/arch/i386/i386/disksubr.c	2002/09/28 01:17:09	1.46
+++ sys/arch/i386/i386/disksubr.c	2002/09/30 22:40:18
@@ -140,10 +140,13 @@
 	struct disklabel *dlp;
 	char *msg = NULL;
 	int dospartoff, cyl, i, *ip;
+	int sectoDB = lp->d_secsize / DEV_BSIZE;
 
 	/* minimal requirements for archtypal disk label */
-	if (lp->d_secsize == 0)
+	if (lp->d_secsize == 0) {
 		lp->d_secsize = DEV_BSIZE;
+		sectoDB = 1;
+	}
 	if (lp->d_secperunit == 0)
 		lp->d_secperunit = 0x1fffffff;
 #if 0
@@ -176,7 +179,7 @@
 	dp = osdep->dosparts;
 
 	/* read master boot record */
-	bp->b_blkno = MBR_BBSECTOR;
+	bp->b_blkno = MBR_BBSECTOR * sectoDB;
 	bp->b_bcount = lp->d_secsize;
 	bp->b_flags |= B_READ;
 	bp->b_cylinder = MBR_BBSECTOR / lp->d_secpercyl;
@@ -247,7 +250,7 @@
 
 nombrpart:
 	/* next, dig out disk label */
-	bp->b_blkno = dospartoff + LABELSECTOR;
+	bp->b_blkno = (dospartoff + LABELSECTOR) * sectoDB;
 	bp->b_cylinder = cyl;
 	bp->b_bcount = lp->d_secsize;
 	bp->b_flags &= ~(B_DONE);
@@ -391,6 +394,7 @@
 	struct buf *bp;
 	struct disklabel *dlp;
 	int error, dospartoff, cyl;
+	int sectoDB = lp->d_secsize / DEV_BSIZE;
 
 	/* get a buffer and initialize it */
 	bp = geteblk((int)lp->d_secsize);
@@ -404,7 +408,7 @@
 	dp = osdep->dosparts;
 
 	/* read master boot record */
-	bp->b_blkno = MBR_BBSECTOR;
+	bp->b_blkno = MBR_BBSECTOR * sectoDB;
 	bp->b_bcount = lp->d_secsize;
 	bp->b_flags |= B_READ;
 	bp->b_cylinder = MBR_BBSECTOR / lp->d_secpercyl;
@@ -436,7 +440,7 @@
 #endif
 
 	/* next, dig out disk label */
-	bp->b_blkno = dospartoff + LABELSECTOR;
+	bp->b_blkno = (dospartoff + LABELSECTOR) * sectoDB;
 	bp->b_cylinder = cyl;
 	bp->b_bcount = lp->d_secsize;
 	bp->b_flags &= ~(B_DONE);
@@ -478,13 +482,15 @@
 	int wlabel;
 {
 	struct partition *p = lp->d_partitions + DISKPART(bp->b_dev);
-	int labelsector = lp->d_partitions[2].p_offset + LABELSECTOR;
+	int sectoDB = lp->d_secsize / DEV_BSIZE;
+	int labelblock = (lp->d_partitions[2].p_offset + LABELSECTOR)
+			* sectoDB;
 	int sz;
 
-	sz = howmany(bp->b_bcount, lp->d_secsize);
+	sz = howmany(bp->b_bcount, DEV_BSIZE);
 
-	if (bp->b_blkno + sz > p->p_size) {
-		sz = p->p_size - bp->b_blkno;
+	if (bp->b_blkno + sz > p->p_size * sectoDB) {
+		sz = p->p_size * sectoDB - bp->b_blkno;
 		if (sz == 0) {
 			/* If exactly at end of disk, return EOF. */
 			bp->b_resid = bp->b_bcount;
@@ -500,9 +506,9 @@
 	}
 
 	/* Overwriting disk label? */
-	if (bp->b_blkno + p->p_offset <= labelsector &&
+	if (bp->b_blkno + p->p_offset * sectoDB <= labelblock &&
 #if LABELSECTOR != 0
-	    bp->b_blkno + p->p_offset + sz > labelsector &&
+	    bp->b_blkno + p->p_offset * sectoDB + sz > labelblock &&
 #endif
 	    (bp->b_flags & B_READ) == 0 && !wlabel) {
 		bp->b_error = EROFS;
@@ -510,8 +516,8 @@
 	}
 
 	/* calculate cylinder for disksort to order transfers with */
-	bp->b_cylinder = (bp->b_blkno + p->p_offset) /
-	    (lp->d_secsize / DEV_BSIZE) / lp->d_secpercyl;
+	bp->b_cylinder = (bp->b_blkno / sectoDB + p->p_offset)
+		/ lp->d_secpercyl;
 	return (1);
 
 bad:
Index: sys/arch/i386/stand/installboot/installboot.c
===================================================================
RCS file: /cvsroot/syssrc/sys/arch/i386/stand/installboot/installboot.c,v
retrieving revision 1.16
diff -u -r1.16 installboot.c
--- sys/arch/i386/stand/installboot/installboot.c	2002/07/20 08:36:18	1.16
+++ sys/arch/i386/stand/installboot/installboot.c	2002/09/30 22:40:19
@@ -1,4 +1,4 @@
-/* $NetBSD: installboot.c,v 1.16 2002/07/20 08:36:18 grant Exp $	 */
+/* $NetBSD: installboot.c,v 1.15 1999/09/10 16:45:27 drochner Exp $	 */
 
 /*
  * Copyright (c) 1994 Paul Kranenburg
@@ -181,7 +181,7 @@
 	int nblk;
 
 	/* convert to disk blocks */
-	blk = fsbtodb(fs, blk);
+	blk = fsbtoDB(fs, blk);
 	nblk = fs->fs_bsize / DEV_BSIZE;
 	if (nblk > blcnt)
 		nblk = blcnt;
@@ -245,7 +245,7 @@
 		warnx("No memory for filesystem block");
 		goto out;
 	}
-	blk = fsbtodb(fs, ino_to_fsba(fs, inode));
+	blk = fsbtoDB(fs, ino_to_fsba(fs, inode));
 	if (devread(devfd, buf, blk, (size_t)fs->fs_bsize, "inode"))
 		goto out;
 	ip = (struct dinode *)buf + ino_to_fsbo(fs, inode);
@@ -270,7 +270,7 @@
 	         * Just one level of indirections; there isn't much room
 	         * for more in the 1st-level bootblocks anyway.
 	         */
-		blk = fsbtodb(fs, ip->di_ib[0]);
+		blk = fsbtoDB(fs, ip->di_ib[0]);
 		if (devread(devfd, buf, blk, (size_t)fs->fs_bsize,
 			    "indirect block"))
 			goto out;
Index: sys/arch/mvme68k/stand/installboot/installboot.c
===================================================================
RCS file: /cvsroot/syssrc/sys/arch/mvme68k/stand/installboot/installboot.c,v
retrieving revision 1.7
diff -u -r1.7 installboot.c
--- sys/arch/mvme68k/stand/installboot/installboot.c	2000/12/09 22:33:24	1.7
+++ sys/arch/mvme68k/stand/installboot/installboot.c	2002/09/30 22:40:20
@@ -304,7 +304,7 @@
 	if ((buf = malloc(fs->fs_bsize)) == NULL)
 		errx(1, "No memory for filesystem block");
 
-	blk = fsbtodb(fs, ino_to_fsba(fs, statbuf.st_ino));
+	blk = fsbtoDB(fs, ino_to_fsba(fs, statbuf.st_ino));
 	devread(devfd, buf, blk, fs->fs_bsize, "inode");
 	ip = (struct dinode *)(buf) + ino_to_fsbo(fs, statbuf.st_ino);
 
@@ -325,7 +325,7 @@
 	 */
 	ap = ip->di_db;
 	for (i = 0; i < NDADDR && *ap && ndb; i++, ap++, ndb--) {
-		blk = fsbtodb(fs, *ap);
+		blk = fsbtoDB(fs, *ap);
 		if (verbose)
 			printf("%d: %d\n", i, blk);
 		block_table[i] = blk;
@@ -337,11 +337,11 @@
 	 * Just one level of indirections; there isn't much room
 	 * for more in the 1st-level bootblocks anyway.
 	 */
-	blk = fsbtodb(fs, ip->di_ib[0]);
+	blk = fsbtoDB(fs, ip->di_ib[0]);
 	devread(devfd, buf, blk, fs->fs_bsize, "indirect block");
 	ap = (daddr_t *)buf;
 	for (; i < NINDIR(fs) && *ap && ndb; i++, ap++, ndb--) {
-		blk = fsbtodb(fs, *ap);
+		blk = fsbtoDB(fs, *ap);
 		if (verbose)
 			printf("%d: %d\n", i, blk);
 		block_table[i] = blk;
Index: sys/arch/x68k/stand/boot_ufs/readufs_ffs.c
===================================================================
RCS file: /cvsroot/syssrc/sys/arch/x68k/stand/boot_ufs/readufs_ffs.c,v
retrieving revision 1.2
diff -u -r1.2 readufs_ffs.c
--- sys/arch/x68k/stand/boot_ufs/readufs_ffs.c	2002/03/17 16:14:30	1.2
+++ sys/arch/x68k/stand/boot_ufs/readufs_ffs.c	2002/09/30 22:40:20
@@ -90,7 +90,7 @@
 	struct dinode *buf = alloca((size_t) fsi.bsize);
 	struct dinode *di;
 
-	RAW_READ(buf, fsbtodb(&fsi, ino_to_fsba(&fsi, ino)),
+	RAW_READ(buf, fsbtoDB(&fsi, ino_to_fsba(&fsi, ino)),
 			(size_t) fsi.bsize);
 
 	di = &buf[ino_to_fsbo(&fsi, ino)];
Index: sys/ufs/ext2fs/ext2fs_vfsops.c
===================================================================
RCS file: /cvsroot/syssrc/sys/ufs/ext2fs/ext2fs_vfsops.c,v
retrieving revision 1.52
diff -u -r1.52 ext2fs_vfsops.c
--- sys/ufs/ext2fs/ext2fs_vfsops.c	2002/09/21 18:14:49	1.52
+++ sys/ufs/ext2fs/ext2fs_vfsops.c	2002/09/30 22:40:24
@@ -388,8 +388,7 @@
 	struct buf *bp;
 	struct m_ext2fs *fs;
 	struct ext2fs *newfs;
-	struct partinfo dpart;
-	int i, size, error;
+	int i, error;
 	caddr_t cp;
 
 	if ((mountp->mnt_flag & MNT_RDONLY) == 0)
@@ -406,11 +405,8 @@
 	/*
 	 * Step 2: re-read superblock from disk.
 	 */
-	if (VOP_IOCTL(devvp, DIOCGPART, (caddr_t)&dpart, FREAD, NOCRED, p) != 0)
-		size = DEV_BSIZE;
-	else
-		size = dpart.disklab->d_secsize;
-	error = bread(devvp, (ufs_daddr_t)(SBOFF / size), SBSIZE, NOCRED, &bp);
+	error = bread(devvp, (ufs_daddr_t)(SBOFF / DEV_BSIZE), SBSIZE,
+		      NOCRED, &bp);
 	if (error) {
 		brelse(bp);
 		return (error);
@@ -516,8 +512,7 @@
 	struct ext2fs *fs;
 	struct m_ext2fs *m_fs;
 	dev_t dev;
-	struct partinfo dpart;
-	int error, i, size, ronly;
+	int error, i, ronly;
 	struct ucred *cred;
 	extern struct vnode *rootvp;
 
@@ -543,10 +538,6 @@
 	error = VOP_OPEN(devvp, ronly ? FREAD : FREAD|FWRITE, FSCRED, p);
 	if (error)
 		return (error);
-	if (VOP_IOCTL(devvp, DIOCGPART, (caddr_t)&dpart, FREAD, cred, p) != 0)
-		size = DEV_BSIZE;
-	else
-		size = dpart.disklab->d_secsize;
 
 	bp = NULL;
 	ump = NULL;
@@ -555,7 +546,7 @@
 	printf("sb size: %d ino size %d\n", sizeof(struct ext2fs),
 	    EXT2_DINODE_SIZE);
 #endif
-	error = bread(devvp, (SBOFF / size), SBSIZE, cred, &bp);
+	error = bread(devvp, (SBOFF / DEV_BSIZE), SBSIZE, cred, &bp);
 	if (error)
 		goto out;
 	fs = (struct ext2fs *)bp->b_data;
Index: sbin/disklabel/disklabel.c
===================================================================
RCS file: /cvsroot/basesrc/sbin/disklabel/disklabel.c,v
retrieving revision 1.107
diff -u -r1.107 disklabel.c
--- sbin/disklabel/disklabel.c	2002/09/28 00:47:25	1.107
+++ sbin/disklabel/disklabel.c	2002/09/30 22:40:27
@@ -290,6 +290,20 @@
 	if (f < 0)
 		err(4, "%s", specname);
 
+	/*
+	 * Get the default label so we have some physical parameters
+	 * (i.e., sector size -- required for valid I/O ops)
+	 */
+	if (ioctl(f, DIOCGDEFLABEL, &lab) < 0) {
+		warn("no default label; falling back to 512 byte sector size");
+		lab.d_secsize = 512;
+	}
+	else if (lab.d_secsize > 8192 ||
+		 (lab.d_secsize & (lab.d_secsize - 1)) != 0) {
+		warn("%s has an invalid sector size (%d); using 512 instead",
+			dkname, lab.d_secsize);
+		lab.d_secsize = 512;
+	}
 #ifdef USE_MBR
 	/*
 	 * Check for presence of DOS partition table in
@@ -523,7 +537,7 @@
 
 #ifdef USE_ACORN
 		/* XXX */
-		sectoffset = (off_t)filecore_partition_offset * DEV_BSIZE;
+		sectoffset = (off_t)filecore_partition_offset * lab.d_secsize;
 #endif	/* USE_ACORN */
 
 		/*
@@ -646,13 +660,13 @@
 readmbr(int f)
 {
 	struct mbr_partition *dp;
-	static char	 mbr[DEV_BSIZE];
+	static char	 mbr[8192];
 	u_int16_t	*mbrmagicp;
 	int		 part;
 
 	dp = (struct mbr_partition *)&mbr[MBR_PARTOFF];
-	if (lseek(f, (off_t)MBR_BBSECTOR * DEV_BSIZE, SEEK_SET) < 0 ||
-	    read(f, mbr, sizeof(mbr)) != sizeof(mbr)) {
+	if (lseek(f, (off_t)MBR_BBSECTOR * lab.d_secsize, SEEK_SET) < 0 ||
+	    read(f, mbr, lab.d_secsize) != lab.d_secsize) {
 		warn("can't read master boot record");
 		return (0);
 	}
@@ -771,11 +785,11 @@
 get_filecore_partition(int f)
 {
 	struct filecore_bootblock	*fcbb;
-	static char	bb[DEV_BSIZE];
+	static char	bb[8192];
 	u_int		offset;
 
-	if (lseek(f, (off_t)FILECORE_BOOT_SECTOR * DEV_BSIZE, SEEK_SET) < 0 ||
-	    read(f, bb, sizeof(bb)) != sizeof(bb))
+	if (lseek(f, (off_t)FILECORE_BOOT_SECTOR * lab.d_secsize, SEEK_SET) < 0 ||
+	    read(f, bb, lab.d_secsize) != lab.d_secsize)
 		err(4, "can't read filecore boot block");
 	fcbb = (struct filecore_bootblock *)bb;
 
@@ -802,7 +816,7 @@
 		 * XXX is use of 'Empty:' really desirable?! -- cgd
 		 */
 
-		if (lseek(f, (off_t)offset * DEV_BSIZE, SEEK_SET) < 0 ||
+		if (lseek(f, (off_t)offset * lab.d_secsize, SEEK_SET) < 0 ||
 		    read(f, bb, sizeof(bb)) != sizeof(bb))
 			err(4, "can't read riscix partition table");
 		riscix_part = (struct riscix_partition_table *)bb;
@@ -861,12 +875,12 @@
 
 #ifdef USE_MBR
 		if (dosdp)
-			sectoffset = (off_t)dosdp->mbrp_start * DEV_BSIZE;
+			sectoffset = (off_t)dosdp->mbrp_start * lab.d_secsize;
 #endif	/* USE_MBR */
 
 #ifdef USE_ACORN
 		/* XXX */
-		sectoffset = (off_t)filecore_partition_offset * DEV_BSIZE;
+		sectoffset = (off_t)filecore_partition_offset * lab.d_secsize;
 #endif	/* USE_ACORN */
 
 		if (lseek(f, sectoffset, SEEK_SET) < 0 ||
@@ -922,7 +936,7 @@
 
 	/* XXX */
 	if (dp->d_secsize == 0) {
-		dp->d_secsize = DEV_BSIZE;
+		dp->d_secsize = lab.d_secsize;
 		dp->d_bbsize = BBSIZE;
 	}
 	lp = (struct disklabel *)
@@ -958,13 +972,14 @@
 			sectoffset = 0;
 #ifdef USE_MBR
 			if (dosdp)
-				sectoffset = (off_t)dosdp->mbrp_start * DEV_BSIZE;
+				sectoffset = (off_t)dosdp->mbrp_start *
+						dp->d_secsize;
 #endif	/* USE_MBR */
 
 #ifdef USE_ACORN
 			/* XXX */
 			sectoffset = (off_t)filecore_partition_offset
-			    * DEV_BSIZE;
+			    * dp->d_secsize;
 #endif	/* USE_ACORN */
 
 			if (lseek(f, sectoffset, SEEK_SET) < 0 ||
Index: sbin/newfs_lfs/lfs.c
===================================================================
RCS file: /cvsroot/basesrc/sbin/newfs_lfs/lfs.c,v
retrieving revision 1.23
diff -u -r1.23 lfs.c
--- sbin/newfs_lfs/lfs.c	2001/07/13 21:09:55	1.23
+++ sbin/newfs_lfs/lfs.c	2002/09/30 22:40:30
@@ -101,7 +101,11 @@
 	/* 32 K */ 1 << 31,
 };
 
-static struct lfs lfs_default =  {
+static struct {
+  struct lfs sb;
+  u_int8_t padding[8192 - sizeof(struct lfs)];
+} lfs_default =  {
+    {
 	{ /* lfs_dlfs */
 		/* dlfs_magic */	LFS_MAGIC,
 		/* dlfs_version */	LFS_VERSION,
@@ -177,6 +181,7 @@
 	/* lfs_fmod */		0,
 	/* lfs_ronly */		0,
 	/* lfs_flags */		0
+    }
 };
 
 #define	UMASK	0755
@@ -227,7 +232,7 @@
 	int block_array_size;	/* How many entries in block array */
 	int bsize;		/* Block size */
 	int fsize;		/* Fragment size */
-	int db_per_blk;		/* Disk blocks per file block */
+	int db_per_blk;		/* Disk sectors per file block */
 	int i, j;
 	off_t off, startoff;	/* Offset at which to write */
 	int sb_interval;	/* number of segs between super blocks */
@@ -240,7 +245,7 @@
 	int curw, ww;
 	char tbuf[BUFSIZ];
 
-	lfsp = &lfs_default;
+	lfsp = &lfs_default.sb;
 
 	lfsp->lfs_version = version;
 
@@ -264,20 +269,27 @@
 			ssize = DFL_LFSSEG;
 		}
 	}
-	if (version > 1) {
-		if (ibsize == 0)
-			ibsize = fsize;
-		if (ibsize <= 0 || ibsize % fsize)
-			fatal("illegal inode block size: %d\n", ibsize);
-	} else if (ibsize && ibsize != bsize)
-		fatal("cannot specify inode block size when version == 1\n");
 
-	/* Sanity check: fsize<=bsize<ssize */
+	/* Sanity check: secsize<=fsize<=bsize<ssize */
+	if (fsize < lp->d_secsize) {
+		/* Only complain if fsize was explicitly set */
+		if(frag_size)
+			fatal("fragment size must be >= sector size %d",
+				lp->d_secsize);
+		fsize = lp->d_secsize;
+	}
 	if (fsize > bsize) {
 		/* Only complain if fsize was explicitly set */
 		if(frag_size)
 			fatal("fragment size must be <= block size %d", bsize);
-		fsize = bsize;
+		if (bsize < lp->d_secsize) {
+			if(block_size)
+				fatal("block size must be >= sector size %d",
+					lp->d_secsize);
+			bsize = lp->d_secsize;
+		} else {
+			fsize = bsize;
+		}
 	}
 	if (bsize >= ssize) {
 		/* Only fatal if ssize was explicitly set */
@@ -295,6 +307,14 @@
 		start = LFS_LABELPAD / lp->d_secsize;
 	}
 
+	if (version > 1) {
+		if (ibsize == 0)
+			ibsize = fsize;
+		if (ibsize <= 0 || ibsize % fsize)
+			fatal("illegal inode block size: %d\n", ibsize);
+	} else if (ibsize && ibsize != bsize)
+		fatal("cannot specify inode block size when version == 1\n");
+
     tryagain:
 	/* Modify parts of superblock overridden by command line arguments */
 	if (bsize != DFL_LFSBLOCK || fsize != DFL_LFSFRAG) {
@@ -622,7 +642,6 @@
 	/* Make all the other dinodes invalid */
 	for (i = INOPB(lfsp)-3, dip++; i; i--, dip++)
 		dip->di_inumber = LFS_UNUSED_INUM;
-	
 
 	/* Link remaining IFILE entries in free list */
 	if (version == 1) {
@@ -750,14 +769,14 @@
 	lfsp->lfs_avail += segtod(lfsp, lfsp->lfs_minfreeseg / 2);
 	lfsp->lfs_cksum = lfs_sb_cksum(&(lfsp->lfs_dlfs));
 
-	put(fd, (off_t)LFS_LABELPAD, &(lfsp->lfs_dlfs), sizeof(struct dlfs));
+	put(fd, (off_t)LFS_LABELPAD, &(lfsp->lfs_dlfs), lp->d_secsize);
 	/* If that was different from lfs_sboffs[0], write the latter too */
 	if (LFS_LABELPAD < fsbtob(lfsp, (off_t)lfsp->lfs_sboffs[0])) {
 		printf("Writing 1st superblock at both %lld and %lld bytes\n",
 		       (long long)LFS_LABELPAD,
 		       fsbtob(lfsp, (long long)lfsp->lfs_sboffs[0]));
 		put(fd, (off_t)lfsp->lfs_sboffs[0], &(lfsp->lfs_dlfs),
-		    sizeof(struct dlfs));
+		    lp->d_secsize);
 	}
 
 	/* 
@@ -891,7 +910,7 @@
 			lfsp->lfs_cksum = lfs_sb_cksum(&(lfsp->lfs_dlfs));
 		}
 		seg_seek = fsbtob(lfsp, (off_t)seg_addr);
-		put(fd, seg_seek, &(lfsp->lfs_dlfs), sizeof(struct dlfs));
+		put(fd, seg_seek, &(lfsp->lfs_dlfs), lp->d_secsize);
 	}
 	printf("\n");
 	free(ipagep);
Index: sbin/fdisk/fdisk.c
===================================================================
RCS file: /cvsroot/basesrc/sbin/fdisk/fdisk.c,v
retrieving revision 1.55
diff -u -r1.55 fdisk.c
--- sbin/fdisk/fdisk.c	2002/09/27 23:19:56	1.55
+++ sbin/fdisk/fdisk.c	2002/09/30 22:40:32
@@ -75,10 +75,11 @@
 int cylinders, sectors, heads, cylindersectors, disksectors;
 
 struct mboot {
-	u_int8_t	padding[2]; /* force the longs to be long alligned */
+	u_int8_t	padding[2]; /* force the longs to be long aligned */
 	u_int8_t	bootinst[MBR_PARTOFF];
 	struct mbr_partition parts[NMBRPART];
 	u_int16_t	signature;
+	u_int8_t	overflow[8192-512]; /* handle large sector sizes */
 };
 struct mboot mboot;
 
@@ -572,7 +573,8 @@
 	printf("%*s    start %lld, size %ld (%ld MB), flag 0x%x\n",
 	    indent, "",
 	    start, getlong(&partp->mbrp_size),
-	    getlong(&partp->mbrp_size) * 512 / (1024 * 1024), partp->mbrp_flag);
+	    getlong(&partp->mbrp_size) / (1024 * 1024 / disklabel.d_secsize),
+	    partp->mbrp_flag);
 	printf("%*s        beg: cylinder %4d, head %3d, sector %2d\n",
 	    indent, "",
 	    MBR_PCYL(partp->mbrp_scyl, partp->mbrp_ssect),
@@ -1276,9 +1278,9 @@
 
 	if (fd == -1)
 		errx(1, "read_disk(); fd == -1");
-	if (lseek(fd, sector * 512, 0) == -1)
+	if (lseek(fd, sector * disklabel.d_secsize, 0) == -1)
 		return (-1);
-	return (read(fd, buf, 512));
+	return (read(fd, buf, disklabel.d_secsize));
 }
 
 int
@@ -1287,9 +1289,9 @@
 
 	if (fd == -1)
 		errx(1, "write_disk(); fd == -1");
-	if (lseek(fd, sector * 512, 0) == -1)
+	if (lseek(fd, sector * disklabel.d_secsize, 0) == -1)
 		return (-1);
-	return (write(fd, buf, 512));
+	return (write(fd, buf, disklabel.d_secsize));
 }
 
 int
@@ -1309,6 +1311,12 @@
 	dos_sectors = sectors = disklabel.d_nsectors;
 	dos_cylindersectors = cylindersectors = heads * sectors;
 	disksectors = disklabel.d_secperunit;
+	if (disklabel.d_secsize > 8192 ||
+	    (disklabel.d_secsize & (disklabel.d_secsize - 1))) {
+		warn("invalid sector size %d for %s",
+		    disklabel.d_secsize, disk);
+		disklabel.d_secsize = 512;
+	}
 
 	return (0);
 }
Index: sbin/mbrlabel/mbrlabel.c
===================================================================
RCS file: /cvsroot/basesrc/sbin/mbrlabel/mbrlabel.c,v
retrieving revision 1.21
diff -u -r1.21 mbrlabel.c
--- sbin/mbrlabel/mbrlabel.c	2002/09/28 00:56:26	1.21
+++ sbin/mbrlabel/mbrlabel.c	2002/09/30 22:40:32
@@ -140,25 +140,28 @@
 int
 getparts(int sd, u_int32_t off, u_int32_t extoff, int verbose)
 {
-	unsigned char		buf[DEV_BSIZE];
+	unsigned char		*buf;
 	struct mbr_partition	parts[NMBRPART];
 	struct partition	npe;
 	off_t			loff;
 	int			i, j, unused, changed;
 
 	changed = 0;
-	loff = (off_t)off * DEV_BSIZE;
+	loff = (off_t)off * label.d_secsize;
 
 	if (lseek(sd, loff, SEEK_SET) != loff) {
 		perror("seek label");
 		exit(1);
 	}
-	if (read(sd, buf, sizeof buf) != DEV_BSIZE) {
+	buf = malloc (label.d_secsize);
+	if (read(sd, buf, label.d_secsize) != label.d_secsize) {
 		perror("read label");
 		exit(1);
 	}
-	if (getshort(buf + MBR_MAGICOFF) != MBR_MAGIC)
+	if (getshort(buf + MBR_MAGICOFF) != MBR_MAGIC) {
+		free (buf);
 		return (changed);
+	}
 	memcpy(parts, buf + MBR_PARTOFF, sizeof parts);
 
 				/* scan partition table */
@@ -253,6 +256,7 @@
 			    extoff ? extoff : poff, verbose);
 		}
 	}
+	free (buf);
 	return (changed);
 }
 
Index: sbin/dump/traverse.c
===================================================================
RCS file: /cvsroot/basesrc/sbin/dump/traverse.c,v
retrieving revision 1.34
diff -u -r1.34 traverse.c
--- sbin/dump/traverse.c	2001/12/23 12:54:54	1.34
+++ sbin/dump/traverse.c	2002/09/30 22:40:33
@@ -74,6 +74,8 @@
 static	void dmpindir(ino_t, daddr_t, int, fsizeT *);
 static	int searchdir(ino_t, daddr_t, long, long, long *, int);
 
+extern struct fs *sblock;
+
 /*
  * This is an estimation of the number of TP_BSIZE blocks in the file.
  * It estimates the number of blocks in files with holes by assuming
@@ -100,7 +102,7 @@
 	 *	dump blocks (sizeest vs. blkest in the indirect block
 	 *	calculation).
 	 */
-	blkest = howmany(dbtob((u_int64_t)dp->di_blocks), TP_BSIZE);
+	blkest = howmany(sectob(sblock, (u_int64_t)dp->di_blocks), TP_BSIZE);
 	sizeest = howmany(dp->di_size, TP_BSIZE);
 	if (blkest > sizeest)
 		blkest = sizeest;
Index: sbin/clri/clri.c
===================================================================
RCS file: /cvsroot/basesrc/sbin/clri/clri.c,v
retrieving revision 1.14
diff -u -r1.14 clri.c
--- sbin/clri/clri.c	2001/08/17 02:18:47	1.14
+++ sbin/clri/clri.c	2002/09/30 22:40:34
@@ -139,8 +139,7 @@
 
 		/* read in the appropriate block. */
 		offset = ino_to_fsba(sbp, inonum);	/* inode to fs blk */
-		offset = fsbtodb(sbp, offset);		/* fs blk disk blk */
-		offset *= DEV_BSIZE;			/* disk blk to bytes */
+		offset <<= sbp->fs_fshift;		/* fs blk to bytes */
 
 		/* seek and read the block */
 		if (lseek(fd, offset, SEEK_SET) < 0)
Index: sbin/fsirand/fsirand.c
===================================================================
RCS file: /cvsroot/basesrc/sbin/fsirand/fsirand.c,v
retrieving revision 1.19
diff -u -r1.19 fsirand.c
--- sbin/fsirand/fsirand.c	2002/01/08 05:01:50	1.19
+++ sbin/fsirand/fsirand.c	2002/09/30 22:40:34
@@ -65,7 +65,7 @@
 
 static void usage(void);
 static void getsblock(int, const char *, struct fs *);
-static void fixinodes(int, struct fs *, struct disklabel *, int, long);
+static void fixinodes(int, struct fs *, int, long);
 static void statussig(int);
 
 int main(int, char *[]);
@@ -127,7 +127,7 @@
  *	Randomize the inode generation numbers
  */
 static void
-fixinodes(int fd, struct fs *fs, struct disklabel *lab, int pflag, long xorval)
+fixinodes(int fd, struct fs *fs, int pflag, long xorval)
 {
 	int inopb = INOPB(fs);
 	int size = inopb * DINODE_SIZE;
@@ -140,8 +140,7 @@
 
 	for (ino = 0, imax = fs->fs_ipg * fs->fs_ncg; ino < imax;) {
 		off_t sp;
-		sp = (off_t) fsbtodb(fs, ino_to_fsba(fs, ino)) *
-		     (off_t) lab->d_secsize;
+		sp = (off_t) ino_to_fsba(fs, ino) << fs->fs_fshift;
 
 		if (lseek(fd, sp, SEEK_SET) == (off_t) -1)
 			err(1, "Seeking to inode %d failed", ino);
@@ -205,7 +204,6 @@
 	const char *special;
 	char buf[SBSIZE], device[MAXPATHLEN];
 	struct fs *fs = (struct fs *) buf;
-	struct disklabel lab;
 	long xorval;
 	char *ep;
 	struct timeval tv;
@@ -254,18 +252,10 @@
 	if (fd == -1)
 		err(1, "Cannot open `%s'", special);
 
-	if (Fflag) {
-		memset(&lab, 0, sizeof(lab));
-		lab.d_secsize = DEV_BSIZE;	/* XXX */
-	} else {
-		if (ioctl(fd, DIOCGDINFO, &lab) == -1)
-			err(1, "%s: cannot get disklabel information", special);
-	}
-
 	time(&tstart);
 	(void)signal(SIGINFO, statussig);
 	getsblock(fd, special, fs);
-	fixinodes(fd, fs, &lab, pflag, xorval);
+	fixinodes(fd, fs, pflag, xorval);
 
 	(void) close(fd);
 	return 0;
Index: usr.sbin/quot/quot.c
===================================================================
RCS file: /cvsroot/basesrc/usr.sbin/quot/quot.c,v
retrieving revision 1.17
diff -u -r1.17 quot.c
--- usr.sbin/quot/quot.c	2001/10/26 05:56:11	1.17
+++ usr.sbin/quot/quot.c	2002/09/30 22:40:35
@@ -69,9 +69,9 @@
  * kByte when done (on request).
  */
 #ifdef	COMPAT
-#define	SIZE(n)	((long long)(n))
+#define	SIZE(sb, n)	((long long)(n))
 #else
-#define	SIZE(n)	howmany((long long)(n) * DEV_BSIZE, (long long)blocksize)
+#define	SIZE(sb, n)	howmany(sectob(sb, (long long)(n)), (long long)blocksize)
 #endif
 
 #define	INOCNT(fs)	((fs)->fs_ipg)
@@ -128,7 +128,7 @@
 }
 
 #ifdef	COMPAT
-#define	actualblocks(super, ip)	((ip)->di_blocks / 2)
+#define	actualblocks(super, ip)	(sectob(super, (ip)->di_blocks) / 1024)
 #else
 #define	actualblocks(super, ip)	((ip)->di_blocks)
 #endif
@@ -163,7 +163,7 @@
 	} else
 		nblk = fragroundup(super, sz);
 	
-	return nblk / DEV_BSIZE;
+	return btosec(super, nblk);
 #endif	/* COMPAT */
 }
 
@@ -375,7 +375,7 @@
 				fsizes->fsz_sz[sz] += sz;
 			}
 #else	/* COMPAT */
-			ksz = SIZE(sz);
+			ksz = SIZE(super, sz);
 			for (fsp = &fsizes; (fp = *fsp) != NULL;
 			    fsp = &fp->fsz_next) {
 				if (ksz < fp->fsz_last)
@@ -407,7 +407,7 @@
 				printf("%ld\t%ld\t%lld\n",
 				    (long)(fp->fsz_first + i),
 				    (long)fp->fsz_count[i],
-				    SIZE(sz += fp->fsz_sz[i]));
+				    SIZE(super, sz += fp->fsz_sz[i]));
 		}
 	}
 }
@@ -438,14 +438,14 @@
 	memmove(usrs, users, nusers * sizeof(struct user));
 	sortusers(usrs);
 	for (usr = usrs, n = nusers; --n >= 0 && usr->count; usr++) {
-		printf("%5lld", SIZE(usr->space));
+		printf("%5lld", SIZE(super, usr->space));
 		if (count)
 			printf("\t%5ld", usr->count);
 		printf("\t%-8s", usr->name);
 		if (unused)
 			printf("\t%5lld\t%5lld\t%5lld",
-			    SIZE(usr->spc30), SIZE(usr->spc60),
-			    SIZE(usr->spc90));
+			    SIZE(super, usr->spc30), SIZE(super, usr->spc60),
+			    SIZE(super, usr->spc90));
 		printf("\n");
 	}
 	free(usrs);
Index: usr.sbin/installboot/ffs.c
===================================================================
RCS file: /cvsroot/basesrc/usr.sbin/installboot/ffs.c,v
retrieving revision 1.6
diff -u -r1.6 ffs.c
--- usr.sbin/installboot/ffs.c	2002/05/15 09:44:55	1.6
+++ usr.sbin/installboot/ffs.c	2002/09/30 22:40:36
@@ -147,7 +147,7 @@
 	}
 
 	/* Read the inode. */
-	if (! ffs_read_disk_block(params, fsbtodb(fs, ino_to_fsba(fs, ino)),
+	if (! ffs_read_disk_block(params, fsbtoDB(fs, ino_to_fsba(fs, ino)),
 		fs->fs_bsize, inodebuf))
 		return (0);
 	inode = (struct dinode *)inodebuf;
@@ -202,7 +202,7 @@
 			if (blk == 0)
 				memset(level[level_i].diskbuf, 0, MAXBSIZE);
 			else if (! ffs_read_disk_block(params, 
-				fsbtodb(fs, blk),
+				fsbtoDB(fs, blk),
 				fs->fs_bsize, level[level_i].diskbuf))
 				return (0);
 			level[level_i].blknums = 
Index: usr.sbin/makefs/ffs/ffs_alloc.c
===================================================================
RCS file: /cvsroot/basesrc/usr.sbin/makefs/ffs/ffs_alloc.c,v
retrieving revision 1.10
diff -u -r1.10 ffs_alloc.c
--- usr.sbin/makefs/ffs/ffs_alloc.c	2002/07/20 08:40:18	1.10
+++ usr.sbin/makefs/ffs/ffs_alloc.c	2002/09/30 22:40:39
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_alloc.c,v 1.10 2002/07/20 08:40:18 grant Exp $	*/
+/*	$NetBSD: ffs_alloc.c,v 1.9 2002/02/06 15:36:30 lukem Exp $	*/
 /* From: NetBSD: ffs_alloc.c,v 1.50 2001/09/06 02:16:01 lukem Exp */
 
 /*
@@ -38,7 +38,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID) && !defined(__lint)
-__RCSID("$NetBSD: ffs_alloc.c,v 1.10 2002/07/20 08:40:18 grant Exp $");
+__RCSID("$NetBSD: ffs_alloc.c,v 1.9 2002/02/06 15:36:30 lukem Exp $");
 #endif	/* !__lint */
 
 #include <sys/param.h>
@@ -112,7 +112,7 @@
 	bno = (ufs_daddr_t)ffs_hashalloc(ip, cg, (long)bpref, size,
 	    			     ffs_alloccg);
 	if (bno > 0) {
-		ip->i_ffs_blocks += size / DEV_BSIZE;
+		ip->i_ffs_blocks += btosec(fs, size);
 		*bnp = bno;
 		return (0);
 	}
Index: sys/ufs/ffs/ffs_alloc.c
===================================================================
RCS file: /cvsroot/syssrc/sys/ufs/ffs/ffs_alloc.c,v
retrieving revision 1.56
diff -u -r1.56 ffs_alloc.c
--- sys/ufs/ffs/ffs_alloc.c	2002/09/27 15:38:03	1.56
+++ sys/ufs/ffs/ffs_alloc.c	2002/09/30 22:40:42
@@ -168,7 +168,10 @@
 	bno = (ufs_daddr_t)ffs_hashalloc(ip, cg, (long)bpref, size,
 	    			     ffs_alloccg);
 	if (bno > 0) {
-		ip->i_ffs_blocks += btodb(size);
+	/*
+	 * Add the number of sectors used in the allocation.
+	 */
+		ip->i_ffs_blocks += btosec(fs, size);
 		ip->i_flag |= IN_CHANGE | IN_UPDATE;
 		*bnp = bno;
 		return (0);
@@ -266,11 +269,11 @@
 	 */
 	cg = dtog(fs, bprev);
 	if ((bno = ffs_fragextend(ip, cg, (long)bprev, osize, nsize)) != 0) {
-		ip->i_ffs_blocks += btodb(nsize - osize);
+		ip->i_ffs_blocks += btosec(fs, nsize - osize);
 		ip->i_flag |= IN_CHANGE | IN_UPDATE;
 
 		if (bpp != NULL) {
-			if (bp->b_blkno != fsbtodb(fs, bno))
+			if (bp->b_blkno != fsbtoDB(fs, bno))
 				panic("bad blockno");
 			allocbuf(bp, nsize);
 			bp->b_flags |= B_DONE;
@@ -348,10 +351,10 @@
 		if (nsize < request)
 			ffs_blkfree(ip, bno + numfrags(fs, nsize),
 			    (long)(request - nsize));
-		ip->i_ffs_blocks += btodb(nsize - osize);
+		ip->i_ffs_blocks += btosec(fs, nsize - osize);
 		ip->i_flag |= IN_CHANGE | IN_UPDATE;
 		if (bpp != NULL) {
-			bp->b_blkno = fsbtodb(fs, bno);
+			bp->b_blkno = fsbtoDB(fs, bno);
 			allocbuf(bp, nsize);
 			bp->b_flags |= B_DONE;
 			memset(bp->b_data + osize, 0, (u_int)nsize - osize);
@@ -441,13 +444,13 @@
 #ifdef DIAGNOSTIC
 	for (i = 0; i < len; i++)
 		if (!ffs_checkblk(ip,
-		   dbtofsb(fs, buflist->bs_children[i]->b_blkno), fs->fs_bsize))
+		   DBtofsb(fs, buflist->bs_children[i]->b_blkno), fs->fs_bsize))
 			panic("ffs_reallocblks: unallocated block 1");
 	for (i = 1; i < len; i++)
 		if (buflist->bs_children[i]->b_lblkno != start_lbn + i)
 			panic("ffs_reallocblks: non-logical cluster");
 	blkno = buflist->bs_children[0]->b_blkno;
-	ssize = fsbtodb(fs, fs->fs_frag);
+	ssize = fsbtoDB(fs, fs->fs_frag);
 	for (i = 1; i < len - 1; i++)
 		if (buflist->bs_children[i]->b_blkno != blkno + (i * ssize))
 			panic("ffs_reallocblks: non-physical cluster %d", i);
@@ -457,8 +460,8 @@
 	 * the filesystem has decided to move and do not force it back to
 	 * the previous cylinder group.
 	 */
-	if (dtog(fs, dbtofsb(fs, buflist->bs_children[0]->b_blkno)) !=
-	    dtog(fs, dbtofsb(fs, buflist->bs_children[len - 1]->b_blkno)))
+	if (dtog(fs, DBtofsb(fs, buflist->bs_children[0]->b_blkno)) !=
+	    dtog(fs, DBtofsb(fs, buflist->bs_children[len - 1]->b_blkno)))
 		return (ENOSPC);
 	if (ufs_getlbns(vp, start_lbn, start_ap, &start_lvl) ||
 	    ufs_getlbns(vp, end_lbn, end_ap, &end_lvl))
@@ -526,9 +529,9 @@
 		ba = ufs_rw32(*bap, UFS_FSNEEDSWAP(fs));
 #ifdef DIAGNOSTIC
 		if (!ffs_checkblk(ip,
-		   dbtofsb(fs, buflist->bs_children[i]->b_blkno), fs->fs_bsize))
+		   DBtofsb(fs, buflist->bs_children[i]->b_blkno), fs->fs_bsize))
 			panic("ffs_reallocblks: unallocated block 2");
-		if (dbtofsb(fs, buflist->bs_children[i]->b_blkno) != ba)
+		if (DBtofsb(fs, buflist->bs_children[i]->b_blkno) != ba)
 			panic("ffs_reallocblks: alloc mismatch");
 #endif
 #ifdef DEBUG
@@ -587,12 +590,12 @@
 	for (blkno = newblk, i = 0; i < len; i++, blkno += fs->fs_frag) {
 		if (!DOINGSOFTDEP(vp))
 			ffs_blkfree(ip,
-			    dbtofsb(fs, buflist->bs_children[i]->b_blkno),
+			    DBtofsb(fs, buflist->bs_children[i]->b_blkno),
 			    fs->fs_bsize);
-		buflist->bs_children[i]->b_blkno = fsbtodb(fs, blkno);
+		buflist->bs_children[i]->b_blkno = fsbtoDB(fs, blkno);
 #ifdef DEBUG
 		if (!ffs_checkblk(ip,
-		   dbtofsb(fs, buflist->bs_children[i]->b_blkno), fs->fs_bsize))
+		   DBtofsb(fs, buflist->bs_children[i]->b_blkno), fs->fs_bsize))
 			panic("ffs_reallocblks: unallocated block 3");
 		if (prtrealloc)
 			printf(" %d,", blkno);
@@ -688,7 +691,7 @@
 	}
 	if (ip->i_ffs_blocks) {				/* XXX */
 		printf("free inode %s/%d had %d blocks\n",
-		    fs->fs_fsmnt, ino, ip->i_ffs_blocks);
+		    fs->fs_fsmnt, ino, dbtofsb(fs, ip->i_ffs_blocks));
 		ip->i_ffs_blocks = 0;
 	}
 	ip->i_ffs_flags = 0;
@@ -986,7 +989,7 @@
 		/* cannot extend across a block boundary */
 		return (0);
 	}
-	error = bread(ip->i_devvp, fsbtodb(fs, cgtod(fs, cg)),
+	error = bread(ip->i_devvp, fsbtoDB(fs, cgtod(fs, cg)),
 		(int)fs->fs_cgsize, NOCRED, &bp);
 	if (error) {
 		brelse(bp);
@@ -1053,7 +1056,7 @@
 
 	if (fs->fs_cs(fs, cg).cs_nbfree == 0 && size == fs->fs_bsize)
 		return (0);
-	error = bread(ip->i_devvp, fsbtodb(fs, cgtod(fs, cg)),
+	error = bread(ip->i_devvp, fsbtoDB(fs, cgtod(fs, cg)),
 		(int)fs->fs_cgsize, NOCRED, &bp);
 	if (error) {
 		brelse(bp);
@@ -1280,7 +1283,7 @@
 	fs = ip->i_fs;
 	if (fs->fs_maxcluster[cg] < len)
 		return (0);
-	if (bread(ip->i_devvp, fsbtodb(fs, cgtod(fs, cg)), (int)fs->fs_cgsize,
+	if (bread(ip->i_devvp, fsbtoDB(fs, cgtod(fs, cg)), (int)fs->fs_cgsize,
 	    NOCRED, &bp))
 		goto fail;
 	cgp = (struct cg *)bp->b_data;
@@ -1396,7 +1399,7 @@
 
 	if (fs->fs_cs(fs, cg).cs_nifree == 0)
 		return (0);
-	error = bread(ip->i_devvp, fsbtodb(fs, cgtod(fs, cg)),
+	error = bread(ip->i_devvp, fsbtoDB(fs, cgtod(fs, cg)),
 		(int)fs->fs_cgsize, NOCRED, &bp);
 	if (error) {
 		brelse(bp);
@@ -1490,7 +1493,7 @@
 		ffs_fserr(fs, ip->i_ffs_uid, "bad block");
 		return;
 	}
-	error = bread(ip->i_devvp, fsbtodb(fs, cgtod(fs, cg)),
+	error = bread(ip->i_devvp, fsbtoDB(fs, cgtod(fs, cg)),
 		(int)fs->fs_cgsize, NOCRED, &bp);
 	if (error) {
 		brelse(bp);
@@ -1594,7 +1597,7 @@
 	}
 	if ((u_int)bno >= fs->fs_size)
 		panic("checkblk: bad block %d", bno);
-	error = bread(ip->i_devvp, fsbtodb(fs, cgtod(fs, dtog(fs, bno))),
+	error = bread(ip->i_devvp, fsbtoDB(fs, cgtod(fs, dtog(fs, bno))),
 		(int)fs->fs_cgsize, NOCRED, &bp);
 	if (error) {
 		brelse(bp);
@@ -1670,7 +1673,7 @@
 		panic("ifree: range: dev = 0x%x, ino = %d, fs = %s",
 		    pip->i_dev, ino, fs->fs_fsmnt);
 	cg = ino_to_cg(fs, ino);
-	error = bread(pip->i_devvp, fsbtodb(fs, cgtod(fs, cg)),
+	error = bread(pip->i_devvp, fsbtoDB(fs, cgtod(fs, cg)),
 		(int)fs->fs_cgsize, NOCRED, &bp);
 	if (error) {
 		brelse(bp);
Index: sys/ufs/ffs/ffs_balloc.c
===================================================================
RCS file: /cvsroot/syssrc/sys/ufs/ffs/ffs_balloc.c,v
retrieving revision 1.30
diff -u -r1.30 ffs_balloc.c
--- sys/ufs/ffs/ffs_balloc.c	2002/06/05 05:23:51	1.30
+++ sys/ufs/ffs/ffs_balloc.c	2002/09/30 22:40:43
@@ -231,7 +231,7 @@
 				return (error);
 			if (bpp != NULL) {
 				bp = getblk(vp, lbn, nsize, 0, 0);
-				bp->b_blkno = fsbtodb(fs, newb);
+				bp->b_blkno = fsbtoDB(fs, newb);
 				if (flags & B_CLRBUF)
 					clrbuf(bp);
 				*bpp = bp;
@@ -271,7 +271,7 @@
 		nb = newb;
 		*allocblk++ = nb;
 		bp = getblk(vp, indirs[1].in_lbn, fs->fs_bsize, 0, 0);
-		bp->b_blkno = fsbtodb(fs, nb);
+		bp->b_blkno = fsbtoDB(fs, nb);
 		clrbuf(bp);
 		if (DOINGSOFTDEP(vp)) {
 			softdep_setup_allocdirect(ip, NDADDR + indirs[0].in_off,
@@ -324,7 +324,7 @@
 		nb = newb;
 		*allocblk++ = nb;
 		nbp = getblk(vp, indirs[i].in_lbn, fs->fs_bsize, 0, 0);
-		nbp->b_blkno = fsbtodb(fs, nb);
+		nbp->b_blkno = fsbtoDB(fs, nb);
 		clrbuf(nbp);
 		if (DOINGSOFTDEP(vp)) {
 			softdep_setup_allocindir_meta(nbp, ip, bp,
@@ -374,7 +374,7 @@
 		*allocblk++ = nb;
 		if (bpp != NULL) {
 			nbp = getblk(vp, lbn, fs->fs_bsize, 0, 0);
-			nbp->b_blkno = fsbtodb(fs, nb);
+			nbp->b_blkno = fsbtoDB(fs, nb);
 			if (flags & B_CLRBUF)
 				clrbuf(nbp);
 			*bpp = nbp;
@@ -409,7 +409,7 @@
 			}
 		} else {
 			nbp = getblk(vp, lbn, fs->fs_bsize, 0, 0);
-			nbp->b_blkno = fsbtodb(fs, nb);
+			nbp->b_blkno = fsbtoDB(fs, nb);
 			clrbuf(nbp);
 		}
 		*bpp = nbp;
@@ -438,8 +438,8 @@
 			bp = getblk(vp, indirs[i].in_lbn, (int)fs->fs_bsize, 0,
 			    0);
 			if (bp->b_flags & B_DELWRI) {
-				nb = fsbtodb(fs, cgtod(fs, dtog(fs,
-				    dbtofsb(fs, bp->b_blkno))));
+				nb = fsbtoDB(fs, cgtod(fs, dtog(fs,
+				    DBtofsb(fs, bp->b_blkno))));
 				bwrite(bp);
 				bp = getblk(ip->i_devvp, nb, (int)fs->fs_cgsize,
 				    0, 0);
@@ -500,7 +500,10 @@
 		 */
 		(void)chkdq(ip, (long)-btodb(deallocated), cred, FORCE);
 #endif
-		ip->i_ffs_blocks -= btodb(deallocated);
+		/*
+		 * Subtract the number of sectors used in the allocation.
+		 */
+		ip->i_ffs_blocks -= btosec(fs, deallocated);
 		ip->i_flag |= IN_CHANGE | IN_UPDATE;
 	}
 	return (error);
Index: sys/ufs/ffs/ffs_inode.c
===================================================================
RCS file: /cvsroot/syssrc/sys/ufs/ffs/ffs_inode.c,v
retrieving revision 1.52
diff -u -r1.52 ffs_inode.c
--- sys/ufs/ffs/ffs_inode.c	2002/09/26 21:35:27	1.52
+++ sys/ufs/ffs/ffs_inode.c	2002/09/30 22:40:45
@@ -125,7 +125,7 @@
 		ip->i_din.ffs_din.di_ogid = ip->i_ffs_gid;	/* XXX */
 	}							/* XXX */
 	error = bread(ip->i_devvp,
-		      fsbtodb(fs, ino_to_fsba(fs, ip->i_number)),
+		      fsbtoDB(fs, ino_to_fsba(fs, ip->i_number)),
 		      (int)fs->fs_bsize, NOCRED, &bp);
 	if (error) {
 		brelse(bp);
@@ -305,7 +305,8 @@
 		} else {
 			uvm_vnp_setsize(ovp, length);
 #ifdef QUOTA
- 			(void) chkdq(oip, -oip->i_ffs_blocks, NOCRED, 0);
+ 			(void) chkdq(oip, -fsbtoDB(fs, dbtofsb(fs,
+					oip->i_ffs_blocks)), NOCRED, 0);
 #endif
 			softdep_setup_freeblocks(oip, length);
 			(void) vinvalbuf(ovp, 0, ap->a_cred, ap->a_p, 0, 0);
@@ -369,7 +370,7 @@
 		bn = ufs_rw32(oip->i_ffs_ib[level], UFS_FSNEEDSWAP(fs));
 		if (bn != 0) {
 			error = ffs_indirtrunc(oip, indir_lbn[level],
-			    fsbtodb(fs, bn), lastiblock[level], level, &count);
+			    fsbtoDB(fs, bn), lastiblock[level], level, &count);
 			if (error)
 				allerror = error;
 			blocksreleased += count;
@@ -445,7 +446,7 @@
 	 * Put back the real size.
 	 */
 	oip->i_ffs_size = length;
-	oip->i_ffs_blocks -= blocksreleased;
+	oip->i_ffs_blocks -= fsbtodb(fs, DBtofsb(fs, blocksreleased));
 	lockmgr(&gp->g_glock, LK_RELEASE, NULL);
 	oip->i_flag |= IN_CHANGE;
 #ifdef QUOTA
@@ -544,7 +545,7 @@
 		if (nb == 0)
 			continue;
 		if (level > SINGLE) {
-			error = ffs_indirtrunc(ip, nlbn, fsbtodb(fs, nb),
+			error = ffs_indirtrunc(ip, nlbn, fsbtoDB(fs, nb),
 					       (ufs_daddr_t)-1, level - 1,
 					       &blkcount);
 			if (error)
@@ -562,7 +563,7 @@
 		last = lastbn % factor;
 		nb = ufs_rw32(bap[i], UFS_FSNEEDSWAP(fs));
 		if (nb != 0) {
-			error = ffs_indirtrunc(ip, nlbn, fsbtodb(fs, nb),
+			error = ffs_indirtrunc(ip, nlbn, fsbtoDB(fs, nb),
 					       last, level - 1, &blkcount);
 			if (error)
 				allerror = error;
Index: sys/ufs/ffs/ffs_softdep.c
===================================================================
RCS file: /cvsroot/syssrc/sys/ufs/ffs/ffs_softdep.c,v
retrieving revision 1.35
diff -u -r1.35 ffs_softdep.c
--- sys/ufs/ffs/ffs_softdep.c	2002/09/27 15:38:04	1.35
+++ sys/ufs/ffs/ffs_softdep.c	2002/09/30 22:40:57
@@ -1188,7 +1188,7 @@
 		return (0);
 	bzero(&cstotal, sizeof cstotal);
 	for (cyl = 0; cyl < fs->fs_ncg; cyl++) {
-		if ((error = bread(devvp, fsbtodb(fs, cgtod(fs, cyl)),
+		if ((error = bread(devvp, fsbtoDB(fs, cgtod(fs, cyl)),
 		    fs->fs_cgsize, cred, &bp)) != 0) {
 			brelse(bp);
 			return (error);
@@ -1874,7 +1874,7 @@
 	freeblks->fb_fs = fs;
 	freeblks->fb_oldsize = ip->i_ffs_size;
 	freeblks->fb_newsize = length;
-	freeblks->fb_chkcnt = ip->i_ffs_blocks;
+	freeblks->fb_chkcnt = fsbtoDB(fs, dbtofsb(fs, ip->i_ffs_blocks));
 	for (i = 0; i < NDADDR; i++) {
 		freeblks->fb_dblks[i] = ufs_rw32(ip->i_ffs_db[i], needswap);
 		ip->i_ffs_db[i] = 0;
@@ -1891,14 +1891,14 @@
 	 * file is merely being truncated, then we account for it now.
 	 */
 	if ((ip->i_flag & IN_SPACECOUNTED) == 0)
-		fs->fs_pendingblocks += freeblks->fb_chkcnt;
+		fs->fs_pendingblocks += fsbtodb(fs, DBtofsb(fs, freeblks->fb_chkcnt));
 	/*
 	 * Push the zero'ed inode to to its disk buffer so that we are free
 	 * to delete its dependencies below. Once the dependencies are gone
 	 * the buffer can be safely released.
 	 */
 	if ((error = bread(ip->i_devvp,
-	    fsbtodb(fs, ino_to_fsba(fs, ip->i_number)),
+	    fsbtoDB(fs, ino_to_fsba(fs, ip->i_number)),
 	    (int)fs->fs_bsize, NOCRED, &bp)) != 0)
 		softdep_error("softdep_setup_freeblocks", error);
 #ifdef FFS_EI
@@ -2345,11 +2345,11 @@
 	for (level = (NIADDR - 1); level >= 0; level--) {
 		if ((bn = freeblks->fb_iblks[level]) == 0)
 			continue;
-		if ((error = indir_trunc(&tip, fsbtodb(fs, bn), level,
+		if ((error = indir_trunc(&tip, fsbtoDB(fs, bn), level,
 		    baselbns[level], &blocksreleased)) != 0)
 			allerror = error;
 		ffs_blkfree(&tip, bn, fs->fs_bsize);
-		fs->fs_pendingblocks -= nblocks;
+		fs->fs_pendingblocks -= fsbtodb(fs, DBtofsb(fs, nblocks));
 		blocksreleased += nblocks;
 	}
 	/*
@@ -2360,7 +2360,7 @@
 			continue;
 		bsize = blksize(fs, &tip, i);
 		ffs_blkfree(&tip, bn, bsize);
-		fs->fs_pendingblocks -= btodb(bsize);
+		fs->fs_pendingblocks -= btosec(fs, bsize);
 		blocksreleased += btodb(bsize);
 	}
 	lockmgr(&tip.i_gnode.g_glock, LK_RELEASE, NULL);
@@ -2443,12 +2443,12 @@
 		if ((nb = ufs_rw32(bap[i], needswap)) == 0)
 			continue;
 		if (level != 0) {
-			if ((error = indir_trunc(ip, fsbtodb(fs, nb),
+			if ((error = indir_trunc(ip, fsbtoDB(fs, nb),
 			     level - 1, lbn + (i * lbnadd), countp)) != 0)
 				allerror = error;
 		}
 		ffs_blkfree(ip, nb, fs->fs_bsize);
-		fs->fs_pendingblocks -= nblocks;
+		fs->fs_pendingblocks -= fsbtodb(fs, DBtofsb(fs, nblocks));
 		*countp += nblocks;
 	}
 	bp->b_flags |= B_INVAL | B_NOCACHE;
@@ -4875,7 +4875,7 @@
 		 */
 		FREE_LOCK(&lk);
 		if ((error = bread(ump->um_devvp,
-		    fsbtodb(ump->um_fs, ino_to_fsba(ump->um_fs, inum)),
+		    fsbtoDB(ump->um_fs, ino_to_fsba(ump->um_fs, inum)),
 		    (int)ump->um_fs->fs_bsize, NOCRED, &bp)) != 0)
 			break;
 		if ((error = VOP_BWRITE(bp)) != 0)
Index: sys/ufs/ffs/ffs_vfsops.c
===================================================================
RCS file: /cvsroot/syssrc/sys/ufs/ffs/ffs_vfsops.c,v
retrieving revision 1.102
diff -u -r1.102 ffs_vfsops.c
--- sys/ufs/ffs/ffs_vfsops.c	2002/09/21 18:14:50	1.102
+++ sys/ufs/ffs/ffs_vfsops.c	2002/09/30 22:41:00
@@ -310,7 +310,7 @@
 				error = ffs_flushfiles(mp, flags, p);
 			if (fs->fs_pendingblocks != 0 ||
 			    fs->fs_pendinginodes != 0) {
-				printf("%s: update error: blocks %d files %d\n",
+				printf("%s: update error: sectors %d files %d\n",
 				    fs->fs_fsmnt, fs->fs_pendingblocks,
 				    fs->fs_pendinginodes);
 				fs->fs_pendingblocks = 0;
@@ -417,7 +417,7 @@
 		else {
 			printf("%s: file system not clean (fs_clean=%x); please fsck(8)\n",
 			    mp->mnt_stat.f_mntfromname, fs->fs_clean);
-			printf("%s: lost blocks %d files %d\n",
+			printf("%s: lost sectors %d files %d\n",
 			    mp->mnt_stat.f_mntfromname, fs->fs_pendingblocks,
 			    fs->fs_pendinginodes);
 		}
@@ -450,7 +450,6 @@
 	void *space;
 	struct buf *bp;
 	struct fs *fs, *newfs;
-	struct partinfo dpart;
 	int i, blks, size, error;
 	int32_t *lp;
 	caddr_t cp;
@@ -469,11 +468,8 @@
 	/*
 	 * Step 2: re-read superblock from disk.
 	 */
-	if (VOP_IOCTL(devvp, DIOCGPART, (caddr_t)&dpart, FREAD, NOCRED, p) != 0)
-		size = DEV_BSIZE;
-	else
-		size = dpart.disklab->d_secsize;
-	error = bread(devvp, (ufs_daddr_t)(SBOFF / size), SBSIZE, NOCRED, &bp);
+	error = bread(devvp, (ufs_daddr_t)(SBOFF / DEV_BSIZE), SBSIZE,
+		      NOCRED, &bp);
 	if (error) {
 		brelse(bp);
 		return (error);
@@ -529,7 +525,7 @@
 		size = fs->fs_bsize;
 		if (i + fs->fs_frag > blks)
 			size = (blks - i) * fs->fs_fsize;
-		error = bread(devvp, fsbtodb(fs, fs->fs_csaddr + i), size,
+		error = bread(devvp, fsbtoDB(fs, fs->fs_csaddr + i), size,
 			      NOCRED, &bp);
 		if (error) {
 			brelse(bp);
@@ -582,7 +578,7 @@
 		 * Step 6: re-read inode data for all active vnodes.
 		 */
 		ip = VTOI(vp);
-		error = bread(devvp, fsbtodb(fs, ino_to_fsba(fs, ip->i_number)),
+		error = bread(devvp, fsbtoDB(fs, ino_to_fsba(fs, ip->i_number)),
 			      (int)fs->fs_bsize, NOCRED, &bp);
 		if (error) {
 			brelse(bp);
@@ -620,7 +616,6 @@
 	struct buf *bp;
 	struct fs *fs;
 	dev_t dev;
-	struct partinfo dpart;
 	void *space;
 	int blks;
 	int error, i, size, ronly;
@@ -654,14 +649,10 @@
 	error = VOP_OPEN(devvp, ronly ? FREAD : FREAD|FWRITE, FSCRED, p);
 	if (error)
 		return (error);
-	if (VOP_IOCTL(devvp, DIOCGPART, (caddr_t)&dpart, FREAD, cred, p) != 0)
-		size = DEV_BSIZE;
-	else
-		size = dpart.disklab->d_secsize;
-
 	bp = NULL;
 	ump = NULL;
-	error = bread(devvp, (ufs_daddr_t)(SBOFF / size), SBSIZE, cred, &bp);
+	error = bread(devvp, (ufs_daddr_t)(SBOFF / DEV_BSIZE), SBSIZE,
+		      cred, &bp);
 	if (error)
 		goto out;
 
@@ -729,7 +720,7 @@
 	 */
 
 	if (!ronly) {
-		error = bread(devvp, fsbtodb(fs, fs->fs_size - 1), fs->fs_fsize,
+		error = bread(devvp, fsbtoDB(fs, fs->fs_size - 1), fs->fs_fsize,
 		    cred, &bp);
 		if (bp->b_bcount != fs->fs_fsize)
 			error = EINVAL;
@@ -756,7 +747,7 @@
 		size = fs->fs_bsize;
 		if (i + fs->fs_frag > blks)
 			size = (blks - i) * fs->fs_fsize;
-		error = bread(devvp, fsbtodb(fs, fs->fs_csaddr + i), size,
+		error = bread(devvp, fsbtoDB(fs, fs->fs_csaddr + i), size,
 			      cred, &bp);
 		if (error) {
 			free(fs->fs_csp, M_UFSMNT);
@@ -805,7 +796,7 @@
 	ump->um_devvp = devvp;
 	ump->um_nindir = fs->fs_nindir;
 	ump->um_lognindir = ffs(fs->fs_nindir) - 1;
-	ump->um_bptrtodb = fs->fs_fsbtodb;
+	ump->um_bptrtodb = fs->fs_fshift - DEV_BSHIFT;
 	ump->um_seqinc = fs->fs_frag;
 	for (i = 0; i < MAXQUOTAS; i++)
 		ump->um_quotas[i] = NULLVP;
@@ -894,7 +885,7 @@
 	ump = VFSTOUFS(mp);
 	fs = ump->um_fs;
 	if (fs->fs_pendingblocks != 0 || fs->fs_pendinginodes != 0) {
-		printf("%s: unmount pending error: blocks %d files %d\n",
+		printf("%s: unmount pending error: sectors %d files %d\n",
 		    fs->fs_fsmnt, fs->fs_pendingblocks, fs->fs_pendinginodes);
 		fs->fs_pendingblocks = 0;
 		fs->fs_pendinginodes = 0;
@@ -1183,7 +1174,7 @@
 	lockmgr(&ufs_hashlock, LK_RELEASE, 0);
 
 	/* Read in the disk contents for the inode, copy into the inode. */
-	error = bread(ump->um_devvp, fsbtodb(fs, ino_to_fsba(fs, ino)),
+	error = bread(ump->um_devvp, fsbtoDB(fs, ino_to_fsba(fs, ino)),
 		      (int)fs->fs_bsize, NOCRED, &bp);
 	if (error) {
 
@@ -1379,7 +1370,7 @@
 	}							/* XXX */
 	fs->fs_maxfilesize = mp->um_savedmaxfilesize;	/* XXX */
 
-	bp = getblk(mp->um_devvp, SBOFF >> (fs->fs_fshift - fs->fs_fsbtodb),
+	bp = getblk(mp->um_devvp, SBOFF >> DEV_BSHIFT,
 	    (int)fs->fs_sbsize, 0, 0);
 	saveflag = fs->fs_flags & FS_INTERNAL;
 	fs->fs_flags &= ~FS_INTERNAL;
@@ -1420,7 +1411,7 @@
 		size = fs->fs_bsize;
 		if (i + fs->fs_frag > blks)
 			size = (blks - i) * fs->fs_fsize;
-		bp = getblk(mp->um_devvp, fsbtodb(fs, fs->fs_csaddr + i),
+		bp = getblk(mp->um_devvp, fsbtoDB(fs, fs->fs_csaddr + i),
 		    size, 0, 0);
 #ifdef FFS_EI
 		if (mp->um_flags & UFS_NEEDSWAP)
Index: sys/ufs/ffs/fs.h
===================================================================
RCS file: /cvsroot/syssrc/sys/ufs/ffs/fs.h,v
retrieving revision 1.25
diff -u -r1.25 fs.h
--- sys/ufs/ffs/fs.h	2002/04/10 14:31:07	1.25
+++ sys/ufs/ffs/fs.h	2002/09/30 22:41:02
@@ -174,12 +174,12 @@
 struct fs {
 	int32_t	 fs_firstfield;		/* historic file system linked list, */
 	int32_t	 fs_unused_1;		/*     used for incore super blocks */
-	ufs_daddr_t fs_sblkno;		/* addr of super-block in filesys */
-	ufs_daddr_t fs_cblkno;		/* offset of cyl-block in filesys */
-	ufs_daddr_t fs_iblkno;		/* offset of inode-blocks in filesys */
-	ufs_daddr_t fs_dblkno;		/* offset of first data after cg */
+	ufs_daddr_t fs_sblkno;		/* offset of dup super-block in cg */
+	ufs_daddr_t fs_cblkno;		/* offset of cyl-block in cyl grp */
+	ufs_daddr_t fs_iblkno;		/* offset of inode-blocks in cyl grp */
+	ufs_daddr_t fs_dblkno;		/* offset of first data block in cg */
 	int32_t	 fs_cgoffset;		/* cylinder group offset in cylinder */
-	int32_t	 fs_cgmask;		/* used to calc mod fs_ntrak */
+	int32_t	 fs_cgmask;		/* used to calc start of cg block */
 	int32_t	 fs_time;		/* last time written */
 	int32_t	 fs_size;		/* number of blocks in fs */
 	int32_t	 fs_dsize;		/* number of data blocks in fs */
@@ -201,13 +201,14 @@
 	int32_t	 fs_maxbpg;		/* max number of blks per cyl group */
 /* these fields can be computed from the others */
 	int32_t	 fs_fragshift;		/* block to frag shift */
-	int32_t	 fs_fsbtodb;		/* fsbtodb and dbtofsb shift constant */
+	int32_t	 fs_fsbtodb;		/* frag to sector shift (don't use
+					 * unless you REALLY want sectors!) */
 	int32_t	 fs_sbsize;		/* actual size of super block */
 	int32_t	 fs_csmask;		/* csum block offset (now unused) */
 	int32_t	 fs_csshift;		/* csum block number (now unused) */
-	int32_t	 fs_nindir;		/* value of NINDIR */
-	int32_t	 fs_inopb;		/* value of INOPB */
-	int32_t	 fs_nspf;		/* value of NSPF */
+	int32_t	 fs_nindir;		/* number of indirects in a block */
+	int32_t	 fs_inopb;		/* number of inodes per block */
+	int32_t	 fs_nspf;		/* number of sectors per fragment */
 /* yet another configuration parameter */
 	int32_t	 fs_optim;		/* optimization preference, see below */
 /* these fields are derived from the hardware */
@@ -229,7 +230,7 @@
 /* these fields can be computed from the others */
 	int32_t	 fs_cpg;		/* cylinders per group */
 	int32_t	 fs_ipg;		/* inodes per group */
-	int32_t	 fs_fpg;		/* blocks per group * fs_frag */
+	int32_t	 fs_fpg;		/* frags per group */
 /* this data must be re-computed after crashes */
 	struct	csum fs_cstotal;	/* cylinder summary information */
 /* these fields are cleared at mount time */
@@ -250,7 +251,7 @@
 	int32_t	 fs_avgfilesize;	/* expected average file size */
 	int32_t	 fs_avgfpdir;		/* expected # of files per directory */
 	int32_t	 fs_sparecon[26];	/* RESERVED for future constants */
-	int32_t  fs_pendingblocks;	/* blocks in process of being freed */
+	int32_t  fs_pendingblocks;	/* sectors in process of being freed */
 	int32_t  fs_pendinginodes;	/* inodes in process of being freed */
 	int32_t	 fs_contigsumsize;	/* size of cluster summary array */
 	int32_t	 fs_maxsymlinklen;	/* max length of an internal symlink */
@@ -432,14 +433,28 @@
 
 /*
  * Turn file system block numbers into disk block addresses.
- * This maps file system blocks to device size blocks.
+ * This maps file system blocks to sector size blocks.
  */
 #define	fsbtodb(fs, b)	((b) << (fs)->fs_fsbtodb)
 #define	dbtofsb(fs, b)	((b) >> (fs)->fs_fsbtodb)
 
 /*
+ * Turn file system block numbers into logical block addresses.
+ * This maps file system blocks to DEV_BSIZE blocks.
+ */
+#define	fsbtoDB(fs, b)	((b) << ((fs)->fs_fshift - DEV_BSHIFT))
+#define	DBtofsb(fs, b)	((b) >> ((fs)->fs_fshift - DEV_BSHIFT))
+
+/*
+ * Convert a number of bytes to a number of sectors.
+ */
+#define btosec(fs, b)	((b) >> ((fs)->fs_fshift - (fs)->fs_fsbtodb))
+#define sectob(fs, b)	((b) << ((fs)->fs_fshift - (fs)->fs_fsbtodb))
+
+/*
  * Cylinder group macros to locate things in cylinder groups.
  * They calc file system addresses of cylinder group data structures.
+ * All values are fragment numbers within the filesystem.
  */
 #define	cgbase(fs, c)	((ufs_daddr_t)((fs)->fs_fpg * (c)))
 #define	cgdmin(fs, c)	(cgstart(fs, c) + (fs)->fs_dblkno)	/* 1st data */
@@ -470,10 +485,12 @@
 
 /*
  * Extract the bits for a block from a map.
- * Compute the cylinder and rotational position of a cyl block addr.
  */
 #define	blkmap(fs, map, loc) \
     (((map)[(loc) / NBBY] >> ((loc) % NBBY)) & (0xff >> (NBBY - (fs)->fs_frag)))
+/*
+ * Compute the cylinder and rotational position of a cyl block addr. (fragment)
+ */
 #define	cbtocylno(fs, bno) \
     (fsbtodb(fs, bno) / (fs)->fs_spc)
 #define	cbtorpos(fs, bno) \
@@ -532,8 +549,7 @@
 	    : (fragroundup(fs, blkoff(fs, (dip)->di_size))))
 
 /*
- * Number of disk sectors per block/fragment; assumes DEV_BSIZE byte
- * sector size.
+ * Number of disk sectors per block/fragment.
  */
 #define	NSPB(fs)	((fs)->fs_nspf << (fs)->fs_fragshift)
 #define	NSPF(fs)	((fs)->fs_nspf)
Index: sys/ufs/lfs/lfs.h
===================================================================
RCS file: /cvsroot/syssrc/sys/ufs/lfs/lfs.h,v
retrieving revision 1.41
diff -u -r1.41 lfs.h
--- sys/ufs/lfs/lfs.h	2002/07/06 01:30:11	1.41
+++ sys/ufs/lfs/lfs.h	2002/09/30 22:41:05
@@ -282,6 +282,12 @@
 };
 
 
+/*
+ * Note: In the following structure, 'fsb' is a block unit equivalent
+ * to the sector size in LFS v1, or to the fragment size in LFS v2.
+ * The constraints are:
+ * DEV_BSIZE <= sector size <= fsb <= frag size <= ibsize <=  block size <= segment size
+ */
 /* On-disk super block. */
 struct dlfs {
 #define        LFS_MAGIC       0x070162
@@ -300,9 +306,9 @@
 
 /* Checkpoint region. */
         u_int32_t dlfs_free;      /* 32: start of the free list */
-        u_int32_t dlfs_bfree;     /* 36: number of free disk blocks */
+        u_int32_t dlfs_bfree;     /* 36: number of free fsb blocks */
         u_int32_t dlfs_nfiles;    /* 40: number of allocated inodes */
-        int32_t   dlfs_avail;     /* 44: blocks available for writing */
+        int32_t   dlfs_avail;     /* 44: fsb blocks available for writing */
         int32_t   dlfs_uinodes;   /* 48: inodes in cache not yet on disk */
         ufs_daddr_t  dlfs_idaddr; /* 52: inode file disk address */
         u_int32_t dlfs_ifile;     /* 56: inode file inode number */
@@ -325,7 +331,7 @@
         u_int32_t dlfs_sepb;      /* 108: SEGUSE entries per block */
         u_int32_t dlfs_nindir;    /* 112: indirect pointers per block */
         u_int32_t dlfs_nseg;      /* 116: number of segments */
-        u_int32_t dlfs_nspf;      /* 120: number of sectors per fragment */
+        u_int32_t dlfs_nspf;      /* 120: sectors per fragment (unused) */
         u_int32_t dlfs_cleansz;   /* 124: cleaner info size in blocks */
         u_int32_t dlfs_segtabsz;  /* 128: segment table size in blocks */
         u_int32_t dlfs_segmask;   /* 132: calculate offset within a segment */
@@ -336,12 +342,12 @@
         u_int64_t dlfs_bmask;     /* 152: calc block offset from file offset */
         u_int64_t dlfs_ffmask;    /* 160: calc frag offset from file offset */
         u_int64_t dlfs_fbmask;    /* 168: calc frag offset from block offset */
-        u_int32_t dlfs_blktodb;   /* 176: blktodb and dbtoblk shift constant */
+        u_int32_t dlfs_blktodb;   /* 176: shift blocks to sectors */
         u_int32_t dlfs_sushift;   /* 180: fast mult/div for segusage table */
 
         int32_t   dlfs_maxsymlinklen; /* 184: max length of an internal symlink */
 #define LFS_MIN_SBINTERVAL      5  /* minimum superblock segment spacing */
-#define LFS_MAXNUMSB            10 /* 188: superblock disk offsets */
+#define LFS_MAXNUMSB            10 /* 188: superblock disk offsets (frags) */
         ufs_daddr_t       dlfs_sboffs[LFS_MAXNUMSB];
 
 	u_int32_t dlfs_nclean;    /* 228: Number of clean segments */
@@ -360,7 +366,7 @@
 	u_int32_t dlfs_inodefmt;  /* 360: inode format version */
 	u_int32_t dlfs_interleave; /* 364: segment interleave */
 	u_int32_t dlfs_ident;     /* 368: per-fs identifier */
-	u_int32_t dlfs_fsbtodb;   /* 372: fsbtodb abd dbtodsb shift constant */
+	u_int32_t dlfs_fsbtodb;   /* 372: shift fsb's to sectors */
 	int8_t    dlfs_pad[132];  /* 376: round to 512 bytes */
 /* Checksum -- last valid disk field. */
 	u_int32_t dlfs_cksum;     /* 508: checksum for superblock checking */
@@ -457,8 +463,8 @@
 	struct vnode *lfs_flushvp;      /* vnode being flushed */
 	struct vnode *lfs_unlockvp;     /* being inactivated in lfs_segunlock */
 	u_int32_t lfs_diropwait;	/* # procs waiting on dirop flush */
-	size_t lfs_devbsize;		/* Device block size */
-	size_t lfs_devbshift;		/* Device block shift */
+	size_t lfs_devbsize;		/* Device sector size (unused) */
+	size_t lfs_devbshift;		/* 0 (unused) */
 	struct lock lfs_freelock;
 	struct lock lfs_fraglock;
 	pid_t lfs_rfpid;		/* Process ID of roll-forward agent */
@@ -586,21 +592,34 @@
 #define	blkoff(fs, loc)		((int)(loc) & (fs)->lfs_bmask)
 #define fragoff(fs, loc)    /* calculates (loc % fs->lfs_fsize) */ \
     ((int)((loc) & (fs)->lfs_ffmask))
+/* Shift fsb units to sectors */
 #define	fsbtodb(fs, b)		((b) << (fs)->lfs_fsbtodb)
 #define	dbtofsb(fs, b)		((b) >> (fs)->lfs_fsbtodb)
+/* Shift frags to sectors */
 #define fragstodb(fs, b)	((b) << ((fs)->lfs_blktodb - (fs)->lfs_fbshift))
 #define dbtofrags(fs, b)	((b) >> ((fs)->lfs_blktodb - (fs)->lfs_fbshift))
 #define	lblkno(fs, loc)		((loc) >> (fs)->lfs_bshift)
 #define	lblktosize(fs, blk)	((blk) << (fs)->lfs_bshift)
-/* Same as above, but named like dbtob(), btodb() */
+/* Shift fsb units to bytes. */
 #define fsbtob(fs, b)		((b) << ((fs)->lfs_bshift - \
 				(fs)->lfs_blktodb + (fs)->lfs_fsbtodb))
 #define btofsb(fs, b)		((b) >> ((fs)->lfs_bshift - \
 				(fs)->lfs_blktodb + (fs)->lfs_fsbtodb))
+/* Shift fsb units to frags. */
 #define fsbtofrags(fs, b)	((b) >> ((fs)->lfs_blktodb - (fs)->lfs_fbshift - \
 				(fs)->lfs_fsbtodb))
 #define fragstofsb(fs, b)	((b) << ((fs)->lfs_blktodb - (fs)->lfs_fbshift - \
 				(fs)->lfs_fsbtodb))
+/* Shift fsb units to DEV_BSIZE units. */
+#define	fsbtoDB(fs, b)		((b) << ((fs)->lfs_bshift - (fs)->lfs_blktodb + \
+				(fs)->lfs_fsbtodb - DEV_BSHIFT))
+#define	DBtofsb(fs, b)		((b) >> ((fs)->lfs_bshift - (fs)->lfs_blktodb + \
+				(fs)->lfs_fsbtodb - DEV_BSHIFT))
+
+/* Shift bytes to sectors. */
+#define btosec(fs, b)		((b) >> ((fs)->lfs_bshift - (fs)->lfs_blktodb))
+#define sectob(fs, b)		((b) << ((fs)->lfs_bshift - (fs)->lfs_blktodb))
+
 #define btofrags(fs, b)		((b) >> (fs)->lfs_ffshift)
 #define numfrags(fs, loc)	/* calculates (loc / fs->lfs_fsize) */	\
 	((loc) >> (fs)->lfs_ffshift)
@@ -624,9 +643,9 @@
 #define segtod(fs, seg) (((fs)->lfs_version == 1     ?       \
 			   (fs)->lfs_ssize << (fs)->lfs_blktodb :       \
 			   btofsb((fs), (fs)->lfs_ssize)) * (seg))
-#define	dtosn(fs, daddr)	/* block address to segment number */	\
+#define	dtosn(fs, daddr)	/* fsb block number to segment number */ \
 	(((daddr) - (fs)->lfs_start) / segtod((fs), 1))
-#define sntod(fs, sn) 		/* segment number to disk address */	\
+#define sntod(fs, sn) 		/* segment number to fsb block number */ \
 	((ufs_daddr_t)(segtod((fs), (sn)) + (fs)->lfs_start))
 
 /* Read in the block with the cleaner info from the ifile. */
Index: sys/ufs/lfs/lfs_balloc.c
===================================================================
RCS file: /cvsroot/syssrc/sys/ufs/lfs/lfs_balloc.c,v
retrieving revision 1.33
diff -u -r1.33 lfs_balloc.c
--- sys/ufs/lfs/lfs_balloc.c	2002/07/06 01:30:12	1.33
+++ sys/ufs/lfs/lfs_balloc.c	2002/09/30 22:41:05
@@ -253,7 +253,7 @@
 				clrbuf(ibp);
 				ibp->b_blkno = UNWRITTEN;
 			} else if (!(ibp->b_flags & (B_DELWRI | B_DONE))) {
-				ibp->b_blkno = fsbtodb(fs, idaddr);
+				ibp->b_blkno = fsbtoDB(fs, idaddr);
 				ibp->b_flags |= B_READ;
 				VOP_STRATEGY(ibp);
 				biowait(ibp);
@@ -339,7 +339,7 @@
 {
 	struct inode *ip;
 	struct lfs *fs;
-	long bb;
+	long bb;		/* = number of fsb blocks to add */
 	int error;
 	extern long locked_queue_bytes;
 	size_t obufsize;
@@ -368,7 +368,7 @@
 		goto out;
 	}
 #ifdef QUOTA
-	if ((error = chkdq(ip, bb, cred, 0))) {
+	if ((error = chkdq(ip, fsbtoDB(fs, bb), cred, 0))) {
 		brelse(*bpp);
 		goto out;
 	}
@@ -384,7 +384,7 @@
 		if (!lfs_fits(fs, bb)) {
 			brelse(*bpp);
 #ifdef QUOTA
-			chkdq(ip, -bb, cred, 0);
+			chkdq(ip, -fsbtoDB(fs, bb), cred, 0);
 #endif
 #ifdef LFS_FRAGSIZE_SEGLOCK
 			lfs_segunlock(fs);
Index: sys/ufs/lfs/lfs_debug.c
===================================================================
RCS file: /cvsroot/syssrc/sys/ufs/lfs/lfs_debug.c,v
retrieving revision 1.16
diff -u -r1.16 lfs_debug.c
--- sys/ufs/lfs/lfs_debug.c	2002/05/14 20:03:53	1.16
+++ sys/ufs/lfs/lfs_debug.c	2002/09/30 22:41:06
@@ -289,7 +289,7 @@
 				       (*bpp)->b_blkno);
 			}
 		}
-		blkno += fsbtodb(fs, btofsb(fs, (*bpp)->b_bcount));
+		blkno += (*bpp)->b_bcount >> DEV_BSHIFT;
 	}
 }
 #endif /* DEBUG */
Index: sys/ufs/lfs/lfs_inode.c
===================================================================
RCS file: /cvsroot/syssrc/sys/ufs/lfs/lfs_inode.c,v
retrieving revision 1.60
diff -u -r1.60 lfs_inode.c
--- sys/ufs/lfs/lfs_inode.c	2002/09/27 15:38:05	1.60
+++ sys/ufs/lfs/lfs_inode.c	2002/09/30 22:41:09
@@ -135,8 +135,8 @@
 	printf("searched %d entries\n", (int)(fin - dip));
 	printf("offset is 0x%x (seg %d)\n", fs->lfs_offset,
 	       dtosn(fs, fs->lfs_offset));
-	printf("block is 0x%x (seg %d)\n", dbtofsb(fs, bp->b_blkno),
-	       dtosn(fs, dbtofsb(fs, bp->b_blkno)));
+	printf("block is 0x%x (seg %d)\n", DBtofsb(fs, bp->b_blkno),
+	       dtosn(fs, DBtofsb(fs, bp->b_blkno)));
 
 	return NULL;
 }
@@ -506,7 +506,7 @@
 #endif
 	oip->i_flag |= IN_CHANGE;
 #ifdef QUOTA
-	(void) chkdq(oip, -blocksreleased, NOCRED, 0);
+	(void) chkdq(oip, -fsbtoDB(fs, blocksreleased), NOCRED, 0);
 #endif
 	lfs_reserve(fs, ovp, -btofsb(fs, (2 * NIADDR + 3) << fs->lfs_bshift));
 #ifdef LFS_FRAGSIZE_SEGLOCK
@@ -615,7 +615,7 @@
 		bp->b_flags |= B_READ;
 		if (bp->b_bcount > bp->b_bufsize)
 			panic("lfs_indirtrunc: bad buffer size");
-		bp->b_blkno = fsbtodb(fs, dbn);
+		bp->b_blkno = fsbtoDB(fs, dbn);
 		VOP_STRATEGY(bp);
 		error = biowait(bp);
 	}
Index: sys/ufs/lfs/lfs_segment.c
===================================================================
RCS file: /cvsroot/syssrc/sys/ufs/lfs/lfs_segment.c,v
retrieving revision 1.82
diff -u -r1.82 lfs_segment.c
--- sys/ufs/lfs/lfs_segment.c	2002/09/27 15:38:06	1.82
+++ sys/ufs/lfs/lfs_segment.c	2002/09/30 22:41:14
@@ -828,7 +828,7 @@
 		daddr = fs->lfs_offset;
 		fs->lfs_offset += btofsb(fs, fs->lfs_ibsize);
 		sp->ibp = *sp->cbpp++ =
-			getblk(VTOI(fs->lfs_ivnode)->i_devvp, fsbtodb(fs, daddr),
+			getblk(VTOI(fs->lfs_ivnode)->i_devvp, fsbtoDB(fs, daddr),
 			       fs->lfs_ibsize, 0, 0);
 		gotblk++;
 
@@ -936,11 +936,11 @@
 	ino = ip->i_number;
 	if (ino == LFS_IFILE_INUM) {
 		daddr = fs->lfs_idaddr;
-		fs->lfs_idaddr = dbtofsb(fs, bp->b_blkno);
+		fs->lfs_idaddr = DBtofsb(fs, bp->b_blkno);
 	} else {
 		LFS_IENTRY(ifp, fs, ino, ibp);
 		daddr = ifp->if_daddr;
-		ifp->if_daddr = dbtofsb(fs, bp->b_blkno) + fsb;
+		ifp->if_daddr = DBtofsb(fs, bp->b_blkno) + fsb;
 #ifdef LFS_DEBUG_NEXTFREE
 		if (ino > 3 && ifp->if_nextfree) {
 			vprint("lfs_writeinode",ITOV(ip));
@@ -961,7 +961,7 @@
 	 * zero here; keep track of how many duplicates we have in 
 	 * "dupino" so we don't panic below.
 	 */
-	if (daddr >= fs->lfs_lastpseg && daddr <= dbtofsb(fs, bp->b_blkno)) {
+	if (daddr >= fs->lfs_lastpseg && daddr <= DBtofsb(fs, bp->b_blkno)) {
 		++sp->ndupino;
 		printf("lfs_writeinode: last inode addr in current pseg "
 		       "(ino %d daddr 0x%x) ndupino=%d\n", ino, daddr,
@@ -1107,7 +1107,7 @@
 			if (!(bp->b_flags & B_LOCKED)) {
 				printf("lfs_gather: lbn %d blk %d"
 				       " not B_LOCKED\n", bp->b_lblkno,
-				       dbtofsb(fs, bp->b_blkno));
+				       DBtofsb(fs, bp->b_blkno));
 				VOP_PRINT(bp->b_vp);
 				panic("lfs_gather: bp not B_LOCKED");
 			}
@@ -1185,7 +1185,7 @@
 		lbn = *sp->start_lbp++;
 		sbp = *sp->start_bpp;
 
-		sbp->b_blkno = fsbtodb(fs, fs->lfs_offset);
+		sbp->b_blkno = fsbtoDB(fs, fs->lfs_offset);
 		off = fs->lfs_offset;
 		if (sbp->b_blkno == sbp->b_lblkno) {
 			printf("lfs_updatemeta: ino %d blk %d"
@@ -1207,7 +1207,7 @@
 		fs->lfs_offset += bb;
 		error = ufs_bmaparray(vp, lbn, &daddr, a, &num, NULL);
 		if (daddr > 0)
-			daddr = dbtofsb(fs, daddr);
+			daddr = DBtofsb(fs, daddr);
 		if (error)
 			panic("lfs_updatemeta: ufs_bmaparray %d", error);
 		ip = VTOI(vp);
@@ -1282,8 +1282,8 @@
 #ifdef DIAGNOSTIC
 			if (sup->su_nbytes < osize + DINODE_SIZE * sp->ndupino) {
 				printf("lfs_updatemeta: negative bytes "
-				       "(segment %d short by %d)\n",
-				       dtosn(fs, daddr),
+				       "(%d for segment %d short by %d)\n",
+				       sup->su_nbytes, dtosn(fs, daddr),
 				       osize - sup->su_nbytes);
 				printf("lfs_updatemeta: ino %d, lbn %d, "
 				       "addr = 0x%x\n", VTOI(sp->vp)->i_number,
@@ -1373,11 +1373,11 @@
 	sp->cbpp = sp->bpp;
 #ifdef LFS_MALLOC_SUMMARY
 	sbp = *sp->cbpp = lfs_newbuf(fs, VTOI(fs->lfs_ivnode)->i_devvp,
-				     fsbtodb(fs, fs->lfs_offset), fs->lfs_sumsize);
+				     fsbtoDB(fs, fs->lfs_offset), fs->lfs_sumsize);
   	sp->segsum = (*sp->cbpp)->b_data;
 #else
 	sbp = *sp->cbpp = getblk(VTOI(fs->lfs_ivnode)->i_devvp,
-				 fsbtodb(fs, fs->lfs_offset), NBPG, 0, 0);
+				 fsbtoDB(fs, fs->lfs_offset), NBPG, 0, 0);
 	memset(sbp->b_data, 0x5a, NBPG);
 	sp->segsum = (*sp->cbpp)->b_data + NBPG - fs->lfs_sumsize;
 #endif
@@ -1586,7 +1586,7 @@
 	if (propeller == 4)
 		propeller = 0;
 #endif
-	pseg_daddr = (*(sp->bpp))->b_blkno;
+	pseg_daddr = (*(sp->bpp))->b_blkno;	/* XXX? */
 
 	/*
 	 * If there are no buffers other than the segment summary to write
@@ -1846,11 +1846,11 @@
 			cbp->b_data = malloc(CHUNKSIZE, M_SEGMENT, M_WAITOK);
 		}
 #if defined(DEBUG) && defined(DIAGNOSTIC)
-		if(dtosn(fs, dbtofsb(fs, (*bpp)->b_blkno + btodb((*bpp)->b_bcount - 1))) !=
-		   dtosn(fs, dbtofsb(fs, cbp->b_blkno))) {
+		if(dtosn(fs, DBtofsb(fs, (*bpp)->b_blkno + btodb((*bpp)->b_bcount - 1))) !=
+		   dtosn(fs, DBtofsb(fs, cbp->b_blkno))) {
 			printf("block at %x (%d), cbp at %x (%d)\n",
-				(*bpp)->b_blkno, dtosn(fs, dbtofsb(fs, (*bpp)->b_blkno)),
-			       cbp->b_blkno, dtosn(fs, dbtofsb(fs, cbp->b_blkno)));
+				(*bpp)->b_blkno, dtosn(fs, DBtofsb(fs, (*bpp)->b_blkno)),
+			       cbp->b_blkno, dtosn(fs, DBtofsb(fs, cbp->b_blkno)));
 			panic("lfs_writeseg: Segment overwrite");
 		}
 #endif
@@ -2024,7 +2024,7 @@
 
 	/* Checksum the superblock and copy it into a buffer. */
 	fs->lfs_cksum = lfs_sb_cksum(&(fs->lfs_dlfs));
-	bp = lfs_newbuf(fs, VTOI(fs->lfs_ivnode)->i_devvp, fsbtodb(fs, daddr), LFS_SBPAD);
+	bp = lfs_newbuf(fs, VTOI(fs->lfs_ivnode)->i_devvp, fsbtoDB(fs, daddr), LFS_SBPAD);
 	*(struct dlfs *)bp->b_data = fs->lfs_dlfs;
 	
 	bp->b_dev = i_dev;
Index: sys/ufs/lfs/lfs_syscalls.c
===================================================================
RCS file: /cvsroot/syssrc/sys/ufs/lfs/lfs_syscalls.c,v
retrieving revision 1.71
diff -u -r1.71 lfs_syscalls.c
--- sys/ufs/lfs/lfs_syscalls.c	2002/08/03 00:12:49	1.71
+++ sys/ufs/lfs/lfs_syscalls.c	2002/09/30 22:41:17
@@ -437,13 +437,13 @@
 		b_daddr = 0;
 		if (blkp->bi_daddr != LFS_FORCE_WRITE) {
 			if (VOP_BMAP(vp, blkp->bi_lbn, NULL, &b_daddr, NULL) ||
-			    dbtofsb(fs, b_daddr) != blkp->bi_daddr)
+			    DBtofsb(fs, b_daddr) != blkp->bi_daddr)
 			{
-				if (dtosn(fs,dbtofsb(fs, b_daddr))
+				if (dtosn(fs,DBtofsb(fs, b_daddr))
 				   == dtosn(fs,blkp->bi_daddr))
 				{
 					printf("lfs_markv: wrong da same seg: %x vs %x\n",
-					       blkp->bi_daddr, dbtofsb(fs, b_daddr));
+					       blkp->bi_daddr, DBtofsb(fs, b_daddr));
 				}
 				do_again++;
 				continue;
@@ -481,7 +481,7 @@
 			bp = lfs_fakebuf(fs, vp, blkp->bi_lbn,
 					 blkp->bi_size, blkp->bi_bp);
 			/* Pretend we used bread() to get it */
-			bp->b_blkno = fsbtodb(fs, blkp->bi_daddr);
+			bp->b_blkno = fsbtoDB(fs, blkp->bi_daddr);
 		} else {
 			/* Indirect block */
 			bp = getblk(vp, blkp->bi_lbn, blkp->bi_size, 0, 0);
@@ -834,7 +834,7 @@
 				blkp->bi_daddr = LFS_UNUSED_DADDR;
 				continue;
 			}
-			blkp->bi_daddr = dbtofsb(fs, blkp->bi_daddr);
+			blkp->bi_daddr = DBtofsb(fs, blkp->bi_daddr);
 			/* Fill in the block size, too */
 			blkp->bi_size = blksize(fs, ip, blkp->bi_lbn);
 		}
@@ -933,7 +933,7 @@
 		vfs_unbusy(mntp);
 		return (EALREADY);
 	}
-	
+
 	fs->lfs_avail += segtod(fs, 1);
 	if (sup->su_flags & SEGUSE_SUPERBLOCK)
 		fs->lfs_avail -= btofsb(fs, LFS_SBPAD);
@@ -1168,7 +1168,7 @@
 	} else {
 		retries = 0;
 	    again:
-		error = bread(ump->um_devvp, fsbtodb(fs, daddr), fs->lfs_ibsize,
+		error = bread(ump->um_devvp, fsbtoDB(fs, daddr), fs->lfs_ibsize,
 			      NOCRED, &bp);
 		if (error) {
 			printf("lfs_fastvget: bread failed with %d\n",error);
Index: sys/ufs/lfs/lfs_vfsops.c
===================================================================
RCS file: /cvsroot/syssrc/sys/ufs/lfs/lfs_vfsops.c,v
retrieving revision 1.82
diff -u -r1.82 lfs_vfsops.c
--- sys/ufs/lfs/lfs_vfsops.c	2002/09/27 15:38:07	1.82
+++ sys/ufs/lfs/lfs_vfsops.c	2002/09/30 22:41:19
@@ -439,12 +439,12 @@
 
 	/* Update segment usage information. */
 	if (odaddr > 0) {
-		LFS_SEGENTRY(sup, fs, dtosn(fs, dbtofsb(fs, odaddr)), bp);
+		LFS_SEGENTRY(sup, fs, dtosn(fs, DBtofsb(fs, odaddr)), bp);
 #ifdef DIAGNOSTIC
 		if (sup->su_nbytes < size) {
 			panic("update_meta: negative bytes "
 			      "(segment %d short by %ld)\n",
-			      dtosn(fs, dbtofsb(fs, odaddr)), (long)size - sup->su_nbytes);
+			      dtosn(fs, DBtofsb(fs, odaddr)), (long)size - sup->su_nbytes);
 			sup->su_nbytes = size;
 		}
 #endif
@@ -461,7 +461,7 @@
 #ifdef DEBUG_LFS_RFW
 	/* Now look again to make sure it worked */
 	ufs_bmaparray(vp, lbn, &odaddr, &a[0], &num, NULL );
-	if (dbtofsb(fs, odaddr) != ndaddr)
+	if (DBtofsb(sf, odaddr) != ndaddr)
 		printf("update_meta: failed setting ino %d lbn %d to %x\n",
 		       ino, lbn, ndaddr);
 #endif
@@ -488,7 +488,7 @@
 	 * Get the inode, update times and perms.
 	 * DO NOT update disk blocks, we do that separately.
 	 */
-	error = bread(devvp, fsbtodb(fs, offset), fs->lfs_ibsize, cred, &dbp);
+	error = bread(devvp, fsbtoDB(fs, offset), fs->lfs_ibsize, cred, &dbp);
 	if (error) {
 #ifdef DEBUG_LFS_RFW
 		printf("update_inoblk: bread returned %d\n", error);
@@ -533,17 +533,17 @@
 			/* Record change in location */
 			LFS_IENTRY(ifp, fs, dip->di_inumber, ibp);
 			daddr = ifp->if_daddr;
-			ifp->if_daddr = dbtofsb(fs, dbp->b_blkno);
+			ifp->if_daddr = DBtofsb(fs, dbp->b_blkno);
 			error = LFS_BWRITE_LOG(ibp); /* Ifile */
 			/* And do segment accounting */
-			if (dtosn(fs, daddr) != dtosn(fs, dbtofsb(fs, dbp->b_blkno))) {
+			if (dtosn(fs, daddr) != dtosn(fs, DBtofsb(fs, dbp->b_blkno))) {
 				if (daddr > 0) {
 					LFS_SEGENTRY(sup, fs, dtosn(fs, daddr),
 						     ibp);
 					sup->su_nbytes -= DINODE_SIZE;
 					LFS_BWRITE_LOG(ibp);
 				}
-				LFS_SEGENTRY(sup, fs, dtosn(fs, dbtofsb(fs, dbp->b_blkno)),
+				LFS_SEGENTRY(sup, fs, dtosn(fs, DBtofsb(fs, dbp->b_blkno)),
 					     ibp);
 				sup->su_nbytes += DINODE_SIZE;
 				LFS_BWRITE_LOG(ibp);
@@ -587,7 +587,7 @@
 	}
 
 	/* Read in the segment summary */
-	error = bread(devvp, offset, fs->lfs_sumsize, cred, &bp);
+	error = bread(devvp, fsbtoDB(fs, offset), fs->lfs_sumsize, cred, &bp);
 	if (error)
 		return -1;
 	
@@ -668,7 +668,7 @@
 		if (ninos && *iaddr == offset) {
 			if (flags & CHECK_CKSUM) {
 				/* Read in the head and add to the buffer */
-				error = bread(devvp, fsbtodb(fs, offset), fs->lfs_bsize,
+				error = bread(devvp, fsbtoDB(fs, offset), fs->lfs_bsize,
 					      cred, &dbp);
 				if (error) {
 					offset = -1;
@@ -698,7 +698,7 @@
 			if (j == fip->fi_nblocks - 1)
 				size = fip->fi_lastlength;
 			if (flags & CHECK_CKSUM) {
-				error = bread(devvp, fsbtodb(fs, offset), size, cred, &dbp);
+				error = bread(devvp, fsbtoDB(fs, offset), size, cred, &dbp);
 				if (error) {
 					offset = -1;
 					goto err2;
@@ -825,7 +825,8 @@
 	sb_addr = LFS_LABELPAD / secsize;
 	while (1) {
 		/* Read in the superblock. */
-		error = bread(devvp, sb_addr, LFS_SBPAD, cred, &bp);
+		error = bread(devvp, sb_addr * (secsize / DEV_BSIZE),
+			      LFS_SBPAD, cred, &bp);
 		if (error)
 			goto out;
 		dfs = (struct dlfs *)bp->b_data;
@@ -879,7 +880,7 @@
 	if (dfs->dlfs_sboffs[1] &&
 	    dfs->dlfs_sboffs[1] - LFS_LABELPAD / fsbsize > LFS_SBPAD / fsbsize)
 	{
-		error = bread(devvp, dfs->dlfs_sboffs[1] * (fsbsize / secsize), 
+		error = bread(devvp, dfs->dlfs_sboffs[1] * (fsbsize / DEV_BSIZE), 
 			LFS_SBPAD, cred, &abp);
 		if (error)
 			goto out;
@@ -983,12 +984,14 @@
 	ump->um_mountp = mp;
 	ump->um_dev = dev;
 	ump->um_devvp = devvp;
-	ump->um_bptrtodb = fs->lfs_fsbtodb;
+	ump->um_bptrtodb = (fs->lfs_bshift - fs->lfs_blktodb
+			    + fs->lfs_fsbtodb - DEV_BSHIFT);
 	ump->um_seqinc = fragstofsb(fs, fs->lfs_frag);
 	ump->um_nindir = fs->lfs_nindir;
 	ump->um_lognindir = ffs(fs->lfs_nindir) - 1;
 	for (i = 0; i < MAXQUOTAS; i++)
 		ump->um_quotas[i] = NULLVP;
+	ump->um_dibshift = fs->lfs_bshift - fs->lfs_blktodb + fs->lfs_fsbtodb;
 	devvp->v_specmountpoint = mp;
 
 	/*
@@ -1285,7 +1288,7 @@
 	sbp->f_bfree = fsbtofrags(fs, LFS_EST_BFREE(fs));
 	sbp->f_bavail = fsbtofrags(fs, (long)LFS_EST_BFREE(fs) -
 				  (long)LFS_EST_RSVD(fs));
-	
+
 	sbp->f_files = fs->lfs_bfree / btofsb(fs, fs->lfs_ibsize) * INOPB(fs);
 	sbp->f_ffree = sbp->f_files - fs->lfs_nfiles;
 	if (sbp != &mp->mnt_stat) {
@@ -1419,7 +1422,7 @@
 	/* Read in the disk contents for the inode, copy into the inode. */
 	retries = 0;
     again:
-	error = bread(ump->um_devvp, fsbtodb(fs, daddr), 
+	error = bread(ump->um_devvp, fsbtoDB(fs, daddr),
 		(fs->lfs_version == 1 ? fs->lfs_bsize : fs->lfs_ibsize),
 		NOCRED, &bp);
 	if (error) {
Index: sys/ufs/ufs/dinode.h
===================================================================
RCS file: /cvsroot/syssrc/sys/ufs/ufs/dinode.h,v
retrieving revision 1.13
diff -u -r1.13 dinode.h
--- sys/ufs/ufs/dinode.h	2001/07/27 01:24:54	1.13
+++ sys/ufs/ufs/dinode.h	2002/09/30 22:41:20
@@ -89,7 +89,8 @@
 	ufs_daddr_t	di_db[NDADDR];	/*  40: Direct disk blocks. */
 	ufs_daddr_t	di_ib[NIADDR];	/*  88: Indirect disk blocks. */
 	u_int32_t	di_flags;	/* 100: Status flags (chflags). */
-	u_int32_t	di_blocks;	/* 104: Blocks actually held. */
+	u_int32_t	di_blocks;	/* 104: Ffs: Sectors actually held. */
+					/*	Lfs: fsb's actually held. */
 	int32_t		di_gen;		/* 108: Generation number. */
 	u_int32_t	di_uid;		/* 112: File owner. */
 	u_int32_t	di_gid;		/* 116: File group. */
Index: sys/ufs/ufs/ufs_vnops.c
===================================================================
RCS file: /cvsroot/syssrc/sys/ufs/ufs/ufs_vnops.c,v
retrieving revision 1.86
diff -u -r1.86 ufs_vnops.c
--- sys/ufs/ufs/ufs_vnops.c	2002/05/14 17:37:52	1.86
+++ sys/ufs/ufs/ufs_vnops.c	2002/09/30 22:41:24
@@ -335,7 +335,7 @@
 		vap->va_blocksize = MAXBSIZE;
 	else
 		vap->va_blocksize = vp->v_mount->mnt_stat.f_iosize;
-	vap->va_bytes = dbtob((u_quad_t)ip->i_ffs_blocks);
+	vap->va_bytes = dibtob (VFSTOUFS(vp->v_mount), (u_quad_t)ip->i_ffs_blocks);
 	vap->va_type = vp->v_type;
 	vap->va_filerev = ip->i_modrev;
 	return (0);
@@ -533,7 +533,7 @@
 		dqrele(vp, ip->i_dquot[GRPQUOTA]);
 		ip->i_dquot[GRPQUOTA] = NODQUOT;
 	}
-	change = ip->i_ffs_blocks;
+	change = dibtoDB (VFSTOUFS(vp->v_mount), ip->i_ffs_blocks);
 	(void) chkdq(ip, -change, cred, CHOWN);
 	(void) chkiq(ip, -1, cred, CHOWN);
 	for (i = 0; i < MAXQUOTAS; i++) {
Index: sys/ufs/ufs/ufsmount.h
===================================================================
RCS file: /cvsroot/syssrc/sys/ufs/ufs/ufsmount.h,v
retrieving revision 1.8
diff -u -r1.8 ufsmount.h
--- sys/ufs/ufs/ufsmount.h	2000/11/27 08:40:02	1.8
+++ sys/ufs/ufs/ufsmount.h	2002/09/30 22:41:24
@@ -83,13 +83,14 @@
 	struct	ucred *um_cred[MAXQUOTAS];	/* quota file access cred */
 	u_long	um_nindir;			/* indirect ptrs per block */
 	u_long	um_lognindir;			/* log2 of um_nindir */
-	u_long	um_bptrtodb;			/* indir ptr to disk block */
+	u_long	um_bptrtodb;			/* indir ptr to disk sector */
 	u_long	um_seqinc;			/* inc between seq blocks */
 	time_t	um_btime[MAXQUOTAS];		/* block quota time limit */
 	time_t	um_itime[MAXQUOTAS];		/* inode quota time limit */
 	char	um_qflags[MAXQUOTAS];		/* quota specific flags */
 	struct	netexport um_export;		/* export information */
 	u_int64_t um_savedmaxfilesize;		/* XXX - limit maxfilesize */
+	u_int32_t um_dibshift;			/* log2 of di_block unit */
 };
 
 /* UFS-specific flags */
@@ -111,4 +112,10 @@
 #define MNINDIR(ump)			((ump)->um_nindir)
 #define	blkptrtodb(ump, b)		((b) << (ump)->um_bptrtodb)
 #define	is_sequential(ump, a, b)	((b) == (a) + ump->um_seqinc)
+
+/*
+ * Convert inode block count to bytes or DEV_BSIZE blocks.
+ */
+#define dibtob(ump, b)		((b) << (ump)->um_dibshift)
+#define dibtoDB(ump, b)		((b) << ((ump)->um_dibshift - DEV_BSHIFT))
 #endif /* _KERNEL */
Index: sbin/newfs/mkfs.c
===================================================================
RCS file: /cvsroot/basesrc/sbin/newfs/mkfs.c,v
retrieving revision 1.64
diff -u -r1.64 mkfs.c
--- sbin/newfs/mkfs.c	2002/04/10 17:28:13	1.64
+++ sbin/newfs/mkfs.c	2002/09/30 22:41:28
@@ -248,13 +248,29 @@
 	sblock.fs_cblkno = (daddr_t)(sblock.fs_sblkno +
 	    roundup(howmany(sbsize, sblock.fs_fsize), sblock.fs_frag));
 	sblock.fs_iblkno = sblock.fs_cblkno + sblock.fs_frag;
+	/*
+	 * Set the cylinder group offset to the number of frags per track,
+	 * rounded up to the next full block boundary.  This skews the cg
+	 * block by approximately one track per group.
+	 */
 	sblock.fs_cgoffset = roundup(
 	    howmany(sblock.fs_nsect, NSPF(&sblock)), sblock.fs_frag);
+	/*
+	 * Set the cylinder group mask to the number of tracks
+	 * rounded up to the next power of 2, negated.  The
+	 * cgstart() macro uses ~fs_cgmask to wrap the cg block
+	 * back to the first cylinder in the group after
+	 * fs_cgoffset takes it through all of the platters.
+	 */
 	for (sblock.fs_cgmask = 0xffffffff, i = sblock.fs_ntrak; i > 1; i >>= 1)
 		sblock.fs_cgmask <<= 1;
 	if (!POWEROF2(sblock.fs_ntrak))
 		sblock.fs_cgmask <<= 1;
 	sblock.fs_maxfilesize = sblock.fs_bsize * NDADDR - 1;
+	/*
+	 * Each indirect block addresses NINDIR^N * fs_bsize bytes,
+	 * where N is the indirect block number + 1.
+	 */
 	for (sizepb = sblock.fs_bsize, i = 0; i < NIADDR; i++) {
 		sizepb *= NINDIR(&sblock);
 		sblock.fs_maxfilesize += sizepb;
@@ -264,6 +280,10 @@
 	 * and calculate minimum cylinders per group.
 	 */
 	sblock.fs_spc = secpercyl;
+	/*
+	 * cylinders per cycle == number of cylinders required to align
+	 * the first sector in a cylinder on a block boundary.
+	 */
 	for (sblock.fs_cpc = NSPB(&sblock), i = sblock.fs_spc;
 	     sblock.fs_cpc > 1 && (i & 1) == 0;
 	     sblock.fs_cpc >>= 1, i >>= 1)
@@ -396,7 +416,7 @@
 	}
 	sblock.fs_fpg = (sblock.fs_cpg * sblock.fs_spc) / NSPF(&sblock);
 	if ((sblock.fs_cpg * sblock.fs_spc) % NSPB(&sblock) != 0) {
-		printf("panic (fs_cpg * fs_spc) %% NSPF != 0");
+		printf("panic (fs_cpg * fs_spc) %% NSPB != 0");
 		exit(24);
 	}
 	if (sblock.fs_cpg < mincpg) {
@@ -411,7 +431,7 @@
 		else if (mapcramped)
 			printf("Block size restricts");
 		else
-			printf("Bytes per inode restrict");
+			printf("Bytes per inode restricts");
 		printf(" cylinders per group to %d.\n", sblock.fs_cpg);
 		exit(27);
 	}
@@ -419,6 +439,8 @@
 	/*
 	 * Now have size for file system and nsect and ntrak.
 	 * Determine number of cylinders and blocks in the file system.
+	 * ATTENTION: At this point, the units of fssize changes
+	 *	      from sectors to fragments.
 	 */
 	sblock.fs_size = fssize = dbtofsb(&sblock, fssize);
 	sblock.fs_ncyl = fssize * NSPF(&sblock) / sblock.fs_spc;
@@ -599,10 +621,10 @@
 	nprintcols = 76 / (printcolwidth + 2);
 	/*
 	 * Now build the cylinders group blocks and
-	 * then print out indices of cylinder groups.
+	 * then print out sector indices of cylinder groups.
 	 */
 	if (!mfs)
-		printf("super-block backups (for fsck -b #) at:");
+		printf("super-block backups (for fsck -b #) at sector:");
 	for (cylno = 0; cylno < sblock.fs_ncg; cylno++) {
 		initcg(cylno, utime);
 		if (mfs)
@@ -896,7 +918,7 @@
 	node.di_nlink = 2;
 	node.di_size = sblock.fs_bsize;
 	node.di_db[0] = alloc(node.di_size, node.di_mode);
-	node.di_blocks = btodb(fragroundup(&sblock, node.di_size));
+	node.di_blocks = btosec(&sblock, fragroundup(&sblock, node.di_size));
 	node.di_uid = geteuid();
 	node.di_gid = getegid();
 	wtfs(fsbtodb(&sblock, node.di_db[0]), node.di_size, buf);
@@ -922,7 +944,7 @@
 	node.di_db[0] = alloc(sblock.fs_fsize, node.di_mode);
 	if (node.di_db[0] == 0)
 		return (0);
-	node.di_blocks = btodb(fragroundup(&sblock, node.di_size));
+	node.di_blocks = btosec(&sblock, fragroundup(&sblock, node.di_size));
 	wtfs(fsbtodb(&sblock, node.di_db[0]), sblock.fs_fsize, buf);
 	iput(&node, ROOTINO);
 	return (1);
@@ -1094,28 +1116,28 @@
  * read a block from the file system
  */
 void
-rdfs(daddr_t bno, int size, void *bf)
+rdfs(daddr_t secnum, int size, void *bf)
 {
 	int n;
 	off_t offset;
 
 #ifdef MFS
 	if (mfs) {
-		memmove(bf, membase + bno * sectorsize, size);
+		memmove(bf, membase + secnum * sectorsize, size);
 		return;
 	}
 #endif
-	offset = bno;
+	offset = secnum;
 	offset *= sectorsize;
 	if (lseek(fsi, offset, SEEK_SET) < 0) {
 		printf("rdfs: seek error for sector %d: %s\n",
-		    bno, strerror(errno));
+		    secnum, strerror(errno));
 		exit(33);
 	}
 	n = read(fsi, bf, size);
 	if (n != size) {
 		printf("rdfs: read error for sector %d: %s\n",
-		    bno, strerror(errno));
+		    secnum, strerror(errno));
 		exit(34);
 	}
 }
@@ -1124,30 +1146,30 @@
  * write a block to the file system
  */
 void
-wtfs(daddr_t bno, int size, void *bf)
+wtfs(daddr_t secnum, int size, void *bf)
 {
 	int n;
 	off_t offset;
 
 #ifdef MFS
 	if (mfs) {
-		memmove(membase + bno * sectorsize, bf, size);
+		memmove(membase + secnum * sectorsize, bf, size);
 		return;
 	}
 #endif
 	if (Nflag)
 		return;
-	offset = bno;
+	offset = secnum;
 	offset *= sectorsize;
 	if (lseek(fso, offset, SEEK_SET) < 0) {
 		printf("wtfs: seek error for sector %d: %s\n",
-		    bno, strerror(errno));
+		    secnum, strerror(errno));
 		exit(35);
 	}
 	n = write(fso, bf, size);
 	if (n != size) {
 		printf("wtfs: write error for sector %d: %s\n",
-		    bno, strerror(errno));
+		    secnum, strerror(errno));
 		exit(36);
 	}
 }
@@ -1276,7 +1298,7 @@
 	for (i=0; i < MAXFRAG; i++)
 		n->cg_frsum[i] = bswap32(o->cg_frsum[i]);
 
-	/* alays new format */
+	/* alay's new format */
 	if (n->cg_magic == CG_MAGIC) {
 		btotsize = n->cg_boff - n->cg_btotoff;
 		fbsize = n->cg_iusedoff - n->cg_boff;
Index: sbin/newfs/newfs.8
===================================================================
RCS file: /cvsroot/basesrc/sbin/newfs/newfs.8,v
retrieving revision 1.43
diff -u -r1.43 newfs.8
--- sbin/newfs/newfs.8	2002/08/20 16:07:45	1.43
+++ sbin/newfs/newfs.8	2002/09/30 22:41:28
@@ -149,9 +149,9 @@
 .Ar block-size
 .It \&\*[Lt] 20 MB
 4 KB
-.It \&\*[Lt] 1024 MB
+.It \&\*[Lt] 1000 MB
 8 KB
-.It \&\*[Gt]\&= 1024 MB
+.It \&\*[Gt]\&= 1000 MB
 16 KB
 .El
 .It Fl c Ar cpg
@@ -179,7 +179,7 @@
 The fragment size of the file system in bytes.
 It must be a power of two ranging in value between
 .Ar block-size Ns /8
-and
+(or the sector size, whichever is greater) and
 .Ar block-size .
 The optimal
 .Ar block-size : Ns Ar frag-size
@@ -193,9 +193,9 @@
 .Ar frag-size
 .It \&\*[Lt] 20 MB
 0.5 KB
-.It \&\*[Lt] 1024 MB
+.It \&\*[Lt] 1000 MB
 1 KB
-.It \&\*[Gt]\&= 1024 MB
+.It \&\*[Gt]\&= 1000 MB
 2 KB
 .El
 .It Fl g Ar avgfilesize
@@ -215,9 +215,9 @@
 .Ar bytes-per-inode
 .It \&\*[Lt] 20 MB
 2 KB
-.It \&\*[Lt] 1024 MB
+.It \&\*[Lt] 1000 MB
 4 KB
-.It \&\*[Gt]\&= 1024 MB
+.It \&\*[Gt]\&= 1000 MB
 8 KB
 .El
 .It Fl m Ar free-space
@@ -245,7 +245,7 @@
 .Xr tunefs 8
 for more details on how to set this option.
 .It Fl s Ar size
-The size of the file system in sectors.
+The size of the file system.
 An
 .Sq s
 suffix will be interpreted as the number of sectors (the default).
@@ -269,8 +269,8 @@
 to find the alternative superblocks if the standard superblock is lost.
 .Bl -tag -width Fl
 .It Fl S Ar sector-size
-The size of a sector in bytes (almost never anything but 512).
-Defaults to 512.
+The size of a sector in bytes.
+Defaults to the sector size read from the disk label.
 .It Fl k Ar skew
 Sector \&0 skew, per track.
 Used to describe perturbations in the media format to compensate for
@@ -297,8 +297,8 @@
 The speed of the disk in revolutions per minute.
 .ne 1i
 .It Fl t Ar ntracks
-The number of tracks per cylinder available for data allocation by the file
-system.
+The number of tracks per cylinder (heads) available for data
+allocation by the file system.
 .It Fl u Ar nsectors
 The number of sectors per track available for data allocation by the file
 system.
Index: sbin/newfs/newfs.c
===================================================================
RCS file: /cvsroot/basesrc/sbin/newfs/newfs.c,v
retrieving revision 1.60
diff -u -r1.60 newfs.c
--- sbin/newfs/newfs.c	2002/09/21 18:43:39	1.60
+++ sbin/newfs/newfs.c	2002/09/30 22:41:30
@@ -101,6 +101,8 @@
 
 #define	COMPAT			/* allow non-labeled disks */
 
+#define	POWEROF2(num)	(((num) & ((num) - 1)) == 0)
+
 /*
  * The following two constants set the default block and fragment sizes.
  * Both constants must be a power of 2 and meet the following constraints:
@@ -113,10 +115,10 @@
  * otherwise if less than MEDIUM_FSSIZE use M_DFL_*, otherwise use
  * L_DFL_*.
  */
-#define	SMALL_FSSIZE	(20*1024*2)
+#define	SMALL_FSSIZE	(20*1024*1024)
 #define	S_DFL_FRAGSIZE	512
 #define	S_DFL_BLKSIZE	4096
-#define	MEDIUM_FSSIZE	(1000*1024*2)
+#define	MEDIUM_FSSIZE	(1000*1024*1024)
 #define	M_DFL_FRAGSIZE	1024
 #define	M_DFL_BLKSIZE	8192
 #define	L_DFL_FRAGSIZE	2048
@@ -172,7 +174,7 @@
 int	mfs;			/* run as the memory based filesystem */
 int	Nflag;			/* run without writing file system */
 int	Oflag;			/* format as an 4.3BSD file system */
-int	fssize;			/* file system size */
+int	fssize;			/* file system size in sectors */
 int	ntracks;		/* # tracks/cylinder */
 int	nsectors;		/* # sectors/track */
 int	nphyssectors;		/* # sectors/track including spares */
@@ -220,7 +222,7 @@
 	int ch, fsi, fso, len, maxpartitions, n, Fflag, Iflag, Zflag;
 	char *cp, *endp, *s1, *s2, *special;
 	const char *opstring;
-	long long llsize;
+	long long llsize = 0;
 	int dfl_fragsize, dfl_blksize;
 #ifdef MFS
 	char mountfromname[100];
@@ -279,6 +281,12 @@
 		case 'S':
 			sectorsize = strsuftoi("sector size",
 			    optarg, 1, INT_MAX);
+			if (sectorsize % DEV_BSIZE)
+				errx(1,
+			    "sector size must be a multiple of %d bytes.",
+				    DEV_BSIZE);
+			if (!POWEROF2(sectorsize))
+				errx(1, "Sector size must be a power of 2.");
 			break;
 #ifdef COMPAT
 		case 'T':
@@ -375,41 +383,39 @@
 			    optarg, 1, INT_MAX);
 			break;
 		case 's':
+			fssize = 0;
 			llsize = strtoll(optarg, &endp, 10);
 			if (endp[0] != '\0' && endp[1] != '\0')
 				llsize = -1;
 			else {
-				int	ssiz;
-
-				ssiz = (sectorsize ? sectorsize : DFL_SECSIZE);
 				switch (tolower((unsigned char)endp[0])) {
 				case 'b':
-					llsize /= ssiz;
 					break;
 				case 'k':
-					llsize *= 1024 / ssiz;
+					llsize *= 1024;
 					break;
 				case 'm':
-					llsize *= 1024 * 1024 / ssiz;
+					llsize *= 1024 * 1024;
 					break;
 				case 'g':
-					llsize *= 1024 * 1024 * 1024 / ssiz;
+					llsize *= 1024 * 1024 * 1024;
 					break;
 				case '\0':
 				case 's':
+					if (llsize > INT_MAX)
+					    errx(1, "file system size `%s'"
+						 " is too large.", optarg);
+					fssize = llsize;
+					llsize = 0;
 					break;
 				default:
 					llsize = -1;
 				}
 			}
-			if (llsize > INT_MAX)
-				errx(1, "file system size `%s' is too large.",
-				    optarg);
-			if (llsize <= 0)
+			if (llsize <= 0 && !fssize)
 				errx(1,
 			    "`%s' is not a valid number for file system size.",
 				    optarg);
-			fssize = (int)llsize;
 			break;
 		case 't':
 			ntracks = strsuftoi("total tracks",
@@ -449,8 +455,15 @@
 			sectorsize = DFL_SECSIZE;
 
 		if (Fflag && !Nflag) {	/* creating image in a regular file */
-			if (fssize == 0)
+			if (fssize == 0) {
+			    if (llsize == 0)
 				errx(1, "need to specify size when using -F");
+			    llsize /= sectorsize;
+			    if (llsize > INT_MAX)
+				errx(1, "file system size `%s' is too large.",
+				    optarg);
+			    fssize = llsize;
+			}
 			fso = open(special, O_RDWR | O_CREAT | O_TRUNC, 0777);
 			if (fso == -1)
 				err(1, "can't open file %s", special);
@@ -565,11 +578,6 @@
 			errx(1, "`%c' partition type is not `4.2BSD'", *cp);
 	}	/* !Fflag && !mfs */
 
-	if (fssize == 0)
-		fssize = pp->p_size;
-	if (fssize > pp->p_size && !mfs && !Fflag)
-		errx(1, "maximum file system size on the `%c' partition is %d",
-		    *cp, pp->p_size);
 	if (rpm == 0) {
 		rpm = lp->d_rpm;
 		if (rpm <= 0)
@@ -590,6 +598,21 @@
 		if (sectorsize <= 0)
 			errx(1, "no default sector size");
 	}
+	if (fssize == 0) {
+		if (llsize == 0)
+			fssize = pp->p_size;
+		else {
+			llsize /= sectorsize;
+			if (llsize > INT_MAX)
+				errx(1, "file system size `%s' is too large.",
+				     optarg);
+			fssize = llsize;
+		}
+	}
+	if (fssize > pp->p_size && !mfs && !Fflag)
+		errx(1, "maximum file system size on the `%c' partition is %d"
+		     " sectors (%gMB)", *cp, pp->p_size,
+		     (double) pp->p_size * sectorsize / (1024 * 1024));
 	if (trackskew == -1) {
 		trackskew = lp->d_trackskew;
 		if (trackskew < 0)
@@ -601,10 +624,10 @@
 			interleave = 1;
 	}
 
-	if (fssize < SMALL_FSSIZE) {
+	if (fssize < SMALL_FSSIZE / sectorsize) {
 		dfl_fragsize = S_DFL_FRAGSIZE;
 		dfl_blksize = S_DFL_BLKSIZE;
-	} else if (fssize < MEDIUM_FSSIZE) {
+	} else if (fssize < MEDIUM_FSSIZE / sectorsize) {
 		dfl_fragsize = M_DFL_FRAGSIZE;
 		dfl_blksize = M_DFL_BLKSIZE;
 	} else {
Index: sbin/fsck_ffs/dir.c
===================================================================
RCS file: /cvsroot/basesrc/sbin/fsck_ffs/dir.c,v
retrieving revision 1.33
diff -u -r1.33 dir.c
--- sbin/fsck_ffs/dir.c	2002/05/09 02:55:50	1.33
+++ sbin/fsck_ffs/dir.c	2002/09/30 22:41:32
@@ -662,7 +662,8 @@
 	dp->di_db[lastbn + 1] = dp->di_db[lastbn];
 	dp->di_db[lastbn] = iswap32(newblk);
 	dp->di_size = iswap64(iswap64(dp->di_size) + sblock->fs_bsize);
-	dp->di_blocks = iswap32(iswap32(dp->di_blocks) + btodb(sblock->fs_bsize));
+	dp->di_blocks = iswap32(iswap32(dp->di_blocks) +
+				btosec(sblock, sblock->fs_bsize));
 	bp = getdirblk(iswap32(dp->di_db[lastbn + 1]),
 		(long)dblksize(sblock, dp, lastbn + 1));
 	if (bp->b_errs)
@@ -695,7 +696,8 @@
 	dp->di_db[lastbn] = dp->di_db[lastbn + 1];
 	dp->di_db[lastbn + 1] = 0;
 	dp->di_size = iswap64(iswap64(dp->di_size) - sblock->fs_bsize);
-	dp->di_blocks = iswap32(iswap32(dp->di_blocks) - btodb(sblock->fs_bsize));
+	dp->di_blocks = iswap32(iswap32(dp->di_blocks) -
+				btosec(sblock, sblock->fs_bsize));
 	freeblk(newblk, sblock->fs_frag);
 	markclean = 0;
 	return (0);
Index: sbin/fsck_ffs/fsck.h
===================================================================
RCS file: /cvsroot/basesrc/sbin/fsck_ffs/fsck.h,v
retrieving revision 1.28
diff -u -r1.28 fsck.h
--- sbin/fsck_ffs/fsck.h	2002/05/06 03:17:43	1.28
+++ sbin/fsck_ffs/fsck.h	2002/09/30 22:41:33
@@ -175,7 +175,7 @@
 } **inphead, **inpsort;
 long numdirs, listmax, inplast;
 
-long	dev_bsize;		/* computed value of DEV_BSIZE */
+long	disk_blocksize;		/* computed value of disk block size */
 long	secsize;		/* actual disk sector size */
 char	nflag;			/* assume a no response */
 char	yflag;			/* assume a yes response */
Index: sbin/fsck_ffs/inode.c
===================================================================
RCS file: /cvsroot/basesrc/sbin/fsck_ffs/inode.c,v
retrieving revision 1.34
diff -u -r1.34 inode.c
--- sbin/fsck_ffs/inode.c	2001/01/05 02:02:57	1.34
+++ sbin/fsck_ffs/inode.c	2002/09/30 22:41:34
@@ -660,7 +660,7 @@
 	dp->di_atime = iswap32(t);
 	dp->di_mtime = dp->di_ctime = dp->di_atime;
 	dp->di_size = iswap64(sblock->fs_fsize);
-	dp->di_blocks = iswap32(btodb(sblock->fs_fsize));
+	dp->di_blocks = iswap32(btosec(sblock, sblock->fs_fsize));
 	n_files++;
 	inodirty();
 	if (newinofmt)
Index: sbin/fsck_ffs/pass1.c
===================================================================
RCS file: /cvsroot/basesrc/sbin/fsck_ffs/pass1.c,v
retrieving revision 1.24
diff -u -r1.24 pass1.c
--- sbin/fsck_ffs/pass1.c	2002/05/06 03:17:43	1.24
+++ sbin/fsck_ffs/pass1.c	2002/09/30 22:41:36
@@ -266,7 +266,7 @@
 	badblk = dupblk = 0;
 	idesc->id_number = inumber;
 	(void)ckinode(dp, idesc);
-	idesc->id_entryno *= btodb(sblock->fs_fsize);
+	idesc->id_entryno *= btosec(sblock, sblock->fs_fsize);
 	if (iswap32(dp->di_blocks) != idesc->id_entryno) {
 		pwarn("INCORRECT BLOCK COUNT I=%u (%d should be %d)",
 		    inumber, iswap32(dp->di_blocks), idesc->id_entryno);
Index: sbin/fsck_ffs/setup.c
===================================================================
RCS file: /cvsroot/basesrc/sbin/fsck_ffs/setup.c,v
retrieving revision 1.53
diff -u -r1.53 setup.c
--- sbin/fsck_ffs/setup.c	2002/06/30 22:57:31	1.53
+++ sbin/fsck_ffs/setup.c	2002/09/30 22:41:37
@@ -130,9 +130,9 @@
 		sblock == NULL || altsblock == NULL)
 		errx(EEXIT, "cannot allocate space for superblock");
 	if (!forceimage && (lp = getdisklabel(NULL, fsreadfd)) != NULL)
-		dev_bsize = secsize = lp->d_secsize;
+		disk_blocksize = secsize = lp->d_secsize;
 	else
-		dev_bsize = secsize = DEV_BSIZE;
+		disk_blocksize = secsize = DEV_BSIZE;
 	/*
 	 * Read in the superblock, looking for alternates if necessary
 	 */
@@ -452,7 +452,7 @@
 readsb(listerr)
 	int listerr;
 {
-	ufs_daddr_t super = bflag ? bflag : SBOFF / dev_bsize;
+	ufs_daddr_t super = bflag ? bflag : SBOFF / disk_blocksize;
 	struct fs *fs;
 
 	if (bread(fsreadfd, (char *)sblk.b_un.b_fs, super, (long)SBSIZE) != 0)
@@ -523,9 +523,9 @@
 	 * according to fsbtodb, and adjust superblock block number
 	 * so we can tell if this is an alternate later.
 	 */
-	super *= dev_bsize;
-	dev_bsize = sblock->fs_fsize / fsbtodb(sblock, 1);
-	sblk.b_bno = super / dev_bsize;
+	super *= disk_blocksize;
+	disk_blocksize = sblock->fs_fsize / fsbtodb(sblock, 1);
+	sblk.b_bno = super / disk_blocksize;
 
 	if (bflag) {
 		havesb = 1;
@@ -703,7 +703,7 @@
 	fs->fs_ncg = howmany(fs->fs_size / fs->fs_spc, fs->fs_cpg);
 	for (fs->fs_fsbtodb = 0, i = NSPF(fs); i > 1; i >>= 1)
 		fs->fs_fsbtodb++;
-	dev_bsize = lp->d_secsize;
+	disk_blocksize = lp->d_secsize;
 	return (1);
 }
 
Index: sbin/fsck_ffs/utilities.c
===================================================================
RCS file: /cvsroot/basesrc/sbin/fsck_ffs/utilities.c,v
retrieving revision 1.33
diff -u -r1.33 utilities.c
--- sbin/fsck_ffs/utilities.c	2002/05/06 03:17:43	1.33
+++ sbin/fsck_ffs/utilities.c	2002/09/30 22:41:38
@@ -228,7 +228,7 @@
 		return;
 	if (bp->b_errs != 0)
 		pfatal("WRITING %sZERO'ED BLOCK %d TO DISK\n",
-		    (bp->b_errs == bp->b_size / dev_bsize) ? "" : "PARTIALLY ",
+		    (bp->b_errs == bp->b_size / disk_blocksize) ? "" : "PARTIALLY ",
 		    bp->b_bno);
 	bp->b_dirty = 0;
 	bp->b_errs = 0;
@@ -273,9 +273,9 @@
 		return;
 	}
 	flush(fswritefd, &sblk);
-	if (havesb && sblk.b_bno != SBOFF / dev_bsize &&
+	if (havesb && sblk.b_bno != SBOFF / disk_blocksize &&
 	    !preen && reply("UPDATE STANDARD SUPERBLOCK")) {
-		sblk.b_bno = SBOFF / dev_bsize;
+		sblk.b_bno = SBOFF / disk_blocksize;
 		sbdirty();
 		flush(fswritefd, &sblk);
 	}
@@ -331,7 +331,7 @@
 	off_t offset;
 
 	offset = blk;
-	offset *= dev_bsize;
+	offset *= disk_blocksize;
 	if (lseek(fd, offset, 0) < 0)
 		rwerror("SEEK", blk);
 	else if (read(fd, buf, (int)size) == size)
@@ -345,12 +345,12 @@
 	for (cp = buf, i = 0; i < size; i += secsize, cp += secsize) {
 		if (read(fd, cp, (int)secsize) != secsize) {
 			(void)lseek(fd, offset + i + secsize, 0);
-			if (secsize != dev_bsize && dev_bsize != 1)
+			if (secsize != disk_blocksize && disk_blocksize != 1)
 				printf(" %ld (%ld),",
-				    (blk * dev_bsize + i) / secsize,
-				    blk + i / dev_bsize);
+				    (blk * disk_blocksize + i) / secsize,
+				    blk + i / disk_blocksize);
 			else
-				printf(" %ld,", blk + i / dev_bsize);
+				printf(" %ld,", blk + i / disk_blocksize);
 			errs++;
 		}
 	}
@@ -372,7 +372,7 @@
 	if (fd < 0)
 		return;
 	offset = blk;
-	offset *= dev_bsize;
+	offset *= disk_blocksize;
 	if (lseek(fd, offset, 0) < 0)
 		rwerror("SEEK", blk);
 	else if (write(fd, buf, (int)size) == size) {
@@ -383,10 +383,10 @@
 	if (lseek(fd, offset, 0) < 0)
 		rwerror("SEEK", blk);
 	printf("THE FOLLOWING SECTORS COULD NOT BE WRITTEN:");
-	for (cp = buf, i = 0; i < size; i += dev_bsize, cp += dev_bsize)
-		if (write(fd, cp, (int)dev_bsize) != dev_bsize) {
-			(void)lseek(fd, offset + i + dev_bsize, 0);
-			printf(" %ld,", blk + i / dev_bsize);
+	for (cp = buf, i = 0; i < size; i += disk_blocksize, cp += disk_blocksize)
+		if (write(fd, cp, (int)disk_blocksize) != disk_blocksize) {
+			(void)lseek(fd, offset + i + disk_blocksize, 0);
+			printf(" %ld,", blk + i / disk_blocksize);
 		}
 	printf("\n");
 	return;
Index: sbin/fsck_lfs/fsck_vars.h
===================================================================
RCS file: /cvsroot/basesrc/sbin/fsck_lfs/fsck_vars.h,v
retrieving revision 1.4
diff -u -r1.4 fsck_vars.h
--- sbin/fsck_lfs/fsck_vars.h	2000/06/14 18:43:58	1.4
+++ sbin/fsck_lfs/fsck_vars.h	2002/09/30 22:41:38
@@ -52,7 +52,6 @@
 extern daddr_t	idaddr;         /* inode block containing ifile inode */
 extern long     numdirs, listmax, inplast;
 
-extern long     dev_bsize;	/* computed value of DEV_BSIZE */
 extern long     secsize;	/* actual disk sector size */
 extern char     nflag;		/* assume a no response */
 extern char     yflag;		/* assume a yes response */
Index: sbin/fsck_lfs/inode.c
===================================================================
RCS file: /cvsroot/basesrc/sbin/fsck_lfs/inode.c,v
retrieving revision 1.13
diff -u -r1.13 inode.c
--- sbin/fsck_lfs/inode.c	2002/05/23 04:05:11	1.13
+++ sbin/fsck_lfs/inode.c	2002/09/30 22:41:40
@@ -121,7 +121,7 @@
 	ufs_daddr_t     residue, up, off = 0;
 	struct bufarea *bp;
 
-	if (lbn > 0 && lbn > (idinode->di_size - 1) / dev_bsize) {
+	if (lbn > 0 && lbn > (idinode->di_size - 1) / secsize) {
 		return UNASSIGNED;
 	}
 	/*
Index: sbin/fsck_lfs/setup.c
===================================================================
RCS file: /cvsroot/basesrc/sbin/fsck_lfs/setup.c,v
retrieving revision 1.11
diff -u -r1.11 setup.c
--- sbin/fsck_lfs/setup.c	2002/02/04 23:43:43	1.11
+++ sbin/fsck_lfs/setup.c	2002/09/30 22:41:43
@@ -203,9 +203,9 @@
 	if (sblk.b_un.b_buf == NULL || asblk.b_un.b_buf == NULL)
 		errexit("cannot allocate space for superblock\n");
 	if ((lp = getdisklabel((char *) NULL, fsreadfd)) != NULL)
-		dev_bsize = secsize = lp->d_secsize;
+		secsize = lp->d_secsize;
 	else
-		dev_bsize = secsize = DEV_BSIZE;
+		secsize = DEV_BSIZE;
 
 	/*
 	 * Read in the superblock, looking for alternates if necessary
@@ -247,7 +247,7 @@
 		 * and need to read the real one.
 		 */
 		if (sblock.lfs_sboffs[0] != dbtofsb(&sblock,
-						    LFS_LABELPAD / dev_bsize))
+						    LFS_LABELPAD / secsize))
 		{
 			if (debug)
 				pwarn("Getting 'real' primary superblock from 0x%x\n",
@@ -335,7 +335,7 @@
 	if (idaddr == 0x0)
 		idaddr = sblock.lfs_idaddr;
 	if (debug) {
-		printf("dev_bsize = %lu\n", dev_bsize);
+		printf("secsize = %lu\n", secsize);
 		printf("lfs_bsize = %lu\n", (unsigned long)sblock.lfs_bsize);
 		printf("lfs_fsize = %lu\n", (unsigned long)sblock.lfs_fsize);
 		printf("lfs_frag  = %lu\n", (unsigned long)sblock.lfs_frag);
@@ -376,7 +376,7 @@
 	seg_table = (SEGUSE *)malloc(sblock.lfs_nseg * sizeof(SEGUSE));
 	memset(seg_table, 0, sblock.lfs_nseg * sizeof(SEGUSE));
 	if (sblock.lfs_version == 1) 
- 		maxfsblock = sblock.lfs_size * (sblock.lfs_bsize / dev_bsize);
+ 		maxfsblock = sblock.lfs_size * (sblock.lfs_bsize / secsize);
  	else
 		maxfsblock = sblock.lfs_size;
 	maxfilesize = maxtable[sblock.lfs_bshift] << sblock.lfs_bshift;
@@ -485,7 +485,7 @@
 static int
 readsb(int listerr)
 {
-	daddr_t         super = bflag ? bflag : LFS_LABELPAD / dev_bsize;
+	daddr_t         super = bflag ? bflag : LFS_LABELPAD / secsize;
 	u_int32_t       checksum;
 
 	if (bread(fsreadfd, (char *) &sblock, super, (long) LFS_SBPAD) != 0)
@@ -531,11 +531,11 @@
 	 * according to fsbtodb, and adjust superblock block number
 	 * so we can tell if this is an alternate later.
 	 */
-	super *= dev_bsize;
+	super *= secsize;
 #if 0
-	dev_bsize = sblock.lfs_bsize / fsbtodb(&sblock, 1);
+	secsize = sblock.lfs_bsize / fsbtodb(&sblock, 1);
 #endif
-	sblk.b_bno = super / dev_bsize;
+	sblk.b_bno = super / secsize;
 	if (bflag) {
 		havesb = 1;
 		return (1);
@@ -639,7 +639,7 @@
 	}
 	lp = getdisklabel(dev, devfd);
 	if (lp == NULL) {
-		dev_bsize = DEV_BSIZE;
+		secsize = DEV_BSIZE;
 	} else {
 		if (isdigit(*cp))
 			pp = &lp->d_partitions[0];
@@ -656,7 +656,7 @@
 		fs->lfs_frag = pp->p_frag;
 		fs->lfs_size = pp->p_size;
 		fs->lfs_nspf = fs->lfs_fsize / lp->d_secsize;
-		dev_bsize = lp->d_secsize;
+		secsize = lp->d_secsize;
 		for (fs->lfs_fsbtodb = 0, i = fs->lfs_nspf; i > 1; i >>= 1)
 			fs->lfs_fsbtodb++;
 	}
Index: sbin/fsck_lfs/utilities.c
===================================================================
RCS file: /cvsroot/basesrc/sbin/fsck_lfs/utilities.c,v
retrieving revision 1.9
diff -u -r1.9 utilities.c
--- sbin/fsck_lfs/utilities.c	2002/05/23 04:05:11	1.9
+++ sbin/fsck_lfs/utilities.c	2002/09/30 22:41:43
@@ -215,7 +215,7 @@
 		return;
 	if (bp->b_errs != 0)
 		pfatal("WRITING %sZERO'ED BLOCK %d TO DISK\n",
-		 (bp->b_errs == bp->b_size / dev_bsize) ? "" : "PARTIALLY ",
+		 (bp->b_errs == bp->b_size / secsize) ? "" : "PARTIALLY ",
 		       bp->b_bno);
 	bp->b_dirty = 0;
 	bp->b_errs = 0;
@@ -270,7 +270,7 @@
 		} else if (sblk.b_bno == 
 			fsbtodb(&sblock, sblock.lfs_sboffs[1])) {
 			/* Do the primary */
-			sblk.b_bno = LFS_LABELPAD / dev_bsize;
+			sblk.b_bno = LFS_LABELPAD / secsize;
 			sbdirty();
 			flush(fswritefd, &sblk);
 		}
@@ -299,7 +299,7 @@
 			sblock.lfs_pflags |= LFS_PF_CLEAN;
 			sbdirty();
 			flush(fswritefd, &sblk);
-			if (sblk.b_bno == LFS_LABELPAD / dev_bsize) {
+			if (sblk.b_bno == LFS_LABELPAD / secsize) {
 				/* Do the first alternate */
 				sblk.b_bno = fsbtodb(&sblock, 
 					sblock.lfs_sboffs[0]);
@@ -307,7 +307,7 @@
 			} else if (sblk.b_bno == fsbtodb(&sblock, 
 				sblock.lfs_sboffs[0])) {
 				/* Do the primary */
-				sblk.b_bno = LFS_LABELPAD / dev_bsize;
+				sblk.b_bno = LFS_LABELPAD / secsize;
 				flush(fswritefd, &sblk);
 			}
 		}
@@ -327,7 +327,7 @@
 	off_t           offset;
 
 	offset = blk;
-	offset *= dev_bsize;
+	offset *= secsize;
 	if (lseek(fd, offset, 0) < 0) {
 		rwerror("SEEK", blk);
 	} else if (read(fd, buf, (int)size) == size)
@@ -341,12 +341,7 @@
 	for (cp = buf, i = 0; i < size; i += secsize, cp += secsize) {
 		if (read(fd, cp, (int)secsize) != secsize) {
 			(void)lseek(fd, offset + i + secsize, 0);
-			if (secsize != dev_bsize && dev_bsize != 1)
-				printf(" %ld (%ld),",
-				       (blk * dev_bsize + i) / secsize,
-				       blk + i / dev_bsize);
-			else
-				printf(" %ld,", blk + i / dev_bsize);
+			printf(" %ld,", blk + i / secsize);
 			errs++;
 		}
 	}
@@ -364,7 +359,7 @@
 	if (fd < 0)
 		return;
 	offset = blk;
-	offset *= dev_bsize;
+	offset *= secsize;
 	if (lseek(fd, offset, 0) < 0)
 		rwerror("SEEK", blk);
 	else if (write(fd, buf, (int)size) == size) {
@@ -375,10 +370,10 @@
 	if (lseek(fd, offset, 0) < 0)
 		rwerror("SEEK", blk);
 	printf("THE FOLLOWING SECTORS COULD NOT BE WRITTEN:");
-	for (cp = buf, i = 0; i < size; i += dev_bsize, cp += dev_bsize)
-		if (write(fd, cp, (int)dev_bsize) != dev_bsize) {
-			(void)lseek(fd, offset + i + dev_bsize, 0);
-			printf(" %ld,", blk + i / dev_bsize);
+	for (cp = buf, i = 0; i < size; i += secsize, cp += secsize)
+		if (write(fd, cp, (int)secsize) != secsize) {
+			(void)lseek(fd, offset + i + secsize, 0);
+			printf(" %ld,", blk + i / secsize);
 		}
 	printf("\n");
 	return;
Index: sbin/fsck_lfs/vars.c
===================================================================
RCS file: /cvsroot/basesrc/sbin/fsck_lfs/vars.c,v
retrieving revision 1.5
diff -u -r1.5 vars.c
--- sbin/fsck_lfs/vars.c	2001/02/04 21:52:04	1.5
+++ sbin/fsck_lfs/vars.c	2002/09/30 22:41:43
@@ -24,7 +24,6 @@
 daddr_t		idaddr;		/* inode block containing ifile inode */
 long            numdirs, listmax, inplast;
 
-long            dev_bsize;	/* computed value of DEV_BSIZE */
 long            secsize;	/* actual disk sector size */
 char            nflag;		/* assume a no response */
 char            yflag;		/* assume a yes response */

>Release-Note:
>Audit-Trail:
>Unformatted: