[Ocfs2-tools-devel] [PATCH 01/10] Ocfs2-tools: Define new corrupt code to make it compatible with fsck.ocfs2.
Tristan Ye
tristan.ye at oracle.com
Fri Jun 5 00:45:34 PDT 2009
In main.c, we redefine the corrupt_codes array to let it become FSCK_TYPE specific,
which can be provided as comma-separated-values string to fswreck binary.
As our goal is to change the logic of corrupt operation as few as possible, their
associated handling funcs will still use former corrupt_* func family.
Former CORRUPT_CODE enum will be abandoned as our new one will be more exact and
specific.
Signed-off-by: Tristan Ye <tristan.ye at oracle.com>
---
fswreck/include/fsck_type.h | 6 +-
fswreck/include/main.h | 38 ---
fswreck/main.c | 672 ++++++++++++++++++++++++++++++++++++++-----
3 files changed, 601 insertions(+), 115 deletions(-)
diff --git a/fswreck/include/fsck_type.h b/fswreck/include/fsck_type.h
index a03333d..20056b4 100644
--- a/fswreck/include/fsck_type.h
+++ b/fswreck/include/fsck_type.h
@@ -44,7 +44,8 @@ enum fsck_type
EXTENT_LIST_FREE,
EXTENT_BLKNO_RANGE,
CHAIN_CPG,
- SUPERBLOCK_CLUSTERS,
+ SUPERBLOCK_CLUSTERS_EXCESS,
+ SUPERBLOCK_CLUSTERS_LACK,
GROUP_UNEXPECTED_DESC,
GROUP_EXPECTED_DESC,
GROUP_GEN,
@@ -81,6 +82,7 @@ enum fsck_type
INODE_GEN,
INODE_GEN_FIX,
INODE_BLKNO,
+ INODE_LINK_NOT_CONNECTED,
ROOT_NOTDIR,
INODE_NZ_DTIME,
LINK_FAST_DATA,
@@ -112,8 +114,10 @@ enum fsck_type
INODE_NOT_CONNECTED,
INODE_COUNT,
INODE_ORPHANED,
+ CLUSTER_GROUP_DESC,
INLINE_DATA_FLAG_INVALID,
INLINE_DATA_COUNT_INVALID,
+ DUPLICATE_CLUSTERS,
NUM_FSCK_TYPE
};
diff --git a/fswreck/include/main.h b/fswreck/include/main.h
index 96230f4..3b19ed6 100644
--- a/fswreck/include/main.h
+++ b/fswreck/include/main.h
@@ -74,44 +74,6 @@
#undef min
#define min(a,b) ((a) < (b) ? (a) : (b))
-enum{
- CORRUPT_EXTENT_BLOCK = 13,
- CORRUPT_EXTENT_LIST,
- CORRUPT_EXTENT_REC,
- CORRUPT_CHAIN_LIST,
- CORRUPT_CHAIN_REC,
- CORRUPT_CHAIN_INODE,
- CORRUPT_CHAIN_GROUP,
- CORRUPT_CHAIN_GROUP_MAGIC,
- CORRUPT_CHAIN_CPG,
- CORRUPT_SUPERBLOCK_CLUSTERS_EXCESS,
- CORRUPT_SUPERBLOCK_CLUSTERS_LACK,
- CORRUPT_GROUP_MINOR,
- CORRUPT_GROUP_GENERATION,
- CORRUPT_GROUP_LIST,
- CORRUPT_INODE_FIELD,
- CORRUPT_INODE_NOT_CONNECTED,
- CORRUPT_INODE_ORPHANED,
- CORRUPT_INODE_ALLOC_REPAIR,
- CORRUPT_LOCAL_ALLOC_EMPTY,
- CORRUPT_LOCAL_ALLOC_BITMAP,
- CORRUPT_LOCAL_ALLOC_USED,
- CORRUPT_TRUNCATE_LOG_LIST,
- CORRUPT_TRUNCATE_LOG_REC,
- CORRUPT_SYMLINK,
- CORRUPT_SPECIAL_FILE,
- CORRUPT_DIR_INODE,
- CORRUPT_DIR_DOT,
- CORRUPT_DIR_ENT,
- CORRUPT_DIR_PARENT_DUP,
- CORRUPT_DIR_NOT_CONNECTED,
- CORRUPT_CLUSTER_AND_GROUP_DESC,
- CORRUPT_INLINE_DATA_FLAG,
- CORRUPT_INLINE_DATA_COUNT,
- CORRUPT_DUPLICATE_CLUSTERS,
- MAX_CORRUPT
-};
-
#define ARRAY_ELEMENTS(arr) (sizeof(arr) / sizeof(arr[0]))
/* remaining headers */
diff --git a/fswreck/main.c b/fswreck/main.c
index bc889d8..2690862 100644
--- a/fswreck/main.c
+++ b/fswreck/main.c
@@ -30,72 +30,531 @@ char *progname = NULL;
static char *device = NULL;
static uint16_t slotnum = UINT16_MAX;
-struct corrupt_funcs {
- void (*func) (ocfs2_filesys *fs, int code, uint16_t slotnum);
- char *desc;
+static int corrupt[NUM_FSCK_TYPE];
+
+struct prompt_code {
+
+ enum fsck_type type;
+ char *str;
+ void (*func)(ocfs2_filesys *fs, enum fsck_type code, uint16_t slotnum);
+ char *desc;
};
-static struct corrupt_funcs cf[MAX_CORRUPT] = {
- { NULL, "Not applicable"},
- { NULL, "Not applicable"},
- { NULL, "Not applicable"},
- /* Following relates to the Global bitmap: */
- { &corrupt_chains, "Delink the last chain from the inode"},
- { &corrupt_chains, "Corrupt cl_count"},
- { &corrupt_chains, "Corrupt cl_next_free_rec"},
- { NULL, "Not applicable"},
- { &corrupt_chains, "Corrupt id1.bitmap1.i_total/i_used"},
- { &corrupt_chains, "Corrupt c_blkno of the first record with a number larger than volume size"},
- { NULL, "Not applicable"},
- { &corrupt_chains, "Corrupt c_blkno of the first record with an unaligned number"},
- { &corrupt_chains, "Corrupt c_blkno of the first record with 0"},
- { &corrupt_chains, "Corrupt c_total/c_free of the first record"},
- { &corrupt_file, "Extent block error: EB_BLKNO, EB_GEN, EB_GEN_FIX, EXTENT_EB_INVALID"},
- { &corrupt_file, "Extent list error: EXTENT_LIST_DEPTH, EXTENT_LIST_COUNT, EXTENT_LIST_FREE"},
- { &corrupt_file, "Extent record error: EXTENT_BLKNO_UNALIGNED, EXTENT_CLUSTERS_OVERRUN, EXTENT_BLKNO_RANGE"},
- { &corrupt_sys_file, "Chain list error: CHAIN_COUNT, CHAIN_NEXT_FREE"},
- { &corrupt_sys_file, "Chain record error: CHAIN_EMPTY, CHAIN_HEAD_LINK_RANGE, CHAIN_BITS, CLUSTER_ALLOC_BIT"},
- { &corrupt_sys_file, "Chain inode error: CHAIN_I_CLUSTERS, CHAIN_I_SIZE, CHAIN_GROUP_BITS"},
- { &corrupt_sys_file, "Chain group error: CHAIN_LINK_GEN, CHAIN_LINK_RANGE"},
- { &corrupt_sys_file, "Group magic error: CHAIN_LINK_MAGIC"},
- { &corrupt_sys_file, "Chain resize error: CHAIN_CPG"},
- { &corrupt_sys_file, "Superblock error: SUPERBLOCK_CLUSTERS_EXCESS, excess error"},
- { &corrupt_sys_file, "Superblock error: SUPERBLOCK_CLUSTERS_LACK, lack error"},
- /* Following relates to corrupting group descriptor */
- { &corrupt_group_desc, "Group minor field error: GROUP_PARENT, GROUP_BLKNO, GROUP_CHAIN, GROUP_FREE_BITS"},
- { &corrupt_group_desc, "Group generation error: GROUP_GEN"},
- { &corrupt_group_desc, "Group list error: GROUP_UNEXPECTED_DESC, GROUP_EXPECTED_DESC"},
- /* Following relates to corrupting inode information */
- { &corrupt_file, "Inode field error: INODE_SUBALLOC, INODE_GEN, INODE_GEN_FIX,INODE_BLKNO,"
- "INODE_NZ_DTIME, INODE_SIZE, INODE_CLUSTERS, INODE_COUNT"},
- { &corrupt_file, "Inode link not connected error: INODE_LINK_NOT_CONNECTED "},
- { &corrupt_sys_file, "Inode orphaned error: INODE_ORPHANED"},
- { &corrupt_sys_file, "Inode alloc error: INODE_ALLOC_REPAIR"},
- /* Following relates to corrupting local alloc file */
- { &corrupt_local_alloc, "Empty local alloc error: LALLOC_SIZE, LALLOC_NZ_USED, LALLOC_NZ_BM"},
- { &corrupt_local_alloc, "Local alloc bitmap error: LALLOC_BM_OVERRUN, LALLOC_BM_STRADDLE,LALLOC_BM_SIZE"},
- { &corrupt_local_alloc, "Local alloc used info error: LALLOC_USED_OVERRUN, LALLOC_CLEAR"},
- /* Following relates to corrupting truncate log file */
- { &corrupt_truncate_log,"Truncate log list error: DEALLOC_COUNT, DEALLOC_USED"},
- { &corrupt_truncate_log,"Truncate log rec error: TRUNCATE_REC_START_RANGE, TRUNCATE_REC_WRAP, TRUNCATE_REC_RANGE"},
- /* Following relates to corrupting symlink file */
- { &corrupt_file, "Link file error: LINK_FAST_DATA, LINK_NULLTERM, LINK_SIZE, LINK_BLOCKS"},
- /* Following relates to corrupting root and lost+found */
- { &corrupt_file, "Special files error: ROOT_NOTDIR, ROOT_DIR_MISSING, LOSTFOUND_MISSING"},
- /* Following relates to corrupting directory */
- { &corrupt_file, "Directory inode error: DIR_ZERO"},
- { &corrupt_file, "Dirent dot error: DIRENT_DOTTY_DUP, DIRENT_NOT_DOTTY, DIRENT_DOT_INODE, DIRENT_DOT_EXCESS"},
- { &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_group_desc, "Create an error of GROUP_FREE_BITS and CLUSTER_ALLOC_BITS, simulate bug841 in oss.oracle.com/bugzilla"},
- { &corrupt_file, "Inline file dyn_features flag error: INLINE_DATA_FLAG_INVALID"},
- { &corrupt_file, "Inline file id_count,i_clusters and i_size error: INLINE_DATA_COUNT_INVALID"},
- { &corrupt_file, "Allocate the same cluster to two different files"},
+static struct prompt_code prompt_codes[NUM_FSCK_TYPE] = {
+
+ { .type = EB_BLKNO,
+ .str = "EB_BLKNO",
+ .func = &corrupt_file,
+ .desc = "Extent block error: EB_BLKNO",
+ },
+
+ { .type = EB_GEN,
+ .str = "EB_GEN",
+ .func = &corrupt_file,
+ .desc = "Extent block error: EB_GEN",
+ },
+
+ { .type = EB_GEN_FIX,
+ .str = "EB_GEN_FIX",
+ .func = &corrupt_file,
+ .desc = "Extent block error: EB_GEN_FIX",
+ },
+
+ {
+ .type = EXTENT_EB_INVALID,
+ .str = "EXTENT_EB_INVALID",
+ .func = &corrupt_file,
+ .desc = "Extent block error: EXTENT_EB_INVALID",
+ },
+
+ { .type = EXTENT_BLKNO_UNALIGNED,
+ .str = "EXTENT_BLKNO_UNALIGNED",
+ .func = &corrupt_file,
+ .desc = "Extent record error: EB_BLKNO_UNALIGNED",
+ },
+
+ { .type = EXTENT_CLUSTERS_OVERRUN,
+ .str = "EXTENT_CLUSTERS_OVERRUN",
+ .func = &corrupt_file,
+ .desc = "Extent record error: EB_CLUSTERS_OVERRUN",
+ },
+
+ { .type = EXTENT_BLKNO_RANGE,
+ .str = "EXTENT_BLKNO_RANGE",
+ .func = &corrupt_file,
+ .desc = "Extent record error: EXTENT_BLKNO_RANGE",
+ },
+
+ { .type = EXTENT_LIST_DEPTH,
+ .str = "EXTENT_LIST_DEPTH",
+ .func = &corrupt_file,
+ .desc = "Extent list error: EXTENT_LIST_DEPTH",
+ },
+
+ { .type = EXTENT_LIST_COUNT,
+ .str = "EXTENT_LIST_COUNT",
+ .func = &corrupt_file,
+ .desc = "Extent list error: EXTENT_LIST_COUNT",
+ },
+
+ { .type = EXTENT_LIST_FREE,
+ .str = "EXTENT_LIST_FREE",
+ .func = &corrupt_file,
+ .desc = "Extent list error: EXTENT_LIST_FREE",
+ },
+
+ { .type = INODE_SUBALLOC,
+ .str = "INODE_SUBALLOC",
+ .func = &corrupt_file,
+ .desc = "Inode field error: INODE_SUBALLOC",
+ },
+
+ { .type = INODE_GEN,
+ .str = "INODE_GEN",
+ .func = &corrupt_file,
+ .desc = "Inode field error: INODE_GEN",
+ },
+
+ { .type = INODE_GEN_FIX,
+ .str = "INODE_GEN_FIX",
+ .func = &corrupt_file,
+ .desc = "Inode field error: INODE_GEN_FIX",
+ },
+
+ { .type = INODE_BLKNO,
+ .str = "INODE_BLKNO",
+ .func = &corrupt_file,
+ .desc = "Inode field error: INODE_BLKNO",
+ },
+
+ { .type = INODE_NZ_DTIME,
+ .str = "INODE_NZ_DTIME",
+ .func = &corrupt_file,
+ .desc = "Inode field error: INODE_NZ_DTIME",
+ },
+
+ { .type = INODE_SIZE,
+ .str = "INODE_SIZE",
+ .func = &corrupt_file,
+ .desc = "Inode field error: INODE_SIZE",
+ },
+
+ { .type = INODE_CLUSTERS,
+ .str = "INODE_CLUSTERS",
+ .func = &corrupt_file,
+ .desc = "Inode field error: INODE_CLUSTERS",
+ },
+
+ { .type = INODE_COUNT,
+ .str = "INODE_COUNT",
+ .func = &corrupt_file,
+ .desc = "Inode field error: INODE_COUNT",
+ },
+
+ { .type = INODE_LINK_NOT_CONNECTED,
+ .str = "INODE_LINK_NOT_CONNECTED",
+ .func = &corrupt_file,
+ .desc = "Inode link not connected error: INODE_LINK_NOT_CONNECTED",
+ },
+
+ { .type = INODE_NOT_CONNECTED,
+ .str = "INODE_NOT_CONNECTED",
+ .func = NULL,
+ .desc = "Unimplemented corrupt code",
+ },
+
+ { .type = LINK_FAST_DATA,
+ .str = "LINK_FAST_DATA",
+ .func = &corrupt_file,
+ .desc = "Link file error: LINK_FAST_DATA",
+ },
+
+ { .type = LINK_NULLTERM,
+ .str = "LINK_NULLTERM",
+ .func = &corrupt_file,
+ .desc = "Link file error: LINK_NULLTERM",
+ },
+
+ { .type = LINK_SIZE,
+ .str = "LINK_SIZE",
+ .func = &corrupt_file,
+ .desc = "Link file error: LINK_SIZE",
+ },
+
+ { .type = LINK_BLOCKS,
+ .str = "LINK_BLOCKS",
+ .func = &corrupt_file,
+ .desc = "Link file error: LINK_BLOCKS",
+ },
+
+ { .type = ROOT_NOTDIR,
+ .str = "ROOT_NOTDIR",
+ .func = &corrupt_file,
+ .desc = "Special files error: ROOT_NOTDIR",
+ },
+
+ { .type = ROOT_DIR_MISSING,
+ .str = "ROOT_DIR_MISSING",
+ .func = &corrupt_file,
+ .desc = "Special files error: ROOT_DIR_MISSING",
+ },
+
+ { .type = LOSTFOUND_MISSING,
+ .str = "LOSTFOUND_MISSING",
+ .func = &corrupt_file,
+ .desc = "Special files error: LOSTFOUND_MISSING",
+ },
+
+ { .type = DIR_DOTDOT,
+ .str = "DIR_DOTDOT",
+ .func = NULL,
+ .desc = "Unimplemented corrupt code",
+ },
+
+ { .type = DIR_ZERO,
+ .str = "DIR_ZERO",
+ .func = &corrupt_file,
+ .desc = "Directory inode error: DIR_ZERO",
+ },
+
+ { .type = DIRENT_DOTTY_DUP,
+ .str = "DIRENT_DOTTY_DUP",
+ .func = &corrupt_file,
+ .desc = "Dirent dot error: DIRENT_DOTTY_DUP",
+ },
+
+ { .type = DIRENT_NOT_DOTTY,
+ .str = "DIRENT_NOT_DOTTY",
+ .func = &corrupt_file,
+ .desc = "Dirent dot error: DIRENT_NOT_DOTTY",
+ },
+
+ { .type = DIRENT_DOT_INODE,
+ .str = "DIRENT_DOT_INODE",
+ .func = &corrupt_file,
+ .desc = "Dirent dot error: DIRENT_DOT_INODE",
+ },
+
+ { .type = DIRENT_DOT_EXCESS,
+ .str = "DIRENT_DOT_EXCESS",
+ .func = &corrupt_file,
+ .desc = "Dirent dot error: DIRENT_DOT_EXCESS",
+ },
+
+ { .type = DIRENT_ZERO,
+ .str = "DIRENT_ZERO",
+ .func = &corrupt_file,
+ .desc = "Dirent field error: DIRENT_ZERO",
+ },
+
+ { .type = DIRENT_NAME_CHARS,
+ .str = "DIRENT_NAME_CHARS",
+ .func = &corrupt_file,
+ .desc = "Dirent field error: DIRENT_NAME_CHARS",
+ },
+
+ { .type = DIRENT_INODE_RANGE,
+ .str = "DIRENT_INODE_RANGE",
+ .func = &corrupt_file,
+ .desc = "Dirent field error: DIRENT_INODE_RANGE",
+ },
+
+ { .type = DIRENT_INODE_FREE,
+ .str = "DIRENT_INODE_FREE",
+ .func = &corrupt_file,
+ .desc = "Dirent field error: DIRENT_INODE_FREE",
+ },
+
+ { .type = DIRENT_TYPE,
+ .str = "DIRENT_TYPE",
+ .func = &corrupt_file,
+ .desc = "Dirent field error: DIRENT_TYPE",
+ },
+
+ { .type = DIRENT_DUPLICATE,
+ .str = "DIRENT_DUPLICATE",
+ .func = &corrupt_file,
+ .desc = "Dirent field error: DIRENT_DUPLICATE",
+ },
+
+ { .type = DIRENT_LENGTH,
+ .str = "DIRENT_LENGTH",
+ .func = &corrupt_file,
+ .desc = "Dirent field error: DIRENT_LENGTH",
+ },
+
+ { .type = DIR_PARENT_DUP,
+ .str = "DIR_PARENT_DUP",
+ .func = &corrupt_file,
+ .desc = "Directory parent duplicate error: DIR_PARENT_DUP",
+ },
+
+ { .type = DIR_NOT_CONNECTED,
+ .str = "DIR_NOT_CONNECTED",
+ .func = &corrupt_file,
+ .desc = "Directory not connected error: DIR_NOT_CONNECTED",
+ },
+
+ { .type = INLINE_DATA_FLAG_INVALID,
+ .str = "INLINE_DATA_FLAG_INVALID",
+ .func = &corrupt_file,
+ .desc = "Inline file dyn_features flag error: INLINE_DATA_FLAG_INVALID",
+ },
+
+ { .type = INLINE_DATA_COUNT_INVALID,
+ .str = "INLINE_DATA_COUNT_INVALID",
+ .func = &corrupt_file,
+ .desc = "Inline file id_count,i_clusters and i_size error: INLINE_DATA_COUNT_INVALID",
+ },
+
+ { .type = DUPLICATE_CLUSTERS,
+ .str = "DUPLICATE_CLUSTERS",
+ .func = &corrupt_file,
+ .desc = "Allocate the same cluster to two different files: DUPLICATE_CLUSTERS",
+ },
+
+ { .type = CHAIN_COUNT,
+ .str = "CHAIN_COUNT",
+ .func = &corrupt_sys_file,
+ .desc = "hain list error: CHAIN_COUNT"
+ },
+
+ { .type = CHAIN_NEXT_FREE,
+ .str = "CHAIN_NEXT_FREE",
+ .func = &corrupt_sys_file,
+ .desc = "hain list error: CHAIN_NEXT_FREE"
+ },
+
+ { .type = CHAIN_EMPTY,
+ .str = "CHAIN_EMPTY",
+ .func = &corrupt_sys_file,
+ .desc = "Chain record error: CHAIN_EMPTY"
+ },
+
+ { .type = CHAIN_HEAD_LINK_RANGE,
+ .str = "CHAIN_HEAD_LINK_RANGE",
+ .func = &corrupt_sys_file,
+ .desc = "Chain record error: CHAIN_HEAD_LINK_RANGE"
+ },
+
+ { .type = CHAIN_BITS,
+ .str = "CHAIN_BITS",
+ .func = &corrupt_sys_file,
+ .desc = "Chain record error: CHAIN_BITS"
+ },
+
+ { .type = CLUSTER_ALLOC_BIT,
+ .str = "CLUSTER_ALLOC_BIT",
+ .func = &corrupt_sys_file,
+ .desc = "Chain record error: CLUSTER_ALLOC_BIT"
+ },
+
+ { .type = CHAIN_I_CLUSTERS,
+ .str = "CHAIN_I_CLUSTERS",
+ .func = &corrupt_sys_file,
+ .desc = "Chain inode error: CHAIN_I_CLUSTERS"
+ },
+
+ { .type = CHAIN_I_SIZE,
+ .str = "CHAIN_I_SIZE",
+ .func = &corrupt_sys_file,
+ .desc = "Chain inode error: CHAIN_I_SIZE"
+ },
+
+ { .type = CHAIN_GROUP_BITS,
+ .str = "CHAIN_GROUP_BITS",
+ .func = &corrupt_sys_file,
+ .desc = "Chain inode error: CHAIN_GROUP_BITS"
+ },
+
+ { .type = CHAIN_LINK_GEN,
+ .str = "CHAIN_LINK_GEN",
+ .func = &corrupt_sys_file,
+ .desc = "Chain group error: CHAIN_LINK_GEN"
+ },
+
+ { .type = CHAIN_LINK_RANGE,
+ .str = "CHAIN_LINK_RANGE",
+ .func = &corrupt_sys_file,
+ .desc = "Chain group error: CHAIN_LINK_RANGE"
+ },
+
+ { .type = CHAIN_LINK_MAGIC,
+ .str = "CHAIN_LINK_MAGIC",
+ .func = &corrupt_sys_file,
+ .desc = "Group magic error: CHAIN_LINK_MAGIC"
+ },
+
+ { .type = CHAIN_CPG,
+ .str = "CHAIN_CPG",
+ .func = &corrupt_sys_file,
+ .desc = "Chain resize error: CHAIN_CPG"
+ },
+
+ { .type = SUPERBLOCK_CLUSTERS_EXCESS,
+ .str = "SUPERBLOCK_CLUSTERS_EXCESS",
+ .func = &corrupt_sys_file,
+ .desc = "Superblock error: SUPERBLOCK_CLUSTERS_EXCESS"
+ },
+
+ { .type = SUPERBLOCK_CLUSTERS_LACK,
+ .str = "SUPERBLOCK_CLUSTERS_LACK",
+ .func = &corrupt_sys_file,
+ .desc = "Superblock error: SUPERBLOCK_CLUSTERS_LACK"
+ },
+
+ { .type = INODE_ORPHANED,
+ .str = "INODE_ORPHANED",
+ .func = &corrupt_sys_file,
+ .desc = "Inode orphaned error: INODE_ORPHANED"
+ },
+
+ { .type = INODE_ALLOC_REPAIR,
+ .str = "INODE_ALLOC_REPAIR",
+ .func = &corrupt_sys_file,
+ .desc = "Inode alloc error: INODE_ALLOC_REPAIR"
+ },
+
+ { .type = GROUP_PARENT,
+ .str = "GROUP_PARENT",
+ .func = &corrupt_group_desc,
+ .desc = "Group minor field error: GROUP_PARENT"
+ },
+
+ { .type = GROUP_BLKNO,
+ .str = "GROUP_BLKNO",
+ .func = &corrupt_group_desc,
+ .desc = "Group minor field error: GROUP_BLKNO"
+ },
+
+ { .type = GROUP_CHAIN,
+ .str = "GROUP_CHAIN",
+ .func = &corrupt_group_desc,
+ .desc = "Group minor field error: GROUP_CHAIN"
+ },
+
+ { .type = GROUP_FREE_BITS,
+ .str = "GROUP_FREE_BITS",
+ .func = &corrupt_group_desc,
+ .desc = "Group minor field error: GROUP_FREE_BITS"
+ },
+
+ { .type = GROUP_GEN,
+ .str = "GROUP_GEN",
+ .func = &corrupt_group_desc,
+ .desc = "Group generation error: GROUP_GEN"
+ },
+
+ { .type = GROUP_UNEXPECTED_DESC,
+ .str = "GROUP_UNEXPECTED_DESC",
+ .func = &corrupt_group_desc,
+ .desc = "Group list error: GROUP_UNEXPECTED_DESC"
+ },
+
+ { .type = GROUP_EXPECTED_DESC,
+ .str = "GROUP_EXPECTED_DESC",
+ .func = &corrupt_group_desc,
+ .desc = "Group list error: GROUP_EXPECTED_DESC"
+ },
+
+ { .type = CLUSTER_GROUP_DESC,
+ .str = "CLUSTER_GROUP_DESC",
+ .func = &corrupt_group_desc,
+ .desc = "Create an error of GROUP_FREE_BITS and CLUSTER_ALLOC_BITS, simulate bug841 in oss.oracle.com/bugzilla"
+ },
+
+ { .type = LALLOC_SIZE,
+ .str = "LALLOC_SIZE",
+ .func = &corrupt_local_alloc,
+ .desc = "Empty local alloc error: LALLOC_SIZE"
+ },
+
+ { .type = LALLOC_NZ_USED,
+ .str = "LALLOC_NZ_USED",
+ .func = &corrupt_local_alloc,
+ .desc = "Empty local alloc error: LALLOC_NZ_USED"
+ },
+
+ { .type = LALLOC_NZ_BM,
+ .str = "LALLOC_NZ_BM",
+ .func = &corrupt_local_alloc,
+ .desc = "Empty local alloc error: LALLOC_NZ_BM"
+ },
+
+ { .type = LALLOC_BM_OVERRUN,
+ .str = "LALLOC_BM_OVERRUN",
+ .func = &corrupt_local_alloc,
+ .desc = "Local alloc bitmap error: LALLOC_BM_OVERRUN"
+ },
+
+ { .type = LALLOC_BM_STRADDLE,
+ .str = "LALLOC_BM_STRADDLE",
+ .func = &corrupt_local_alloc,
+ .desc = "Local alloc bitmap error: LALLOC_BM_STRADDLE"
+ },
+
+ { .type = LALLOC_BM_SIZE,
+ .str = "LALLOC_BM_SIZE",
+ .func = &corrupt_local_alloc,
+ .desc = "Local alloc bitmap error: LALLOC_BM_SIZE"
+ },
+
+ { .type = LALLOC_USED_OVERRUN,
+ .str = "LALLOC_USED_OVERRUN",
+ .func = &corrupt_local_alloc,
+ .desc = "Local alloc used info error: LALLOC_USED_OVERRUN"
+ },
+
+ { .type = LALLOC_CLEAR,
+ .str = "LALLOC_CLEAR",
+ .func = &corrupt_local_alloc,
+ .desc = "Local alloc used info error: LALLOC_CLEAR"
+ },
+
+ { .type = LALLOC_REPAIR,
+ .str = "LALLOC_REPAIR",
+ .func = NULL,
+ .desc = "Unimplemented corrupt code",
+ },
+
+ { .type = LALLOC_USED,
+ .str = "LALLOC_USED",
+ .func = NULL,
+ .desc = "Unimplemented corrupt code",
+ },
+
+ { .type = DEALLOC_COUNT,
+ .str = "DEALLOC_COUNT",
+ .func = &corrupt_truncate_log,
+ .desc = "Truncate log list error: DEALLOC_COUNT"
+ },
+
+ { .type = DEALLOC_USED,
+ .str = "DEALLOC_USED",
+ .func = &corrupt_truncate_log,
+ .desc = "Truncate log list error: DEALLOC_USED"
+ },
+
+ { .type = TRUNCATE_REC_START_RANGE,
+ .str = "TRUNCATE_REC_START_RANGE",
+ .func = &corrupt_truncate_log,
+ .desc = "Truncate log rec error: TRUNCATE_REC_START_RANGE"
+ },
+
+ { .type = TRUNCATE_REC_WRAP,
+ .str = "TRUNCATE_REC_WRAP",
+ .func = &corrupt_truncate_log,
+ .desc = "Truncate log rec error: TRUNCATE_REC_WRAP"
+ },
+
+ { .type = TRUNCATE_REC_RANGE,
+ .str = "TRUNCATE_REC_RANGE",
+ .func = &corrupt_truncate_log,
+ .desc = "Truncate log rec error: TRUNCATE_REC_RANGE"
+ },
};
-static int corrupt[MAX_CORRUPT];
/*
* usage()
*
@@ -110,8 +569,9 @@ static void usage (char *progname)
g_print (" -n <node slot number>\n");
g_print (" -c <corrupt code>\n");
g_print (" corrupt code description:\n");
- for (i = 0; i < MAX_CORRUPT; i++)
- g_print (" %02d - %s\n", i, cf[i].desc);
+ for (i = 0; i < NUM_FSCK_TYPE; i++)
+ g_print(" %s - %s\n", prompt_codes[i].str,
+ prompt_codes[i].desc);
exit (0);
} /* usage */
@@ -141,6 +601,67 @@ static void handle_signal (int sig)
return ;
} /* handle_signal */
+static int corrupt_code_match(const char *corrupt_codes)
+{
+ int i;
+
+ for (i = 0; i < NUM_FSCK_TYPE; i++)
+ if (strcmp(corrupt_codes, prompt_codes[i].str) == 0)
+ return i;
+
+ return -1;
+}
+
+static int parse_corrupt_codes(const char *corrupt_codes)
+{
+ int ret = 0, i = -2;
+ char *codes;
+ char *p;
+ char *token = NULL;
+
+ p = corrupt_codes;
+ codes = strdup(corrupt_codes);
+
+ while (p) {
+
+ token = p;
+ p = strchr(p, ',');
+
+ if (p)
+ *p = 0;
+
+ if (strcmp(token, "") != 0) {
+
+ i = corrupt_code_match(token);
+
+ if (i >= 0)
+ corrupt[i] = 1;
+ else {
+
+ fprintf(stderr, "Corrupt code \"%s\" was not "
+ "supported.\n", token);
+ ret = -1;
+ break;
+ }
+
+ }
+
+ if (!p)
+ continue;
+ p++;
+
+ }
+
+ free(codes);
+
+ if (i == -2) {
+ fprintf(stderr, "At least one corrupt code needed.\n");
+ ret = -1;
+ }
+
+ return ret;
+}
+
/*
* read_options()
@@ -149,7 +670,7 @@ static void handle_signal (int sig)
static int read_options(int argc, char **argv)
{
int c;
- int ind;
+ int ret = 0;
progname = basename(argv[0]);
@@ -165,13 +686,7 @@ static int read_options(int argc, char **argv)
switch (c) {
case 'c': /* corrupt */
- ind = strtoul(optarg, NULL, 0);
- if (ind < MAX_CORRUPT)
- corrupt[ind] = 1;
- else {
- fprintf(stderr, "Invalid corrupt code:%d\n", ind);
- return -1;
- }
+ ret = parse_corrupt_codes(optarg);
break;
case 'n': /* slotnum */
@@ -186,7 +701,10 @@ static int read_options(int argc, char **argv)
if (optind < argc && argv[optind])
device = argv[optind];
- return 0;
+ if (ret < 0)
+ usage(progname);
+
+ return ret;
}
/*
@@ -230,12 +748,14 @@ int main (int argc, char **argv)
goto bail;
}
- for (i = 1; i < MAX_CORRUPT; ++i) {
+ for (i = 1; i < NUM_FSCK_TYPE; ++i) {
if (corrupt[i]) {
- if (cf[i].func)
- cf[i].func(fs, i, slotnum);
+ if (prompt_codes[i].func)
+ prompt_codes[i].func(fs, prompt_codes[i].type,
+ slotnum);
else
- fprintf(stderr, "Unimplemented corrupt code = %d\n", i);
+ fprintf(stderr, "Unimplemented corrupt code "
+ "= %s\n", prompt_codes[i].str);
}
}
--
1.5.5
More information about the Ocfs2-tools-devel
mailing list