diff --git a/fs/ext2/super.c b/fs/ext2/super.c
index 336771e9f77f9c34042b2e29fd940fb56b294d5d..8fea7194653b4ff2e2efe77929b72af87f42805b 100644
--- a/fs/ext2/super.c
+++ b/fs/ext2/super.c
@@ -529,6 +529,7 @@ static unsigned long descriptor_loc(struct super_block *sb,
 {
 	struct ext2_sb_info *sbi = EXT2_SB(sb);
 	unsigned long bg, first_data_block, first_meta_bg;
+	int has_super = 0;
 	
 	first_data_block = le32_to_cpu(sbi->s_es->s_first_data_block);
 	first_meta_bg = le32_to_cpu(sbi->s_es->s_first_meta_bg);
@@ -537,7 +538,9 @@ static unsigned long descriptor_loc(struct super_block *sb,
 	    nr < first_meta_bg)
 		return (logic_sb_block + nr + 1);
 	bg = sbi->s_desc_per_block * nr;
-	return (first_data_block + 1 + (bg * sbi->s_blocks_per_group));
+	if (ext2_bg_has_super(sb, bg))
+		has_super = 1;
+	return (first_data_block + has_super + (bg * sbi->s_blocks_per_group));
 }
 
 static int ext2_fill_super(struct super_block *sb, void *data, int silent)
diff --git a/fs/ext3/dir.c b/fs/ext3/dir.c
index cacacbb1f87ad5d11658beea638615f12068b7bd..936ed5234988309278d3448854f30802e807087b 100644
--- a/fs/ext3/dir.c
+++ b/fs/ext3/dir.c
@@ -314,7 +314,7 @@ void ext3_htree_free_dir_info(struct dir_private_info *p)
 /*
  * Given a directory entry, enter it into the fname rb tree.
  */
-void ext3_htree_store_dirent(struct file *dir_file, __u32 hash,
+int ext3_htree_store_dirent(struct file *dir_file, __u32 hash,
 			     __u32 minor_hash,
 			     struct ext3_dir_entry_2 *dirent)
 {
@@ -329,6 +329,8 @@ void ext3_htree_store_dirent(struct file *dir_file, __u32 hash,
 	/* Create and allocate the fname structure */
 	len = sizeof(struct fname) + dirent->name_len + 1;
 	new_fn = kmalloc(len, GFP_KERNEL);
+	if (!new_fn)
+		return -ENOMEM;
 	memset(new_fn, 0, len);
 	new_fn->hash = hash;
 	new_fn->minor_hash = minor_hash;
@@ -350,7 +352,7 @@ void ext3_htree_store_dirent(struct file *dir_file, __u32 hash,
 		    (new_fn->minor_hash == fname->minor_hash)) {
 			new_fn->next = fname->next;
 			fname->next = new_fn;
-			return;
+			return 0;
 		}
 			
 		if (new_fn->hash < fname->hash)
@@ -365,6 +367,7 @@ void ext3_htree_store_dirent(struct file *dir_file, __u32 hash,
 
 	rb_link_node(&new_fn->rb_hash, parent, p);
 	rb_insert_color(&new_fn->rb_hash, &info->root);
+	return 0;
 }
 
 
diff --git a/fs/ext3/ialloc.c b/fs/ext3/ialloc.c
index 72ff75412bdab37e2387a200be16723127da7c9b..de8c64403b2f95f654b25ec452b8bf6224d7381d 100644
--- a/fs/ext3/ialloc.c
+++ b/fs/ext3/ialloc.c
@@ -208,7 +208,7 @@ static int find_group_dir(struct super_block *sb, struct inode *parent)
 	int ngroups = EXT3_SB(sb)->s_groups_count;
 	int avefreei = le32_to_cpu(es->s_free_inodes_count) / ngroups;
 	struct ext3_group_desc *desc, *best_desc = NULL;
-	struct buffer_head *bh, *best_bh = NULL;
+	struct buffer_head *bh;
 	int group, best_group = -1;
 
 	for (group = 0; group < ngroups; group++) {
@@ -222,16 +222,8 @@ static int find_group_dir(struct super_block *sb, struct inode *parent)
 		     le16_to_cpu(best_desc->bg_free_blocks_count))) {
 			best_group = group;
 			best_desc = desc;
-			best_bh = bh;
 		}
 	}
-	if (!best_desc)
-		return -1;
-	best_desc->bg_free_inodes_count =
-		cpu_to_le16(le16_to_cpu(best_desc->bg_free_inodes_count) - 1);
-	best_desc->bg_used_dirs_count =
-		cpu_to_le16(le16_to_cpu(best_desc->bg_used_dirs_count) + 1);
-	mark_buffer_dirty(best_bh);
 	return best_group;
 }
 
@@ -281,8 +273,6 @@ static int find_group_orlov(struct super_block *sb, struct inode *parent)
 
 	if ((parent == sb->s_root->d_inode) ||
 	    (parent->i_flags & EXT3_TOPDIR_FL)) {
-		struct ext3_group_desc *best_desc = NULL;
-		struct buffer_head *best_bh = NULL;
 		int best_ndir = inodes_per_group;
 		int best_group = -1;
 
@@ -301,15 +291,9 @@ static int find_group_orlov(struct super_block *sb, struct inode *parent)
 				continue;
 			best_group = group;
 			best_ndir = le16_to_cpu(desc->bg_used_dirs_count);
-			best_desc = desc;
-			best_bh = bh;
-		}
-		if (best_group >= 0) {
-			desc = best_desc;
-			bh = best_bh;
-			group = best_group;
-			goto found;
 		}
+		if (best_group >= 0)
+			return best_group;
 		goto fallback;
 	}
 
@@ -341,7 +325,7 @@ static int find_group_orlov(struct super_block *sb, struct inode *parent)
 			continue;
 		if (le16_to_cpu(desc->bg_free_blocks_count) < min_blocks)
 			continue;
-		goto found;
+		return group;
 	}
 
 fallback:
@@ -351,19 +335,10 @@ static int find_group_orlov(struct super_block *sb, struct inode *parent)
 		if (!desc || !desc->bg_free_inodes_count)
 			continue;
 		if (le16_to_cpu(desc->bg_free_inodes_count) >= avefreei)
-			goto found;
+			return group;
 	}
 
 	return -1;
-
-found:
-	desc->bg_free_inodes_count =
-		cpu_to_le16(le16_to_cpu(desc->bg_free_inodes_count) - 1);
-	desc->bg_used_dirs_count =
-		cpu_to_le16(le16_to_cpu(desc->bg_used_dirs_count) + 1);
-	sbi->s_dir_count++;
-	mark_buffer_dirty(bh);
-	return group;
 }
 
 static int find_group_other(struct super_block *sb, struct inode *parent)
@@ -380,7 +355,7 @@ static int find_group_other(struct super_block *sb, struct inode *parent)
 	group = parent_group;
 	desc = ext3_get_group_desc (sb, group, &bh);
 	if (desc && le16_to_cpu(desc->bg_free_inodes_count))
-		goto found;
+		return group;
 
 	/*
 	 * Use a quadratic hash to find a group with a
@@ -392,7 +367,7 @@ static int find_group_other(struct super_block *sb, struct inode *parent)
 			group -= ngroups;
 		desc = ext3_get_group_desc (sb, group, &bh);
 		if (desc && le16_to_cpu(desc->bg_free_inodes_count))
-			goto found;
+			return group;
 	}
 
 	/*
@@ -404,16 +379,10 @@ static int find_group_other(struct super_block *sb, struct inode *parent)
 			group = 0;
 		desc = ext3_get_group_desc (sb, group, &bh);
 		if (desc && le16_to_cpu(desc->bg_free_inodes_count))
-			goto found;
+			return group;
 	}
 
 	return -1;
-
-found:
-	desc->bg_free_inodes_count =
-		cpu_to_le16(le16_to_cpu(desc->bg_free_inodes_count) - 1);
-	mark_buffer_dirty(bh);
-	return group;
 }
 
 /*
@@ -521,9 +490,11 @@ struct inode *ext3_new_inode(handle_t *handle, struct inode * dir, int mode)
 	if (err) goto fail;
 	gdp->bg_free_inodes_count =
 		cpu_to_le16(le16_to_cpu(gdp->bg_free_inodes_count) - 1);
-	if (S_ISDIR(mode))
+	if (S_ISDIR(mode)) {
 		gdp->bg_used_dirs_count =
 			cpu_to_le16(le16_to_cpu(gdp->bg_used_dirs_count) + 1);
+		EXT3_SB(sb)->s_dir_count++;
+	}
 	BUFFER_TRACE(bh2, "call ext3_journal_dirty_metadata");
 	err = ext3_journal_dirty_metadata(handle, bh2);
 	if (err) goto fail;
diff --git a/fs/ext3/namei.c b/fs/ext3/namei.c
index 2f1c40ec481f5b05cabd79e6f64dc9ab63b29fc9..98ac54526a5d0c660786abba0afce795abcdae47 100644
--- a/fs/ext3/namei.c
+++ b/fs/ext3/namei.c
@@ -549,6 +549,17 @@ int ext3_htree_fill_tree(struct file *dir_file, __u32 start_hash,
 	if (!frame)
 		return err;
 
+	/* Add '.' and '..' from the htree header */
+	if (!start_hash && !start_minor_hash) {
+		de = (struct ext3_dir_entry_2 *) frames[0].bh->b_data;
+		if ((err = ext3_htree_store_dirent(dir_file, 0, 0, de)) != 0)
+			goto errout;
+		de = ext3_next_entry(de);
+		if ((err = ext3_htree_store_dirent(dir_file, 0, 0, de)) != 0)
+			goto errout;
+		count += 2;
+	}
+
 	while (1) {
 		block = dx_get_block(frame->at);
 		dxtrace(printk("Reading block %d\n", block));
@@ -564,8 +575,9 @@ int ext3_htree_fill_tree(struct file *dir_file, __u32 start_hash,
 			    ((hinfo.hash == start_hash) &&
 			     (hinfo.minor_hash < start_minor_hash)))
 				continue;
-			ext3_htree_store_dirent(dir_file, hinfo.hash,
-						hinfo.minor_hash, de);
+			if ((err = ext3_htree_store_dirent(dir_file,
+				   hinfo.hash, hinfo.minor_hash, de)) != 0)
+				goto errout;
 			count++;
 		}
 		brelse (bh);
@@ -2231,7 +2243,26 @@ static int ext3_rename (struct inode * old_dir, struct dentry *old_dentry,
 	/*
 	 * ok, that's it
 	 */
-	ext3_delete_entry(handle, old_dir, old_de, old_bh);
+	retval = ext3_delete_entry(handle, old_dir, old_de, old_bh);
+	if (retval == -ENOENT) {
+		/*
+		 * old_de could have moved out from under us.
+		 */
+		struct buffer_head *old_bh2;
+		struct ext3_dir_entry_2 *old_de2;
+		
+		old_bh2 = ext3_find_entry(old_dentry, &old_de2);
+		if (old_bh2) {
+			retval = ext3_delete_entry(handle, old_dir,
+						   old_de2, old_bh2);
+			brelse(old_bh2);
+		}
+	}
+	if (retval) {
+		ext3_warning(old_dir->i_sb, "ext3_rename",
+				"Deleting old file (%lu), %d, error=%d",
+				old_dir->i_ino, old_dir->i_nlink, retval);
+	}
 
 	if (new_inode) {
 		new_inode->i_nlink--;
diff --git a/fs/ext3/super.c b/fs/ext3/super.c
index 195280c454ffac0e45fa0ee4cecc767ba68711bf..424f807dadb5f00e82e5c2b6cbbe03841235f5ab 100644
--- a/fs/ext3/super.c
+++ b/fs/ext3/super.c
@@ -979,6 +979,7 @@ static unsigned long descriptor_loc(struct super_block *sb,
 {
 	struct ext3_sb_info *sbi = EXT3_SB(sb);
 	unsigned long bg, first_data_block, first_meta_bg;
+	int has_super = 0;
 	
 	first_data_block = le32_to_cpu(sbi->s_es->s_first_data_block);
 	first_meta_bg = le32_to_cpu(sbi->s_es->s_first_meta_bg);
@@ -987,7 +988,9 @@ static unsigned long descriptor_loc(struct super_block *sb,
 	    nr < first_meta_bg)
 		return (logic_sb_block + nr + 1);
 	bg = sbi->s_desc_per_block * nr;
-	return (first_data_block + 1 + (bg * sbi->s_blocks_per_group));
+	if (ext3_bg_has_super(sb, bg))
+		has_super = 1;
+	return (first_data_block + has_super + (bg * sbi->s_blocks_per_group));
 }
 
 
diff --git a/fs/mbcache.c b/fs/mbcache.c
index 0ebd3c0fd7739527be1d9de4e40fe2e10c2e3c55..57140dd0961f5ce9834a359ad35cbbaa0f1a49e6 100644
--- a/fs/mbcache.c
+++ b/fs/mbcache.c
@@ -324,14 +324,6 @@ mb_cache_create(const char *name, struct mb_cache_op *cache_op,
 		goto fail;
 
 	spin_lock(&mb_cache_spinlock);
-	if (list_empty(&mb_cache_list)) {
-		if (mb_shrinker) {
-			printk(KERN_ERR "%s: already have a shrinker!\n",
-					__FUNCTION__);
-			remove_shrinker(mb_shrinker);
-		}
-		mb_shrinker = set_shrinker(DEFAULT_SEEKS, mb_cache_shrink_fn);
-	}
 	list_add(&cache->c_cache_list, &mb_cache_list);
 	spin_unlock(&mb_cache_spinlock);
 	return cache;
@@ -414,10 +406,6 @@ mb_cache_destroy(struct mb_cache *cache)
 		}
 	}
 	list_del(&cache->c_cache_list);
-	if (list_empty(&mb_cache_list) && mb_shrinker) {
-		remove_shrinker(mb_shrinker);
-		mb_shrinker = 0;
-	}
 	spin_unlock(&mb_cache_spinlock);
 
 	l = free_list.prev;
@@ -700,3 +688,18 @@ mb_cache_entry_find_next(struct mb_cache_entry *prev, int index,
 }
 
 #endif  /* !defined(MB_CACHE_INDEXES_COUNT) || (MB_CACHE_INDEXES_COUNT > 0) */
+
+static int __init init_mbcache(void)
+{
+	mb_shrinker = set_shrinker(DEFAULT_SEEKS, mb_cache_shrink_fn);
+	return 0;
+}
+
+static void __exit exit_mbcache(void)
+{
+	remove_shrinker(mb_shrinker);
+}
+
+module_init(init_mbcache)
+module_exit(exit_mbcache)
+
diff --git a/include/linux/ext3_fs.h b/include/linux/ext3_fs.h
index 01aa11bcdb9e6c740777cbad0834276102bf038f..458326125d02cbcc4c7cf2bdf332d80c9977a0f0 100644
--- a/include/linux/ext3_fs.h
+++ b/include/linux/ext3_fs.h
@@ -513,10 +513,9 @@ static inline struct ext3_inode_info *EXT3_I(struct inode *inode)
 #define EXT3_FEATURE_INCOMPAT_META_BG		0x0010
 
 #define EXT3_FEATURE_COMPAT_SUPP	EXT2_FEATURE_COMPAT_EXT_ATTR
-#define EXT2_FEATURE_INCOMPAT_SUPP	(EXT2_FEATURE_INCOMPAT_FILETYPE| \
-					 EXT2_FEATURE_INCOMPAT_META_BG)
 #define EXT3_FEATURE_INCOMPAT_SUPP	(EXT3_FEATURE_INCOMPAT_FILETYPE| \
-					 EXT3_FEATURE_INCOMPAT_RECOVER)
+					 EXT3_FEATURE_INCOMPAT_RECOVER| \
+					 EXT3_FEATURE_INCOMPAT_META_BG)
 #define EXT3_FEATURE_RO_COMPAT_SUPP	(EXT3_FEATURE_RO_COMPAT_SPARSE_SUPER| \
 					 EXT3_FEATURE_RO_COMPAT_LARGE_FILE| \
 					 EXT3_FEATURE_RO_COMPAT_BTREE_DIR)
@@ -689,7 +688,7 @@ extern struct ext3_group_desc * ext3_get_group_desc(struct super_block * sb,
 extern int ext3_check_dir_entry(const char *, struct inode *,
 				struct ext3_dir_entry_2 *,
 				struct buffer_head *, unsigned long);
-extern void ext3_htree_store_dirent(struct file *dir_file, __u32 hash,
+extern int ext3_htree_store_dirent(struct file *dir_file, __u32 hash,
 				    __u32 minor_hash,
 				    struct ext3_dir_entry_2 *dirent);
 extern void ext3_htree_free_dir_info(struct dir_private_info *p);