]> git.ipfire.org Git - thirdparty/e2fsprogs.git/commitdiff
Don't write changes to the backup superblocks by default
authorTheodore Ts'o <tytso@mit.edu>
Mon, 18 Jun 2007 22:26:50 +0000 (18:26 -0400)
committerTheodore Ts'o <tytso@mit.edu>
Mon, 18 Jun 2007 22:26:50 +0000 (18:26 -0400)
This patch changes ext2fs_open() to set EXT2_FLAG_MASTER_SB_ONLY by
default.  This avoids some problems in e2fsck (reported by Jim Garlick)
where a corrupt journal can end up writing the bad superblock to the
backups.  In general, only e2fsck (after the filesystem is clean),
tune2fs, and resize2fs should change the backup superblocks by default.
Most callers of ext2fs_open() should not be touching anything where the
backups should be touched.  So let's change the defaults to avoid
potential problems.

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
e2fsck/ChangeLog
e2fsck/journal.c
e2fsck/unix.c
lib/ext2fs/ChangeLog
lib/ext2fs/openfs.c
misc/ChangeLog
misc/tune2fs.c
resize/ChangeLog
resize/resize2fs.c

index fa40d282d75da55e784f44429036289018c5e34e..3fbeef2dd5ae511f2cfc633b006e7c9888338439 100644 (file)
@@ -1,3 +1,10 @@
+2007-06-18  Theodore Tso  <tytso@mit.edu>
+
+       * journal.c (e2fsck_run_ext3_journal), unix.c (main): Explicitly
+               add the EXT2_FLAG_MASTER_SB_ONLY flag to make sure we
+               won't write out the backup superblocks until we're sure
+               that we want write them out.
+
 2007-06-04  Theodore Tso  <tytso@mit.edu>
 
        * super.c (check_super_block, e2fsck_get_device_size), 
index f1e3ad02aece5e38cd0b01494bcd7045903fb7ef..519df487cf0144c48ebf49bb61516365e8a9025a 100644 (file)
@@ -832,6 +832,7 @@ int e2fsck_run_ext3_journal(e2fsck_t ctx)
        }
        ctx->fs->priv_data = ctx;
        ctx->fs->now = ctx->now;
+       ctx->fs->flags |= EXT2_FLAG_MASTER_SB_ONLY;
 
        /* Set the superblock flags */
        e2fsck_clear_recover(ctx, recover_retval);
index 79578944ad2e003f0e8e9965cf18869dd09f82a1..72091f882c79b2a6e79c7d57f0292a79d1900fa1 100644 (file)
@@ -981,6 +981,18 @@ restart:
                        fix_problem(ctx, PR_0_SB_CORRUPT, &pctx);
                fatal_error(ctx, 0);
        }
+       /*
+        * We only update the master superblock because (a) paranoia;
+        * we don't want to corrupt the backup superblocks, and (b) we
+        * don't need to update the mount count and last checked
+        * fields in the backup superblock (the kernel doesn't update
+        * the backup superblocks anyway).  With newer versions of the
+        * library this flag is set by ext2fs_open2(), but we set this
+        * here just to be sure.  (No, we don't support e2fsck running
+        * with some other libext2fs than the one that it was shipped
+        * with, but just in case....)
+        */
+       fs->flags |= EXT2_FLAG_MASTER_SB_ONLY;
 
        if (!(ctx->flags & E2F_FLAG_GOT_DEVSIZE)) {
                __u32 blocksize = EXT2_BLOCK_SIZE(fs->super);
@@ -1127,15 +1139,6 @@ restart:
            !(ctx->options & E2F_OPT_READONLY))
                ext2fs_mark_super_dirty(fs);
 
-       /*
-        * We only update the master superblock because (a) paranoia;
-        * we don't want to corrupt the backup superblocks, and (b) we
-        * don't need to update the mount count and last checked
-        * fields in the backup superblock (the kernel doesn't
-        * update the backup superblocks anyway).
-        */
-       fs->flags |= EXT2_FLAG_MASTER_SB_ONLY;
-
        ehandler_init(fs->io);
 
        if (ctx->superblock)
index 9eb5ef9647c8ee94abddb72e3a6a9d753441f4a3..02604b50862fc6b251648f539abe5b0e8a295851 100644 (file)
@@ -1,3 +1,10 @@
+2007-06-12  Theodore Tso  <tytso@mit.edu>
+
+       * openfs.c (ext2fs_open2): We now set EXT2_FLAG_MASTER_SB_ONLY
+               when we open a filesystem.  Applications that want to
+               write changes to the backup superblocks need to explicitly
+               clear this flag.
+
 2007-05-31  Theodore Tso  <tytso@mit.edu>
 
        * tst_super_size.c (main): Add sanity check to make sure the
index ea1037304f830fb448e1ebde03d2d1f015431245..55cc077100b15a9cbb87c3eca83c67a67a23dfb1 100644 (file)
@@ -101,6 +101,8 @@ errcode_t ext2fs_open2(const char *name, const char *io_options,
        memset(fs, 0, sizeof(struct struct_ext2_filsys));
        fs->magic = EXT2_ET_MAGIC_EXT2FS_FILSYS;
        fs->flags = flags;
+       /* don't overwrite sb backups unless flag is explicitly cleared */
+       fs->flags |= EXT2_FLAG_MASTER_SB_ONLY;
        fs->umask = 022;
        retval = ext2fs_get_mem(strlen(name)+1, &fs->device_name);
        if (retval)
index 5b680c5f938b1640367ab6426c2e77a3f1a828a0..d1b4b79514cdd7a93ec8f21528eaaa7b4db87460 100644 (file)
@@ -1,3 +1,9 @@
+2007-06-12  Theodore Tso  <tytso@mit.edu>
+
+       * tune2fs.c (main): Clear the EXT2_FLAG_MASTER_SB_ONLY flag
+               because we want tune2fs changes to get written to the
+               backup blocks.
+
 2007-06-04  Theodore Tso  <tytso@mit.edu>
 
        * badblocks.c (main): Fix error checking of the last-block and
index 967b58935799d1a0957fed9a3d71b0d1eaf42669..833b994300e76b73455c8dc9483ade84e0b2c036 100644 (file)
@@ -780,6 +780,7 @@ int main (int argc, char ** argv)
                exit(1);
        }
        sb = fs->super;
+       fs->flags &= ~EXT2_FLAG_MASTER_SB_ONLY;
        if (print_label) {
                /* For e2label emulation */
                printf("%.*s\n", (int) sizeof(sb->s_volume_name),
index e1f616bfafde847901307ed9002bfe01f95e2748..9c8a8c21e7987136ac009cb3b55f5cbaa5583ef9 100644 (file)
@@ -1,3 +1,9 @@
+2007-06-12  Theodore Tso  <tytso@mit.edu>
+
+       * resize2fs.c (resize_fs): Clear the EXT2_FLAG_MASTER_SB_ONLY flag
+               to make sure the superblock changes are written out to the
+               backup superblocks.
+
 2007-05-22  Theodore Tso  <tytso@mit.edu>
 
        * sim_progress.c (ext2fs_progress_init): Fix type-punning warning.
index a25cb05afae0ab8993013e02006bb6d848d3d320..0d6a082416656bb9880dec10abd0c659fd312a08 100644 (file)
@@ -138,6 +138,7 @@ errcode_t resize_fs(ext2_filsys fs, blk_t *new_size, int flags,
        if (retval)
                goto errout;
 
+       rfs->new_fs->flags &= ~EXT2_FLAG_MASTER_SB_ONLY;        
        retval = ext2fs_close(rfs->new_fs);
        if (retval)
                goto errout;