Whamcloud - gitweb
debian: drop "new-essential-package" lintian override
[tools/e2fsprogs.git] / resize / resize2fs.c
index 0bd325b..c2e1047 100644 (file)
@@ -756,7 +756,7 @@ retry:
         */
        new_inodes =(unsigned long long) fs->super->s_inodes_per_group * fs->group_desc_count;
        if (new_inodes > ~0U) {
-               fprintf(stderr, _("inodes (%llu) must be less than %u"),
+               fprintf(stderr, _("inodes (%llu) must be less than %u\n"),
                                   new_inodes, ~0U);
                return EXT2_ET_TOO_MANY_INODES;
        }
@@ -920,8 +920,9 @@ retry:
        group_block = ext2fs_group_first_block2(fs,
                                                old_fs->group_desc_count);
        csum_flag = ext2fs_has_group_desc_csum(fs);
-       if (!getenv("RESIZE2FS_FORCE_ITABLE_INIT") &&
-           access("/sys/fs/ext4/features/lazy_itable_init", F_OK) == 0)
+       if (getenv("RESIZE2FS_FORCE_LAZY_ITABLE_INIT") ||
+           (!getenv("RESIZE2FS_FORCE_ITABLE_INIT") &&
+            access("/sys/fs/ext4/features/lazy_itable_init", F_OK) == 0))
                lazy_itable_init = 1;
        if (ext2fs_has_feature_meta_bg(fs->super))
                old_desc_blocks = fs->super->s_first_meta_bg;
@@ -1926,59 +1927,6 @@ out:
        return err;
 }
 
-/* Rewrite extents */
-static errcode_t rewrite_extents(ext2_filsys fs, ext2_ino_t ino)
-{
-       ext2_extent_handle_t    handle;
-       struct ext2fs_extent    extent;
-       errcode_t               errcode;
-       struct ext2_extent_info info;
-
-       errcode = ext2fs_extent_open(fs, ino, &handle);
-       if (errcode)
-               return errcode;
-
-       errcode = ext2fs_extent_get(handle, EXT2_EXTENT_ROOT, &extent);
-       if (errcode)
-               goto out;
-
-       do {
-               errcode = ext2fs_extent_get_info(handle, &info);
-               if (errcode)
-                       break;
-
-               /*
-                * If this is the first extent in an extent block that we
-                * haven't visited, rewrite the extent to force the ETB
-                * checksum to be rewritten.
-                */
-               if (info.curr_entry == 1 && info.curr_level != 0 &&
-                   !(extent.e_flags & EXT2_EXTENT_FLAGS_SECOND_VISIT)) {
-                       errcode = ext2fs_extent_replace(handle, 0, &extent);
-                       if (errcode)
-                               break;
-               }
-
-               /* Skip to the end of a block of leaf nodes */
-               if (extent.e_flags & EXT2_EXTENT_FLAGS_LEAF) {
-                       errcode = ext2fs_extent_get(handle,
-                                                   EXT2_EXTENT_LAST_SIB,
-                                                   &extent);
-                       if (errcode)
-                               break;
-               }
-
-               errcode = ext2fs_extent_get(handle, EXT2_EXTENT_NEXT, &extent);
-       } while (errcode == 0);
-
-out:
-       /* Ok if we run off the end */
-       if (errcode == EXT2_ET_EXTENT_NO_NEXT)
-               errcode = 0;
-       ext2fs_extent_free(handle);
-       return errcode;
-}
-
 static void quiet_com_err_proc(const char *whoami EXT2FS_ATTR((unused)),
                               errcode_t code EXT2FS_ATTR((unused)),
                               const char *fmt EXT2FS_ATTR((unused)),
@@ -1991,7 +1939,6 @@ static int fix_ea_entries(ext2_extent imap, struct ext2_ext_attr_entry *entry,
 {
        int modified = 0;
        ext2_ino_t new_ino;
-       errcode_t retval;
 
        while (entry < end && !EXT2_EXT_IS_LAST_ENTRY(entry)) {
                if (entry->e_value_inum > last_ino) {
@@ -2061,10 +2008,12 @@ static errcode_t fix_ea_inode_refs(ext2_resize_t rfs, struct ext2_inode *inode,
        int             inode_size = EXT2_INODE_SIZE(fs->super);
        blk64_t         blk;
        int             modified;
-       struct blk_cache blk_cache = { 0 };
+       struct blk_cache blk_cache;
        struct ext2_ext_attr_header *header;
        errcode_t               retval;
 
+       memset(&blk_cache, 0, sizeof(blk_cache));
+
        header = (struct ext2_ext_attr_header *)block_buf;
 
        retval = ext2fs_open_inode_scan(fs, 0, &scan);
@@ -2242,31 +2191,20 @@ remap_blocks:
                if (retval)
                        goto errout;
 
-               /* Rewrite extent block checksums with new inode number */
-               if (ext2fs_has_feature_metadata_csum(rfs->old_fs->super) &&
-                   (inode->i_flags & EXT4_EXTENTS_FL)) {
-                       rfs->old_fs->flags |= EXT2_FLAG_IGNORE_CSUM_ERRORS;
-                       retval = rewrite_extents(rfs->old_fs, new_inode);
-                       rfs->old_fs->flags &= ~EXT2_FLAG_IGNORE_CSUM_ERRORS;
-                       if (retval)
-                               goto errout;
-               }
-
                /*
                 * Update inodes to point to new blocks; schedule directory
                 * blocks for inode remapping.  Need to write out dir blocks
                 * with new inode numbers if we have metadata_csum enabled.
                 */
+               rfs->old_fs->flags |= EXT2_FLAG_IGNORE_CSUM_ERRORS;
                if (ext2fs_inode_has_valid_blocks2(rfs->old_fs, inode) &&
                    (rfs->bmap || pb.is_dir)) {
                        pb.ino = new_inode;
                        pb.old_ino = ino;
                        pb.has_extents = inode->i_flags & EXT4_EXTENTS_FL;
-                       rfs->old_fs->flags |= EXT2_FLAG_IGNORE_CSUM_ERRORS;
                        retval = ext2fs_block_iterate3(rfs->old_fs,
                                                       new_inode, 0, block_buf,
                                                       process_block, &pb);
-                       rfs->old_fs->flags &= ~EXT2_FLAG_IGNORE_CSUM_ERRORS;
                        if (retval)
                                goto errout;
                        if (pb.error) {
@@ -2281,6 +2219,15 @@ remap_blocks:
                        if (retval)
                                goto errout;
                }
+
+               /* Fix up extent block checksums with the new inode number */
+               if (ext2fs_has_feature_metadata_csum(rfs->old_fs->super) &&
+                   (inode->i_flags & EXT4_EXTENTS_FL)) {
+                       retval = ext2fs_fix_extents_checksums(rfs->old_fs,
+                                                             new_inode, NULL);
+                       if (retval)
+                               goto errout;
+               }
        }
 
        if (update_ea_inode_refs &&
@@ -2294,6 +2241,7 @@ remap_blocks:
 
 errout:
        reset_com_err_hook();
+       rfs->old_fs->flags &= ~EXT2_FLAG_IGNORE_CSUM_ERRORS;
        if (rfs->bmap) {
                ext2fs_free_extent_table(rfs->bmap);
                rfs->bmap = 0;