]> git.ipfire.org Git - thirdparty/e2fsprogs.git/blobdiff - e2fsck/pass2.c
e2fsck: reduce memory usage for many directories
[thirdparty/e2fsprogs.git] / e2fsck / pass2.c
index a7d9c47dbe8e914ec33ee249c80d63ffa50ff1a0..b691417e04d4da3d4ef533959784f86c803acfe1 100644 (file)
@@ -71,8 +71,8 @@ static int allocate_dir_block(e2fsck_t ctx,
                              struct ext2_db_entry2 *dir_blocks_info,
                              char *buf, struct problem_context *pctx);
 static void clear_htree(e2fsck_t ctx, ext2_ino_t ino);
-static int htree_depth(struct dx_dir_info *dx_dir,
-                      struct dx_dirblock_info *dx_db);
+static short htree_depth(struct dx_dir_info *dx_dir,
+                        struct dx_dirblock_info *dx_db);
 static EXT2_QSORT_TYPE special_dir_block_cmp(const void *a, const void *b);
 
 struct check_dir_struct {
@@ -131,7 +131,8 @@ void e2fsck_pass2(e2fsck_t ctx)
        struct dx_dir_info      *dx_dir;
        struct dx_dirblock_info *dx_db;
        int                     b;
-       int                     i, depth;
+       ext2_ino_t              i;
+       short                   depth;
        problem_t               code;
        int                     bad_dir;
        int (*check_dir_func)(ext2_filsys fs,
@@ -310,10 +311,10 @@ cleanup:
 }
 
 #define MAX_DEPTH 32000
-static int htree_depth(struct dx_dir_info *dx_dir,
-                      struct dx_dirblock_info *dx_db)
+static short htree_depth(struct dx_dir_info *dx_dir,
+                        struct dx_dirblock_info *dx_db)
 {
-       int     depth = 0;
+       short depth = 0;
 
        while (dx_db->type != DX_DIRBLOCK_ROOT && depth < MAX_DEPTH) {
                dx_db = &dx_dir->dx_block[dx_db->parent];
@@ -586,10 +587,10 @@ static void parse_int_node(ext2_filsys fs,
 #ifdef DX_DEBUG
                printf("Root node dump:\n");
                printf("\t Reserved zero: %u\n", root->reserved_zero);
-               printf("\t Hash Version: %d\n", root->hash_version);
-               printf("\t Info length: %d\n", root->info_length);
-               printf("\t Indirect levels: %d\n", root->indirect_levels);
-               printf("\t Flags: %d\n", root->unused_flags);
+               printf("\t Hash Version: %u\n", root->hash_version);
+               printf("\t Info length: %u\n", root->info_length);
+               printf("\t Indirect levels: %u\n", root->indirect_levels);
+               printf("\t Flags: %x\n", root->unused_flags);
 #endif
 
                ent = (struct ext2_dx_entry *) (block_buf + 24 + root->info_length);
@@ -934,6 +935,7 @@ static int check_dir_block(ext2_filsys fs,
        int     encrypted = 0;
        size_t  max_block_size;
        int     hash_flags = 0;
+       static char *eop_read_dirblock = NULL;
 
        cd = (struct check_dir_struct *) priv_data;
        ibuf = buf = cd->buf;
@@ -980,7 +982,8 @@ static int check_dir_block(ext2_filsys fs,
         * very large and then the files are deleted. For now, all that is
         * needed is to avoid e2fsck filling in these holes as part of
         * feature flag. */
-       if (db->blk == 0 && ext2fs_has_feature_largedir(fs->super))
+       if (db->blk == 0 && ext2fs_has_feature_largedir(fs->super) &&
+           !ext2fs_has_feature_inline_data(fs->super))
                return 0;
 
        if (db->blk == 0 && !inline_data_size) {
@@ -1003,7 +1006,9 @@ static int check_dir_block(ext2_filsys fs,
               db->blockcnt, ino);
 #endif
 
-       ehandler_operation(_("reading directory block"));
+       if (!eop_read_dirblock)
+               eop_read_dirblock = (char *) _("reading directory block");
+       ehandler_operation(eop_read_dirblock);
        if (inline_data_size) {
                memset(buf, 0, fs->blocksize - inline_data_size);
                cd->pctx.errcode = ext2fs_inline_data_get(fs, ino, 0, buf, 0);