[Ocfs2-tools-commits] smushran commits r468 - in trunk/fswreck: .
include
svn-commits at oss.oracle.com
svn-commits at oss.oracle.com
Wed Dec 8 15:15:14 CST 2004
Author: smushran
Date: 2004-12-08 15:15:13 -0600 (Wed, 08 Dec 2004)
New Revision: 468
Modified:
trunk/fswreck/chain.c
trunk/fswreck/corrupt.c
trunk/fswreck/include/chain.h
trunk/fswreck/include/corrupt.h
trunk/fswreck/main.c
Log:
corrupt checks 3-6 added
Modified: trunk/fswreck/chain.c
===================================================================
--- trunk/fswreck/chain.c 2004-12-07 01:17:14 UTC (rev 467)
+++ trunk/fswreck/chain.c 2004-12-08 21:15:13 UTC (rev 468)
@@ -28,17 +28,17 @@
extern char *progname;
/*
- * delink_chain_group()
+ * mess_up_chains()
*
*/
-void delink_chain_group(ocfs2_filesys *fs, int blkno, int count)
+void mess_up_chains(ocfs2_filesys *fs, uint64_t blkno, int code)
{
errcode_t ret;
char *buf = NULL;
ocfs2_dinode *di;
ocfs2_chain_list *cl;
ocfs2_chain_rec *cr;
- int i, j;
+ int i;
ret = ocfs2_malloc_block(fs->fs_io, &buf);
if (ret)
@@ -50,29 +50,74 @@
di = (ocfs2_dinode *)buf;
+ if (!(di->i_flags & OCFS2_BITMAP_FL))
+ FSWRK_FATAL("not a bitmap");
+
if (!(di->i_flags & OCFS2_CHAIN_FL))
FSWRK_FATAL("not a chain group");
cl = &(di->id2.i_chain);
- /* delink 'count' chains from the inode */
- for (i = cl->cl_next_free_rec, j = 0; i && j < count; --i, ++j) {
- cr = &(cl->cl_recs[i - 1]);
- fprintf(stdout, "Delinking ind=%d, block#=%"PRIu64", free=%u, total=%u\n",
- i - 1, cr->c_blkno, cr->c_free, cr->c_total);
- cr->c_free = 12345;
- cr->c_total = 67890;
- cr->c_blkno = 1234567890;
+ switch (code) {
+ case 3:
+ /* delink last chain from the inode */
+ fprintf(stdout, "Corrupt #%02d: Delink group descriptor "
+ "at block#%"PRIu64"\n", code, blkno);
+ if (!cl->cl_next_free_rec) {
+ fprintf(stdout, "No chains to delink\n");
+ goto bail;
+ } else {
+ i = cl->cl_next_free_rec - 1;
+ cr = &(cl->cl_recs[i]);
+ fprintf(stdout, "Delinking ind=%d, block#=%"PRIu64", "
+ "free=%u, total=%u\n", i, cr->c_blkno,
+ cr->c_free, cr->c_total);
+ cr->c_free = 12345;
+ cr->c_total = 67890;
+ cr->c_blkno = 1234567890;
+ cl->cl_next_free_rec = i;
+ }
+ break;
+
+ case 4:
+ /* corrupt cl_count */
+ fprintf(stdout, "Corrupt #%02d: Increase chainlist count "
+ "at block#%"PRIu64" from %u to %u\n", code, blkno,
+ cl->cl_count, (cl->cl_count + 123));
+ cl->cl_count += 123;
+ break;
+
+ case 5:
+ /* corrupt cl_next_free_rec */
+ fprintf(stdout, "Corrupt #%02d: Increase chainlist nextfree "
+ "at block#%"PRIu64" from %u to %u\n", code, blkno,
+ cl->cl_next_free_rec, (cl->cl_next_free_rec + 10));
+ cl->cl_next_free_rec += 10;
+ break;
+
+ case 6:
+ /* corrupt id1.bitmap1.i_total/i_used */
+ fprintf(stdout, "Corrupt #%02d: Increase bitmap total "
+ "at block#%"PRIu64" from %u to %u\n", code, blkno,
+ di->id1.bitmap1.i_total, di->id1.bitmap1.i_total + 10);
+ fprintf(stdout, "Corrupt #%02d: Decrease bitmap used "
+ "at block#%"PRIu64" from %u to %u\n", code, blkno,
+ di->id1.bitmap1.i_used, 0);
+ di->id1.bitmap1.i_total += 10;
+ di->id1.bitmap1.i_used = 0;
+ break;
+
+ default:
+ FSWRK_FATAL("Invalid code=%d", code);
}
- cl->cl_next_free_rec = i;
-
ret = ocfs2_write_inode(fs, blkno, buf);
if (ret)
FSWRK_COM_FATAL(progname, ret);
- fprintf(stdout, "Delinked %d blocks\n", j);
+ fprintf(stdout, "Corrupt #%02d: Finito\n", code);
+bail:
if (buf)
ocfs2_free(&buf);
Modified: trunk/fswreck/corrupt.c
===================================================================
--- trunk/fswreck/corrupt.c 2004-12-07 01:17:14 UTC (rev 467)
+++ trunk/fswreck/corrupt.c 2004-12-08 21:15:13 UTC (rev 468)
@@ -27,24 +27,49 @@
extern char *progname;
-void corrupt_3(ocfs2_filesys *fs)
+/*
+ * corrupt_chains()
+ *
+ */
+void corrupt_chains(ocfs2_filesys *fs, int code, uint16_t nodenum)
{
errcode_t ret;
uint64_t blkno;
ocfs2_super_block *sb = OCFS2_RAW_SB(fs->fs_super);
- char *global_bitmap = sysfile_info[GLOBAL_BITMAP_SYSTEM_INODE].name;
+ char sysfile[40];
- ret = ocfs2_lookup(fs, sb->s_system_dir_blkno, global_bitmap,
- strlen(global_bitmap), NULL, &blkno);
+ switch (code) {
+ case 3:
+ case 4:
+ case 5:
+ case 6:
+ snprintf(sysfile, sizeof(sysfile),
+ sysfile_info[GLOBAL_BITMAP_SYSTEM_INODE].name);
+ break;
+#ifdef _LATER_
+ case 1:
+ snprintf(sysfile, sizeof(sysfile),
+ sysfile_info[GLOBAL_INODE_ALLOC_SYSTEM_INODE].name);
+ break;
+ case 2:
+ snprintf(sysfile, sizeof(sysfile),
+ sysfile_info[EXTENT_ALLOC_SYSTEM_INODE].name, nodenum);
+ break;
+ case 3:
+ snprintf(sysfile, sizeof(sysfile),
+ sysfile_info[INODE_ALLOC_SYSTEM_INODE].name, nodenum);
+ break;
+#endif
+ default:
+ FSWRK_FATAL("Invalid code=%d", code);
+ }
+
+ ret = ocfs2_lookup(fs, sb->s_system_dir_blkno, sysfile,
+ strlen(sysfile), NULL, &blkno);
if (ret)
FSWRK_FATAL();
- fprintf(stdout, "Corrupt #3: Delink group descriptor from "
- "global bitmap at block#%"PRIu64"\n", blkno);
+ mess_up_chains(fs, blkno, code);
- delink_chain_group(fs, blkno, 1);
-
- fprintf(stdout, "Corrupt #3: Finito\n");
-
return ;
}
Modified: trunk/fswreck/include/chain.h
===================================================================
--- trunk/fswreck/include/chain.h 2004-12-07 01:17:14 UTC (rev 467)
+++ trunk/fswreck/include/chain.h 2004-12-08 21:15:13 UTC (rev 468)
@@ -26,6 +26,6 @@
#ifndef __CHAIN_H__
#define __CHAIN_H__
-void delink_chain_group(ocfs2_filesys *fs, int blkno, int count);
+void mess_up_chains(ocfs2_filesys *fs, uint64_t blkno, int code);
#endif /* __CHAIN_H__ */
Modified: trunk/fswreck/include/corrupt.h
===================================================================
--- trunk/fswreck/include/corrupt.h 2004-12-07 01:17:14 UTC (rev 467)
+++ trunk/fswreck/include/corrupt.h 2004-12-08 21:15:13 UTC (rev 468)
@@ -26,6 +26,6 @@
#ifndef __CORRUPT_H
#define __CORRUPT_H
-void corrupt_3(ocfs2_filesys *fs);
+void corrupt_chains(ocfs2_filesys *fs, int code, uint16_t nodenum);
#endif /* __CORRUPT_H */
Modified: trunk/fswreck/main.c
===================================================================
--- trunk/fswreck/main.c 2004-12-07 01:17:14 UTC (rev 467)
+++ trunk/fswreck/main.c 2004-12-08 21:15:13 UTC (rev 468)
@@ -25,19 +25,27 @@
#include <main.h>
-#define MAX_CORRUPT 3
+#define MAX_CORRUPT 6
char *progname = NULL;
char *device = NULL;
+uint16_t nodenum = 0;
int corrupt[MAX_CORRUPT];
-void (*corrupt_func[]) (ocfs2_filesys *fs) = {
- NULL,
- NULL,
- NULL,
- &corrupt_3
+struct corrupt_funcs {
+ void (*func) (ocfs2_filesys *fs, int code, uint16_t nodenum);
};
+struct corrupt_funcs cf[] = {
+ { NULL }, /* 0 */
+ { NULL }, /* 1 */
+ { NULL }, /* 2 */
+ { &corrupt_chains }, /* 3 */
+ { &corrupt_chains }, /* 4 */
+ { &corrupt_chains }, /* 5 */
+ { &corrupt_chains } /* 6 */
+};
+
/*
* usage()
*
@@ -45,6 +53,8 @@
static void usage (char *progname)
{
g_print ("Usage: %s [OPTION]... [DEVICE]\n", progname);
+ g_print (" -c <corrupt code>\n");
+ g_print (" -n <node number>\n");
exit (0);
} /* usage */
@@ -91,7 +101,7 @@
}
while(1) {
- c = getopt(argc, argv, "c:");
+ c = getopt(argc, argv, "c:n:");
if (c == -1)
break;
@@ -106,6 +116,10 @@
}
break;
+ case 'n': /* nodenum */
+ nodenum = strtoul(optarg, NULL, 0);
+ break;
+
default:
break;
}
@@ -158,17 +172,19 @@
for (i = 1; i <= MAX_CORRUPT; ++i) {
if (corrupt[i]) {
- if (corrupt_func[i])
- corrupt_func[i](fs);
+ if (cf[i].func)
+ cf[i].func(fs, i, nodenum);
else
printf("Unimplemented corrupt code = %d\n", i);
}
}
bail:
- ret = ocfs2_close(fs);
- if (ret)
- com_err(progname, ret, "while closing \"%s\"", device);
+ if (fs) {
+ ret = ocfs2_close(fs);
+ if (ret)
+ com_err(progname, ret, "while closing \"%s\"", device);
+ }
return 0;
} /* main */
More information about the Ocfs2-tools-commits
mailing list