[Ocfs2-tools-devel] [PATCH 1/1] Add corrupt code for inline data in fswreck
tristan
tristan.ye at oracle.com
Mon Aug 11 04:23:26 PDT 2008
Add corrupt code for inline data in fswreck,include both regular file
and dir.
Mainly aims at corrupting the newly added checking codes in
fsck.ocfs2.checks for inline-data.
Signed-off-by: Tristan Ye <tristan.ye at oracle.com>
---
fswreck/corrupt.c | 13 +++++
fswreck/dir.c | 110
+++++++++++++++++++++++++++++++++++++++++++
fswreck/include/dir.h | 2 +
fswreck/include/fsck_type.h | 12 ++++-
fswreck/include/inode.h | 2 +
fswreck/include/main.h | 5 ++-
fswreck/inode.c | 105
+++++++++++++++++++++++++++++++++++++++++
fswreck/main.c | 4 ++
8 files changed, 251 insertions(+), 2 deletions(-)
diff --git a/fswreck/corrupt.c b/fswreck/corrupt.c
index f698cb0..188b767 100644
--- a/fswreck/corrupt.c
+++ b/fswreck/corrupt.c
@@ -147,6 +147,19 @@ void corrupt_file(ocfs2_filesys *fs, int code,
uint16_t slotnum)
case CORRUPT_DIR_NOT_CONNECTED:
func = mess_up_dir_not_connected;
break;
+ case CORRUPT_REGULAR_INLINE_DATA_FLAG:
+ func = mess_up_regular_inline_flag;
+ break;
+ case CORRUPT_REGULAR_INLINE_DATA_SIZE:
+ func = mess_up_regular_inline_size;
+ break;
+ case CORRUPT_DIR_INLINE_DATA_FLAG:
+ func = mess_up_dir_inline_flag;
+ break;
+ case CORRUPT_DIR_INLINE_DATA_SIZE:
+ func = mess_up_dir_inline_size;
+ break;
+
default:
FSWRK_FATAL("Invalid code=%d", code);
}
diff --git a/fswreck/dir.c b/fswreck/dir.c
index 3338a17..34fdae9 100644
--- a/fswreck/dir.c
+++ b/fswreck/dir.c
@@ -452,3 +452,113 @@ void mess_up_dir_not_connected(ocfs2_filesys *fs,
uint64_t blkno)
return;
}
+
+void create_inline_dir(ocfs2_filesys *fs,const char *dirname,
+ uint64_t blkno, uint64_t *retblkno)
+{
+ errcode_t ret;
+ uint64_t tmp_blkno;
+
+ ret = ocfs2_check_directory(fs,blkno);
+ if (ret)
+ FSWRK_COM_FATAL(progname, ret);
+
+ ret = ocfs2_new_inode(fs, &tmp_blkno, S_IFDIR | 0755);
+ if (ret)
+ FSWRK_COM_FATAL(progname, ret);
+
+ ret = ocfs2_init_dir(fs, tmp_blkno, blkno);
+ if (ret)
+ FSWRK_COM_FATAL(progname, ret);
+
+ ret = ocfs2_link(fs, blkno, dirname, tmp_blkno, OCFS2_FT_DIR);
+ if (ret)
+ FSWRK_COM_FATAL(progname, ret);
+
+ *retblkno = tmp_blkno;
+
+}
+void mess_up_dir_inline_flag(ocfs2_filesys *fs, uint64_t blkno)
+{
+ char inline_dirname[OCFS2_MAX_FILENAME_LEN];
+ char *buf = NULL;
+ uint64_t inline_blkno;
+ errcode_t ret;
+ struct ocfs2_dinode *sb_di = fs->fs_super;
+ struct ocfs2_dinode *di;
+
+ /*mess up inline flag in inode*/
+ snprintf(inline_dirname,OCFS2_MAX_FILENAME_LEN,
+ "inline_dir_mess_flag_%d", getpid());
+ create_inline_dir(fs,inline_dirname,blkno,&inline_blkno);
+
+ ret = ocfs2_malloc_block(fs->fs_io, &buf);
+ if (ret)
+ FSWRK_COM_FATAL(progname, ret);
+
+ ret = ocfs2_read_inode(fs, inline_blkno, buf);
+ if (ret)
+ FSWRK_COM_FATAL(progname, ret);
+
+ di = (struct ocfs2_dinode *)buf;
+
+ if (di->i_dyn_features & OCFS2_INLINE_DATA_FL) {
+ goto bail;
+ }
+ else {
+ di->i_dyn_features |= OCFS2_INLINE_DATA_FL;
+ ret = ocfs2_write_inode(fs,inline_blkno,buf);
+ if (ret)
+ FSWRK_COM_FATAL(progname, ret);
+ }
+
+bail:
+ if (buf)
+ ocfs2_free(&buf);
+
+ return;
+
+}
+void mess_up_dir_inline_size(ocfs2_filesys *fs, uint64_t blkno)
+{
+ char inline_dirname[OCFS2_MAX_FILENAME_LEN];
+ char *buf = NULL;
+ uint64_t inline_blkno;
+ errcode_t ret;
+ struct ocfs2_dinode *di;
+ uint16_t max_inline_sz;
+
+ /*mess up inline flag in inode*/
+ snprintf(inline_dirname,OCFS2_MAX_FILENAME_LEN,
+ "inline_dir_mess_size_%d", getpid());
+ create_inline_dir(fs,inline_dirname,blkno,&inline_blkno);
+
+ ret = ocfs2_malloc_block(fs->fs_io, &buf);
+ if (ret)
+ FSWRK_COM_FATAL(progname, ret);
+
+ ret = ocfs2_read_inode(fs, inline_blkno, buf);
+ if (ret)
+ FSWRK_COM_FATAL(progname, ret);
+
+ di = (struct ocfs2_dinode *)buf;
+ max_inline_sz = ocfs2_max_inline_data(fs->fs_blocksize);
+
+ if (!(di->i_dyn_features & OCFS2_INLINE_DATA_FL)) {
+ di->i_dyn_features |= OCFS2_INLINE_DATA_FL;
+ }
+ /*mess up id_count,i_size and i_cluster in a inline inode*/
+ di->id2.i_data.id_count = 0;
+ di->i_size = max_inline_sz + 1;
+ di->i_clusters = 1;
+
+ ret = ocfs2_write_inode(fs,inline_blkno,buf);
+ if (ret)
+ FSWRK_COM_FATAL(progname, ret);
+
+ if (buf)
+ ocfs2_free(&buf);
+
+ return;
+
+}
diff --git a/fswreck/include/dir.h b/fswreck/include/dir.h
index 57afcfb..77e865c 100644
--- a/fswreck/include/dir.h
+++ b/fswreck/include/dir.h
@@ -30,5 +30,7 @@ void mess_up_dir_dot(ocfs2_filesys *fs, uint64_t
blkno);
void mess_up_dir_ent(ocfs2_filesys *fs, uint64_t blkno);
void mess_up_dir_parent_dup(ocfs2_filesys *fs, uint64_t blkno);
void mess_up_dir_not_connected(ocfs2_filesys *fs, uint64_t blkno);
+void mess_up_dir_inline_flag(ocfs2_filesys *fs, uint64_t blkno);
+void mess_up_dir_inline_size(ocfs2_filesys *fs, uint64_t blkno);
#endif /* __DIR_H */
diff --git a/fswreck/include/fsck_type.h b/fswreck/include/fsck_type.h
index a6a4873..c443a92 100644
--- a/fswreck/include/fsck_type.h
+++ b/fswreck/include/fsck_type.h
@@ -112,7 +112,15 @@ enum fsck_type
INODE_NOT_CONNECTED,
INODE_COUNT,
INODE_ORPHANED,
- NUM_FSCK_TYPE
+ NUM_FSCK_TYPE,
+ REGULAR_INLINE_DATA_FLAG,
+ REGULAR_INLINE_DATA_ID_COUNT,
+ REGULAR_INLINE_DATA_I_CLUSTER,
+ REGULAR_INLINE_DATA_I_SIZE,
+ DIR_INLINE_DATA_FLAG,
+ DIR_INLINE_DATA_ID_COUNT,
+ DIR_INLINE_DATA_I_CLUSTER,
+ DIR_INLINE_DATA_I_SIZE
};
/*
@@ -184,5 +192,7 @@ enum fsck_type
*
* Directory not connected error: DIR_NOT_CONNECTED
*
+ *
+ *
*/
#endif
diff --git a/fswreck/include/inode.h b/fswreck/include/inode.h
index d604e65..876abce 100644
--- a/fswreck/include/inode.h
+++ b/fswreck/include/inode.h
@@ -29,5 +29,7 @@ void mess_up_inode_field(ocfs2_filesys *fs, uint64_t
blkno);
void mess_up_inode_not_connected(ocfs2_filesys *fs, uint64_t blkno);
void mess_up_inode_orphaned(ocfs2_filesys *fs, uint16_t slotnum);
void mess_up_inode_alloc(ocfs2_filesys *fs, uint16_t slotnum);
+void mess_up_regular_inline_flag(ocfs2_filesys *fs, uint64_t blkno);
+void mess_up_regular_inline_size(ocfs2_filesys *fs, uint64_t blkno);
#endif /* __INODE_H */
diff --git a/fswreck/include/main.h b/fswreck/include/main.h
index de9b520..346a271 100644
--- a/fswreck/include/main.h
+++ b/fswreck/include/main.h
@@ -105,9 +105,12 @@ enum{
CORRUPT_DIR_ENT,
CORRUPT_DIR_PARENT_DUP,
CORRUPT_DIR_NOT_CONNECTED,
+ CORRUPT_REGULAR_INLINE_DATA_FLAG,
+ CORRUPT_REGULAR_INLINE_DATA_SIZE,
+ CORRUPT_DIR_INLINE_DATA_FLAG,
+ CORRUPT_DIR_INLINE_DATA_SIZE,
CORRUPT_CLUSTER_AND_GROUP_DESC,
MAX_CORRUPT
-
};
#define ARRAY_ELEMENTS(arr) (sizeof(arr) / sizeof(arr[0]))
diff --git a/fswreck/inode.c b/fswreck/inode.c
index f823117..fef0c5b 100644
--- a/fswreck/inode.c
+++ b/fswreck/inode.c
@@ -224,3 +224,108 @@ void mess_up_inode_alloc(ocfs2_filesys *fs,
uint16_t slotnum)
ocfs2_free(&buf);
return;
}
+
+void create_inline_file(ocfs2_filesys *fs, const char *filename,
+ uint64_t blkno, uint64_t *retblkno)
+{
+ errcode_t ret;
+ uint64_t tmp_blkno;
+
+ ret = ocfs2_check_directory(fs,blkno);
+ if (ret)
+ FSWRK_COM_FATAL(progname, ret);
+
+ ret = ocfs2_new_inode(fs,&tmp_blkno,S_IFREG | 0755);
+ if (ret)
+ FSWRK_COM_FATAL(progname, ret);
+
+ ret = ocfs2_link(fs, blkno, filename, tmp_blkno, OCFS2_FT_REG_FILE);
+ if (ret)
+ FSWRK_COM_FATAL(progname, ret);
+
+ *retblkno = tmp_blkno;
+ return;
+}
+void mess_up_regular_inline_flag(ocfs2_filesys *fs, uint64_t blkno)
+{
+ char inline_filename[OCFS2_MAX_FILENAME_LEN];
+ char *buf = NULL;
+ uint64_t inline_blkno;
+ errcode_t ret;
+ struct ocfs2_dinode *sb_di = fs->fs_super;
+ struct ocfs2_dinode *di;
+
+ /*mess up inline flag in inode*/
+ snprintf(inline_filename,OCFS2_MAX_FILENAME_LEN,
+ "inline_reg_mess_flag_%d", getpid());
+ create_inline_file(fs,inline_filename,blkno,&inline_blkno);
+
+ ret = ocfs2_malloc_block(fs->fs_io, &buf);
+ if (ret)
+ FSWRK_COM_FATAL(progname, ret);
+
+ ret = ocfs2_read_inode(fs, inline_blkno, buf);
+ if (ret)
+ FSWRK_COM_FATAL(progname, ret);
+
+ di = (struct ocfs2_dinode *)buf;
+
+ if (di->i_dyn_features & OCFS2_INLINE_DATA_FL) {
+ goto bail;
+ }
+ else {
+ di->i_dyn_features |= OCFS2_INLINE_DATA_FL;
+ ret = ocfs2_write_inode(fs,inline_blkno,buf);
+ if (ret)
+ FSWRK_COM_FATAL(progname, ret);
+ }
+
+bail:
+ if (buf)
+ ocfs2_free(&buf);
+
+ return;
+}
+
+void mess_up_regular_inline_size(ocfs2_filesys *fs, uint64_t blkno)
+{
+ char inline_filename[OCFS2_MAX_FILENAME_LEN];
+ char *buf = NULL;
+ uint64_t inline_blkno;
+ errcode_t ret;
+ struct ocfs2_dinode *di;
+ uint16_t max_inline_sz;
+
+ /*mess up inline flag in inode*/
+ snprintf(inline_filename,OCFS2_MAX_FILENAME_LEN,
+ "inline_reg_mess_size_%d", getpid());
+ create_inline_file(fs,inline_filename,blkno,&inline_blkno);
+
+ ret = ocfs2_malloc_block(fs->fs_io, &buf);
+ if (ret)
+ FSWRK_COM_FATAL(progname, ret);
+
+ ret = ocfs2_read_inode(fs, inline_blkno, buf);
+ if (ret)
+ FSWRK_COM_FATAL(progname, ret);
+
+ di = (struct ocfs2_dinode *)buf;
+ max_inline_sz = ocfs2_max_inline_data(fs->fs_blocksize);
+
+ if (!(di->i_dyn_features & OCFS2_INLINE_DATA_FL)) {
+ di->i_dyn_features |= OCFS2_INLINE_DATA_FL;
+ }
+ /*mess up id_count,i_size and i_cluster in a inline inode*/
+ di->id2.i_data.id_count = 0;
+ di->i_size = max_inline_sz + 1;
+ di->i_clusters = 1;
+
+ ret = ocfs2_write_inode(fs,inline_blkno,buf);
+ if (ret)
+ FSWRK_COM_FATAL(progname, ret);
+
+ if (buf)
+ ocfs2_free(&buf);
+
+ return;
+}
diff --git a/fswreck/main.c b/fswreck/main.c
index b8afe08..ec06f3e 100644
--- a/fswreck/main.c
+++ b/fswreck/main.c
@@ -88,6 +88,10 @@ static struct corrupt_funcs cf[MAX_CORRUPT] = {
{ &corrupt_file, "Dirent field error: DIRENT_ZERO,
DIRENT_NAME_CHARS,DIRENT_INODE_RANGE, DIRENT_INODE_FREE, DIRENT_TYPE,
DIRENT_DUPLICATE, DIRENT_LENGTH"},
{ &corrupt_file, "Directory parent duplicate error: DIR_PARENT_DUP"},
{ &corrupt_file, "Directory not connected error: DIR_NOT_CONNECTED"},
+ { &corrupt_file, "Regular file inline-data flag
error :REGULAR_INLINE_DATA_FLAG"},
+ { &corrupt_file, "Regular file inline-data id_count,i_clusters and
i_size error : REGULAR_INLINE_DATA_ID_COUNT,
REGULAR_INLINE_DATA_I_CLUSTER, REGULAR_INLINE_DATA_I_SIZE "},
+ { &corrupt_file, "Directory inline-data flag
error :DIR_INLINE_DATA_FLAG"},
+ { &corrupt_file, "Directory inline-data id_count,i_clusters and i_size
error : DIR_INLINE_DATA_ID_COUNT, DIR_INLINE_DATA_I_CLUSTER,
DIR_INLINE_DATA_I_SIZE "},
{ &corrupt_group_desc, "Create an error of GROUP_FREE_BITS and
CLUSTER_ALLOC_BITS, simulate bug841 in oss.oracle.com/bugzilla"}
};
--
1.5.5
More information about the Ocfs2-tools-devel
mailing list