svn commit: r215113 - head/sys/ufs/ffs

Konstantin Belousov kib at FreeBSD.org
Thu Nov 11 11:35:42 UTC 2010


Author: kib
Date: Thu Nov 11 11:35:42 2010
New Revision: 215113
URL: http://svn.freebsd.org/changeset/base/215113

Log:
  Add function lbn_offset to calculate offset of the indirect block of
  given level.
  
  Reviewed by:	jeff
  Tested by:	pho

Modified:
  head/sys/ufs/ffs/ffs_inode.c
  head/sys/ufs/ffs/ffs_softdep.c
  head/sys/ufs/ffs/fs.h

Modified: head/sys/ufs/ffs/ffs_inode.c
==============================================================================
--- head/sys/ufs/ffs/ffs_inode.c	Thu Nov 11 11:26:59 2010	(r215112)
+++ head/sys/ufs/ffs/ffs_inode.c	Thu Nov 11 11:35:42 2010	(r215113)
@@ -582,9 +582,7 @@ ffs_indirtrunc(ip, lbn, dbn, lastbn, lev
 	 * block to be kept.  -1 indicates the entire
 	 * block so we need not calculate the index.
 	 */
-	factor = 1;
-	for (i = SINGLE; i < level; i++)
-		factor *= NINDIR(fs);
+	factor = lbn_offset(fs, level);
 	last = lastbn;
 	if (lastbn > 0)
 		last /= factor;

Modified: head/sys/ufs/ffs/ffs_softdep.c
==============================================================================
--- head/sys/ufs/ffs/ffs_softdep.c	Thu Nov 11 11:26:59 2010	(r215112)
+++ head/sys/ufs/ffs/ffs_softdep.c	Thu Nov 11 11:35:42 2010	(r215113)
@@ -6075,9 +6075,7 @@ indir_trunc(freework, dbn, lbn)
 	fs_pendingblocks = 0;
 	freedeps = 0;
 	needj = UFSTOVFS(ump)->mnt_kern_flag & MNTK_SUJ;
-	lbnadd = 1;
-	for (i = level; i > 0; i--)
-		lbnadd *= NINDIR(fs);
+	lbnadd = lbn_offset(fs, level);
 	/*
 	 * Get buffer of block pointers to be freed. This routine is not
 	 * called until the zero'ed inode has been written, so it is safe

Modified: head/sys/ufs/ffs/fs.h
==============================================================================
--- head/sys/ufs/ffs/fs.h	Thu Nov 11 11:26:59 2010	(r215112)
+++ head/sys/ufs/ffs/fs.h	Thu Nov 11 11:35:42 2010	(r215113)
@@ -607,6 +607,11 @@ struct cg {
 	  : (fragroundup(fs, blkoff(fs, (size)))))
 
 /*
+ * Number of indirects in a filesystem block.
+ */
+#define	NINDIR(fs)	((fs)->fs_nindir)
+
+/*
  * Indirect lbns are aligned on NDADDR addresses where single indirects
  * are the negated address of the lowest lbn reachable, double indirects
  * are this lbn - 1 and triple indirects are this lbn - 2.  This yields
@@ -631,6 +636,17 @@ lbn_level(ufs_lbn_t lbn)
 	}
 	return (-1);
 }
+
+static inline ufs_lbn_t
+lbn_offset(struct fs *fs, int level)
+{
+	ufs_lbn_t res;
+
+	for (res = 1; level > 0; level--)
+		res *= NINDIR(fs);
+	return (res);
+}
+
 /*
  * Number of inodes in a secondary storage block/fragment.
  */
@@ -638,11 +654,6 @@ lbn_level(ufs_lbn_t lbn)
 #define	INOPF(fs)	((fs)->fs_inopb >> (fs)->fs_fragshift)
 
 /*
- * Number of indirects in a filesystem block.
- */
-#define	NINDIR(fs)	((fs)->fs_nindir)
-
-/*
  * Softdep journal record format.
  */
 


More information about the svn-src-all mailing list