All of lore.kernel.org
 help / color / mirror / Atom feed
From: Eric Sandeen <sandeen@redhat.com>
To: Robert Yang <liezhi.yang@windriver.com>
Cc: "Darrick J. Wong" <darrick.wong@oracle.com>,
	linux-ext4@vger.kernel.org, "Theodore Ts'o" <tytso@mit.edu>,
	Darren Hart <dvhart@linux.intel.com>
Subject: [PATCH] debugfs: properly set up extent header in do_write
Date: Wed, 24 Jul 2013 10:11:25 -0500	[thread overview]
Message-ID: <51EFEE9D.9070501@redhat.com> (raw)
In-Reply-To: <51EF975E.2090700@windriver.com>

do_write doesn't fully set up the first extent header on a new
inode, so if we write a 0-length file, and don't write any data
to the new file, we end up creating something that looks corrupt
to kernelspace:

EXT4-fs error (device loop0): ext4_ext_check_inode:464: inode #12: comm ls: bad header/extent: invalid magic - magic 0, entries 0, max 0(0), depth 0(0)

Do something similar to ext4_ext_tree_init() here, and
fill out the first extent header upon creation to avoid this.

Reported-by: Robert Yang <liezhi.yang@windriver.com>
Signed-off-by: Eric Sandeen <sandeen@redhat.com>
---

diff --git a/debugfs/debugfs.c b/debugfs/debugfs.c
index dcf16e2..2660218 100644
--- a/debugfs/debugfs.c
+++ b/debugfs/debugfs.c
@@ -1677,8 +1677,19 @@ void do_write(int argc, char *argv[])
 	inode.i_links_count = 1;
 	inode.i_size = statbuf.st_size;
 	if (current_fs->super->s_feature_incompat &
-	    EXT3_FEATURE_INCOMPAT_EXTENTS)
+	    EXT3_FEATURE_INCOMPAT_EXTENTS) {
+		int i;
+		struct ext3_extent_header *eh;
+
+		eh = (struct ext3_extent_header *) &inode.i_block[0];
+		eh->eh_depth = 0;
+		eh->eh_entries = 0;
+		eh->eh_magic = EXT3_EXT_MAGIC;
+		i = (sizeof(inode.i_block) - sizeof(*eh)) /
+			sizeof(struct ext3_extent);
+		eh->eh_max = ext2fs_cpu_to_le16(i);
 		inode.i_flags |= EXT4_EXTENTS_FL;
+	}
 	if (debugfs_write_new_inode(newfile, &inode, argv[0])) {
 		close(fd);
 		return;


  parent reply	other threads:[~2013-07-24 15:11 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-07-24  8:59 e2fsprogs/debugfs/write: Input/output error when file size is zero Robert Yang
2013-07-24 15:00 ` Eric Sandeen
2013-07-24 15:11 ` Eric Sandeen [this message]
2013-07-25  6:18   ` [PATCH] debugfs: properly set up extent header in do_write Robert Yang
2013-07-29  2:33     ` Theodore Ts'o

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=51EFEE9D.9070501@redhat.com \
    --to=sandeen@redhat.com \
    --cc=darrick.wong@oracle.com \
    --cc=dvhart@linux.intel.com \
    --cc=liezhi.yang@windriver.com \
    --cc=linux-ext4@vger.kernel.org \
    --cc=tytso@mit.edu \
    /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.