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