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