[Ocfs2-tools-devel] [PATCH 5/6] Add EXTENT_OVERLAP and EXTENT_HOLE

Goldwyn Rodrigues rgoldwyn at gmail.com
Tue Aug 16 15:17:23 PDT 2011


EXTENT_OVERLAP creates a file with extents overlapped, so that there
could be multiple extents for a given extent.

EXTENT_HOLE creates a file with a hole. This is not a corruption.
I added it to check that DIR_HOLE does not correct files with holes.
This can also be used to check sparse files in nosparse filesystem
option.

Signed-off-by: Goldwyn Rodrigues <rgoldwyn at suse.de>
---
 fswreck/corrupt.c           |    6 ++++++
 fswreck/extent.c            |   26 ++++++++++++++++++++++++++
 fswreck/include/fsck_type.h |    2 ++
 fswreck/main.c              |    4 ++++
 4 files changed, 38 insertions(+), 0 deletions(-)

diff --git a/fswreck/corrupt.c b/fswreck/corrupt.c
index 161b078..c0c57f1 100644
--- a/fswreck/corrupt.c
+++ b/fswreck/corrupt.c
@@ -85,6 +85,12 @@ void corrupt_file(ocfs2_filesys *fs, enum fsck_type
type, uint16_t slotnum)
 	case EXTENT_BLKNO_RANGE:
 		func = mess_up_extent_record;
 		break;
+	case EXTENT_OVERLAP:
+		func = mess_up_extent_record;
+		break;
+	case EXTENT_HOLE:
+		func = mess_up_extent_record;
+		break;
 	case EXTENT_LIST_DEPTH:
 		func = mess_up_extent_list;
 		break;
diff --git a/fswreck/extent.c b/fswreck/extent.c
index f6fade0..bf3c1b1 100644
--- a/fswreck/extent.c
+++ b/fswreck/extent.c
@@ -364,6 +364,32 @@ static void mess_up_record(ocfs2_filesys *fs,
uint64_t blkno,
 			" from %"PRIu64 " to %"PRIu64"\n",
 			blkno, oldno, er->e_blkno);
 			break;
+		case EXTENT_OVERLAP:
+			ret = ocfs2_extend_allocation(fs, blkno, 2);
+			if (ret)
+				FSWRK_COM_FATAL(progname, ret);
+			ret = ocfs2_read_inode(fs, blkno, buf);
+			if (ret)
+				FSWRK_COM_FATAL(progname, ret);
+			er = &(el->l_recs[1]);
+			er->e_cpos -= 1;
+			fprintf(stdout, "EXTENT_OVERLAP: "
+			"Corrupt inode#%"PRIu64", change cpos "
+			" to overlap\n", blkno);
+			break;
+		case EXTENT_HOLE:
+			ret = ocfs2_extend_allocation(fs, blkno, 2);
+			if (ret)
+				FSWRK_COM_FATAL(progname, ret);
+			ret = ocfs2_read_inode(fs, blkno, buf);
+			if (ret)
+				FSWRK_COM_FATAL(progname, ret);
+			er = &(el->l_recs[1]);
+			er->e_cpos += 11;
+			fprintf(stdout, "EXTENT_HOLE: "
+			"Corrupt inode#%"PRIu64", change cpos "
+			" to increase hole\n", blkno);
+			break;
 		default:
 			goto bail;
 		}
diff --git a/fswreck/include/fsck_type.h b/fswreck/include/fsck_type.h
index c18a134..0466db8 100644
--- a/fswreck/include/fsck_type.h
+++ b/fswreck/include/fsck_type.h
@@ -45,6 +45,8 @@ enum fsck_type
 	EXTENT_LIST_COUNT,
 	EXTENT_LIST_FREE,
 	EXTENT_BLKNO_RANGE,
+	EXTENT_OVERLAP,
+	EXTENT_HOLE,
 	CHAIN_CPG,
 	SUPERBLOCK_CLUSTERS_EXCESS,
 	SUPERBLOCK_CLUSTERS_LACK,
diff --git a/fswreck/main.c b/fswreck/main.c
index 14b0301..3bb886d 100644
--- a/fswreck/main.c
+++ b/fswreck/main.c
@@ -71,6 +71,10 @@ static struct prompt_code prompt_codes[NUM_FSCK_TYPE] = {
 			   "Corrupt extent record's e_leaf_clusters"),
 	define_prompt_code(EXTENT_BLKNO_RANGE, corrupt_file,
 			   "Corrupt extent record's e_blkno to 1"),
+	define_prompt_code(EXTENT_OVERLAP, corrupt_file,
+			   "Corrupt extent record's e_cpos to overlap"),
+	define_prompt_code(EXTENT_HOLE, corrupt_file,
+			   "Corrupt extent record's e_cpos to create hole"),
 	define_prompt_code(EXTENT_LIST_DEPTH, corrupt_file,
 			   "Corrupt first extent block's list depth of an inode"),
 	define_prompt_code(EXTENT_LIST_COUNT, corrupt_file,
-- 
1.7.6



More information about the Ocfs2-tools-devel mailing list