~wb-munzinger/+junk/ocfs2-tools

« back to all changes in this revision

Viewing changes to debugfs.ocfs2/journal.c

  • Committer: Bazaar Package Importer
  • Author(s): Jeremy Lainé
  • Date: 2009-07-06 07:26:30 UTC
  • mfrom: (1.1.7 upstream) (0.1.5 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090706072630-59335sl51k3rvu74
Tags: 1.4.2-1
* New upstream release (Closes: #535471).
* Drop patch for limits.h, included upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
 
1
/* -*- mode: c; c-basic-offset: 8; -*-
 
2
 * vim: noexpandtab sw=8 ts=8 sts=0:
 
3
 *
2
4
 * journal.c
3
5
 *
4
6
 * reads the journal file
23
25
 * Authors: Sunil Mushran, Mark Fasheh
24
26
 */
25
27
 
26
 
#include <main.h>
 
28
#include "main.h"
27
29
 
28
30
extern dbgfs_gbls gbls;
29
31
 
30
 
static void scan_journal(FILE *out, char *buf, int len,
31
 
                         uint64_t *blocknum, uint64_t *last_unknown)
 
32
static enum dump_block_type detect_block (char *buf);
 
33
 
 
34
static void scan_journal(FILE *out, journal_superblock_t *jsb, char *buf,
 
35
                         int len, uint64_t *blocknum, uint64_t *last_unknown)
32
36
{
33
37
        char *block;
34
38
        char *p;
35
 
        int type;
 
39
        enum dump_block_type type;
36
40
        journal_header_t *header;
37
41
 
38
42
        p = buf;
40
44
        while (len) {
41
45
                block = p;
42
46
                header = (journal_header_t *)block;
43
 
                if (header->h_magic == ntohl(JFS_MAGIC_NUMBER)) {
 
47
                if (header->h_magic == ntohl(JBD2_MAGIC_NUMBER)) {
44
48
                        if (*last_unknown) {
45
49
                                dump_jbd_unknown(out, *last_unknown, *blocknum);
46
50
                                *last_unknown = 0;
47
51
                        }
48
 
                        dump_jbd_block(out, header, *blocknum);
 
52
                        dump_jbd_block(out, jsb, header, *blocknum);
49
53
                } else {
50
54
                        type = detect_block(block);
51
 
                        if (type < 0) {
 
55
                        if (type == DUMP_BLOCK_UNKNOWN) {
52
56
                                if (*last_unknown == 0)
53
57
                                        *last_unknown = *blocknum;
54
58
                        } else {
71
75
errcode_t read_journal(ocfs2_filesys *fs, uint64_t blkno, FILE *out)
72
76
{
73
77
        char *buf = NULL;
 
78
        char *jsb_buf = NULL;
74
79
        char *p;
75
80
        uint64_t blocknum;
76
81
        uint64_t len;
81
86
        int buflenbits;
82
87
        ocfs2_cached_inode *ci = NULL;
83
88
        errcode_t ret;
 
89
        journal_superblock_t *jsb;
84
90
 
85
91
        ret = ocfs2_read_cached_inode(fs, blkno, &ci);
86
92
        if (ret) {
88
94
                goto bail;
89
95
        }
90
96
 
 
97
        ret = ocfs2_malloc_block(fs->fs_io, &jsb_buf);
 
98
        if (ret) {
 
99
                com_err(gbls.cmd, ret,
 
100
                        "while allocating journal superblock buffer");
 
101
                goto bail;
 
102
        }
 
103
 
91
104
        buflenbits = buflen >>
92
105
                        OCFS2_RAW_SB(gbls.fs->fs_super)->s_blocksize_bits;
93
106
        ret = ocfs2_malloc_blocks(fs->fs_io, buflenbits, &buf);
98
111
 
99
112
        offset = 0;
100
113
        blocknum = 0;
 
114
        jsb = (journal_superblock_t *)jsb_buf;
101
115
        while (1) {
102
116
                ret = ocfs2_file_read(ci, buf, buflen, offset, &got);
103
117
                if (ret) {
112
126
                len = got;
113
127
 
114
128
                if (offset == 0) {
115
 
                        dump_jbd_superblock(out, (journal_superblock_t *)buf);
 
129
                        memcpy(jsb_buf, buf, fs->fs_blocksize);
 
130
                        dump_jbd_superblock(out, jsb);
 
131
                        ocfs2_swap_journal_superblock(jsb);
116
132
                        blocknum++;
117
133
                        p += fs->fs_blocksize;
118
134
                        len -= fs->fs_blocksize;
119
135
                }
120
136
 
121
 
                scan_journal(out, p, len, &blocknum, &last_unknown);
 
137
                scan_journal(out, jsb, p, len, &blocknum, &last_unknown);
122
138
 
123
139
                if (got < buflen)
124
140
                        break;
131
147
        }
132
148
 
133
149
bail:
 
150
        if (jsb_buf)
 
151
                ocfs2_free(&jsb_buf);
134
152
        if (buf)
135
153
                ocfs2_free(&buf);
136
154
        if (ci)
143
161
 * detect_block()
144
162
 *
145
163
 */
146
 
int detect_block (char *buf)
 
164
static enum dump_block_type detect_block (char *buf)
147
165
{
148
166
        struct ocfs2_dinode *inode;
149
167
        struct ocfs2_extent_block *extent;
150
168
        struct ocfs2_group_desc *group;
151
 
        int ret = -1;
 
169
        struct ocfs2_dir_block_trailer *trailer;
 
170
        enum dump_block_type ret = DUMP_BLOCK_UNKNOWN;
152
171
 
153
172
        inode = (struct ocfs2_dinode *)buf;
154
 
        if (!memcmp(inode->i_signature, OCFS2_INODE_SIGNATURE,
155
 
                    sizeof(OCFS2_INODE_SIGNATURE))) {
156
 
                ret = 1;
 
173
        if (!strncmp((char *)inode->i_signature, OCFS2_INODE_SIGNATURE,
 
174
                     sizeof(inode->i_signature))) {
 
175
                ret = DUMP_BLOCK_INODE;
157
176
                goto bail;
158
177
        }
159
178
 
160
179
        extent = (struct ocfs2_extent_block *)buf;
161
 
        if (!memcmp(extent->h_signature, OCFS2_EXTENT_BLOCK_SIGNATURE,
162
 
                    sizeof(OCFS2_EXTENT_BLOCK_SIGNATURE))) {
163
 
                ret = 2;
 
180
        if (!strncmp((char *)extent->h_signature, OCFS2_EXTENT_BLOCK_SIGNATURE,
 
181
                     sizeof(extent->h_signature))) {
 
182
                ret = DUMP_BLOCK_EXTENT_BLOCK;
164
183
                goto bail;
165
184
        }
166
185
 
167
186
        group = (struct ocfs2_group_desc *)buf;
168
 
        if (!memcmp(group->bg_signature, OCFS2_GROUP_DESC_SIGNATURE,
169
 
                    sizeof(OCFS2_GROUP_DESC_SIGNATURE))) {
170
 
                ret = 3;
 
187
        if (!strncmp((char *)group->bg_signature, OCFS2_GROUP_DESC_SIGNATURE,
 
188
                     sizeof(group->bg_signature))) {
 
189
                ret = DUMP_BLOCK_GROUP_DESCRIPTOR;
 
190
                goto bail;
 
191
        }
 
192
 
 
193
        trailer = ocfs2_dir_trailer_from_block(gbls.fs, buf);
 
194
        if (!strncmp((char *)trailer->db_signature, OCFS2_DIR_TRAILER_SIGNATURE,
 
195
                     sizeof(trailer->db_signature))) {
 
196
                ret = DUMP_BLOCK_DIR_BLOCK;
171
197
                goto bail;
172
198
        }
173
199