All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ted Ts'o <tytso@mit.edu>
To: Akira Fujita <a-fujita@rs.jp.nec.com>
Cc: ext4 development <linux-ext4@vger.kernel.org>
Subject: Re: [PATCH 1/2] e2fsprogs: fix data lost with mke2fs -S
Date: Thu, 16 Feb 2012 23:20:38 -0500	[thread overview]
Message-ID: <20120217042038.GA9319@thunk.org> (raw)
In-Reply-To: <4EF2EA9E.9080500@rs.jp.nec.com>

On Thu, Dec 22, 2011 at 05:30:22PM +0900, Akira Fujita wrote:
> If we run the mke2fs with the -S option and the uninit_bg feature
> simultaneously, the mke2fs marks blockgroups as uninitialized.
> The e2fsck which run immediately after the mke2fs
> removes all of the files.
> 
> To avoid this, the patch prohibits user from
> setting the -S option and the uninit_bg feature simultaneously.

This is not the best fix.  The best fix is to clear the itable_unused
fields in the block group descriptors if mke2fs -S is set.  See below
for what I have in my tree.

					- Ted

commit 9b6a158524fe82202bef6d0d8a101b47e6c02b64
Author: Theodore Ts'o <tytso@mit.edu>
Date:   Thu Feb 16 23:16:34 2012 -0500

    mke2fs: allow file systems w/ uninit_bg to be recovered with mke2fs -S
    
    The command mke2fs -S is used as a last ditch recovery command to
    write new superblock and block group descriptors, but _not_ to destroy
    the inode table in hopes of recovering from a badly corrupted file
    system.  If the uninit_bg feature is enabled, we need to make sure to
    clear the unused inodes count field in the block group descriptors or
    else e2fsck -fy will leave the file system completely empty.
    
    Thanks to Akira Fujita for reporting this problem.
    
    Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>

diff --git a/misc/mke2fs.c b/misc/mke2fs.c
index 08789c4..c70c1b4 100644
--- a/misc/mke2fs.c
+++ b/misc/mke2fs.c
@@ -2434,6 +2434,17 @@ int main (int argc, char *argv[])
 	if (super_only) {
 		fs->super->s_state |= EXT2_ERROR_FS;
 		fs->flags &= ~(EXT2_FLAG_IB_DIRTY|EXT2_FLAG_BB_DIRTY);
+		/* 
+		 * The command "mke2fs -S" is used to recover
+		 * corrupted file systems, so do not mark any of the
+		 * inodes as unused; we want e2fsck to consider all
+		 * inodes as potentially containing recoverable data.
+		 */
+		if (fs->super->s_feature_ro_compat &
+		    EXT4_FEATURE_RO_COMPAT_GDT_CSUM) {
+			for (i = 1; i < fs->group_desc_count; i++)
+				ext2fs_bg_itable_unused_set(fs, i, 0);
+		}
 	} else {
 		/* rsv must be a power of two (64kB is MD RAID sb alignment) */
 		blk64_t rsv = 65536 / fs->blocksize;

  reply	other threads:[~2012-02-17  4:20 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-12-22  8:30 [PATCH 1/2] e2fsprogs: fix data lost with mke2fs -S Akira Fujita
2012-02-17  4:20 ` Ted Ts'o [this message]
2012-02-21  7:09   ` Akira Fujita
2012-02-27  5:54     ` Ted Ts'o
2012-02-27  6:26       ` Akira Fujita

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20120217042038.GA9319@thunk.org \
    --to=tytso@mit.edu \
    --cc=a-fujita@rs.jp.nec.com \
    --cc=linux-ext4@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.