linux-f2fs-devel.lists.sourceforge.net archive mirror
 help / color / mirror / Atom feed
From: Jaegeuk Kim <jaegeuk@kernel.org>
To: linux-f2fs-devel@lists.sourceforge.net
Cc: Jaegeuk Kim <jaegeuk@kernel.org>
Subject: [PATCH 3/8] fsck.f2fs: fix corrupted dentries
Date: Thu,  2 Apr 2015 10:50:50 -0700	[thread overview]
Message-ID: <1427997055-10715-3-git-send-email-jaegeuk@kernel.org> (raw)
In-Reply-To: <1427997055-10715-1-git-send-email-jaegeuk@kernel.org>

This patch fixes corrupted dentries such as name_len == 0.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
---
 fsck/fsck.c | 47 +++++++++++++++++++++++++++++++----------------
 1 file changed, 31 insertions(+), 16 deletions(-)

diff --git a/fsck/fsck.c b/fsck/fsck.c
index ecb18f2..debae1c 100644
--- a/fsck/fsck.c
+++ b/fsck/fsck.c
@@ -796,22 +796,24 @@ static int __chk_dentries(struct f2fs_sb_info *sbi, u32 *child_cnt,
 	int i;
 
 	/* readahead inode blocks */
-	for (i = 0; i < max;) {
-		if (test_bit(i, bitmap) == 0) {
-			i++;
+	for (i = 0; i < max; i++) {
+		if (test_bit(i, bitmap) == 0)
 			continue;
-		}
+
 		ino = le32_to_cpu(dentry[i].ino);
 
 		if (IS_VALID_NID(sbi, ino)) {
 			struct node_info ni;
 
 			get_node_info(sbi, ino, &ni);
-			if (IS_VALID_BLK_ADDR(sbi, ni.blk_addr))
+			if (IS_VALID_BLK_ADDR(sbi, ni.blk_addr)) {
 				dev_reada_block(ni.blk_addr);
+				name_len = le16_to_cpu(dentry[i].name_len);
+				if (name_len > 0)
+					i += (name_len + F2FS_SLOT_LEN - 1) / F2FS_SLOT_LEN - 1;
+				continue;
+			}
 		}
-		name_len = le16_to_cpu(dentry[i].name_len);
-		i += (name_len + F2FS_SLOT_LEN - 1) / F2FS_SLOT_LEN;
 	}
 
 	for (i = 0; i < max;) {
@@ -820,31 +822,44 @@ static int __chk_dentries(struct f2fs_sb_info *sbi, u32 *child_cnt,
 			continue;
 		}
 		if (!IS_VALID_NID(sbi, le32_to_cpu(dentry[i].ino))) {
-			DBG(1, "Bad dentry 0x%x with invalid NID/ino 0x%x",
-			    i, le32_to_cpu(dentry[i].ino));
+			ASSERT_MSG("Bad dentry 0x%x with invalid NID/ino 0x%x",
+				    i, le32_to_cpu(dentry[i].ino));
 			if (config.fix_on) {
 				FIX_MSG("Clear bad dentry 0x%x with bad ino 0x%x",
 					i, le32_to_cpu(dentry[i].ino));
 				clear_bit(i, bitmap);
-				i++;
 				fixed = 1;
-				continue;
 			}
+			i++;
+			continue;
 		}
+
 		ftype = dentry[i].file_type;
-		if ((ftype <= F2FS_FT_UNKNOWN || ftype > F2FS_FT_LAST_FILE_TYPE) && config.fix_on) {
-			DBG(1, "Bad dentry 0x%x with unexpected ftype 0x%x",
-			    i, ftype);
+		if ((ftype <= F2FS_FT_UNKNOWN || ftype > F2FS_FT_LAST_FILE_TYPE)) {
+			ASSERT_MSG("Bad dentry 0x%x with unexpected ftype 0x%x", i, ftype);
 			if (config.fix_on) {
 				FIX_MSG("Clear bad dentry 0x%x with bad ftype 0x%x",
 					i, ftype);
 				clear_bit(i, bitmap);
-				i++;
 				fixed = 1;
-				continue;
 			}
+			i++;
+			continue;
 		}
+
 		name_len = le16_to_cpu(dentry[i].name_len);
+
+		if (name_len == 0) {
+			ASSERT_MSG("Bad dentry 0x%x with zero name_len", i);
+			if (config.fix_on) {
+				FIX_MSG("Clear bad dentry 0x%x", i);
+				clear_bit(i, bitmap);
+				fixed = 1;
+			}
+			i++;
+			continue;
+		}
+
 		name = calloc(name_len + 1, 1);
 		memcpy(name, filenames[i], name_len);
 		hash_code = f2fs_dentry_hash((const unsigned char *)name,
-- 
2.1.1


------------------------------------------------------------------------------
Dive into the World of Parallel Programming The Go Parallel Website, sponsored
by Intel and developed in partnership with Slashdot Media, is your hub for all
things parallel software development, from weekly thought leadership blogs to
news, videos, case studies, tutorials and more. Take a look and join the 
conversation now. http://goparallel.sourceforge.net/

  parent reply	other threads:[~2015-04-02 17:51 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-02 17:50 [PATCH 1/8] fsck.f2fs: return summary block pointer and types Jaegeuk Kim
2015-04-02 17:50 ` [PATCH 2/8] fsck.f2fs: fix summary block Jaegeuk Kim
2015-04-02 17:50 ` Jaegeuk Kim [this message]
2015-04-02 17:50 ` [PATCH 4/8] fsck.f2fs: count child directories correctly for i_links Jaegeuk Kim
2015-04-02 17:50 ` [PATCH 5/8] fsck.f2fs: fix missing i_links Jaegeuk Kim
2015-04-02 17:50 ` [PATCH 6/8] fsck.f2fs: clean up child information Jaegeuk Kim
2015-04-02 17:50 ` [PATCH 7/8] fsck.f2fs: fix missing dentries Jaegeuk Kim
2015-04-02 17:50 ` [PATCH 8/8] fsck.f2fs: fix orphan inode's link count Jaegeuk Kim

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=1427997055-10715-3-git-send-email-jaegeuk@kernel.org \
    --to=jaegeuk@kernel.org \
    --cc=linux-f2fs-devel@lists.sourceforge.net \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).