[Ocfs2-tools-devel] [PATCH 2/3] Ocfs2-tools: Implement new prompt codes of sparse file for fswreck.
Tristan Ye
tristan.ye at oracle.com
Tue Jun 30 21:58:05 PDT 2009
Adding new corruptions of sparse file for fswreck after fsck.ocfs2
supported new separated prompt codes.
Signed-off-by: Tristan Ye <tristan.ye at oracle.com>
---
fswreck/corrupt.c | 6 ++++++
fswreck/include/fsck_type.h | 2 ++
fswreck/inode.c | 35 ++++++++++++++++++++++++++++++++---
fswreck/main.c | 4 ++++
4 files changed, 44 insertions(+), 3 deletions(-)
diff --git a/fswreck/corrupt.c b/fswreck/corrupt.c
index 151d308..a9e5188 100644
--- a/fswreck/corrupt.c
+++ b/fswreck/corrupt.c
@@ -162,9 +162,15 @@ void corrupt_file(ocfs2_filesys *fs, enum fsck_type type, uint16_t slotnum)
case INODE_SIZE:
func = mess_up_inode_field;
break;
+ case INODE_SPARSE_SIZE:
+ func = mess_up_inode_field;
+ break;
case INODE_CLUSTERS:
func = mess_up_inode_field;
break;
+ case INODE_SPARSE_CLUSTERS:
+ func = mess_up_inode_field;
+ break;
case INODE_COUNT:
func = mess_up_inode_field;
break;
diff --git a/fswreck/include/fsck_type.h b/fswreck/include/fsck_type.h
index 968b38a..c7b9170 100644
--- a/fswreck/include/fsck_type.h
+++ b/fswreck/include/fsck_type.h
@@ -91,7 +91,9 @@ enum fsck_type
LINK_BLOCKS,
DIR_ZERO,
INODE_SIZE,
+ INODE_SPARSE_SIZE,
INODE_CLUSTERS,
+ INODE_SPARSE_CLUSTERS,
LALLOC_REPAIR,
LALLOC_USED,
CLUSTER_ALLOC_BIT,
diff --git a/fswreck/inode.c b/fswreck/inode.c
index a66ff3f..4c28e4d 100644
--- a/fswreck/inode.c
+++ b/fswreck/inode.c
@@ -47,6 +47,23 @@ static void damage_inode(ocfs2_filesys *fs, uint64_t blkno,
errcode_t ret;
char *buf = NULL;
struct ocfs2_dinode *di;
+ struct ocfs2_dinode *sb_di;
+ char *sb_blk;
+
+ if ((type == INODE_SPARSE_SIZE) || (type == INODE_SPARSE_CLUSTERS)) {
+
+ sb_blk = (char *)fs->fs_super;
+ sb_di = (struct ocfs2_dinode *)sb_blk;
+ if (!(sb_di->id2.i_super.s_feature_incompat &
+ OCFS2_FEATURE_INCOMPAT_SPARSE_ALLOC)) {
+
+ sb_di->id2.i_super.s_feature_incompat |= OCFS2_FEATURE_INCOMPAT_SPARSE_ALLOC;
+ ret = ocfs2_write_inode(fs, OCFS2_SUPER_BLOCK_BLKNO,
+ sb_blk);
+ if (ret)
+ FSWRK_COM_FATAL(progname, ret);
+ }
+ }
ret = ocfs2_malloc_block(fs->fs_io, &buf);
if (ret)
@@ -81,7 +98,7 @@ static void damage_inode(ocfs2_filesys *fs, uint64_t blkno,
"Corrupt inode#%"PRIu64", change i_blkno from %"PRIu64
" to %"PRIu64"\n",
blkno, di->i_blkno, (di->i_blkno + 10));
- di->i_blkno += 100;
+ di->i_blkno += 10;
break;
case INODE_NZ_DTIME:
fprintf(stdout, "INODE_NZ_DTIME: "
@@ -103,12 +120,25 @@ static void damage_inode(ocfs2_filesys *fs, uint64_t blkno,
blkno, di->i_size, (di->i_size + 100));
di->i_size += 100;
break;
+ case INODE_SPARSE_SIZE:
+ fprintf(stdout, "INODE_SPARSE_SIZE: "
+ "Corrupt inode#%"PRIu64", change i_size"
+ " from %"PRIu64" to %"PRIu64"\n",
+ blkno, di->i_size, (di->i_size + 100));
+ di->i_size += 100;
+ break;
case INODE_CLUSTERS:
fprintf(stdout, "INODE_CLUSTER: "
"Corrupt inode#%"PRIu64", change i_clusters"
" from %u to 0\n", blkno, di->i_clusters);
di->i_clusters = 0;
break;
+ case INODE_SPARSE_CLUSTERS:
+ fprintf(stdout, "INODE_SPARSE_CLUSTER: "
+ "Corrupt inode#%"PRIu64", change i_clusters"
+ " from %u to 0\n", blkno, di->i_clusters);
+ di->i_clusters = 0;
+ break;
case INODE_COUNT:
di->i_links_count = 0;
fprintf(stdout, "INODE_COUNT: "
@@ -130,14 +160,13 @@ static void damage_inode(ocfs2_filesys *fs, uint64_t blkno,
void mess_up_inode_field(ocfs2_filesys *fs, enum fsck_type type, uint64_t blkno)
{
- int i;
errcode_t ret;
uint64_t tmpblkno;
uint32_t clusters = 10;
create_file(fs, blkno, &tmpblkno);
- if (type == INODE_CLUSTERS) {
+ if ((type == INODE_CLUSTERS) || (type == INODE_SPARSE_CLUSTERS)) {
ret = ocfs2_extend_allocation(fs, tmpblkno, clusters);
if (ret)
FSWRK_COM_FATAL(progname, ret);
diff --git a/fswreck/main.c b/fswreck/main.c
index ecd254b..f69f1dc 100644
--- a/fswreck/main.c
+++ b/fswreck/main.c
@@ -83,8 +83,12 @@ static struct prompt_code prompt_codes[NUM_FSCK_TYPE] = {
"Corrupt inode's i_dtime field"),
define_prompt_code(INODE_SIZE, corrupt_file,
"Corrupt inode's i_size field"),
+ define_prompt_code(INODE_SPARSE_SIZE, corrupt_file,
+ "Corrupt sparse inode's i_size field"),
define_prompt_code(INODE_CLUSTERS, corrupt_file,
"Corrupt inode's i_clusters field"),
+ define_prompt_code(INODE_SPARSE_CLUSTERS, corrupt_file,
+ "Corrupt sparse inode's i_clusters field"),
define_prompt_code(INODE_COUNT, corrupt_file,
"Corrupt inode's i_links_count field"),
define_prompt_code(INODE_LINK_NOT_CONNECTED, corrupt_file,
--
1.5.5
More information about the Ocfs2-tools-devel
mailing list