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