Whamcloud - gitweb
e2fsck: When optimizing non-htree directories, sort by inode number
authorTheodore Ts'o <tytso@mit.edu>
Tue, 1 Jan 2008 15:59:57 +0000 (10:59 -0500)
committerTheodore Ts'o <tytso@mit.edu>
Tue, 1 Jan 2008 15:59:57 +0000 (10:59 -0500)
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" <tytso@mit.edu>
e2fsck/rehash.c

index 3aa3c06..8e25f52 100644 (file)
@@ -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);