]> git.ipfire.org Git - thirdparty/e2fsprogs.git/blobdiff - misc/tune2fs.c
Merge branch 'maint' into next
[thirdparty/e2fsprogs.git] / misc / tune2fs.c
index 4327ca0bd21c33783c87a3bbda772af561a625c3..601a6c85efb3e2d111d1673e5bc3ff369c235e5c 100644 (file)
@@ -60,7 +60,7 @@ extern int optind;
 #include "jfs_user.h"
 #include "util.h"
 #include "blkid/blkid.h"
-#include "quota/mkquota.h"
+#include "quota/quotaio.h"
 
 #include "../version.h"
 #include "nls-enable.h"
@@ -374,7 +374,7 @@ static int check_fsck_needed(ext2_filsys fs)
                return 0;
        printf("\n%s\n", _(please_fsck));
        if (mount_flags & EXT2_MF_READONLY)
-               printf(_("(and reboot afterwards!)\n"));
+               printf("%s", _("(and reboot afterwards!)\n"));
        return 1;
 }
 
@@ -387,7 +387,7 @@ static void request_dir_fsck_afterwards(ext2_filsys fs)
        fs->super->s_state &= ~EXT2_VALID_FS;
        printf("\n%s\n", _(please_dir_fsck));
        if (mount_flags & EXT2_MF_READONLY)
-               printf(_("(and reboot afterwards!)\n"));
+               printf("%s", _("(and reboot afterwards!)\n"));
 }
 
 static void request_fsck_afterwards(ext2_filsys fs)
@@ -693,7 +693,8 @@ static void rewrite_inodes(ext2_filsys fs)
                        exit(1);
                }
 
-               if (LINUX_S_ISDIR(inode->i_mode)) {
+               if (LINUX_S_ISDIR(inode->i_mode) &&
+                   ext2fs_inode_has_valid_blocks2(fs, inode)) {
                        retval = rewrite_directory(fs, ino, inode);
                        if (retval) {
                                com_err("rewrite_directory", retval,
@@ -915,8 +916,9 @@ static int update_feature_set(ext2_filsys fs, char *features)
                                "read-only.\n"), stderr);
                        return 1;
                }
-               if (sb->s_feature_incompat &
-                   EXT3_FEATURE_INCOMPAT_RECOVER) {
+               if ((sb->s_feature_incompat &
+                   EXT3_FEATURE_INCOMPAT_RECOVER) &&
+                   f_flag < 2) {
                        fputs(_("The needs_recovery flag is set.  "
                                "Please run e2fsck before clearing\n"
                                "the has_journal flag.\n"), stderr);
@@ -931,6 +933,19 @@ static int update_feature_set(ext2_filsys fs, char *features)
                                return 1;
                }
        }
+
+       if (FEATURE_ON(E2P_FEATURE_RO_INCOMPAT,
+               EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER)) {
+               if (sb->s_feature_incompat &
+                       EXT2_FEATURE_INCOMPAT_META_BG) {
+                       fputs(_("Setting filesystem feature 'sparse_super' "
+                               "not supported\nfor filesystems with "
+                               "the meta_bg feature enabled.\n"),
+                               stderr);
+                       return 1;
+               }
+       }
+
        if (FEATURE_ON(E2P_FEATURE_INCOMPAT, EXT4_FEATURE_INCOMPAT_MMP)) {
                int error;
 
@@ -1169,7 +1184,9 @@ static int add_journal(ext2_filsys fs)
                goto err;
        }
        if (journal_device) {
-               check_plausibility(journal_device);
+               if (!check_plausibility(journal_device, CHECK_BLOCK_DEV,
+                                       NULL))
+                       proceed_question(-1);
                check_mount(journal_device, 0, _("journal"));
 #ifdef CONFIG_TESTIO_DEBUG
                if (getenv("TEST_IO_FLAGS") || getenv("TEST_IO_BLOCK")) {
@@ -1192,7 +1209,7 @@ static int add_journal(ext2_filsys fs)
                fflush(stdout);
 
                retval = ext2fs_add_journal_device(fs, jfs);
-               ext2fs_close(jfs);
+               ext2fs_close_free(&jfs);
                if (retval) {
                        com_err(program_name, retval,
                                _("while adding filesystem to journal on %s"),
@@ -1270,10 +1287,6 @@ static void handle_quota_options(ext2_filsys fs)
        quota_release_context(&qctx);
 
        if ((usrquota == QOPT_ENABLE) || (grpquota == QOPT_ENABLE)) {
-               fprintf(stderr, "%s", _("\nWarning: the quota feature is still "
-                                 "under development\n"
-                                 "See https://ext4.wiki.kernel.org/"
-                                 "index.php/Quota for more information\n\n"));
                fs->super->s_feature_ro_compat |= EXT4_FEATURE_RO_COMPAT_QUOTA;
                ext2fs_mark_super_dirty(fs);
        } else if (!fs->super->s_usr_quota_inum &&
@@ -1445,7 +1458,7 @@ static void parse_tune2fs_options(int argc, char **argv)
                        open_flag |= EXT2_FLAG_RW;
                        break;
                case 'f': /* Force */
-                       f_flag = 1;
+                       f_flag++;
                        break;
                case 'g':
                        resgid = strtoul(optarg, &tmp, 0);
@@ -1881,7 +1894,7 @@ static int ext2fs_is_block_in_group(ext2_filsys fs, dgrp_t group, blk64_t blk)
 {
        blk64_t start_blk, end_blk;
        start_blk = fs->super->s_first_data_block +
-                       EXT2_BLOCKS_PER_GROUP(fs->super) * group;
+                       EXT2_GROUPS_TO_BLOCKS(fs->super, group);
        /*
         * We cannot get new block beyond end_blk for for the last block group
         * so we can check with EXT2_BLOCKS_PER_GROUP even for last block group
@@ -2499,7 +2512,7 @@ retry_open:
                        goto closefs;
                }
                if (io_ptr != io_ptr_orig) {
-                       ext2fs_close(fs);
+                       ext2fs_close_free(&fs);
                        goto retry_open;
                }
        }
@@ -2548,7 +2561,7 @@ retry_open:
                printf(_("Setting reserved blocks gid to %lu\n"), resgid);
        }
        if (i_flag) {
-               if (interval >= (1ULL << 32)) {
+               if ((unsigned long long)interval >= (1ULL << 32)) {
                        com_err(program_name, 0,
                                _("interval between checks is too big (%lu)"),
                                interval);
@@ -2582,10 +2595,18 @@ retry_open:
        }
        if (s_flag == 1) {
                if (sb->s_feature_ro_compat &
-                   EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER)
+                   EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER) {
                        fputs(_("\nThe filesystem already has sparse "
                                "superblocks.\n"), stderr);
-               else {
+               } else if (sb->s_feature_incompat &
+                       EXT2_FEATURE_INCOMPAT_META_BG) {
+                       fputs(_("\nSetting the sparse superblock flag not "
+                               "supported\nfor filesystems with "
+                               "the meta_bg feature enabled.\n"),
+                               stderr);
+                       rc = 1;
+                       goto closefs;
+               } else {
                        sb->s_feature_ro_compat |=
                                EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER;
                        sb->s_state &= ~EXT2_VALID_FS;
@@ -2595,7 +2616,7 @@ retry_open:
                }
        }
        if (s_flag == 0) {
-               fputs(_("\nClearing the sparse superflag not supported.\n"),
+               fputs(_("\nClearing the sparse superblock flag not supported.\n"),
                      stderr);
                rc = 1;
                goto closefs;
@@ -2784,5 +2805,5 @@ closefs:
                exit(1);
        }
 
-       return (ext2fs_close(fs) ? 1 : 0);
+       return (ext2fs_close_free(&fs) ? 1 : 0);
 }