22afb069b14c2b0d80780f1a2d429cdf90f6be1a
[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 ERANGE
167 #define ERANGE 34
168 #endif
169
170 #ifndef ENODATA
171 #define ENODATA 61
172 #endif
173
174 #ifndef ENOTEMPTY
175 #define ENOTEMPTY 39
176 #endif
177
178 #ifndef ENAMETOOLONG
179 #define ENAMETOOLONG 36
180 #endif
181
182 #ifndef ENOMEM
183 #define ENOMEM 12
184 #endif
185
186 #ifndef EEXIST
187 #define EEXIST 17
188 #endif
189
190 #ifndef ENOTDIR
191 #define ENOTDIR 20
192 #endif
193
194 #ifndef EISDIR
195 #define EISDIR 21
196 #endif
197
198
199 // Mode flags
200
201 #ifndef S_IFMT
202 #define S_IFMT          0170000
203 #endif
204
205 #ifndef S_IFLNK
206 #define S_IFLNK         0120000
207 #endif
208
209 #ifndef S_IFDIR
210 #define S_IFDIR         0040000
211 #endif
212
213 #ifndef S_IFREG
214 #define S_IFREG         0100000
215 #endif
216
217 #ifndef S_IREAD 
218 #define S_IREAD         0000400
219 #endif
220
221 #ifndef S_IWRITE
222 #define S_IWRITE        0000200
223 #endif
224
225 #ifndef S_IEXEC
226 #define S_IEXEC 0000100
227 #endif
228
229 #ifndef XATTR_CREATE
230 #define XATTR_CREATE 1
231 #endif
232
233 #ifndef XATTR_REPLACE
234 #define XATTR_REPLACE 2
235 #endif
236
237 #ifndef R_OK
238 #define R_OK    4
239 #define W_OK    2
240 #define X_OK    1
241 #define F_OK    0
242 #endif
243
244 #else
245 #include <errno.h>
246 #include <sys/stat.h>
247 #include <fcntl.h>
248 #endif
249
250 #endif
251
252 #ifndef Y_DUMP_STACK
253 #define Y_DUMP_STACK() do { } while (0)
254 #endif
255
256 #ifndef YBUG
257 #define YBUG() do {\
258         T(YAFFS_TRACE_BUG,\
259                 (TSTR("==>> yaffs bug: " __FILE__ " %d" TENDSTR),\
260                 __LINE__));\
261         Y_DUMP_STACK();\
262 } while (0)
263 #endif
264
265
266 #endif
267
268 /*
269  * YAFFS: Yet another Flash File System . A NAND-flash specific file system.
270  *
271  * Copyright (C) 2002-2010 Aleph One Ltd.
272  *   for Toby Churchill Ltd and Brightstar Engineering
273  *
274  * Created by Charles Manning <charles@aleph1.co.uk>
275  *
276  * This program is free software; you can redistribute it and/or modify
277  * it under the terms of the GNU Lesser General Public License version 2.1 as
278  * published by the Free Software Foundation.
279  *
280  * Note: Only YAFFS headers are LGPL, YAFFS C code is covered by GPL.
281  */
282
283 /*
284  * This file is just holds extra declarations of macros that would normally
285  * be provided in the Linux kernel. These macros have been written from
286  * scratch but are functionally equivalent to the Linux ones.
287  *
288  */
289
290 #ifndef __EXTRAS_H__
291 #define __EXTRAS_H__
292
293
294 /* Definition of types */
295 typedef unsigned char u8;
296 typedef unsigned short u16;
297 typedef unsigned u32;
298
299
300 #ifndef WIN32
301 #include <sys/stat.h>
302 #endif
303
304
305 #ifdef CONFIG_YAFFS_PROVIDE_DEFS
306 /* File types */
307
308
309 #define DT_UNKNOWN      0
310 #define DT_FIFO         1
311 #define DT_CHR          2
312 #define DT_DIR          4
313 #define DT_BLK          6
314 #define DT_REG          8
315 #define DT_LNK          10
316 #define DT_SOCK         12
317 #define DT_WHT          14
318
319
320 #ifndef WIN32
321 #include <sys/stat.h>
322 #endif
323
324 /*
325  * Attribute flags.  These should be or-ed together to figure out what
326  * has been changed!
327  */
328 #define ATTR_MODE       1
329 #define ATTR_UID        2
330 #define ATTR_GID        4
331 #define ATTR_SIZE       8
332 #define ATTR_ATIME      16
333 #define ATTR_MTIME      32
334 #define ATTR_CTIME      64
335
336 struct iattr {
337         unsigned int ia_valid;
338         unsigned ia_mode;
339         unsigned ia_uid;
340         unsigned ia_gid;
341         unsigned ia_size;
342         unsigned ia_atime;
343         unsigned ia_mtime;
344         unsigned ia_ctime;
345         unsigned int ia_attr_flags;
346 };
347
348 #endif
349
350
351
352 #endif