]> git.ipfire.org Git - thirdparty/e2fsprogs.git/blobdiff - misc/tune2fs.c
Merge branch 'maint' into next
[thirdparty/e2fsprogs.git] / misc / tune2fs.c
index 9b53dc28e9cb90884b1c16edf8d43ade7564ec1b..0f095f4d7d51e68e47f5702a5e72000f86b15abe 100644 (file)
@@ -116,6 +116,8 @@ struct blk_move {
 
 errcode_t ext2fs_run_ext3_journal(ext2_filsys *fs);
 
+static const char *fsck_explain = N_("\nThis operation requires a freshly checked filesystem.\n");
+
 static const char *please_fsck = N_("Please run e2fsck -f on the filesystem.\n");
 static const char *please_dir_fsck =
                N_("Please run e2fsck -fD on the filesystem.\n");
@@ -135,9 +137,8 @@ static void usage(void)
                  "[-g group]\n"
                  "\t[-i interval[d|m|w]] [-j] [-J journal_options] [-l]\n"
                  "\t[-m reserved_blocks_percent] [-o [^]mount_options[,...]]\n"
-                 "\t[-p mmp_update_interval] [-r reserved_blocks_count] "
-                 "[-u user]\n"
-                 "\t[-C mount_count] [-L volume_label] [-M last_mounted_dir]\n"
+                 "\t[-r reserved_blocks_count] [-u user] [-C mount_count]\n"
+                 "\t[-L volume_label] [-M last_mounted_dir]\n"
                  "\t[-O [^]feature[,...]] [-Q quota_options]\n"
                  "\t[-E extended-option[,...]] [-T last_check_time] "
                  "[-U UUID]\n\t[-I new_inode_size] [-z undo_file] device\n"),
@@ -169,7 +170,8 @@ static __u32 ok_features[3] = {
                EXT4_FEATURE_RO_COMPAT_QUOTA |
                EXT4_FEATURE_RO_COMPAT_METADATA_CSUM |
                EXT4_FEATURE_RO_COMPAT_READONLY |
-               EXT4_FEATURE_RO_COMPAT_PROJECT
+               EXT4_FEATURE_RO_COMPAT_PROJECT |
+               EXT4_FEATURE_RO_COMPAT_VERITY
 };
 
 static __u32 clear_ok_features[3] = {
@@ -421,7 +423,8 @@ static void check_fsck_needed(ext2_filsys fs, const char *prompt)
        if (!(fs->super->s_state & EXT2_VALID_FS) ||
            (fs->super->s_state & EXT2_ERROR_FS) ||
            (fs->super->s_lastcheck < fs->super->s_mtime)) {
-               printf("\n%s\n", _(please_fsck));
+               puts(_(fsck_explain));
+               puts(_(please_fsck));
                if (mount_flags & EXT2_MF_READONLY)
                        printf("%s", _("(and reboot afterwards!)\n"));
                exit(1);
@@ -443,7 +446,8 @@ static void request_dir_fsck_afterwards(ext2_filsys fs)
                return;
        fsck_requested++;
        fs->super->s_state &= ~EXT2_VALID_FS;
-       printf("\n%s\n", _(please_dir_fsck));
+       puts(_(fsck_explain));
+       puts(_(please_dir_fsck));
        if (mount_flags & EXT2_MF_READONLY)
                printf("%s", _("(and reboot afterwards!)\n"));
 }
@@ -463,9 +467,6 @@ static void request_fsck_afterwards(ext2_filsys fs)
 
 static void convert_64bit(ext2_filsys fs, int direction)
 {
-       if (!direction)
-               return;
-
        /*
         * Is resize2fs going to demand a fsck run? Might as well tell the
         * user now.
@@ -753,7 +754,8 @@ static void update_ea_inode_hash(struct rewrite_context *ctx, ext2_ino_t ino,
        if (retval)
                fatal_err(retval, "close ea_inode");
 
-       hash = ext2fs_crc32c_le(ctx->fs->csum_seed, ctx->ea_buf, inode->i_size);
+       hash = ext2fs_crc32c_le(ctx->fs->csum_seed,
+                               (unsigned char *) ctx->ea_buf, inode->i_size);
        ext2fs_set_ea_inode_hash(inode, hash);
 }
 
@@ -802,7 +804,7 @@ static void update_inline_xattr_hashes(struct rewrite_context *ctx,
 }
 
 static void update_block_xattr_hashes(struct rewrite_context *ctx,
-                                     void *block_buf)
+                                     char *block_buf)
 {
        struct ext2_ext_attr_header *header;
        struct ext2_ext_attr_entry *start, *end;
@@ -925,8 +927,10 @@ static void rewrite_inodes(ext2_filsys fs)
                        if (!ino)
                                break;
 
-                       if (pass == 1 && (inode->i_flags & EXT4_EA_INODE_FL) ||
-                           pass == 2 && !(inode->i_flags & EXT4_EA_INODE_FL))
+                       if (((pass == 1) &&
+                            (inode->i_flags & EXT4_EA_INODE_FL)) ||
+                           ((pass == 2) &&
+                            !(inode->i_flags & EXT4_EA_INODE_FL)))
                                rewrite_one_inode(&ctx, ino, inode);
                } while (ino);
 
@@ -1418,6 +1422,11 @@ mmp_error:
 
        if (FEATURE_ON(E2P_FEATURE_RO_INCOMPAT,
                       EXT4_FEATURE_RO_COMPAT_PROJECT)) {
+               if (fs->super->s_inode_size == EXT2_GOOD_OLD_INODE_SIZE) {
+                       fprintf(stderr, _("Cannot enable project feature; "
+                                         "inode size too small.\n"));
+                       exit(1);
+               }
                Q_flag = 1;
                quota_enable[PRJQUOTA] = QOPT_ENABLE;
        }
@@ -1469,16 +1478,18 @@ mmp_error:
 
                uuid_seed = ext2fs_crc32c_le(~0, fs->super->s_uuid,
                                        sizeof(fs->super->s_uuid));
-               if (fs->super->s_checksum_seed != uuid_seed &&
-                   (mount_flags & EXT2_MF_MOUNTED)) {
-                       fputs(_("UUID has changed since enabling "
-                               "metadata_csum.  Filesystem must be unmounted "
-                               "\nto safely rewrite all metadata to "
-                               "match the new UUID.\n"), stderr);
-                       return 1;
+               if (fs->super->s_checksum_seed != uuid_seed) {
+                       if (mount_flags & (EXT2_MF_BUSY|EXT2_MF_MOUNTED)) {
+                               fputs(_("UUID has changed since enabling "
+               "metadata_csum.  Filesystem must be unmounted "
+               "\nto safely rewrite all metadata to match the new UUID.\n"),
+                                     stderr);
+                               return 1;
+                       }
+                       check_fsck_needed(fs, _("Recalculating checksums "
+                                               "could take some time."));
+                       rewrite_checksums = 1;
                }
-
-               rewrite_checksums = 1;
        }
 
        if (sb->s_rev_level == EXT2_GOOD_OLD_REV &&
@@ -1605,6 +1616,13 @@ static void handle_quota_options(ext2_filsys fs)
                /* Nothing to do. */
                return;
 
+       if (quota_enable[PRJQUOTA] == QOPT_ENABLE &&
+           fs->super->s_inode_size == EXT2_GOOD_OLD_INODE_SIZE) {
+               fprintf(stderr, _("Cannot enable project quota; "
+                                 "inode size too small.\n"));
+               exit(1);
+       }
+
        for (qtype = 0; qtype < MAXQUOTAS; qtype++) {
                if (quota_enable[qtype] == QOPT_ENABLE)
                        qtype_bits |= 1 << qtype;
@@ -2101,6 +2119,10 @@ static int parse_extended_opts(ext2_filsys fs, const char *opts)
                               intv);
                        fs->super->s_mmp_update_interval = intv;
                        ext2fs_mark_super_dirty(fs);
+               } else if (!strcmp(token, "force_fsck")) {
+                       fs->super->s_state |= EXT2_ERROR_FS;
+                       printf(_("Setting filesystem error flag to force fsck.\n"));
+                       ext2fs_mark_super_dirty(fs);
                } else if (!strcmp(token, "test_fs")) {
                        fs->super->s_flags |= EXT2_FLAGS_TEST_FILESYS;
                        printf("Setting test filesystem flag\n");
@@ -2180,8 +2202,10 @@ static int parse_extended_opts(ext2_filsys fs, const char *opts)
                        "\tclear_mmp\n"
                        "\thash_alg=<hash algorithm>\n"
                        "\tmount_opts=<extended default mount options>\n"
+                       "\tmmp_update_interval=<mmp update interval in seconds>\n"
                        "\tstride=<RAID per-disk chunk size in blocks>\n"
                        "\tstripe_width=<RAID stride*data disks in blocks>\n"
+                       "\tforce_fsck\n"
                        "\ttest_fs\n"
                        "\t^test_fs\n"));
                free(buf);
@@ -3005,6 +3029,36 @@ retry_open:
                rc = 1;
                goto closefs;
        }
+
+#ifdef NO_RECOVERY
+       /* Warn if file system needs recovery and it is opened for writing. */
+       if ((open_flag & EXT2_FLAG_RW) && !(mount_flags & EXT2_MF_MOUNTED) &&
+           (sb->s_feature_compat & EXT3_FEATURE_COMPAT_HAS_JOURNAL) &&
+           (sb->s_feature_incompat & EXT3_FEATURE_INCOMPAT_RECOVER)) {
+               fprintf(stderr,
+_("Warning: The journal is dirty. You may wish to replay the journal like:\n\n"
+  "\te2fsck -E journal_only %s\n\n"
+  "then rerun this command.  Otherwise, any changes made may be overwritten\n"
+  "by journal recovery.\n"), device_name);
+       }
+#else
+       /* Recover the journal if possible. */
+       if ((open_flag & EXT2_FLAG_RW) && !(mount_flags & (EXT2_MF_BUSY | EXT2_MF_MOUNTED)) &&
+           ext2fs_has_feature_journal_needs_recovery(fs->super)) {
+               errcode_t err;
+
+               printf(_("Recovering journal.\n"));
+               err = ext2fs_run_ext3_journal(&fs);
+               if (err) {
+                       com_err("tune2fs", err, "while recovering journal.\n");
+                       printf(_("Please run e2fsck -fy %s.\n"), argv[1]);
+                       if (fs)
+                               ext2fs_close_free(&fs);
+                       exit(1);
+               }
+       }
+#endif
+
        /* Normally we only need to write out the superblock */
        fs->flags |= EXT2_FLAG_SUPER_ONLY;
 
@@ -3309,35 +3363,6 @@ retry_open:
                free(ext_mount_opts);
        }
 
-#ifdef NO_RECOVERY
-       /* Warn if file system needs recovery and it is opened for writing. */
-       if ((open_flag & EXT2_FLAG_RW) && !(mount_flags & EXT2_MF_MOUNTED) &&
-           (sb->s_feature_compat & EXT3_FEATURE_COMPAT_HAS_JOURNAL) &&
-           (sb->s_feature_incompat & EXT3_FEATURE_INCOMPAT_RECOVER)) {
-               fprintf(stderr,
-_("Warning: The journal is dirty. You may wish to replay the journal like:\n\n"
-  "\te2fsck -E journal_only %s\n\n"
-  "then rerun this command.  Otherwise, any changes made may be overwritten\n"
-  "by journal recovery.\n"), device_name);
-       }
-#else
-       /* Recover the journal if possible. */
-       if ((open_flag & EXT2_FLAG_RW) && !(mount_flags & EXT2_MF_MOUNTED) &&
-           ext2fs_has_feature_journal_needs_recovery(fs->super)) {
-               errcode_t err;
-
-               printf(_("Recovering journal.\n"));
-               err = ext2fs_run_ext3_journal(&fs);
-               if (err) {
-                       com_err("tune2fs", err, "while recovering journal.\n");
-                       printf(_("Please run e2fsck -fy %s.\n"), argv[1]);
-                       goto closefs;
-               }
-               ext2fs_clear_feature_journal_needs_recovery(fs->super);
-               ext2fs_mark_super_dirty(fs);
-       }
-#endif
-
        free(device_name);
        remove_error_table(&et_ext2_error_table);
 
@@ -3349,6 +3374,7 @@ closefs:
 #endif
        }
 
-       convert_64bit(fs, feature_64bit);
+       if (feature_64bit)
+               convert_64bit(fs, feature_64bit);
        return (ext2fs_close_free(&fs) ? 1 : 0);
 }