Whamcloud - gitweb
e2fsck.8: minor man page fixes
[tools/e2fsprogs.git] / e2fsck / rehash.c
index 8cc36f2..4847d17 100644 (file)
@@ -89,9 +89,9 @@ struct fill_dir_struct {
 };
 
 struct hash_entry {
-       ext2_dirhash_t  hash;
-       ext2_dirhash_t  minor_hash;
-       ino_t           ino;
+       ext2_dirhash_t          hash;
+       ext2_dirhash_t          minor_hash;
+       ext2_ino_t              ino;
        struct ext2_dir_entry   *dir;
 };
 
@@ -414,6 +414,8 @@ static void mutate_name(char *str, unsigned int *len)
                        l += 2;
                else
                        l = (l+3) & ~3;
+               if (l > 255)
+                       l = 255;
                str[l-2] = '~';
                str[l-1] = '0';
                *len = l;
@@ -985,14 +987,18 @@ errcode_t e2fsck_rehash_dir(e2fsck_t ctx, ext2_ino_t ino,
 {
        ext2_filsys             fs = ctx->fs;
        errcode_t               retval;
-       struct ext2_inode       inode;
+       struct ext2_inode_large inode;
        char                    *dir_buf = 0;
        struct fill_dir_struct  fd = { NULL, NULL, 0, 0, 0, NULL,
                                       0, 0, 0, 0, 0, 0 };
        struct out_dir          outdir = { 0, 0, 0, 0 };
-       struct name_cmp_ctx name_cmp_ctx = {0, NULL};
+       struct name_cmp_ctx     name_cmp_ctx = {0, NULL};
+       __u64                   osize;
+
+       e2fsck_read_inode_full(ctx, ino, EXT2_INODE(&inode),
+                              sizeof(inode), "rehash_dir");
 
-       e2fsck_read_inode(ctx, ino, &inode, "rehash_dir");
+       osize = EXT2_I_SIZE(&inode);
 
        if (ext2fs_has_feature_inline_data(fs->super) &&
           (inode.i_flags & EXT4_INLINE_DATA_FL))
@@ -1011,7 +1017,7 @@ errcode_t e2fsck_rehash_dir(e2fsck_t ctx, ext2_ino_t ino,
        fd.ino = ino;
        fd.ctx = ctx;
        fd.buf = dir_buf;
-       fd.inode = &inode;
+       fd.inode = EXT2_INODE(&inode);
        fd.dir = ino;
        if (!ext2fs_has_feature_dir_index(fs->super) ||
            (inode.i_size / fs->blocksize) < 2)
@@ -1051,13 +1057,11 @@ retry_nohash:
        /* Sort the list */
 resort:
        if (fd.compress && fd.num_array > 1)
-               sort_r_simple(fd.harray+2, fd.num_array-2,
-                             sizeof(struct hash_entry),
-                             hash_cmp, &name_cmp_ctx);
+               sort_r(fd.harray+2, fd.num_array-2, sizeof(struct hash_entry),
+                      hash_cmp, &name_cmp_ctx);
        else
-               sort_r_simple(fd.harray, fd.num_array,
-                             sizeof(struct hash_entry),
-                             hash_cmp, &name_cmp_ctx);
+               sort_r(fd.harray, fd.num_array, sizeof(struct hash_entry),
+                      hash_cmp, &name_cmp_ctx);
 
        /*
         * Look for duplicates
@@ -1092,14 +1096,25 @@ resort:
                        goto errout;
        }
 
-       retval = write_directory(ctx, fs, &outdir, ino, &inode, fd.compress);
+       retval = write_directory(ctx, fs, &outdir, ino, EXT2_INODE(&inode),
+                                fd.compress);
        if (retval)
                goto errout;
 
+       if ((osize > EXT2_I_SIZE(&inode)) &&
+           (ino != quota_type2inum(PRJQUOTA, fs->super)) &&
+           (ino != fs->super->s_orphan_file_inum) &&
+           (ino == EXT2_ROOT_INO || ino >= EXT2_FIRST_INODE(ctx->fs->super)) &&
+           !(inode.i_flags & EXT4_EA_INODE_FL)) {
+               quota_data_sub(ctx->qctx, &inode,
+                              ino, osize - EXT2_I_SIZE(&inode));
+       }
+
        if (ctx->options & E2F_OPT_CONVERT_BMAP)
                retval = e2fsck_rebuild_extents_later(ctx, ino);
        else
-               retval = e2fsck_check_rebuild_extents(ctx, ino, &inode, pctx);
+               retval = e2fsck_check_rebuild_extents(ctx, ino,
+                                                     EXT2_INODE(&inode), pctx);
 errout:
        ext2fs_free_mem(&dir_buf);
        ext2fs_free_mem(&fd.harray);