--- linux-2.6.25/Documentation/filesystems/ext3.txt.zerofree3	2008-04-17 03:49:44.000000000 +0100
+++ linux-2.6.25/Documentation/filesystems/ext3.txt	2008-07-30 18:15:04.000000000 +0100
@@ -121,6 +121,8 @@ nobh			(a) cache disk block mapping info
 			"nobh" option tries to avoid associating buffer
 			heads (supported only for "writeback" mode).
 
+zerofree		Zero data blocks when they are freed.
+
 
 Specification
 =============
--- linux-2.6.25/fs/ext3/super.c.zerofree3	2008-04-17 03:49:44.000000000 +0100
+++ linux-2.6.25/fs/ext3/super.c	2008-07-30 18:15:04.000000000 +0100
@@ -756,7 +756,7 @@ enum {
 	Opt_usrjquota, Opt_grpjquota, Opt_offusrjquota, Opt_offgrpjquota,
 	Opt_jqfmt_vfsold, Opt_jqfmt_vfsv0, Opt_quota, Opt_noquota,
 	Opt_ignore, Opt_barrier, Opt_err, Opt_resize, Opt_usrquota,
-	Opt_grpquota
+	Opt_grpquota, Opt_zerofree
 };
 
 static match_table_t tokens = {
@@ -802,6 +802,7 @@ static match_table_t tokens = {
 	{Opt_jqfmt_vfsold, "jqfmt=vfsold"},
 	{Opt_jqfmt_vfsv0, "jqfmt=vfsv0"},
 	{Opt_grpquota, "grpquota"},
+	{Opt_zerofree, "zerofree"},
 	{Opt_noquota, "noquota"},
 	{Opt_quota, "quota"},
 	{Opt_usrquota, "usrquota"},
@@ -1138,6 +1139,9 @@ clear_qf_name:
 		case Opt_bh:
 			clear_opt(sbi->s_mount_opt, NOBH);
 			break;
+		case Opt_zerofree:
+			set_opt(sbi->s_mount_opt, ZEROFREE);
+			break;
 		default:
 			printk (KERN_ERR
 				"EXT3-fs: Unrecognized mount option \"%s\" "
--- linux-2.6.25/fs/ext3/balloc.c.zerofree3	2008-04-17 03:49:44.000000000 +0100
+++ linux-2.6.25/fs/ext3/balloc.c	2008-07-30 19:08:36.000000000 +0100
@@ -657,14 +657,41 @@ error_return:
 }
 
 /**
+ * ext3_zero_blocks() -- Zero given blocks
+ * @sb:			super block
+ * @block:		start physical block to zero
+ * @count:		number of blocks to zero
+ */
+static void ext3_zero_blocks(struct super_block *sb, unsigned long block,
+		unsigned long count)
+{
+	unsigned long i;
+	struct buffer_head *bh;
+
+	for (i = 0; i < count; i++) {
+		bh = sb_getblk(sb, block+i);
+		if (!bh)
+			continue;
+
+		lock_buffer(bh) ;
+		memset(bh->b_data, 0, bh->b_size);
+		set_buffer_uptodate(bh);
+		mark_buffer_dirty(bh);
+		unlock_buffer(bh) ;
+		brelse(bh);
+	}
+}
+
+/**
  * ext3_free_blocks() -- Free given blocks and update quota
  * @handle:		handle for this transaction
  * @inode:		inode
  * @block:		start physical block to free
  * @count:		number of blocks to count
+ * @zero:		flag to indicate blocks are to be zeroed
  */
 void ext3_free_blocks(handle_t *handle, struct inode *inode,
-			ext3_fsblk_t block, unsigned long count)
+			ext3_fsblk_t block, unsigned long count, int zero)
 {
 	struct super_block * sb;
 	unsigned long dquot_freed_blocks;
@@ -674,6 +701,8 @@ void ext3_free_blocks(handle_t *handle, 
 		printk ("ext3_free_blocks: nonexistent device");
 		return;
 	}
+	if (test_opt(sb, ZEROFREE) && zero && !ext3_should_journal_data(inode))
+		ext3_zero_blocks(sb, block, count);
 	ext3_free_blocks_sb(handle, sb, block, count, &dquot_freed_blocks);
 	if (dquot_freed_blocks)
 		DQUOT_FREE_BLOCK(inode, dquot_freed_blocks);
--- linux-2.6.25/fs/ext3/inode.c.zerofree3	2008-04-17 03:49:44.000000000 +0100
+++ linux-2.6.25/fs/ext3/inode.c	2008-07-30 18:15:04.000000000 +0100
@@ -559,7 +559,7 @@ static int ext3_alloc_blocks(handle_t *h
 	return ret;
 failed_out:
 	for (i = 0; i <index; i++)
-		ext3_free_blocks(handle, inode, new_blocks[i], 1);
+		ext3_free_blocks(handle, inode, new_blocks[i], 1, 0);
 	return ret;
 }
 
@@ -658,9 +658,9 @@ failed:
 		ext3_journal_forget(handle, branch[i].bh);
 	}
 	for (i = 0; i <indirect_blks; i++)
-		ext3_free_blocks(handle, inode, new_blocks[i], 1);
+		ext3_free_blocks(handle, inode, new_blocks[i], 1, 0);
 
-	ext3_free_blocks(handle, inode, new_blocks[i], num);
+	ext3_free_blocks(handle, inode, new_blocks[i], num, 0);
 
 	return err;
 }
@@ -757,9 +757,9 @@ err_out:
 	for (i = 1; i <= num; i++) {
 		BUFFER_TRACE(where[i].bh, "call journal_forget");
 		ext3_journal_forget(handle, where[i].bh);
-		ext3_free_blocks(handle,inode,le32_to_cpu(where[i-1].key),1);
+		ext3_free_blocks(handle,inode,le32_to_cpu(where[i-1].key),1,0);
 	}
-	ext3_free_blocks(handle, inode, le32_to_cpu(where[num].key), blks);
+	ext3_free_blocks(handle, inode, le32_to_cpu(where[num].key), blks, 0);
 
 	return err;
 }
@@ -2053,7 +2053,7 @@ static void ext3_clear_blocks(handle_t *
 		}
 	}
 
-	ext3_free_blocks(handle, inode, block_to_free, count);
+	ext3_free_blocks(handle, inode, block_to_free, count, 1);
 }
 
 /**
@@ -2226,7 +2226,7 @@ static void ext3_free_branches(handle_t 
 				ext3_journal_test_restart(handle, inode);
 			}
 
-			ext3_free_blocks(handle, inode, nr, 1);
+			ext3_free_blocks(handle, inode, nr, 1, 0);
 
 			if (parent_bh) {
 				/*
--- linux-2.6.25/fs/ext3/xattr.c.zerofree3	2008-07-28 20:12:44.000000000 +0100
+++ linux-2.6.25/fs/ext3/xattr.c	2008-07-30 18:15:04.000000000 +0100
@@ -488,7 +488,7 @@ ext3_xattr_release_block(handle_t *handl
 		ea_bdebug(bh, "refcount now=0; freeing");
 		if (ce)
 			mb_cache_entry_free(ce);
-		ext3_free_blocks(handle, inode, bh->b_blocknr, 1);
+		ext3_free_blocks(handle, inode, bh->b_blocknr, 1, 0);
 		get_bh(bh);
 		ext3_forget(handle, 1, inode, bh, bh->b_blocknr);
 	} else {
@@ -810,7 +810,7 @@ inserted:
 			new_bh = sb_getblk(sb, block);
 			if (!new_bh) {
 getblk_failed:
-				ext3_free_blocks(handle, inode, block, 1);
+				ext3_free_blocks(handle, inode, block, 1, 0);
 				error = -EIO;
 				goto cleanup;
 			}
--- linux-2.6.25/include/linux/ext3_fs.h.zerofree3	2008-04-17 03:49:44.000000000 +0100
+++ linux-2.6.25/include/linux/ext3_fs.h	2008-07-30 18:25:44.000000000 +0100
@@ -380,6 +380,7 @@ struct ext3_inode {
 #define EXT3_MOUNT_QUOTA		0x80000 /* Some quota option set */
 #define EXT3_MOUNT_USRQUOTA		0x100000 /* "old" user quota */
 #define EXT3_MOUNT_GRPQUOTA		0x200000 /* "old" group quota */
+#define EXT3_MOUNT_ZEROFREE		0x400000 /* Zero freed blocks */
 
 /* Compatibility, for having both ext2_fs.h and ext3_fs.h included at once */
 #ifndef _LINUX_EXT2_FS_H
@@ -775,7 +776,7 @@ extern ext3_fsblk_t ext3_new_block (hand
 extern ext3_fsblk_t ext3_new_blocks (handle_t *handle, struct inode *inode,
 			ext3_fsblk_t goal, unsigned long *count, int *errp);
 extern void ext3_free_blocks (handle_t *handle, struct inode *inode,
-			ext3_fsblk_t block, unsigned long count);
+			ext3_fsblk_t block, unsigned long count, int zero);
 extern void ext3_free_blocks_sb (handle_t *handle, struct super_block *sb,
 				 ext3_fsblk_t block, unsigned long count,
 				unsigned long *pdquot_freed_blocks);
