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