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