4
* inode fields corruptions
6
* Copyright (C) 2006 Oracle. All rights reserved.
8
* This program is free software; you can redistribute it and/or
9
* modify it under the terms of the GNU General Public
10
* License as published by the Free Software Foundation; either
11
* version 2 of the License, or (at your option) any later version.
13
* This program is distributed in the hope that it will be useful,
14
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16
* General Public License for more details.
18
* You should have received a copy of the GNU General Public
19
* License along with this program; if not, write to the
20
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21
* Boston, MA 021110-1307, USA.
25
/* This file will create the errors for the inode.
27
* Inode field error: INODE_SUBALLOC, INODE_GEN, INODE_GEN_FIX,INODE_BLKNO,
28
INODE_NZ_DTIME, INODE_SIZE, INODE_CLUSTERS, INODE_COUNT
30
* Inode link not connected error: INODE_LINK_NOT_CONNECTED
32
* Inode orphaned error: INODE_ORPHANED
34
* Inode alloc error: INODE_ALLOC_REPAIR
40
extern char *progname;
42
static void damage_inode(ocfs2_filesys *fs, uint64_t blkno,
47
struct ocfs2_dinode *di;
49
ret = ocfs2_malloc_block(fs->fs_io, &buf);
51
FSWRK_COM_FATAL(progname, ret);
53
ret = ocfs2_read_inode(fs, blkno, buf);
55
FSWRK_COM_FATAL(progname, ret);
57
di = (struct ocfs2_dinode *)buf;
59
if (!(di->i_flags & OCFS2_VALID_FL))
60
FSWRK_FATAL("not a file");
64
fprintf(stdout, "INODE_GEN: "
65
"Corrupt inode#%"PRIu64", change generation "
66
" from %u to 0x1234\n", blkno, di->i_fs_generation);
67
di->i_fs_generation = 0x1234;
70
fprintf(stdout, "INODE_GEN_FIX: "
71
"Corrupt inode#%"PRIu64", change generation "
72
" from %u to 0x1234, please answer 'n' when "
73
"INODE_GEN error shows in fsck.ocfs2\n",
74
blkno, di->i_fs_generation);
75
di->i_fs_generation = 0x1234;
78
fprintf(stdout, "INODE_BLKNO: "
79
"Corrupt inode#%"PRIu64", change i_blkno from %"PRIu64
81
blkno, di->i_blkno, (di->i_blkno + 10));
85
fprintf(stdout, "INODE_NZ_DTIME: "
86
"Corrupt inode#%"PRIu64", change i_dtime from %"PRIu64
87
" to 100\n", blkno, di->i_dtime);
91
fprintf(stdout, "INODE_SUBALLOC: "
92
"Corrupt inode#%"PRIu64", change i_suballoc_slot"
93
" from %u to %u\n", blkno, di->i_suballoc_slot,
94
(di->i_suballoc_slot + 10));
95
di->i_suballoc_slot += 10;
98
fprintf(stdout, "INODE_SIZE: "
99
"Corrupt inode#%"PRIu64", change i_size"
100
" from %"PRIu64" to %"PRIu64"\n",
101
blkno, di->i_size, (di->i_size + 100));
105
fprintf(stdout, "INODE_CLUSTER: "
106
"Corrupt inode#%"PRIu64", change i_clusters"
107
" from %u to 0\n", blkno, di->i_clusters);
111
di->i_links_count = 0;
112
fprintf(stdout, "INODE_COUNT: "
113
"Corrupte inode#%"PRIu64", set link count to 0\n",
117
FSWRK_FATAL("Invalid type[%d]\n", type);
120
ret = ocfs2_write_inode(fs, blkno, buf);
122
FSWRK_COM_FATAL(progname, ret);
129
void mess_up_inode_field(ocfs2_filesys *fs, uint64_t blkno)
134
uint32_t clusters = 10;
135
enum fsck_type types[] = { INODE_GEN, INODE_GEN_FIX, INODE_BLKNO,
136
INODE_NZ_DTIME, INODE_SUBALLOC,
137
INODE_SIZE, INODE_CLUSTERS,
140
for (i = 0; i < ARRAY_ELEMENTS(types); i++) {
141
create_file(fs, blkno, &tmpblkno);
143
if (types[i] == INODE_CLUSTERS) {
144
ret = ocfs2_extend_allocation(fs, tmpblkno, clusters);
146
FSWRK_COM_FATAL(progname, ret);
149
damage_inode(fs, tmpblkno, types[i]);
154
void mess_up_inode_not_connected(ocfs2_filesys *fs, uint64_t blkno)
159
ret = ocfs2_new_inode(fs, &tmpblkno, S_IFREG | 0755);
161
FSWRK_COM_FATAL(progname, ret);
163
fprintf(stdout, "INODE_NOT_CONNECTED: "
164
"Create an inode#%"PRIu64" which has no links\n", tmpblkno);
168
void mess_up_inode_orphaned(ocfs2_filesys *fs, uint16_t slotnum)
171
uint64_t blkno, tmpblkno;
172
char parentdir[OCFS2_MAX_FILENAME_LEN];
173
struct ocfs2_super_block *sb = OCFS2_RAW_SB(fs->fs_super);
175
if (slotnum == UINT16_MAX)
177
snprintf(parentdir, sizeof(parentdir),
178
ocfs2_system_inodes[ORPHAN_DIR_SYSTEM_INODE].si_name, slotnum);
180
ret = ocfs2_lookup(fs, sb->s_system_dir_blkno, parentdir,
181
strlen(parentdir), NULL, &blkno);
183
FSWRK_COM_FATAL(progname, ret);
185
create_file(fs, blkno, &tmpblkno);
187
fprintf(stdout, "INODE_ORPHANED: "
188
"Create an inode#%"PRIu64" under directory %s\n",
189
tmpblkno, parentdir);
193
void mess_up_inode_alloc(ocfs2_filesys *fs, uint16_t slotnum)
198
struct ocfs2_dinode *di;
200
ret = ocfs2_new_inode(fs, &tmpblkno, S_IFREG | 0755);
202
FSWRK_COM_FATAL(progname, ret);
204
ret = ocfs2_malloc_block(fs->fs_io, &buf);
206
FSWRK_COM_FATAL(progname, ret);
208
ret = ocfs2_read_inode(fs, tmpblkno, buf);
210
FSWRK_COM_FATAL(progname, ret);
212
di = (struct ocfs2_dinode *)buf;
214
di->i_flags &= ~OCFS2_VALID_FL;
216
ret = ocfs2_write_inode(fs, tmpblkno, buf);
218
FSWRK_COM_FATAL(progname, ret);
220
fprintf(stdout, "INODE_ALLOC_REPAIR: "
221
"Create an inode#%"PRIu64" and invalidate it.\n", tmpblkno);