---- ./fs/ext3/namei.c.orig 2004-08-19 12:53:21.000000000 +0800
-+++ ./fs/ext3/namei.c 2004-08-19 12:44:18.000000000 +0800
-@@ -1541,11 +1541,16 @@
+Index: linux-2.4.24/fs/ext3/namei.c
+===================================================================
+--- linux-2.4.24.orig/fs/ext3/namei.c
++++ linux-2.4.24/fs/ext3/namei.c
+@@ -1549,11 +1549,17 @@ static int ext3_delete_entry (handle_t *
static inline void ext3_inc_count(handle_t *handle, struct inode *inode)
{
inode->i_nlink++;
+ if (is_dx(inode) && inode->i_nlink > 1) {
-+ if (inode->i_nlink >= 65000) /* limit is 16-bit i_links_count */
++ /* limit is 16-bit i_links_count */
++ if (inode->i_nlink >= EXT3_LINK_MAX || inode->i_nlink == 2)
+ inode->i_nlink = 1;
-+ }
++ }
}
static inline void ext3_dec_count(handle_t *handle, struct inode *inode)
}
static int ext3_add_nondir(handle_t *handle,
-@@ -1646,7 +1651,7 @@
+@@ -1654,7 +1660,7 @@ static int ext3_mkdir(struct inode * dir
struct ext3_dir_entry_2 * de;
int err;
- if (dir->i_nlink >= EXT3_LINK_MAX)
-+ if (EXT3_DIR_LINK_MAXED(dir))
++ if (EXT3_DIR_LINK_MAX(dir))
return -EMLINK;
handle = ext3_journal_start(dir, EXT3_DATA_TRANS_BLOCKS +
-@@ -1668,7 +1673,7 @@
+@@ -1676,7 +1682,7 @@ static int ext3_mkdir(struct inode * dir
inode->i_size = EXT3_I(inode)->i_disksize = inode->i_sb->s_blocksize;
dir_block = ext3_bread (handle, inode, 0, 1, &err);
if (!dir_block) {
ext3_mark_inode_dirty(handle, inode);
iput (inode);
goto out_stop;
-@@ -1700,7 +1705,7 @@
+@@ -1708,7 +1714,7 @@ static int ext3_mkdir(struct inode * dir
iput (inode);
goto out_stop;
}
ext3_update_dx_flag(dir);
ext3_mark_inode_dirty(handle, dir);
d_instantiate(dentry, inode);
-@@ -1761,10 +1766,11 @@
+@@ -1769,10 +1775,11 @@ static int empty_dir (struct inode * ino
}
de = (struct ext3_dir_entry_2 *) bh->b_data;
}
}
if (le32_to_cpu(de->inode)) {
brelse (bh);
-@@ -1957,14 +1963,14 @@
+@@ -1965,14 +1972,14 @@ static int ext3_rmdir (struct inode * di
retval = ext3_delete_entry(handle, dir, de, bh);
if (retval)
goto end_rmdir;
inode->i_ctime = dir->i_ctime = dir->i_mtime = CURRENT_TIME;
ext3_mark_inode_dirty(handle, inode);
ext3_update_dx_flag(dir);
-@@ -2046,7 +2052,7 @@
+@@ -2058,7 +2065,7 @@ static int ext3_unlink(struct inode * di
dir->i_ctime = dir->i_mtime = CURRENT_TIME;
ext3_update_dx_flag(dir);
ext3_mark_inode_dirty(handle, dir);
if (!inode->i_nlink) {
ext3_try_to_delay_deletion(inode);
ext3_orphan_add(handle, inode);
-@@ -2140,9 +2146,8 @@
+@@ -2152,9 +2159,8 @@ static int ext3_link (struct dentry * ol
if (S_ISDIR(inode->i_mode))
return -EPERM;
- if (inode->i_nlink >= EXT3_LINK_MAX) {
-+ if (EXT3_DIR_LINK_MAXED(inode))
++ if (EXT3_DIR_LINK_MAX(inode))
return -EMLINK;
- }
handle = ext3_journal_start(dir, EXT3_DATA_TRANS_BLOCKS +
EXT3_INDEX_EXTRA_TRANS_BLOCKS);
-@@ -2226,8 +2231,8 @@
+@@ -2238,8 +2244,8 @@ static int ext3_rename (struct inode * o
if (le32_to_cpu(PARENT_INO(dir_bh->b_data)) != old_dir->i_ino)
goto end_rename;
retval = -EMLINK;
- if (!new_inode && new_dir!=old_dir &&
- new_dir->i_nlink >= EXT3_LINK_MAX)
+ if (!new_inode && new_dir != old_dir &&
-+ EXT3_DIR_LINK_MAXED(new_dir))
++ EXT3_DIR_LINK_MAX(new_dir))
goto end_rename;
}
if (!new_bh) {
-@@ -2285,7 +2290,7 @@
+@@ -2297,7 +2303,7 @@ static int ext3_rename (struct inode * o
}
if (new_inode) {
new_inode->i_ctime = CURRENT_TIME;
}
old_dir->i_ctime = old_dir->i_mtime = CURRENT_TIME;
-@@ -2296,11 +2301,11 @@
+@@ -2308,11 +2314,13 @@ static int ext3_rename (struct inode * o
PARENT_INO(dir_bh->b_data) = le32_to_cpu(new_dir->i_ino);
BUFFER_TRACE(dir_bh, "call ext3_journal_dirty_metadata");
ext3_journal_dirty_metadata(handle, dir_bh);
+ ext3_dec_count(handle, old_dir);
if (new_inode) {
- new_inode->i_nlink--;
-+ ext3_dec_count(handle, new_inode);
++ /* checked empty_dir above, can't have another parent,
++ * ext3_dec_count() won't work for many-linked dirs */
++ new_inode->i_nlink = 0;
} else {
- new_dir->i_nlink++;
+ ext3_inc_count(handle, new_dir);
ext3_update_dx_flag(new_dir);
ext3_mark_inode_dirty(handle, new_dir);
}
---- ./include/linux/ext3_fs.h.orig 2004-08-19 12:53:52.000000000 +0800
-+++ ./include/linux/ext3_fs.h 2004-08-19 11:06:33.000000000 +0800
-@@ -42,7 +42,7 @@
+Index: linux-2.4.24/include/linux/ext3_fs.h
+===================================================================
+--- linux-2.4.24.orig/include/linux/ext3_fs.h
++++ linux-2.4.24/include/linux/ext3_fs.h
+@@ -79,7 +79,7 @@
/*
- * Always enable hashed directories
+ * Maximal count of links to a file
*/
--#define CONFIG_EXT3_INDEX
-+#define CONFIG_EXT3_INDEX 1
+-#define EXT3_LINK_MAX 32000
++#define EXT3_LINK_MAX 65000
/*
- * Debug code
-@@ -581,14 +581,15 @@
- */
+ * Macro-instructions used to manage several block sizes
+@@ -504,6 +504,7 @@ struct ext3_super_block {
+ #define EXT3_FEATURE_RO_COMPAT_SPARSE_SUPER 0x0001
+ #define EXT3_FEATURE_RO_COMPAT_LARGE_FILE 0x0002
+ #define EXT3_FEATURE_RO_COMPAT_BTREE_DIR 0x0004
++#define EXT3_FEATURE_RO_COMPAT_DIR_NLINK 0x0020
- #ifdef CONFIG_EXT3_INDEX
-- #define is_dx(dir) (EXT3_HAS_COMPAT_FEATURE(dir->i_sb, \
-- EXT3_FEATURE_COMPAT_DIR_INDEX) && \
-+#define is_dx(dir) (EXT3_HAS_COMPAT_FEATURE(dir->i_sb, \
-+ EXT3_FEATURE_COMPAT_DIR_INDEX) && \
- (EXT3_I(dir)->i_flags & EXT3_INDEX_FL))
--#define EXT3_DIR_LINK_MAX(dir) (!is_dx(dir) && (dir)->i_nlink >= EXT3_LINK_MAX)
--#define EXT3_DIR_LINK_EMPTY(dir) ((dir)->i_nlink == 2 || (dir)->i_nlink == 1)
-+#define EXT3_DIR_LINK_MAXED(dir) (!is_dx(dir) && (dir)->i_nlink >=EXT3_LINK_MAX)
-+#define EXT3_DIR_LINK_EMPTY(dir) ((dir)->i_nlink == 2 || \
-+ (is_dx(dir) && (dir)->i_nlink == 1))
- #else
- #define is_dx(dir) 0
--#define EXT3_DIR_LINK_MAX(dir) ((dir)->i_nlink >= EXT3_LINK_MAX)
-+#define EXT3_DIR_LINK_MAXED(dir) ((dir)->i_nlink >= EXT3_LINK_MAX)
- #define EXT3_DIR_LINK_EMPTY(dir) ((dir)->i_nlink == 2)
- #endif
+ #define EXT3_FEATURE_INCOMPAT_COMPRESSION 0x0001
+ #define EXT3_FEATURE_INCOMPAT_FILETYPE 0x0002
+@@ -517,6 +518,7 @@ struct ext3_super_block {
+ EXT3_FEATURE_INCOMPAT_EXTENTS)
+ #define EXT3_FEATURE_RO_COMPAT_SUPP (EXT3_FEATURE_RO_COMPAT_SPARSE_SUPER| \
+ EXT3_FEATURE_RO_COMPAT_LARGE_FILE| \
++ EXT3_FEATURE_RO_COMPAT_DIR_NLINK| \
+ EXT3_FEATURE_RO_COMPAT_BTREE_DIR)
+ /*