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