yaffs: more clean up
[yaffs2.git] / yportenv_multi.h
1 /*
2  * YAFFS: Yet another Flash File System . A NAND-flash specific file system.
3  *
4  * Copyright (C) 2002-2010 Aleph One Ltd.
5  *   for Toby Churchill Ltd and Brightstar Engineering
6  *
7  * Created by Charles Manning <charles@aleph1.co.uk>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU Lesser General Public License version 2.1 as
11  * published by the Free Software Foundation.
12  *
13  * Note: Only YAFFS headers are LGPL, YAFFS C code is covered by GPL.
14  */
15
16
17 #ifndef __YPORTENV_H__
18 #define __YPORTENV_H__
19
20 /*
21  * Define the MTD version in terms of Linux Kernel versions
22  * This allows yaffs to be used independantly of the kernel
23  * as well as with it.
24  */
25
26 #define MTD_VERSION(a, b, c) (((a) << 16) + ((b) << 8) + (c))
27
28 #if defined CONFIG_YAFFS_WINCE
29
30 #include "ywinceenv.h"
31
32 #elif defined __KERNEL__
33
34 #include "moduleconfig.h"
35
36 /* Linux kernel */
37
38 #include <linux/version.h>
39 #define MTD_VERSION_CODE LINUX_VERSION_CODE
40
41 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 19))
42 #include <linux/config.h>
43 #endif
44 #include <linux/version.h>
45 #include <linux/kernel.h>
46 #include <linux/mm.h>
47 #include <linux/sched.h>
48 #include <linux/string.h>
49 #include <linux/slab.h>
50 #include <linux/vmalloc.h>
51 #include <linux/xattr.h>
52 #include <linux/list.h>
53 #include <linux/types.h>
54 #include <linux/fs.h>
55 #include <linux/stat.h>
56 #include <linux/sort.h>
57
58 #define YCHAR char
59 #define YUCHAR unsigned char
60 #define _Y(x)     x
61 #define yaffs_strcat(a, b)     strcat(a, b)
62 #define yaffs_strcpy(a, b)     strcpy(a, b)
63 #define yaffs_strncpy(a, b, c) strncpy(a, b, c)
64 #define yaffs_strncmp(a, b, c) strncmp(a, b, c)
65 #define yaffs_strnlen(s,m)      strnlen(s,m)
66 #define yaffs_sprintf          sprintf
67 #define yaffs_toupper(a)       toupper(a)
68 #define yaffs_sort(base, n, sz, cmp_fn) sort(base, n, sz, cmp_fn, NULL)
69
70
71 #define Y_INLINE __inline__
72
73 #define YAFFS_LOSTNFOUND_NAME           "lost+found"
74 #define YAFFS_LOSTNFOUND_PREFIX         "obj"
75
76 /* #define YPRINTF(x) printk x */
77 #define YMALLOC(x) kmalloc(x, GFP_NOFS)
78 #define YFREE(x)   kfree(x)
79 #define YMALLOC_ALT(x) vmalloc(x)
80 #define YFREE_ALT(x)   vfree(x)
81 #define YMALLOC_DMA(x) YMALLOC(x)
82
83 #define YYIELD() schedule()
84 #define Y_DUMP_STACK() dump_stack()
85
86 #define YAFFS_ROOT_MODE                 0755
87 #define YAFFS_LOSTNFOUND_MODE           0700
88
89 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0))
90 #define Y_CURRENT_TIME CURRENT_TIME.tv_sec
91 #define Y_TIME_CONVERT(x) (x).tv_sec
92 #else
93 #define Y_CURRENT_TIME CURRENT_TIME
94 #define Y_TIME_CONVERT(x) (x)
95 #endif
96
97 #define yaffs_sum_cmp(x, y) ((x) == (y))
98 #define yaffs_strcmp(a, b) strcmp(a, b)
99
100 #define TENDSTR "\n"
101 #define TSTR(x) KERN_DEBUG x
102 #define TCONT(x) x
103 #define TOUT(p) printk p
104
105 #define compile_time_assertion(assertion) \
106         ({ int x = __builtin_choose_expr(assertion, 0, (void)0); (void) x; })
107
108 #elif defined CONFIG_YAFFS_DIRECT
109
110 #define MTD_VERSION_CODE MTD_VERSION(2, 6, 22)
111
112 /* Direct interface */
113 #include "ydirectenv.h"
114
115 #elif defined CONFIG_YAFFS_UTIL
116
117 /* Stuff for YAFFS utilities */
118
119 #include "stdlib.h"
120 #include "stdio.h"
121 #include "string.h"
122
123
124 #define YMALLOC(x) malloc(x)
125 #define YFREE(x)   free(x)
126 #define YMALLOC_ALT(x) malloc(x)
127 #define YFREE_ALT(x) free(x)
128
129 #define YCHAR char
130 #define YUCHAR unsigned char
131 #define _Y(x)     x
132 #define yaffs_strcat(a, b)     strcat(a, b)
133 #define yaffs_strcpy(a, b)     strcpy(a, b)
134 #define yaffs_strncpy(a, b, c) strncpy(a, b, c)
135 #define yaffs_strnlen(s,m)             strnlen(s,m)
136 #define yaffs_sprintf          sprintf
137 #define yaffs_toupper(a)       toupper(a)
138
139 #define Y_INLINE inline
140
141 /* #define YINFO(s) YPRINTF(( __FILE__ " %d %s\n",__LINE__,s)) */
142 /* #define YALERT(s) YINFO(s) */
143
144 #define TENDSTR "\n"
145 #define TSTR(x) x
146 #define TOUT(p) printf p
147
148 #define YAFFS_LOSTNFOUND_NAME           "lost+found"
149 #define YAFFS_LOSTNFOUND_PREFIX         "obj"
150 /* #define YPRINTF(x) printf x */
151
152 #define YAFFS_ROOT_MODE                 0755
153 #define YAFFS_LOSTNFOUND_MODE           0700
154
155 #define yaffs_sum_cmp(x, y) ((x) == (y))
156 #define yaffs_strcmp(a, b) strcmp(a, b)
157
158 #else
159 /* Should have specified a configuration type */
160 #error Unknown configuration
161
162 #endif
163
164 #if defined(CONFIG_YAFFS_DIRECT) || defined(CONFIG_YAFFS_WINCE)
165
166 #ifdef CONFIG_YAFFSFS_PROVIDE_VALUES
167
168 #ifndef O_RDONLY
169 #define O_RDONLY        00
170 #endif
171
172 #ifndef O_WRONLY
173 #define O_WRONLY        01
174 #endif
175
176 #ifndef O_RDWR
177 #define O_RDWR          02
178 #endif
179
180 #ifndef O_CREAT         
181 #define O_CREAT         0100
182 #endif
183
184 #ifndef O_EXCL
185 #define O_EXCL          0200
186 #endif
187
188 #ifndef O_TRUNC
189 #define O_TRUNC         01000
190 #endif
191
192 #ifndef O_APPEND
193 #define O_APPEND        02000
194 #endif
195
196 #ifndef SEEK_SET
197 #define SEEK_SET        0
198 #endif
199
200 #ifndef SEEK_CUR
201 #define SEEK_CUR        1
202 #endif
203
204 #ifndef SEEK_END
205 #define SEEK_END        2
206 #endif
207
208 #ifndef EBUSY
209 #define EBUSY   16
210 #endif
211
212 #ifndef ENODEV
213 #define ENODEV  19
214 #endif
215
216 #ifndef EINVAL
217 #define EINVAL  22
218 #endif
219
220 #ifndef ENFILE
221 #define ENFILE  23
222 #endif
223
224 #ifndef EBADF
225 #define EBADF   9
226 #endif
227
228 #ifndef EACCES
229 #define EACCES  13
230 #endif
231
232 #ifndef EXDEV   
233 #define EXDEV   18
234 #endif
235
236 #ifndef ENOENT
237 #define ENOENT  2
238 #endif
239
240 #ifndef ENOSPC
241 #define ENOSPC  28
242 #endif
243
244 #ifndef ERANGE
245 #define ERANGE 34
246 #endif
247
248 #ifndef ENODATA
249 #define ENODATA 61
250 #endif
251
252 #ifndef ENOTEMPTY
253 #define ENOTEMPTY 39
254 #endif
255
256 #ifndef ENAMETOOLONG
257 #define ENAMETOOLONG 36
258 #endif
259
260 #ifndef ENOMEM
261 #define ENOMEM 12
262 #endif
263
264 #ifndef EEXIST
265 #define EEXIST 17
266 #endif
267
268 #ifndef ENOTDIR
269 #define ENOTDIR 20
270 #endif
271
272 #ifndef EISDIR
273 #define EISDIR 21
274 #endif
275
276
277 // Mode flags
278
279 #ifndef S_IFMT
280 #define S_IFMT          0170000
281 #endif
282
283 #ifndef S_IFLNK
284 #define S_IFLNK         0120000
285 #endif
286
287 #ifndef S_IFDIR
288 #define S_IFDIR         0040000
289 #endif
290
291 #ifndef S_IFREG
292 #define S_IFREG         0100000
293 #endif
294
295 #ifndef S_IREAD 
296 #define S_IREAD         0000400
297 #endif
298
299 #ifndef S_IWRITE
300 #define S_IWRITE        0000200
301 #endif
302
303 #ifndef S_IEXEC
304 #define S_IEXEC 0000100
305 #endif
306
307 #ifndef XATTR_CREATE
308 #define XATTR_CREATE 1
309 #endif
310
311 #ifndef XATTR_REPLACE
312 #define XATTR_REPLACE 2
313 #endif
314
315 #ifndef R_OK
316 #define R_OK    4
317 #define W_OK    2
318 #define X_OK    1
319 #define F_OK    0
320 #endif
321
322 #else
323 #include <errno.h>
324 #include <sys/stat.h>
325 #include <fcntl.h>
326 #endif
327
328 #endif
329
330 #ifndef Y_DUMP_STACK
331 #define Y_DUMP_STACK() do { } while (0)
332 #endif
333
334 #ifndef YBUG
335 #define YBUG() do {\
336         T(YAFFS_TRACE_BUG,\
337                 (TSTR("==>> yaffs bug: " __FILE__ " %d" TENDSTR),\
338                 __LINE__));\
339         Y_DUMP_STACK();\
340 } while (0)
341 #endif
342
343
344 #endif