1 diff -Nur orig/fs/ext3/namei.c patch/fs/ext3/namei.c
2 --- orig/fs/ext3/namei.c 2005-10-12 13:58:19.000000000 -0700
3 +++ patch/fs/ext3/namei.c 2005-10-12 14:00:33.000000000 -0700
4 @@ -1603,11 +1603,17 @@
5 static inline void ext3_inc_count(handle_t *handle, struct inode *inode)
8 + if (is_dx(inode) && inode->i_nlink > 1) {
9 + /* limit is 16-bit i_links_count */
10 + if (inode->i_nlink >= EXT3_LINK_MAX || inode->i_nlink == 2)
15 static inline void ext3_dec_count(handle_t *handle, struct inode *inode)
18 + if (!S_ISDIR(inode->i_mode) || inode->i_nlink > 2)
22 static int ext3_add_nondir(handle_t *handle,
23 @@ -1706,7 +1712,7 @@ static int ext3_add_nondir(handle_t
24 struct ext3_dir_entry_2 * de;
27 - if (dir->i_nlink >= EXT3_LINK_MAX)
28 + if (EXT3_DIR_LINK_MAX(dir))
32 @@ -1729,7 +1735,7 @@ static int ext3_mkdir(struct inode
33 inode->i_size = EXT3_I(inode)->i_disksize = inode->i_sb->s_blocksize;
34 dir_block = ext3_bread (handle, inode, 0, 1, &err);
36 - inode->i_nlink--; /* is this nlink == 0? */
37 + ext3_dec_count(handle, inode); /* is this nlink == 0? */
38 ext3_mark_inode_dirty(handle, inode);
41 @@ -1761,7 +1767,7 @@ static int ext3_mkdir(struct inode
46 + ext3_inc_count(handle, dir);
47 ext3_update_dx_flag(dir);
48 ext3_mark_inode_dirty(handle, dir);
49 d_instantiate(dentry, inode);
50 @@ -2026,10 +2032,10 @@ static int ext3_rmdir (struct inode
51 retval = ext3_delete_entry(handle, dir, de, bh);
54 - if (inode->i_nlink != 2)
55 - ext3_warning (inode->i_sb, "ext3_rmdir",
56 - "empty directory has nlink!=2 (%d)",
58 + if (!EXT3_DIR_LINK_EMPTY(inode))
59 + ext3_warning(inode->i_sb, "ext3_rmdir",
60 + "empty directory has too many links (%d)",
64 /* There's no need to set i_disksize: the fact that i_nlink is
65 @@ -2039,7 +2045,7 @@ static int ext3_rmdir (struct inode
66 ext3_orphan_add(handle, inode);
67 inode->i_ctime = dir->i_ctime = dir->i_mtime = CURRENT_TIME_SEC;
68 ext3_mark_inode_dirty(handle, inode);
70 + ext3_dec_count(handle, dir);
71 ext3_update_dx_flag(dir);
72 ext3_mark_inode_dirty(handle, dir);
74 @@ -2090,7 +2096,7 @@ static int ext3_unlink(struct inode
75 dir->i_ctime = dir->i_mtime = CURRENT_TIME_SEC;
76 ext3_update_dx_flag(dir);
77 ext3_mark_inode_dirty(handle, dir);
79 + ext3_dec_count(handle, inode);
81 ext3_orphan_add(handle, inode);
82 inode->i_ctime = dir->i_ctime;
83 @@ -2165,7 +2171,7 @@ static int ext3_link (struct dentry
84 struct inode *inode = old_dentry->d_inode;
87 - if (inode->i_nlink >= EXT3_LINK_MAX)
88 + if (EXT3_DIR_LINK_MAX(inode))
92 @@ -2252,8 +2258,8 @@ static int ext3_rename (struct inode
93 if (le32_to_cpu(PARENT_INO(dir_bh->b_data)) != old_dir->i_ino)
96 - if (!new_inode && new_dir!=old_dir &&
97 - new_dir->i_nlink >= EXT3_LINK_MAX)
98 + if (!new_inode && new_dir != old_dir &&
99 + EXT3_DIR_LINK_MAX(new_dir))
103 @@ -2310,7 +2316,7 @@ static int ext3_rename (struct inode
107 - new_inode->i_nlink--;
108 + ext3_dec_count(handle, new_inode);
109 new_inode->i_ctime = CURRENT_TIME_SEC;
111 old_dir->i_ctime = old_dir->i_mtime = CURRENT_TIME_SEC;
112 @@ -2321,11 +2327,13 @@ static int ext3_rename (struct inode
113 PARENT_INO(dir_bh->b_data) = cpu_to_le32(new_dir->i_ino);
114 BUFFER_TRACE(dir_bh, "call ext3_journal_dirty_metadata");
115 ext3_journal_dirty_metadata(handle, dir_bh);
116 - old_dir->i_nlink--;
117 + ext3_dec_count(handle, old_dir);
119 - new_inode->i_nlink--;
120 + /* checked empty_dir above, can't have another parent,
121 + * ext3_dec_count() won't work for many-linked dirs */
122 + new_inode->i_nlink = 0;
124 - new_dir->i_nlink++;
125 + ext3_inc_count(handle, new_dir);
126 ext3_update_dx_flag(new_dir);
127 ext3_mark_inode_dirty(handle, new_dir);
130 Index: linux-2.6.7/include/linux/ext3_fs.h
131 ===================================================================
132 --- linux-2.6.7.orig/include/linux/ext3_fs.h 2004-06-15 23:19:36.000000000 -0600
133 +++ linux-2.6.7/include/linux/ext3_fs.h 2004-08-20 17:41:27.000000000 -0600
136 * Maximal count of links to a file
138 -#define EXT3_LINK_MAX 32000
139 +#define EXT3_LINK_MAX 65000
142 * Macro-instructions used to manage several block sizes