Index: linux/fs/ext3/namei.c =================================================================== --- linux.orig/fs/ext3/namei.c Wed Aug 25 11:34:25 2004 +++ linux/fs/ext3/namei.c Wed Aug 25 13:16:03 2004 @@ -1541,11 +1541,17 @@ static inline void ext3_inc_count(handle_t *handle, struct inode *inode) { inode->i_nlink++; + if (is_dx(inode) && inode->i_nlink > 1) { + /* 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) { - inode->i_nlink--; + if (!S_ISDIR(inode->i_mode) || inode->i_nlink > 2) + inode->i_nlink--; } static int ext3_add_nondir(handle_t *handle, @@ -1646,7 +1651,7 @@ struct ext3_dir_entry_2 * de; int err; - if (dir->i_nlink >= EXT3_LINK_MAX) + if (EXT3_DIR_LINK_MAX(dir)) return -EMLINK; handle = ext3_journal_start(dir, EXT3_DATA_TRANS_BLOCKS + @@ -1668,7 +1673,7 @@ 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) { - inode->i_nlink--; /* is this nlink == 0? */ + ext3_dec_count(handle, inode); /* is this nlink == 0? */ ext3_mark_inode_dirty(handle, inode); iput (inode); goto out_stop; @@ -1700,7 +1705,7 @@ iput (inode); goto out_stop; } - dir->i_nlink++; + ext3_inc_count(handle, dir); ext3_update_dx_flag(dir); ext3_mark_inode_dirty(handle, dir); d_instantiate(dentry, inode); @@ -1761,10 +1766,11 @@ } de = (struct ext3_dir_entry_2 *) bh->b_data; } - if (!ext3_check_dir_entry ("empty_dir", inode, de, bh, - offset)) { - brelse (bh); - return 1; + if (!ext3_check_dir_entry("empty_dir", inode, de, bh, offset)) { + /* On error skip the de and offset to the next block. */ + de = (void *)(bh->b_data + sb->s_blocksize); + offset = (offset | (sb->s_blocksize - 1)) + 1; + continue; } if (le32_to_cpu(de->inode)) { brelse (bh); @@ -1957,14 +1963,14 @@ retval = ext3_delete_entry(handle, dir, de, bh); if (retval) goto end_rmdir; - if (inode->i_nlink != 2) - ext3_warning (inode->i_sb, "ext3_rmdir", - "empty directory has nlink!=2 (%d)", - inode->i_nlink); + if (!EXT3_DIR_LINK_EMPTY(inode)) + ext3_warning(inode->i_sb, __FUNCTION__, + "empty directory has too many links (%d)", + inode->i_nlink); inode->i_version = ++event; inode->i_nlink = 0; ext3_orphan_add(handle, inode); - dir->i_nlink--; + ext3_dec_count(handle, dir); inode->i_ctime = dir->i_ctime = dir->i_mtime = CURRENT_TIME; ext3_mark_inode_dirty(handle, inode); ext3_update_dx_flag(dir); @@ -2016,7 +2022,7 @@ dir->i_ctime = dir->i_mtime = CURRENT_TIME; ext3_update_dx_flag(dir); ext3_mark_inode_dirty(handle, dir); - inode->i_nlink--; + ext3_dec_count(handle, inode); if (!inode->i_nlink) ext3_orphan_add(handle, inode); inode->i_ctime = dir->i_ctime; @@ -2108,9 +2114,8 @@ if (S_ISDIR(inode->i_mode)) return -EPERM; - if (inode->i_nlink >= EXT3_LINK_MAX) { + if (EXT3_DIR_LINK_MAX(inode)) return -EMLINK; - } handle = ext3_journal_start(dir, EXT3_DATA_TRANS_BLOCKS + EXT3_INDEX_EXTRA_TRANS_BLOCKS); @@ -2194,8 +2199,8 @@ 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_MAX(new_dir)) goto end_rename; } if (!new_bh) { @@ -2253,7 +2258,7 @@ } if (new_inode) { - new_inode->i_nlink--; + ext3_dec_count(handle, new_inode); new_inode->i_ctime = CURRENT_TIME; } old_dir->i_ctime = old_dir->i_mtime = CURRENT_TIME; @@ -2264,11 +2269,13 @@ 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); - old_dir->i_nlink--; + ext3_dec_count(handle, old_dir); if (new_inode) { - new_inode->i_nlink--; + /* 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); } Index: linux/include/linux/ext3_fs.h =================================================================== --- linux.orig/include/linux/ext3_fs.h Wed Aug 25 11:34:27 2004 +++ linux/include/linux/ext3_fs.h Wed Aug 25 13:14:48 2004 @@ -79,7 +81,7 @@ /* * Maximal count of links to a file */ -#define EXT3_LINK_MAX 32000 +#define EXT3_LINK_MAX 65000 /* * Macro-instructions used to manage several block sizes