~ubuntu-branches/ubuntu/maverick/ocfs2-tools/maverick

« back to all changes in this revision

Viewing changes to fswreck/inode.c

  • Committer: Bazaar Package Importer
  • Author(s): Fabio M. Di Nitto
  • Date: 2007-11-19 06:53:59 UTC
  • Revision ID: james.westby@ubuntu.com-20071119065359-7yan1p3eg1d28sgx
Tags: 1.3.9-0ubuntu1

* Update default timeouts in template and translations files.

* debian/rules: fix clean target to not purge upstream patches/ directory.

* debian/control: rework Build-Depends
  - sort them: debian build specific bits first, upstream after in configure
    check order.
  - add pkg-config.
  - add libselinux1-dev and libsepol1-dev.

* add package ocfs2-tools-static-dev to include all development headers and
  static libraries required to build ocfs2-test (and possibly other tools
  that already in development stage.

* stop shipping local copy of mount.ocfs2.8

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * inode.c
 
3
 *
 
4
 * inode fields corruptions
 
5
 *
 
6
 * Copyright (C) 2006 Oracle.  All rights reserved.
 
7
 *
 
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.
 
12
 * 
 
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.
 
17
 * 
 
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.
 
22
 *
 
23
 */
 
24
 
 
25
/* This file will create the errors for the inode.
 
26
 *
 
27
 * Inode field error:   INODE_SUBALLOC, INODE_GEN, INODE_GEN_FIX,INODE_BLKNO,
 
28
                        INODE_NZ_DTIME, INODE_SIZE, INODE_CLUSTERS, INODE_COUNT
 
29
 *
 
30
 * Inode link not connected error: INODE_LINK_NOT_CONNECTED 
 
31
 *
 
32
 * Inode orphaned error:        INODE_ORPHANED
 
33
 *
 
34
 * Inode alloc error:   INODE_ALLOC_REPAIR
 
35
 *
 
36
 */
 
37
 
 
38
#include <main.h>
 
39
 
 
40
extern char *progname;
 
41
 
 
42
static void damage_inode(ocfs2_filesys *fs, uint64_t blkno,
 
43
                                enum fsck_type type)
 
44
{
 
45
        errcode_t ret;
 
46
        char *buf = NULL;
 
47
        struct ocfs2_dinode *di;
 
48
 
 
49
        ret = ocfs2_malloc_block(fs->fs_io, &buf);
 
50
        if (ret)  
 
51
                FSWRK_COM_FATAL(progname, ret); 
 
52
 
 
53
        ret = ocfs2_read_inode(fs, blkno, buf);
 
54
        if (ret)
 
55
                FSWRK_COM_FATAL(progname, ret); 
 
56
 
 
57
        di = (struct ocfs2_dinode *)buf;
 
58
 
 
59
        if (!(di->i_flags & OCFS2_VALID_FL))
 
60
                FSWRK_FATAL("not a file");
 
61
 
 
62
        switch (type) {
 
63
        case INODE_GEN:
 
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;
 
68
                break;
 
69
        case INODE_GEN_FIX:
 
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;
 
76
                break;
 
77
        case INODE_BLKNO:
 
78
                fprintf(stdout, "INODE_BLKNO: "
 
79
                        "Corrupt inode#%"PRIu64", change i_blkno from %"PRIu64
 
80
                        " to %"PRIu64"\n",
 
81
                        blkno, di->i_blkno, (di->i_blkno + 10));
 
82
                di->i_blkno += 100;
 
83
                break;
 
84
        case INODE_NZ_DTIME:
 
85
                fprintf(stdout, "INODE_NZ_DTIME: "
 
86
                        "Corrupt inode#%"PRIu64", change i_dtime from %"PRIu64
 
87
                        " to 100\n", blkno, di->i_dtime);
 
88
                di->i_dtime = 100;
 
89
                break;
 
90
        case INODE_SUBALLOC:
 
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;
 
96
                break;
 
97
        case INODE_SIZE:
 
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));
 
102
                di->i_size += 100;
 
103
                break;
 
104
        case INODE_CLUSTERS:
 
105
                fprintf(stdout, "INODE_CLUSTER: "
 
106
                        "Corrupt inode#%"PRIu64", change i_clusters"
 
107
                        " from %u to 0\n", blkno, di->i_clusters);
 
108
                di->i_clusters = 0;
 
109
                break;
 
110
        case INODE_COUNT:
 
111
                di->i_links_count = 0;
 
112
                fprintf(stdout, "INODE_COUNT: "
 
113
                        "Corrupte inode#%"PRIu64", set link count to 0\n",
 
114
                        blkno);
 
115
                break;
 
116
        default:
 
117
                FSWRK_FATAL("Invalid type[%d]\n", type);
 
118
        }
 
119
        
 
120
        ret = ocfs2_write_inode(fs, blkno, buf);
 
121
        if (ret)
 
122
                FSWRK_COM_FATAL(progname, ret);
 
123
 
 
124
        if (buf)
 
125
                ocfs2_free(&buf);
 
126
        return;
 
127
}
 
128
 
 
129
void mess_up_inode_field(ocfs2_filesys *fs, uint64_t blkno)
 
130
{
 
131
        int i;
 
132
        errcode_t ret;
 
133
        uint64_t tmpblkno;
 
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,
 
138
                                        INODE_COUNT};
 
139
        
 
140
        for (i = 0; i < ARRAY_ELEMENTS(types); i++) {
 
141
                create_file(fs, blkno, &tmpblkno);
 
142
 
 
143
                if (types[i] == INODE_CLUSTERS) {
 
144
                        ret = ocfs2_extend_allocation(fs, tmpblkno, clusters);
 
145
                        if (ret)
 
146
                                FSWRK_COM_FATAL(progname, ret);
 
147
                }
 
148
 
 
149
                damage_inode(fs, tmpblkno, types[i]);
 
150
        }       
 
151
        return;
 
152
}
 
153
 
 
154
void mess_up_inode_not_connected(ocfs2_filesys *fs, uint64_t blkno)
 
155
{
 
156
        errcode_t ret;
 
157
        uint64_t tmpblkno;
 
158
 
 
159
        ret = ocfs2_new_inode(fs, &tmpblkno, S_IFREG | 0755);
 
160
        if (ret)
 
161
                FSWRK_COM_FATAL(progname, ret);
 
162
 
 
163
        fprintf(stdout, "INODE_NOT_CONNECTED: "
 
164
                "Create an inode#%"PRIu64" which has no links\n", tmpblkno);
 
165
        return ;
 
166
}
 
167
 
 
168
void mess_up_inode_orphaned(ocfs2_filesys *fs, uint16_t slotnum)
 
169
{
 
170
        errcode_t ret;
 
171
        uint64_t blkno, tmpblkno;
 
172
        char parentdir[OCFS2_MAX_FILENAME_LEN];
 
173
        struct ocfs2_super_block *sb = OCFS2_RAW_SB(fs->fs_super);
 
174
 
 
175
        if (slotnum == UINT16_MAX)
 
176
                slotnum = 0;
 
177
        snprintf(parentdir, sizeof(parentdir),  
 
178
                 ocfs2_system_inodes[ORPHAN_DIR_SYSTEM_INODE].si_name, slotnum);
 
179
        
 
180
        ret = ocfs2_lookup(fs, sb->s_system_dir_blkno, parentdir,
 
181
                           strlen(parentdir), NULL, &blkno);
 
182
        if (ret)
 
183
                FSWRK_COM_FATAL(progname, ret);
 
184
        
 
185
        create_file(fs, blkno, &tmpblkno);
 
186
 
 
187
        fprintf(stdout, "INODE_ORPHANED: "
 
188
                "Create an inode#%"PRIu64" under directory %s\n",
 
189
                tmpblkno, parentdir);
 
190
        return;
 
191
}
 
192
 
 
193
void mess_up_inode_alloc(ocfs2_filesys *fs, uint16_t slotnum)
 
194
{
 
195
        errcode_t ret;
 
196
        uint64_t tmpblkno;
 
197
        char *buf = NULL;
 
198
        struct ocfs2_dinode *di;
 
199
 
 
200
        ret = ocfs2_new_inode(fs, &tmpblkno, S_IFREG | 0755);
 
201
        if (ret)
 
202
                FSWRK_COM_FATAL(progname, ret);
 
203
 
 
204
        ret = ocfs2_malloc_block(fs->fs_io, &buf);
 
205
        if (ret)  
 
206
                FSWRK_COM_FATAL(progname, ret);
 
207
 
 
208
        ret = ocfs2_read_inode(fs, tmpblkno, buf);
 
209
        if (ret)
 
210
                FSWRK_COM_FATAL(progname, ret);
 
211
 
 
212
        di = (struct ocfs2_dinode *)buf;
 
213
 
 
214
        di->i_flags &= ~OCFS2_VALID_FL;
 
215
 
 
216
        ret = ocfs2_write_inode(fs, tmpblkno, buf);
 
217
        if (ret)
 
218
                FSWRK_COM_FATAL(progname, ret);
 
219
 
 
220
        fprintf(stdout, "INODE_ALLOC_REPAIR: "
 
221
                "Create an inode#%"PRIu64" and invalidate it.\n", tmpblkno);
 
222
 
 
223
        if (buf)
 
224
                ocfs2_free(&buf);
 
225
        return;
 
226
}