Merge branch 'direct-fix'
[yaffs2.git] / direct / 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
27 #if defined CONFIG_YAFFS_WINCE
28
29 #include "ywinceenv.h"
30
31
32 #elif defined CONFIG_YAFFS_DIRECT
33
34 /* Direct interface */
35 #include "ydirectenv.h"
36
37 #elif defined CONFIG_YAFFS_UTIL
38
39 /* Stuff for YAFFS utilities */
40
41 #include "stdlib.h"
42 #include "stdio.h"
43 #include "string.h"
44
45
46 #define YMALLOC(x) malloc(x)
47 #define YFREE(x)   free(x)
48 #define YMALLOC_ALT(x) malloc(x)
49 #define YFREE_ALT(x) free(x)
50
51 #define YCHAR char
52 #define YUCHAR unsigned char
53 #define _Y(x)     x
54 #define yaffs_strcat(a, b)     strcat(a, b)
55 #define yaffs_strcpy(a, b)     strcpy(a, b)
56 #define yaffs_strncpy(a, b, c) strncpy(a, b, c)
57 #define yaffs_strnlen(s,m)             strnlen(s,m)
58 #define yaffs_sprintf          sprintf
59 #define yaffs_toupper(a)       toupper(a)
60
61 #define Y_INLINE inline
62
63 /* #define YINFO(s) YPRINTF(( __FILE__ " %d %s\n",__LINE__,s)) */
64 /* #define YALERT(s) YINFO(s) */
65
66 #define TENDSTR "\n"
67 #define TSTR(x) x
68 #define TOUT(p) printf p
69
70 #define YAFFS_LOSTNFOUND_NAME           "lost+found"
71 #define YAFFS_LOSTNFOUND_PREFIX         "obj"
72 /* #define YPRINTF(x) printf x */
73
74 #define YAFFS_ROOT_MODE                 0755
75 #define YAFFS_LOSTNFOUND_MODE           0700
76
77 #define yaffs_sum_cmp(x, y) ((x) == (y))
78 #define yaffs_strcmp(a, b) strcmp(a, b)
79
80 #else
81 /* Should have specified a configuration type */
82 #error Unknown configuration
83
84 #endif
85
86 #if defined(CONFIG_YAFFS_DIRECT) || defined(CONFIG_YAFFS_WINCE)
87
88 #ifdef CONFIG_YAFFSFS_PROVIDE_VALUES
89
90 #ifndef O_RDONLY
91 #define O_RDONLY        00
92 #endif
93
94 #ifndef O_WRONLY
95 #define O_WRONLY        01
96 #endif
97
98 #ifndef O_RDWR
99 #define O_RDWR          02
100 #endif
101
102 #ifndef O_CREAT         
103 #define O_CREAT         0100
104 #endif
105
106 #ifndef O_EXCL
107 #define O_EXCL          0200
108 #endif
109
110 #ifndef O_TRUNC
111 #define O_TRUNC         01000
112 #endif
113
114 #ifndef O_APPEND
115 #define O_APPEND        02000
116 #endif
117
118 #ifndef SEEK_SET
119 #define SEEK_SET        0
120 #endif
121
122 #ifndef SEEK_CUR
123 #define SEEK_CUR        1
124 #endif
125
126 #ifndef SEEK_END
127 #define SEEK_END        2
128 #endif
129
130 #ifndef EBUSY
131 #define EBUSY   16
132 #endif
133
134 #ifndef ENODEV
135 #define ENODEV  19
136 #endif
137
138 #ifndef EINVAL
139 #define EINVAL  22
140 #endif
141
142 #ifndef ENFILE
143 #define ENFILE  23
144 #endif
145
146 #ifndef EBADF
147 #define EBADF   9
148 #endif
149
150 #ifndef EACCES
151 #define EACCES  13
152 #endif
153
154 #ifndef EXDEV   
155 #define EXDEV   18
156 #endif
157
158 #ifndef ENOENT
159 #define ENOENT  2
160 #endif
161
162 #ifndef ENOSPC
163 #define ENOSPC  28
164 #endif
165
166 #ifndef EROFS
167 #define EROFS   30
168 #endif
169
170 #ifndef ERANGE
171 #define ERANGE 34
172 #endif
173
174 #ifndef ENODATA
175 #define ENODATA 61
176 #endif
177
178 #ifndef ENOTEMPTY
179 #define ENOTEMPTY 39
180 #endif
181
182 #ifndef ENAMETOOLONG
183 #define ENAMETOOLONG 36
184 #endif
185
186 #ifndef ENOMEM
187 #define ENOMEM 12
188 #endif
189
190 #ifndef EFAULT
191 #define EFAULT 14
192 #endif
193
194 #ifndef EEXIST
195 #define EEXIST 17
196 #endif
197
198 #ifndef ENOTDIR
199 #define ENOTDIR 20
200 #endif
201
202 #ifndef EISDIR
203 #define EISDIR 21
204 #endif
205
206 #ifndef ELOOP
207 #define ELOOP   40
208 #endif
209
210
211 // Mode flags
212
213 #ifndef S_IFMT
214 #define S_IFMT          0170000
215 #endif
216
217 #ifndef S_IFLNK
218 #define S_IFLNK         0120000
219 #endif
220
221 #ifndef S_IFDIR
222 #define S_IFDIR         0040000
223 #endif
224
225 #ifndef S_IFREG
226 #define S_IFREG         0100000
227 #endif
228
229 #ifndef S_IREAD 
230 #define S_IREAD         0000400
231 #endif
232
233 #ifndef S_IWRITE
234 #define S_IWRITE        0000200
235 #endif
236
237 #ifndef S_IEXEC
238 #define S_IEXEC 0000100
239 #endif
240
241 #ifndef XATTR_CREATE
242 #define XATTR_CREATE 1
243 #endif
244
245 #ifndef XATTR_REPLACE
246 #define XATTR_REPLACE 2
247 #endif
248
249 #ifndef R_OK
250 #define R_OK    4
251 #define W_OK    2
252 #define X_OK    1
253 #define F_OK    0
254 #endif
255
256 #else
257 #include <errno.h>
258 #include <sys/stat.h>
259 #include <fcntl.h>
260 #endif
261
262 #endif
263
264 #ifndef Y_DUMP_STACK
265 #define Y_DUMP_STACK() do { } while (0)
266 #endif
267
268 #ifndef YBUG
269 #define YBUG() do {\
270         T(YAFFS_TRACE_BUG,\
271                 (TSTR("==>> yaffs bug: " __FILE__ " %d" TENDSTR),\
272                 __LINE__));\
273         Y_DUMP_STACK();\
274 } while (0)
275 #endif
276
277
278 #endif
279
280 /*
281  * YAFFS: Yet another Flash File System . A NAND-flash specific file system.
282  *
283  * Copyright (C) 2002-2010 Aleph One Ltd.
284  *   for Toby Churchill Ltd and Brightstar Engineering
285  *
286  * Created by Charles Manning <charles@aleph1.co.uk>
287  *
288  * This program is free software; you can redistribute it and/or modify
289  * it under the terms of the GNU Lesser General Public License version 2.1 as
290  * published by the Free Software Foundation.
291  *
292  * Note: Only YAFFS headers are LGPL, YAFFS C code is covered by GPL.
293  */
294
295 /*
296  * This file is just holds extra declarations of macros that would normally
297  * be provided in the Linux kernel. These macros have been written from
298  * scratch but are functionally equivalent to the Linux ones.
299  *
300  */
301
302 #ifndef __EXTRAS_H__
303 #define __EXTRAS_H__
304
305
306 /* Definition of types */
307 typedef unsigned char u8;
308 typedef unsigned short u16;
309 typedef unsigned u32;
310
311
312 #ifndef WIN32
313 #include <sys/stat.h>
314 #endif
315
316
317 #ifdef CONFIG_YAFFS_PROVIDE_DEFS
318 /* File types */
319
320
321 #define DT_UNKNOWN      0
322 #define DT_FIFO         1
323 #define DT_CHR          2
324 #define DT_DIR          4
325 #define DT_BLK          6
326 #define DT_REG          8
327 #define DT_LNK          10
328 #define DT_SOCK         12
329 #define DT_WHT          14
330
331
332 #ifndef WIN32
333 #include <sys/stat.h>
334 #endif
335
336 /*
337  * Attribute flags.  These should be or-ed together to figure out what
338  * has been changed!
339  */
340 #define ATTR_MODE       1
341 #define ATTR_UID        2
342 #define ATTR_GID        4
343 #define ATTR_SIZE       8
344 #define ATTR_ATIME      16
345 #define ATTR_MTIME      32
346 #define ATTR_CTIME      64
347
348 struct iattr {
349         unsigned int ia_valid;
350         unsigned ia_mode;
351         unsigned ia_uid;
352         unsigned ia_gid;
353         unsigned ia_size;
354         unsigned ia_atime;
355         unsigned ia_mtime;
356         unsigned ia_ctime;
357         unsigned int ia_attr_flags;
358 };
359
360 #endif
361
362
363
364 #endif