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