fsck.f2fs: avoid false alarm on SIT type fix

This patch removed a false alarm when detecting any inconsistency in SIT types.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
diff --git a/fsck/f2fs.h b/fsck/f2fs.h
index 47f785d..57bad9b 100644
--- a/fsck/f2fs.h
+++ b/fsck/f2fs.h
@@ -72,6 +72,7 @@
 	unsigned short ckpt_valid_blocks;
 	unsigned char *ckpt_valid_map;
 	unsigned char type;             /* segment type like CURSEG_XXX_TYPE */
+	unsigned char orig_type;        /* segment type like CURSEG_XXX_TYPE */
 	unsigned long long mtime;       /* modification time of the segment */
 };
 
diff --git a/fsck/fsck.c b/fsck/fsck.c
index 78737d5..994145e 100644
--- a/fsck/fsck.c
+++ b/fsck/fsck.c
@@ -23,17 +23,15 @@
 	if (se->type != type) {
 		if (type == CURSEG_WARM_DATA) {
 			if (se->type != CURSEG_COLD_DATA) {
-				FIX_MSG("Wrong segment type [0x%x] %x -> %x",
+				DBG(1, "Wrong segment type [0x%x] %x -> %x",
 						GET_SEGNO(sbi, blk), se->type,
 						CURSEG_WARM_DATA);
 				se->type = CURSEG_WARM_DATA;
-				config.bug_on = 1;
 			}
 		} else {
-			FIX_MSG("Wrong segment type [0x%x] %x -> %x",
+			DBG(1, "Wrong segment type [0x%x] %x -> %x",
 				GET_SEGNO(sbi, blk), se->type, type);
 			se->type = type;
-			config.bug_on = 1;
 		}
 	}
 	return f2fs_set_bit(BLKOFF_FROM_MAIN(sbi, blk), fsck->main_area_bitmap);
@@ -998,6 +996,25 @@
 	return 0;
 }
 
+int check_sit_types(struct f2fs_sb_info *sbi)
+{
+	struct seg_entry *se;
+	unsigned int i;
+	int err = 0;
+
+	for (i = 0; i < TOTAL_SEGS(sbi); i++) {
+		struct seg_entry *se;
+
+		se = get_seg_entry(sbi, i);
+		if (se->orig_type != se->type) {
+			FIX_MSG("Wrong segment type [0x%x] %x -> %x",
+					i, se->orig_type, se->type);
+			err = -EINVAL;
+		}
+	}
+	return err;
+}
+
 int fsck_verify(struct f2fs_sb_info *sbi)
 {
 	unsigned int i = 0;
@@ -1108,13 +1125,21 @@
 		config.bug_on = 1;
 	}
 
+	printf("[FSCK] SIT types                                     ");
+	if (check_sit_types(sbi) == 0) {
+		printf(" [Ok..]\n");
+	} else {
+		printf(" [Fail]\n");
+		ret = EXIT_ERR_CODE;
+		config.bug_on = 1;
+	}
+
 	printf("[FSCK] other corrupted bugs                          ");
 	if (config.bug_on == 0) {
 		printf(" [Ok..]\n");
 	} else {
 		printf(" [Fail]\n");
 		ret = EXIT_ERR_CODE;
-		config.bug_on = 1;
 	}
 
 	/* fix global metadata */
diff --git a/fsck/mount.c b/fsck/mount.c
index 8ff7ff7..0aca60b 100644
--- a/fsck/mount.c
+++ b/fsck/mount.c
@@ -795,6 +795,7 @@
 	memcpy(se->cur_valid_map, raw_sit->valid_map, SIT_VBLOCK_MAP_SIZE);
 	memcpy(se->ckpt_valid_map, raw_sit->valid_map, SIT_VBLOCK_MAP_SIZE);
 	se->type = GET_SIT_TYPE(raw_sit);
+	se->orig_type = GET_SIT_TYPE(raw_sit);
 	se->mtime = le64_to_cpu(raw_sit->mtime);
 }