Module Name:    src
Committed By:   mlelstv
Date:           Sun Jan 31 10:54:10 UTC 2010

Modified Files:
        src/sys/ufs/ffs: ffs_vfsops.c fs.h

Log Message:
Fix block shift to work with different device block sizes.

Unlike other filesystems this has some side issues because
the shift values are stored in the superblock and because
userland utitlies share the same fsbtodb macros.

-> the kernel now ignores the value stored in the superblock.
-> the macro adaption is only done for defined(_KERNEL) code.


To generate a diff of this commit:
cvs rdiff -u -r1.255 -r1.256 src/sys/ufs/ffs/ffs_vfsops.c
cvs rdiff -u -r1.54 -r1.55 src/sys/ufs/ffs/fs.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/ufs/ffs/ffs_vfsops.c
diff -u src/sys/ufs/ffs/ffs_vfsops.c:1.255 src/sys/ufs/ffs/ffs_vfsops.c:1.256
--- src/sys/ufs/ffs/ffs_vfsops.c:1.255	Sun Jan 31 10:50:23 2010
+++ src/sys/ufs/ffs/ffs_vfsops.c	Sun Jan 31 10:54:10 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_vfsops.c,v 1.255 2010/01/31 10:50:23 mlelstv Exp $	*/
+/*	$NetBSD: ffs_vfsops.c,v 1.256 2010/01/31 10:54:10 mlelstv Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -61,7 +61,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ffs_vfsops.c,v 1.255 2010/01/31 10:50:23 mlelstv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ffs_vfsops.c,v 1.256 2010/01/31 10:54:10 mlelstv Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_ffs.h"
@@ -585,8 +585,6 @@
 	struct fs *fs, *newfs;
 	struct partinfo dpart;
 	int i, bsize, blks, error;
-	uint64_t numsecs;
-	unsigned secsize;
 	int32_t *lp;
 	struct ufsmount *ump;
 	daddr_t sblockloc;
@@ -608,11 +606,9 @@
 	 * Step 2: re-read superblock from disk.
 	 */
 	fs = ump->um_fs;
-	error = getdisksize(devvp, &numsecs, &secsize);
-	if (error)
-		secsize = DEV_BSIZE;
+
 	/* XXX we don't handle possibility that superblock moved. */
-	error = bread(devvp, fs->fs_sblockloc / secsize, fs->fs_sbsize,
+	error = bread(devvp, fs->fs_sblockloc / DEV_BSIZE, fs->fs_sbsize,
 		      NOCRED, 0, &bp);
 	if (error) {
 		brelse(bp, 0);
@@ -665,7 +661,7 @@
 		/* Manually look for an apple ufs label, and if a valid one
 		 * is found, then treat it like an Apple UFS filesystem anyway
 		 */
-		error = bread(devvp, (daddr_t)(APPLEUFS_LABEL_OFFSET / secsize),
+		error = bread(devvp, (daddr_t)(APPLEUFS_LABEL_OFFSET / DEV_BSIZE),
 			APPLEUFS_LABEL_SIZE, cred, 0, &bp);
 		if (error) {
 			brelse(bp, 0);
@@ -884,7 +880,7 @@
 			fs = NULL;
 			goto out;
 		}
-		error = bread(devvp, sblock_try[i] / secsize, SBLOCKSIZE, cred,
+		error = bread(devvp, sblock_try[i] / DEV_BSIZE, SBLOCKSIZE, cred,
 			      0, &bp);
 		if (error) {
 			fs = NULL;
@@ -1032,7 +1028,7 @@
 		/* Manually look for an apple ufs label, and if a valid one
 		 * is found, then treat it like an Apple UFS filesystem anyway
 		 */
-		error = bread(devvp, (daddr_t)(APPLEUFS_LABEL_OFFSET / size),
+		error = bread(devvp, (daddr_t)(APPLEUFS_LABEL_OFFSET / DEV_BSIZE),
 			APPLEUFS_LABEL_SIZE, cred, 0, &bp);
 		if (error)
 			goto out;
@@ -1186,7 +1182,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;

Index: src/sys/ufs/ffs/fs.h
diff -u src/sys/ufs/ffs/fs.h:1.54 src/sys/ufs/ffs/fs.h:1.55
--- src/sys/ufs/ffs/fs.h:1.54	Sun Jun 28 09:26:18 2009
+++ src/sys/ufs/ffs/fs.h	Sun Jan 31 10:54:10 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: fs.h,v 1.54 2009/06/28 09:26:18 ad Exp $	*/
+/*	$NetBSD: fs.h,v 1.55 2010/01/31 10:54:10 mlelstv Exp $	*/
 
 /*
  * Copyright (c) 1982, 1986, 1993
@@ -599,8 +599,13 @@
  * Turn file system block numbers into disk block addresses.
  * This maps file system blocks to device size blocks.
  */
+#if defined (_KERNEL)
+#define	fsbtodb(fs, b)	((b) << ((fs)->fs_fshift - DEV_BSHIFT))
+#define	dbtofsb(fs, b)	((b) >> ((fs)->fs_fshift - DEV_BSHIFT))
+#else
 #define	fsbtodb(fs, b)	((b) << (fs)->fs_fsbtodb)
 #define	dbtofsb(fs, b)	((b) >> (fs)->fs_fsbtodb)
+#endif
 
 /*
  * Cylinder group macros to locate things in cylinder groups.

Reply via email to