]> git.ipfire.org Git - thirdparty/e2fsprogs.git/blob - e2fsck/jfs_user.h
debugfs: create journal handling routines
[thirdparty/e2fsprogs.git] / e2fsck / jfs_user.h
1 /*
2 * Compatibility header file for e2fsck which should be included
3 * instead of linux/jfs.h
4 *
5 * Copyright (C) 2000 Stephen C. Tweedie
6 *
7 * This file may be redistributed under the terms of the
8 * GNU General Public License version 2 or at your discretion
9 * any later version.
10 */
11 #ifndef _JFS_USER_H
12 #define _JFS_USER_H
13
14 #ifdef DEBUGFS
15 #if EXT2_FLAT_INCLUDES
16 #include "ext2_fs.h"
17 #include "ext2fs.h"
18 #include "blkid.h"
19 #else
20 #include "ext2fs/ext2_fs.h"
21 #include "ext2fs/ext2fs.h"
22 #include "blkid/blkid.h"
23 #endif
24 #else
25 /*
26 * Pull in the definition of the e2fsck context structure
27 */
28 #include "e2fsck.h"
29 #endif
30
31 struct buffer_head {
32 #ifdef DEBUGFS
33 ext2_filsys b_fs;
34 #else
35 e2fsck_t b_ctx;
36 #endif
37 io_channel b_io;
38 int b_size;
39 unsigned long long b_blocknr;
40 int b_dirty;
41 int b_uptodate;
42 int b_err;
43 char b_data[1024];
44 };
45
46 struct inode {
47 #ifdef DEBUGFS
48 ext2_filsys i_fs;
49 #else
50 e2fsck_t i_ctx;
51 #endif
52 ext2_ino_t i_ino;
53 struct ext2_inode i_ext2;
54 };
55
56 struct kdev_s {
57 #ifdef DEBUGFS
58 ext2_filsys k_fs;
59 #else
60 e2fsck_t k_ctx;
61 #endif
62 int k_dev;
63 };
64
65 #define K_DEV_FS 1
66 #define K_DEV_JOURNAL 2
67
68 typedef struct kdev_s *kdev_t;
69
70 #define lock_buffer(bh) do {} while (0)
71 #define unlock_buffer(bh) do {} while (0)
72 #define buffer_req(bh) 1
73 #define do_readahead(journal, start) do {} while (0)
74
75 typedef struct {
76 int object_length;
77 } lkmem_cache_t;
78
79 #define kmem_cache_alloc(cache, flags) malloc((cache)->object_length)
80 #define kmem_cache_free(cache, obj) free(obj)
81 #define kmem_cache_create(name, len, a, b, c) do_cache_create(len)
82 #define kmem_cache_destroy(cache) do_cache_destroy(cache)
83 #define kmalloc(len, flags) malloc(len)
84 #define kfree(p) free(p)
85
86 #define cond_resched() do { } while (0)
87
88 typedef unsigned int __be32;
89 typedef __u64 __be64;
90
91 #define __init
92
93 /*
94 * Now pull in the real linux/jfs.h definitions.
95 */
96 #include <ext2fs/kernel-jbd.h>
97
98 /*
99 * We use the standard libext2fs portability tricks for inline
100 * functions.
101 */
102 #ifdef NO_INLINE_FUNCS
103 extern lkmem_cache_t *do_cache_create(int len);
104 extern void do_cache_destroy(lkmem_cache_t *cache);
105 extern size_t journal_tag_bytes(journal_t *journal);
106 #endif
107
108 #if (defined(E2FSCK_INCLUDE_INLINE_FUNCS) || !defined(NO_INLINE_FUNCS))
109 #ifdef E2FSCK_INCLUDE_INLINE_FUNCS
110 #if (__STDC_VERSION__ >= 199901L)
111 #define _INLINE_ extern inline
112 #else
113 #define _INLINE_ inline
114 #endif
115 #else /* !E2FSCK_INCLUDE_INLINE FUNCS */
116 #if (__STDC_VERSION__ >= 199901L)
117 #define _INLINE_ inline
118 #else /* not C99 */
119 #ifdef __GNUC__
120 #define _INLINE_ extern __inline__
121 #else /* For Watcom C */
122 #define _INLINE_ extern inline
123 #endif /* __GNUC__ */
124 #endif /* __STDC_VERSION__ >= 199901L */
125 #endif /* E2FSCK_INCLUDE_INLINE_FUNCS */
126
127
128 _INLINE_ lkmem_cache_t *do_cache_create(int len)
129 {
130 lkmem_cache_t *new_cache;
131
132 new_cache = malloc(sizeof(*new_cache));
133 if (new_cache)
134 new_cache->object_length = len;
135 return new_cache;
136 }
137
138 _INLINE_ void do_cache_destroy(lkmem_cache_t *cache)
139 {
140 free(cache);
141 }
142
143 #undef _INLINE_
144 #endif
145
146 /*
147 * Kernel compatibility functions are defined in journal.c
148 */
149 int journal_bmap(journal_t *journal, blk64_t block, unsigned long long *phys);
150 struct buffer_head *getblk(kdev_t ctx, blk64_t blocknr, int blocksize);
151 int sync_blockdev(kdev_t kdev);
152 void ll_rw_block(int rw, int dummy, struct buffer_head *bh[]);
153 void mark_buffer_dirty(struct buffer_head *bh);
154 void mark_buffer_uptodate(struct buffer_head *bh, int val);
155 void brelse(struct buffer_head *bh);
156 int buffer_uptodate(struct buffer_head *bh);
157 void wait_on_buffer(struct buffer_head *bh);
158
159 /*
160 * Define newer 2.5 interfaces
161 */
162 #define __getblk(dev, blocknr, blocksize) getblk(dev, blocknr, blocksize)
163 #define set_buffer_uptodate(bh) mark_buffer_uptodate(bh, 1)
164
165 #ifdef DEBUGFS
166 #include <assert.h>
167 #undef J_ASSERT
168 #define J_ASSERT(x) assert(x)
169
170 #define JSB_HAS_INCOMPAT_FEATURE(jsb, mask) \
171 ((jsb)->s_header.h_blocktype == ext2fs_cpu_to_be32(JFS_SUPERBLOCK_V2) && \
172 ((jsb)->s_feature_incompat & ext2fs_cpu_to_be32((mask))))
173 static inline size_t journal_super_tag_bytes(journal_superblock_t *jsb)
174 {
175 size_t sz;
176
177 if (JSB_HAS_INCOMPAT_FEATURE(jsb, JFS_FEATURE_INCOMPAT_CSUM_V3))
178 return sizeof(journal_block_tag3_t);
179
180 sz = sizeof(journal_block_tag_t);
181
182 if (JSB_HAS_INCOMPAT_FEATURE(jsb, JFS_FEATURE_INCOMPAT_CSUM_V2))
183 sz += sizeof(__u16);
184
185 if (JSB_HAS_INCOMPAT_FEATURE(jsb, JFS_FEATURE_INCOMPAT_64BIT))
186 return sz;
187
188 return sz - sizeof(__u32);
189 }
190 #else /* !DEBUGFS */
191
192 extern e2fsck_t e2fsck_global_ctx; /* Try your very best not to use this! */
193
194 #define J_ASSERT(assert) \
195 do { if (!(assert)) { \
196 printf ("Assertion failure in %s() at %s line %d: " \
197 "\"%s\"\n", \
198 __FUNCTION__, __FILE__, __LINE__, # assert); \
199 fatal_error(e2fsck_global_ctx, 0); \
200 } } while (0)
201
202 #endif /* DEBUGFS */
203
204 #endif /* _JFS_USER_H */