From b71e01835ff844d5be09ecbf7e51acad4d75447b Mon Sep 17 00:00:00 2001 From: Theodore Ts'o Date: Mon, 16 Nov 2009 21:56:24 -0500 Subject: [PATCH] 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" --- e2fsck/rehash.c | 12 ++++++------ tests/f_dup_de2/expect.1 | 16 ++++++++++++++++ tests/f_dup_de2/expect.2 | 7 +++++++ tests/f_dup_de2/image.gz | Bin 0 -> 4860 bytes tests/f_dup_de2/name | 1 + 5 files changed, 30 insertions(+), 6 deletions(-) create mode 100644 tests/f_dup_de2/expect.1 create mode 100644 tests/f_dup_de2/expect.2 create mode 100644 tests/f_dup_de2/image.gz create mode 100644 tests/f_dup_de2/name diff --git a/e2fsck/rehash.c b/e2fsck/rehash.c index 50388f366..46d04e497 100644 --- a/e2fsck/rehash.c +++ b/e2fsck/rehash.c @@ -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 index 000000000..8dd3d9125 --- /dev/null +++ b/tests/f_dup_de2/expect.1 @@ -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 index 000000000..8781274c2 --- /dev/null +++ b/tests/f_dup_de2/expect.2 @@ -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 index 0000000000000000000000000000000000000000..a8e4db3e8ac4c1695b89c714f24635467a61f279 GIT binary patch literal 4860 zc-rlk`%_bA8pp9zvDM1f3wQz2sk^e4BCRyC27y&ZDN+m&!X=mlYYUnbSj5BSKmd!v zS`n(YBB6kYKrWmd0Z))Xf?Zaqa;R`;uCV#9VIR6)5%A3D_%XKwq;;udV>YGlV zU-|TSSksBuA~j3f--v0t`|`RvpRI3x`qEpM*DhVsbosq6XG(+Dt{iOWE!sRWhg;H& zeZx%OnZCzq(|&E<8&>AaaoI-S^^f)av$YNd?e1F2%c&~Tv}^okcmPJr=^OH4 zbaw5h`kF^liv|P6YIeG9+*l0u*}LYtD1mm%)y^3y5(V)oRD%d0;U=^Y2~V28QOTs% zJQ0}L%;bAHmCpvJY)>Yr^}b8({z}z{Zq~tT)64zl3mB*5`aSGZRkpna4ZVu&p;EfB3>aC~3#y``nmO`KI1Zome|wx-hlm zXmef8>CDwGIq&BcGrSY-m~7z%v9?=-S~7r@yV>ts^SE2u76B9mGe!M8C9VQQnXf|8 z6tN6BloY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