1 Index: linux-2.6.7/fs/ext3/namei.c
2 ===================================================================
3 --- linux-2.6.7.orig/fs/ext3/namei.c 2004-06-15 23:19:36.000000000 -0600
4 +++ linux-2.6.7/fs/ext3/namei.c 2004-08-20 17:48:54.000000000 -0600
5 @@ -1596,11 +1596,17 @@ static int ext3_delete_entry (handle_t *
6 static inline void ext3_inc_count(handle_t *handle, struct inode *inode)
9 + if (is_dx(inode) && inode->i_nlink > 1) {
10 + /* limit is 16-bit i_links_count */
11 + if (inode->i_nlink >= EXT3_LINK_MAX || inode->i_nlink == 2)
16 static inline void ext3_dec_count(handle_t *handle, struct inode *inode)
19 + if (!S_ISDIR(inode->i_mode) || inode->i_nlink > 2)
23 static int ext3_add_nondir(handle_t *handle,
24 @@ -1693,7 +1698,7 @@ static int ext3_mkdir(struct inode * dir
25 struct ext3_dir_entry_2 * de;
28 - if (dir->i_nlink >= EXT3_LINK_MAX)
29 + if (EXT3_DIR_LINK_MAX(dir))
32 handle = ext3_journal_start(dir, EXT3_DATA_TRANS_BLOCKS +
33 @@ -1715,7 +1720,7 @@ static int ext3_mkdir(struct inode * dir
34 inode->i_size = EXT3_I(inode)->i_disksize = inode->i_sb->s_blocksize;
35 dir_block = ext3_bread (handle, inode, 0, 1, &err);
37 - inode->i_nlink--; /* is this nlink == 0? */
38 + ext3_dec_count(handle, inode); /* is this nlink == 0? */
39 ext3_mark_inode_dirty(handle, inode);
42 @@ -1747,7 +1752,7 @@ static int ext3_mkdir(struct inode * dir
47 + ext3_inc_count(handle, dir);
48 ext3_update_dx_flag(dir);
49 ext3_mark_inode_dirty(handle, dir);
50 d_instantiate(dentry, inode);
51 @@ -2010,10 +2015,10 @@ static int ext3_rmdir (struct inode * di
52 retval = ext3_delete_entry(handle, dir, de, bh);
55 - if (inode->i_nlink != 2)
56 - ext3_warning (inode->i_sb, "ext3_rmdir",
57 - "empty directory has nlink!=2 (%d)",
59 + if (!EXT3_DIR_LINK_EMPTY(inode))
60 + ext3_warning(inode->i_sb, "ext3_rmdir",
61 + "empty directory has too many links (%d)",
65 /* There's no need to set i_disksize: the fact that i_nlink is
66 @@ -2023,7 +2028,7 @@ static int ext3_rmdir (struct inode * di
67 ext3_orphan_add(handle, inode);
68 inode->i_ctime = dir->i_ctime = dir->i_mtime = CURRENT_TIME;
69 ext3_mark_inode_dirty(handle, inode);
71 + ext3_dec_count(handle, dir);
72 ext3_update_dx_flag(dir);
73 ext3_mark_inode_dirty(handle, dir);
75 @@ -2074,7 +2079,7 @@ static int ext3_unlink(struct inode * di
76 dir->i_ctime = dir->i_mtime = CURRENT_TIME;
77 ext3_update_dx_flag(dir);
78 ext3_mark_inode_dirty(handle, dir);
80 + ext3_dec_count(handle, inode);
82 ext3_orphan_add(handle, inode);
83 inode->i_ctime = dir->i_ctime;
84 @@ -2146,7 +2151,7 @@ static int ext3_link (struct dentry * ol
85 struct inode *inode = old_dentry->d_inode;
88 - if (inode->i_nlink >= EXT3_LINK_MAX)
89 + if (EXT3_DIR_LINK_MAX(inode))
92 handle = ext3_journal_start(dir, EXT3_DATA_TRANS_BLOCKS +
93 @@ -2230,8 +2235,8 @@ static int ext3_rename (struct inode * o
94 if (le32_to_cpu(PARENT_INO(dir_bh->b_data)) != old_dir->i_ino)
97 - if (!new_inode && new_dir!=old_dir &&
98 - new_dir->i_nlink >= EXT3_LINK_MAX)
99 + if (!new_inode && new_dir != old_dir &&
100 + EXT3_DIR_LINK_MAX(new_dir))
104 @@ -2288,7 +2293,7 @@ static int ext3_rename (struct inode * o
108 - new_inode->i_nlink--;
109 + ext3_dec_count(handle, new_inode);
110 new_inode->i_ctime = CURRENT_TIME;
112 old_dir->i_ctime = old_dir->i_mtime = CURRENT_TIME;
113 @@ -2299,11 +2304,13 @@ static int ext3_rename (struct inode * o
114 PARENT_INO(dir_bh->b_data) = le32_to_cpu(new_dir->i_ino);
115 BUFFER_TRACE(dir_bh, "call ext3_journal_dirty_metadata");
116 ext3_journal_dirty_metadata(handle, dir_bh);
117 - old_dir->i_nlink--;
118 + ext3_dec_count(handle, old_dir);
120 - new_inode->i_nlink--;
121 + /* checked empty_dir above, can't have another parent,
122 + * ext3_dec_count() won't work for many-linked dirs */
123 + new_inode->i_nlink = 0;
125 - new_dir->i_nlink++;
126 + ext3_inc_count(handle, new_dir);
127 ext3_update_dx_flag(new_dir);
128 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