Enables to detect corrupted sit journal
a) total count of entries.
b) segment no. in entry.

Signed-off-by: Chao Yu <[email protected]>
---
 fsck/mount.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/fsck/mount.c b/fsck/mount.c
index a627f1d..909c1f4 100644
--- a/fsck/mount.c
+++ b/fsck/mount.c
@@ -1912,8 +1912,25 @@ static int build_sit_entries(struct f2fs_sb_info *sbi)
        }
 
        free(sit_blk);
+
+       if (sits_in_cursum(journal) > SIT_JOURNAL_ENTRIES) {
+               MSG(0, "\tError: build_sit_entries truncate n_sits(%u) to "
+                       "SIT_JOURNAL_ENTRIES(%lu)\n",
+                       sits_in_cursum(journal), SIT_JOURNAL_ENTRIES);
+               journal->n_sits = cpu_to_le16(SIT_JOURNAL_ENTRIES);
+               c.fix_on = 1;
+       }
+
        for (i = 0; i < sits_in_cursum(journal); i++) {
                segno = le32_to_cpu(segno_in_journal(journal, i));
+
+               if (segno >= TOTAL_SEGS(sbi)) {
+                       MSG(0, "\tError: build_sit_entries: segno(%u) is 
invalid!!!\n", segno);
+                       journal->n_sits = cpu_to_le16(i);
+                       c.fix_on = 1;
+                       continue;
+               }
+
                se = &sit_i->sentries[segno];
                sit = sit_in_journal(journal, i);
 
-- 
2.18.0.rc1



_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

Reply via email to