Whamcloud - gitweb
LU-5307 build: add support for RHEL-7 .spec file
[tools/e2fsprogs.git] / misc / tune2fs.c
index 0c1feb1..e48e641 100644 (file)
@@ -142,7 +142,9 @@ static __u32 ok_features[3] = {
        EXT2_FEATURE_INCOMPAT_FILETYPE |
                EXT3_FEATURE_INCOMPAT_EXTENTS |
                EXT4_FEATURE_INCOMPAT_FLEX_BG |
-               EXT4_FEATURE_INCOMPAT_MMP,
+               EXT4_FEATURE_INCOMPAT_EA_INODE|
+               EXT4_FEATURE_INCOMPAT_MMP|
+               EXT4_FEATURE_INCOMPAT_DIRDATA,
        /* R/O compat */
        EXT2_FEATURE_RO_COMPAT_LARGE_FILE |
                EXT4_FEATURE_RO_COMPAT_HUGE_FILE|
@@ -163,7 +165,9 @@ static __u32 clear_ok_features[3] = {
        /* Incompat */
        EXT2_FEATURE_INCOMPAT_FILETYPE |
                EXT4_FEATURE_INCOMPAT_FLEX_BG |
-               EXT4_FEATURE_INCOMPAT_MMP,
+               EXT4_FEATURE_INCOMPAT_EA_INODE|
+               EXT4_FEATURE_INCOMPAT_MMP|
+               EXT4_FEATURE_INCOMPAT_DIRDATA,
        /* R/O compat */
        EXT2_FEATURE_RO_COMPAT_LARGE_FILE |
                EXT4_FEATURE_RO_COMPAT_HUGE_FILE|
@@ -181,7 +185,6 @@ static __u32 clear_ok_features[3] = {
 static int get_journal_sb(ext2_filsys jfs, char buf[SUPERBLOCK_SIZE])
 {
        int retval;
-       int start;
        journal_superblock_t *jsb;
 
        if (!(jfs->super->s_feature_incompat &
@@ -207,8 +210,8 @@ static int get_journal_sb(ext2_filsys jfs, char buf[SUPERBLOCK_SIZE])
        return 0;
 }
 
-static void *
-journal_user(char uuid[UUID_SIZE], char s_users[JFS_USERS_SIZE], int nr_users)
+static __u8 *journal_user(__u8 uuid[UUID_SIZE], __u8 s_users[JFS_USERS_SIZE],
+                         int nr_users)
 {
        int i;
        for (i = 0; i < nr_users; i++) {
@@ -232,7 +235,6 @@ static int remove_journal_device(ext2_filsys fs)
        errcode_t       retval;
        int             commit_remove_journal = 0;
        io_manager      io_ptr;
-       int start;
 
        if (f_flag)
                commit_remove_journal = 1; /* force removal even if error */
@@ -286,8 +288,10 @@ static int remove_journal_device(ext2_filsys fs)
        jsb->s_nr_users = htonl(nr_users);
 
        /* Write back the journal superblock */
-       if ((retval = io_channel_write_blk64(jfs->io, start,
-           -SUPERBLOCK_SIZE, buf))) {
+       retval = io_channel_write_blk64(jfs->io,
+                                       ext2fs_journal_sb_start(fs->blocksize),
+                                       -SUPERBLOCK_SIZE, buf);
+       if (retval) {
                com_err(program_name, retval,
                        "while writing journal superblock.");
                goto no_valid_journal;
@@ -303,6 +307,7 @@ no_valid_journal:
                return 1;
        }
        fs->super->s_journal_dev = 0;
+       memset(fs->super->s_jnl_blocks, 0, sizeof(fs->super->s_jnl_blocks));
        uuid_clear(fs->super->s_journal_uuid);
        ext2fs_mark_super_dirty(fs);
        fputs(_("Journal removed\n"), stdout);
@@ -564,6 +569,9 @@ mmp_error:
                sb->s_mmp_update_interval = 0;
        }
 
+       if (FEATURE_ON(E2P_FEATURE_INCOMPAT, EXT4_FEATURE_INCOMPAT_EA_INODE))
+               sb->s_feature_incompat |= EXT4_FEATURE_INCOMPAT_EA_INODE;
+
        if (FEATURE_ON(E2P_FEATURE_COMPAT, EXT3_FEATURE_COMPAT_HAS_JOURNAL)) {
                /*
                 * If adding a journal flag, let the create journal
@@ -1601,6 +1609,7 @@ static int inode_scan_and_fix(ext2_filsys fs, ext2fs_block_bitmap bmap)
 
 err_out:
        ext2fs_free_mem(&block_buf);
+       ext2fs_close_inode_scan(scan);
 
        return retval;
 }
@@ -1925,12 +1934,13 @@ static int tune2fs_setup_tdb(const char *name, io_manager *io_ptr)
 }
 
 int
-fs_update_journal_user(struct ext2_super_block *sb, char old_uuid[UUID_SIZE])
+fs_update_journal_user(struct ext2_super_block *sb, __u8 old_uuid[UUID_SIZE])
 {
        int retval, nr_users, start;
        journal_superblock_t *jsb;
        ext2_filsys jfs;
-       char *j_uuid, *journal_path;
+       __u8 *j_uuid;
+       char *journal_path;
        char uuid[UUID_STR_SIZE];
        char buf[SUPERBLOCK_SIZE];
 
@@ -1953,7 +1963,8 @@ fs_update_journal_user(struct ext2_super_block *sb, char old_uuid[UUID_SIZE])
                return retval;
        }
 
-       if ((retval = get_journal_sb(jfs, buf))) {
+       retval = get_journal_sb(jfs, buf);
+       if (retval != 0) {
                if (retval == EXT2_ET_UNSUPP_FEATURE)
                        fprintf(stderr, _("%s is not a journal device.\n"),
                                journal_path);
@@ -1964,7 +1975,8 @@ fs_update_journal_user(struct ext2_super_block *sb, char old_uuid[UUID_SIZE])
        /* Find the filesystem UUID */
        nr_users = ntohl(jsb->s_nr_users);
 
-       if (!(j_uuid = journal_user(old_uuid, jsb->s_users, nr_users))) {
+       j_uuid = journal_user(old_uuid, jsb->s_users, nr_users);
+       if (j_uuid == NULL) {
                fputs(_("Filesystem's UUID not found on journal device.\n"),
                      stderr);
                return EXT2_ET_LOAD_EXT_JOURNAL;
@@ -1974,8 +1986,8 @@ fs_update_journal_user(struct ext2_super_block *sb, char old_uuid[UUID_SIZE])
 
        start = ext2fs_journal_sb_start(jfs->blocksize);
        /* Write back the journal superblock */
-       if ((retval = io_channel_write_blk64(jfs->io, start,
-           -SUPERBLOCK_SIZE, buf))) {
+       retval = io_channel_write_blk64(jfs->io, start, -SUPERBLOCK_SIZE, buf);
+       if (retval != 0) {
                com_err(program_name, retval,
                        "while writing journal superblock.");
                return retval;
@@ -2274,7 +2286,7 @@ retry_open:
                int set_csum = 0;
                dgrp_t i;
                char buf[SUPERBLOCK_SIZE];
-               char old_uuid[UUID_SIZE];
+               __u8 old_uuid[UUID_SIZE];
 
                if (sb->s_feature_ro_compat &
                    EXT4_FEATURE_RO_COMPAT_GDT_CSUM) {
@@ -2391,6 +2403,7 @@ retry_open:
                ext2fs_mark_super_dirty(fs);
                printf(_("Setting stripe width to %d\n"), stripe_width);
        }
+
        if (ext_mount_opts) {
                strncpy((char *)(fs->super->s_mount_opts), ext_mount_opts,
                        sizeof(fs->super->s_mount_opts));
@@ -2400,6 +2413,17 @@ retry_open:
                       ext_mount_opts);
                free(ext_mount_opts);
        }
+
+       /* 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: needs_recovery flag is set. You may wish\n"
+                         "replay the journal then rerun this command, or any\n"
+                         "changes may be overwritten by journal recovery.\n"));
+       }
+
        free(device_name);
        remove_error_table(&et_ext2_error_table);