From d66c38329e9897563bd29908043e5187f868b46d Mon Sep 17 00:00:00 2001 From: Theodore Ts'o Date: Tue, 1 Jan 2008 10:59:57 -0500 Subject: [PATCH] e2fsck: When optimizing non-htree directories, sort by inode number Previously "e2fsck -fD" on a non-htree directory would sort the directory alphabetically by name. That's stupid. Better to sort the directory by inode number, since that will optimize performance much more significantly than sorting by name! Addresses-Sourceforge-Feature-Request: #532439 Signed-off-by: "Theodore Ts'o" --- e2fsck/rehash.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/e2fsck/rehash.c b/e2fsck/rehash.c index 3aa3c06..8e25f52 100644 --- a/e2fsck/rehash.c +++ b/e2fsck/rehash.c @@ -66,6 +66,7 @@ struct fill_dir_struct { struct hash_entry { ext2_dirhash_t hash; ext2_dirhash_t minor_hash; + ino_t ino; struct ext2_dir_entry *dir; }; @@ -147,6 +148,7 @@ static int fill_dir_block(ext2_filsys fs, ent = fd->harray + fd->num_array++; ent->dir = dirent; fd->dir_size += EXT2_DIR_REC_LEN(dirent->name_len & 0xFF); + ent->ino = dirent->inode; if (fd->compress) ent->hash = ent->minor_hash = 0; else { @@ -163,6 +165,15 @@ static int fill_dir_block(ext2_filsys fs, } /* Used for sorting the hash entry */ +static EXT2_QSORT_TYPE ino_cmp(const void *a, const void *b) +{ + const struct hash_entry *he_a = (const struct hash_entry *) a; + const struct hash_entry *he_b = (const struct hash_entry *) b; + + return (he_a->ino - he_b->ino); +} + +/* Used for sorting the hash entry */ static EXT2_QSORT_TYPE name_cmp(const void *a, const void *b) { const struct hash_entry *he_a = (const struct hash_entry *) a; @@ -717,7 +728,7 @@ errcode_t e2fsck_rehash_dir(e2fsck_t ctx, ext2_ino_t ino) resort: if (fd.compress) qsort(fd.harray+2, fd.num_array-2, - sizeof(struct hash_entry), name_cmp); + sizeof(struct hash_entry), ino_cmp); else qsort(fd.harray, fd.num_array, sizeof(struct hash_entry), hash_cmp); -- 1.8.3.1