PERFORCE change 165886 for review

Aditya Sarawgi truncs at FreeBSD.org
Thu Jul 9 22:37:31 UTC 2009


http://perforce.freebsd.org/chv.cgi?CH=165886

Change 165886 by truncs at aditya on 2009/07/09 22:36:40

	statfs implementation taken from NetBSD with some changes.

Affected files ...

.. //depot/projects/soc2009/soc_ext2fs/src/sys/gnu/fs/ext2fs/ext2_vfsops.c#12 edit

Differences ...

==== //depot/projects/soc2009/soc_ext2fs/src/sys/gnu/fs/ext2fs/ext2_vfsops.c#12 (text+ko) ====

@@ -781,50 +781,53 @@
 	error = vflush(mp, 0, flags, td);
 	return (error);
 }
-
 /*
  * Get file system statistics.
- * taken from ext2/super.c ext2_statfs.
  */
-static int
+int
 ext2_statfs(struct mount *mp, struct statfs *sbp)
 {
 	struct ext2mount *ump;
 	struct m_ext2fs *fs;
-	struct ext2fs *es;
-	unsigned long overhead;
-	int i, nsb;
+	uint32_t overhead, overhead_per_group, ngdb;
+	int i, ngroups;
 
 	ump = VFSTOEXT2(mp);
 	fs = ump->um_e2fs;
-	es = fs->e2fs;
-
-	if (es->e2fs_magic != E2FS_MAGIC)
-		panic("ext2_statfs - magic number spoiled");
+	if (fs->e2fs->e2fs_magic != E2FS_MAGIC)
+		panic("ext2fs_statvfs");
 
 	/*
 	 * Compute the overhead (FS structures)
 	 */
-	if (es->e2fs_features_rocompat & EXT2F_ROCOMPAT_SPARSESUPER) {
-		nsb = 0;
-		for (i = 0 ; i < fs->e2fs_gcount; i++)
-			if (ext2_group_sparse(i))
-				nsb++;
-	} else
-		nsb = fs->e2fs_gcount;
-	overhead = es->e2fs_first_dblock +
-	/* Superblocks and block group descriptors: */
-	nsb * (1 + fs->e2fs_gdbcount) +
-	/* Inode bitmap, block bitmap, and inode table: */
-	fs->e2fs_gcount * (1 + 1 + fs->e2fs_itpg);
+	overhead_per_group =
+	    1 /* block bitmap */ +
+	    1 /* inode bitmap */ +
+	    fs->e2fs_itpg;
+	overhead = fs->e2fs->e2fs_first_dblock +
+	    fs->e2fs_gcount * overhead_per_group;
+	if (fs->e2fs->e2fs_rev > E2FS_REV0 &&
+	    fs->e2fs->e2fs_features_rocompat & EXT2F_ROCOMPAT_SPARSESUPER) {
+		for (i = 0, ngroups = 0; i < fs->e2fs_gcount; i++) {
+			if (cg_has_sb(i))
+				ngroups++;
+		}
+	} else {
+		ngroups = fs->e2fs_gcount;
+	}
+	ngdb = fs->e2fs_gdbcount;
+	if (fs->e2fs->e2fs_rev > E2FS_REV0 &&
+	    fs->e2fs->e2fs_features_compat & EXT2F_COMPAT_RESIZE)
+		ngdb += fs->e2fs->e2fs_reserved_ngdb;
+	overhead += ngroups * (1 /* superblock */ + ngdb);
 
 	sbp->f_bsize = EXT2_FRAG_SIZE(fs);
 	sbp->f_iosize = EXT2_BLOCK_SIZE(fs);
-	sbp->f_blocks = es->e2fs_bcount - overhead;
-	sbp->f_bfree = es->e2fs_fbcount;
-	sbp->f_bavail = sbp->f_bfree - es->e2fs_rbcount;
-	sbp->f_files = es->e2fs_icount;
-	sbp->f_ffree = es->e2fs_ficount;
+	sbp->f_blocks = fs->e2fs->e2fs_bcount - overhead;
+	sbp->f_bfree = fs->e2fs->e2fs_fbcount;
+	sbp->f_bavail = sbp->f_bfree - fs->e2fs->e2fs_rbcount;
+	sbp->f_files = fs->e2fs->e2fs_icount;
+	sbp->f_ffree = fs->e2fs->e2fs_ficount;
 	return (0);
 }
 


More information about the p4-projects mailing list