e2fsck: Fix duplicate directory entries for non-indexed directories

Duplicate directory entries were not necessarily getting found and
fixed for non-indexed directories, since we were sorting these
directories by inode number, and the duplicate entry code assumed the
entries were getting sorted by name or directory name hash.

Addresses-Sourceforge-Bug: #2862551

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
bitmap-optimize
Theodore Ts'o 2009-11-16 21:56:24 -05:00
parent c7cd908be5
commit b71e01835f
5 changed files with 30 additions and 6 deletions

View File

@ -751,12 +751,7 @@ errcode_t e2fsck_rehash_dir(e2fsck_t ctx, ext2_ino_t ino)
/* Sort the list */
resort:
if (fd.compress)
qsort(fd.harray+2, fd.num_array-2,
sizeof(struct hash_entry), ino_cmp);
else
qsort(fd.harray, fd.num_array,
sizeof(struct hash_entry), hash_cmp);
qsort(fd.harray, fd.num_array, sizeof(struct hash_entry), hash_cmp);
/*
* Look for duplicates
@ -769,6 +764,11 @@ resort:
goto errout;
}
/* Sort non-hashed directories by inode number */
if (fd.compress)
qsort(fd.harray+2, fd.num_array-2,
sizeof(struct hash_entry), ino_cmp);
/*
* Copy the directory entries. In a htree directory these
* will become the leaf nodes.

16
tests/f_dup_de2/expect.1 Normal file
View File

@ -0,0 +1,16 @@
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Duplicate entry 'test-008' found.
Marking / (2) to be rebuilt.
Pass 3: Checking directory connectivity
Pass 3A: Optimizing directories
Entry 'test-008' in / (2) has a non-unique filename.
Rename to test-0~0? yes
Pass 4: Checking reference counts
Pass 5: Checking group summary information
test_filesys: ***** FILE SYSTEM WAS MODIFIED *****
test_filesys: 21/256 files (0.0% non-contiguous), 1087/2048 blocks
Exit status is 1

7
tests/f_dup_de2/expect.2 Normal file
View File

@ -0,0 +1,7 @@
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
test_filesys: 21/256 files (0.0% non-contiguous), 1087/2048 blocks
Exit status is 0

BIN
tests/f_dup_de2/image.gz Normal file

Binary file not shown.

1
tests/f_dup_de2/name Normal file
View File

@ -0,0 +1 @@
duplicate directory entries for non-indexed dirs