OSDN Git Service

e2fsck: Fix duplicate directory entries for non-indexed directories
authorTheodore Ts'o <tytso@mit.edu>
Tue, 17 Nov 2009 02:56:24 +0000 (21:56 -0500)
committerTheodore Ts'o <tytso@mit.edu>
Tue, 17 Nov 2009 02:56:24 +0000 (21:56 -0500)
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>
e2fsck/rehash.c
tests/f_dup_de2/expect.1 [new file with mode: 0644]
tests/f_dup_de2/expect.2 [new file with mode: 0644]
tests/f_dup_de2/image.gz [new file with mode: 0644]
tests/f_dup_de2/name [new file with mode: 0644]

index 50388f3..46d04e4 100644 (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.
diff --git a/tests/f_dup_de2/expect.1 b/tests/f_dup_de2/expect.1
new file mode 100644 (file)
index 0000000..8dd3d91
--- /dev/null
@@ -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
diff --git a/tests/f_dup_de2/expect.2 b/tests/f_dup_de2/expect.2
new file mode 100644 (file)
index 0000000..8781274
--- /dev/null
@@ -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
diff --git a/tests/f_dup_de2/image.gz b/tests/f_dup_de2/image.gz
new file mode 100644 (file)
index 0000000..a8e4db3
Binary files /dev/null and b/tests/f_dup_de2/image.gz differ
diff --git a/tests/f_dup_de2/name b/tests/f_dup_de2/name
new file mode 100644 (file)
index 0000000..e337f10
--- /dev/null
@@ -0,0 +1 @@
+duplicate directory entries for non-indexed dirs