[Ocfs2-tools-devel] [PATCH 1/2] fswreck: corrupt inode block check field
Eric Ren
zren at suse.com
Wed Jul 8 20:40:29 PDT 2015
This one is used to corrupt the inode metadata CRC and ECC value.
INODE_BLOCK_ECC: corrupt block check filed i_check in ocfs2_dinode.
Signed-off-by: Eric Ren <zren at suse.com>
Reviewed-by: Goldwyn Rodrigues <rgoldwyn at suse.com>
Reviewed-by: Gang He <ghe at suse.com>
---
fswreck/corrupt.c | 3 +++
fswreck/include/fsck_type.h | 3 ++-
fswreck/inode.c | 17 +++++++++++++++--
fswreck/main.c | 2 ++
include/ocfs2/ocfs2.h | 2 ++
libocfs2/inode.c | 40 ++++++++++++++++++++++++++++++++++++++++
6 files changed, 64 insertions(+), 3 deletions(-)
diff --git a/fswreck/corrupt.c b/fswreck/corrupt.c
index ba59e23..7ccb164 100644
--- a/fswreck/corrupt.c
+++ b/fswreck/corrupt.c
@@ -225,6 +225,9 @@ void corrupt_file(ocfs2_filesys *fs, enum fsck_type type, uint16_t slotnum)
case REFCOUNT_LOC_INVALID:
func = mess_up_inode_field;
break;
+ case INODE_BLOCK_ECC:
+ func = mess_up_inode_field;
+ break;
default:
FSWRK_FATAL("Invalid code=%d", type);
}
diff --git a/fswreck/include/fsck_type.h b/fswreck/include/fsck_type.h
index fc0ee90..b62585e 100644
--- a/fswreck/include/fsck_type.h
+++ b/fswreck/include/fsck_type.h
@@ -166,7 +166,8 @@ enum fsck_type
REFCOUNT_REC_REDUNDANT,
/*130*/ REFCOUNT_COUNT_INVALID,
DUP_CLUSTERS_ADD_REFCOUNT,
-/*132*/ NUM_FSCK_TYPE
+ INODE_BLOCK_ECC,
+/*133*/ NUM_FSCK_TYPE
};
/*
diff --git a/fswreck/inode.c b/fswreck/inode.c
index 56d9e1b..674ddbc 100644
--- a/fswreck/inode.c
+++ b/fswreck/inode.c
@@ -27,7 +27,8 @@
/* This file will create the errors for the inode.
*
* Inode field error: INODE_SUBALLOC, INODE_GEN, INODE_GEN_FIX,INODE_BLKNO,
- INODE_NZ_DTIME, INODE_SIZE, INODE_CLUSTERS, INODE_COUNT
+ INODE_NZ_DTIME, INODE_SIZE, INODE_CLUSTERS, INODE_COUNT,
+ INODE_BLOCK_ECC
*
* Inode link not connected error: INODE_NOT_CONNECTED
*
@@ -128,6 +129,14 @@ static void damage_inode(ocfs2_filesys *fs, uint64_t blkno,
"Corrupte inode#%"PRIu64", set link count to 0\n",
blkno);
break;
+ case INODE_BLOCK_ECC:
+ fprintf(stdout, "INODE_BLOCK_ECC: "
+ "Corrupte inode#%"PRIu64", set both i_check.bc_crc32e"
+ "=%"PRIu64" and i_check.bc_ecc=%"PRIu64" to 0x1234\n",
+ blkno, di->i_check.bc_crc32e, di->i_check.bc_ecc);
+ di->i_check.bc_crc32e = 0x1234;
+ di->i_check.bc_ecc = 0x1234;
+ break;
case REFCOUNT_FLAG_INVALID:
di->i_dyn_features |= OCFS2_HAS_REFCOUNT_FL;
fprintf(stdout, "REFCOUNT_FLAG_INVALD: "
@@ -145,7 +154,11 @@ static void damage_inode(ocfs2_filesys *fs, uint64_t blkno,
FSWRK_FATAL("Invalid type[%d]\n", type);
}
- ret = ocfs2_write_inode(fs, blkno, buf);
+ if (type != INODE_BLOCK_ECC)
+ ret = ocfs2_write_inode(fs, blkno, buf);
+ else
+ ret = ocfs2_write_inode_without_meta_ecc(fs, blkno, buf);
+
if (ret)
FSWRK_COM_FATAL(progname, ret);
diff --git a/fswreck/main.c b/fswreck/main.c
index d64c2fc..f9227f3 100644
--- a/fswreck/main.c
+++ b/fswreck/main.c
@@ -327,6 +327,8 @@ static struct prompt_code prompt_codes[NUM_FSCK_TYPE] = {
"corrupt the refcount record in a refcount block"),
define_prompt_code(DUP_CLUSTERS_ADD_REFCOUNT, corrupt_refcount, "", 1,
"corrupt refcount record and handle them in dup"),
+ define_prompt_code(INODE_BLOCK_ECC, corrupt_file, "", 1,
+ "corrupt inode's i_check filed"),
};
#undef define_prompt_code
diff --git a/include/ocfs2/ocfs2.h b/include/ocfs2/ocfs2.h
index 3b54880..d33a28d 100644
--- a/include/ocfs2/ocfs2.h
+++ b/include/ocfs2/ocfs2.h
@@ -391,6 +391,8 @@ errcode_t ocfs2_read_inode(ocfs2_filesys *fs, uint64_t blkno,
char *inode_buf);
errcode_t ocfs2_write_inode(ocfs2_filesys *fs, uint64_t blkno,
char *inode_buf);
+errcode_t ocfs2_write_inode_without_meta_ecc(ocfs2_filesys *fs, uint64_t blkno,
+ char *inode_buf);
errcode_t ocfs2_check_directory(ocfs2_filesys *fs, uint64_t dir);
int ocfs2_check_dir_entry(ocfs2_filesys *fs, struct ocfs2_dir_entry *de,
char *dir_buf, unsigned int offset);
diff --git a/libocfs2/inode.c b/libocfs2/inode.c
index bcc462b..ad1e016 100644
--- a/libocfs2/inode.c
+++ b/libocfs2/inode.c
@@ -360,6 +360,46 @@ out:
return ret;
}
+/**
+ * Same as ocfs2_write_inode, but without ocfs2_compute_meta_ecc function so
+ * that the inode meta CRC and ECC value wouldn't be overwritten after corrupted
+ * in fswreck.
+ */
+errcode_t ocfs2_write_inode_without_meta_ecc(ocfs2_filesys *fs, uint64_t blkno,
+ char *inode_buf)
+{
+ errcode_t ret;
+ char *blk;
+ struct ocfs2_dinode *di;
+
+ if (!(fs->fs_flags & OCFS2_FLAG_RW))
+ return OCFS2_ET_RO_FILESYS;
+
+ if ((blkno < OCFS2_SUPER_BLOCK_BLKNO) ||
+ (blkno > fs->fs_blocks))
+ return OCFS2_ET_BAD_BLKNO;
+
+ ret = ocfs2_malloc_block(fs->fs_io, &blk);
+ if (ret)
+ return ret;
+
+ memcpy(blk, inode_buf, fs->fs_blocksize);
+
+ di = (struct ocfs2_dinode *)blk;
+ ocfs2_swap_inode_from_cpu(fs, di);
+
+ ret = io_write_block(fs->fs_io, blkno, 1, blk);
+ if (ret)
+ goto out;
+
+ fs->fs_flags |= OCFS2_FLAG_CHANGED;
+ ret = 0;
+
+out:
+ ocfs2_free(&blk);
+
+ return ret;
+}
#ifdef DEBUG_EXE
#include <stdlib.h>
--
2.1.2
More information about the Ocfs2-tools-devel
mailing list