Re: -27 MB used on ext2?

Theodore Y. Ts'o (tytso@mit.edu)
Sat, 26 Sep 1998 01:36:38 -0400


Date: Fri, 25 Sep 1998 17:19:35 -0400 (EDT)
From: George <greerga@nidhogg.ham.muohio.edu>

Let's try this again. :)

Linux 2.1.122 #146 SMP Sat Sep 19 06:13:55 EDT 1998
mke2fs 1.12, 9-Jul-98 for EXT2 FS 0.5b, 95/08/09

mke2fs -s1 /dev/hdc4

Filesystem 1024-blocks Used Available Capacity Mounted on
/dev/hdc4 7285391 -27197 6935042 0% /mnt/4

This is caused by a bug in ext2's statfs function; it's not properly
taking into account filesystems built with the sparse_superblock flag,
which becomes important as disks become bigger. (For example, on your 7
gig disk, the sparse superblock option saved you approximaetly 27
megabytes.)

Enclosed please find a patch --- Linus, can you please include this
patch into your the next 2.1 release? Thanks!!

- Ted

Patch generated: on Sat Sep 26 01:33:33 EDT 1998 by tytso@rsts-11.mit.edu
against Linux version 2.1.122

===================================================================
RCS file: fs/ext2/RCS/balloc.c,v
retrieving revision 1.1
diff -u -r1.1 fs/ext2/balloc.c
--- fs/ext2/balloc.c 1998/09/26 02:13:48 1.1
+++ fs/ext2/balloc.c 1998/09/26 02:26:33
@@ -686,6 +686,12 @@
}
}

+int ext2_group_sparse(int group)
+{
+ return (test_root(group, 3) || test_root(group, 5) ||
+ test_root(group, 7));
+}
+
void ext2_check_blocks_bitmap (struct super_block * sb)
{
struct buffer_head * bh;
@@ -716,7 +722,7 @@

if (!(le32_to_cpu(sb->u.ext2_sb.s_feature_ro_compat) &
EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER) ||
- (test_root(i, 3) || test_root(i, 5) || test_root(i, 7))) {
+ ext2_group_sparse(i)) {
if (!ext2_test_bit (0, bh->b_data))
ext2_error (sb, "ext2_check_blocks_bitmap",
"Superblock in group %d "
===================================================================
RCS file: fs/ext2/RCS/super.c,v
retrieving revision 1.1
diff -u -r1.1 fs/ext2/super.c
--- fs/ext2/super.c 1998/09/26 02:13:48 1.1
+++ fs/ext2/super.c 1998/09/26 02:38:07
@@ -764,8 +764,8 @@
int ext2_statfs (struct super_block * sb, struct statfs * buf, int bufsiz)
{
unsigned long overhead;
- unsigned long overhead_per_group;
struct statfs tmp;
+ int ngroups, i;

if (test_opt (sb, MINIX_DF))
overhead = 0;
@@ -773,13 +773,35 @@
/*
* Compute the overhead (FS structures)
*/
- overhead_per_group = 1 /* super block */ +
- sb->u.ext2_sb.s_db_per_group /* descriptors */ +
- 1 /* block bitmap */ +
- 1 /* inode bitmap */ +
- sb->u.ext2_sb.s_itb_per_group /* inode table */;
- overhead = le32_to_cpu(sb->u.ext2_sb.s_es->s_first_data_block) +
- sb->u.ext2_sb.s_groups_count * overhead_per_group;
+
+ /*
+ * All of the blocks before first_data_block are
+ * overhead
+ */
+ overhead = le32_to_cpu(sb->u.ext2_sb.s_es->s_first_data_block);
+
+ /*
+ * Add the overhead attributed to the superblock and
+ * block group descriptors. If this is sparse
+ * superblocks is turned on, then not all groups have
+ * this.
+ */
+ if (le32_to_cpu(sb->u.ext2_sb.s_feature_ro_compat) &
+ EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER) {
+ ngroups = 0;
+ for (i=0 ; i < sb->u.ext2_sb.s_groups_count; i++)
+ if (ext2_group_sparse(i))
+ ngroups++;
+ } else
+ ngroups = sb->u.ext2_sb.s_groups_count;
+ overhead += ngroups * (1 + sb->u.ext2_sb.s_db_per_group);
+
+ /*
+ * Every block group has an inode bitmap, a block
+ * bitmap, and an inode table.
+ */
+ overhead += (sb->u.ext2_sb.s_groups_count *
+ (2 + sb->u.ext2_sb.s_itb_per_group));
}

tmp.f_type = EXT2_SUPER_MAGIC;
===================================================================
RCS file: include/linux/RCS/ext2_fs.h,v
retrieving revision 1.1
diff -u -r1.1 include/linux/ext2_fs.h
--- include/linux/ext2_fs.h 1998/09/26 02:16:08 1.1
+++ include/linux/ext2_fs.h 1998/09/26 02:16:29
@@ -520,6 +520,7 @@
extern int ext2_permission (struct inode *, int);

/* balloc.c */
+extern int ext2_group_sparse(int group);
extern int ext2_new_block (const struct inode *, unsigned long,
__u32 *, __u32 *, int *);
extern void ext2_free_blocks (const struct inode *, unsigned long,

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/