Whamcloud - gitweb
Rename the feature "fname_encoding" to be "casefold".
[tools/e2fsprogs.git] / misc / tune2fs.c
index 0f095f4..7d2d38d 100644 (file)
@@ -292,6 +292,12 @@ static int remove_journal_device(ext2_filsys fs)
        jsb = (journal_superblock_t *) buf;
        /* Find the filesystem UUID */
        nr_users = ntohl(jsb->s_nr_users);
+       if (nr_users > JFS_USERS_MAX) {
+               fprintf(stderr, _("Journal superblock is corrupted, nr_users\n"
+                                "is too high (%d).\n"), nr_users);
+               commit_remove_journal = 1;
+               goto no_valid_journal;
+       }
 
        if (!journal_user(fs->super->s_uuid, jsb->s_users, nr_users)) {
                fputs(_("Filesystem's UUID not found on journal device.\n"),
@@ -491,64 +497,6 @@ static void convert_64bit(ext2_filsys fs, int direction)
                fprintf(stderr, _("' to disable 64-bit mode.\n"));
 }
 
-/* Rewrite extents */
-static errcode_t rewrite_extents(ext2_filsys fs, ext2_ino_t ino,
-                                struct ext2_inode *inode)
-{
-       ext2_extent_handle_t    handle;
-       struct ext2fs_extent    extent;
-       errcode_t               errcode;
-       struct ext2_extent_info info;
-
-       if (!(inode->i_flags & EXT4_EXTENTS_FL) ||
-           !ext2fs_has_feature_metadata_csum(fs->super))
-               return 0;
-
-       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;
-}
-
 /*
  * Rewrite directory blocks with checksums
  */
@@ -843,7 +791,7 @@ static void rewrite_one_inode(struct rewrite_context *ctx, ext2_ino_t ino,
        if (retval)
                fatal_err(retval, "while writing inode");
 
-       retval = rewrite_extents(ctx->fs, ino, inode);
+       retval = ext2fs_fix_extents_checksums(ctx->fs, ino, inode);
        if (retval)
                fatal_err(retval, "while rewriting extents");
 
@@ -1453,6 +1401,12 @@ mmp_error:
        }
 
        if (FEATURE_ON(E2P_FEATURE_INCOMPAT, EXT4_FEATURE_INCOMPAT_ENCRYPT)) {
+               if (ext2fs_has_feature_casefold(sb)) {
+                       fputs(_("Cannot enable encrypt feature on filesystems "
+                               "with the encoding feature enabled.\n"),
+                             stderr);
+                       return 1;
+               }
                fs->super->s_encrypt_algos[0] =
                        EXT4_ENCRYPTION_MODE_AES_256_XTS;
                fs->super->s_encrypt_algos[1] =
@@ -2855,6 +2809,11 @@ fs_update_journal_user(struct ext2_super_block *sb, __u8 old_uuid[UUID_SIZE])
        jsb = (journal_superblock_t *) buf;
        /* Find the filesystem UUID */
        nr_users = ntohl(jsb->s_nr_users);
+       if (nr_users > JFS_USERS_MAX) {
+               fprintf(stderr, _("Journal superblock is corrupted, nr_users\n"
+                                "is too high (%d).\n"), nr_users);
+               return EXT2_ET_CORRUPT_JOURNAL_SB;
+       }
 
        j_uuid = journal_user(old_uuid, jsb->s_users, nr_users);
        if (j_uuid == NULL) {
@@ -3056,6 +3015,7 @@ _("Warning: The journal is dirty. You may wish to replay the journal like:\n\n"
                                ext2fs_close_free(&fs);
                        exit(1);
                }
+               sb = fs->super;
        }
 #endif
 
@@ -3214,6 +3174,15 @@ _("Warning: The journal is dirty. You may wish to replay the journal like:\n\n"
                char buf[SUPERBLOCK_SIZE] __attribute__ ((aligned(8)));
                __u8 old_uuid[UUID_SIZE];
 
+               if (!ext2fs_has_feature_csum_seed(fs->super) &&
+                   (ext2fs_has_feature_metadata_csum(fs->super) ||
+                    ext2fs_has_feature_ea_inode(fs->super))) {
+                       check_fsck_needed(fs,
+                               _("Setting the UUID on this "
+                                 "filesystem could take some time."));
+                       rewrite_checksums = 1;
+               }
+
                if (ext2fs_has_group_desc_csum(fs)) {
                        /*
                         * Changing the UUID on a metadata_csum FS requires
@@ -3234,10 +3203,6 @@ _("Warning: The journal is dirty. You may wish to replay the journal like:\n\n"
                                try_confirm_csum_seed_support();
                                exit(1);
                        }
-                       if (!ext2fs_has_feature_csum_seed(fs->super))
-                               check_fsck_needed(fs,
-                                       _("Setting UUID on a checksummed "
-                                         "filesystem could take some time."));
 
                        /*
                         * Determine if the block group checksums are
@@ -3295,10 +3260,6 @@ _("Warning: The journal is dirty. You may wish to replay the journal like:\n\n"
                }
 
                ext2fs_mark_super_dirty(fs);
-               if (!ext2fs_has_feature_csum_seed(fs->super) &&
-                   (ext2fs_has_feature_metadata_csum(fs->super) ||
-                    ext2fs_has_feature_ea_inode(fs->super)))
-                       rewrite_checksums = 1;
        }
 
        if (I_flag) {