yaffs2: Yaffs endian support
[yaffs2.git] / direct / yportenv.h
1 /*
2  * YAFFS: Yet another Flash File System . A NAND-flash specific file system.
3  *
4  * Copyright (C) 2002-2011 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 /* Definition of types */
22 #ifdef CONFIG_YAFFS_DEFINES_TYPES
23 typedef unsigned char u8;
24 typedef unsigned short u16;
25 typedef unsigned int u32;
26 typedef unsigned long long u64;
27 typedef signed int s32;
28 #endif
29
30
31 #ifdef CONFIG_YAFFS_PROVIDE_DEFS
32 /* File types */
33
34
35 #define DT_UNKNOWN      0
36 #define DT_FIFO         1
37 #define DT_CHR          2
38 #define DT_DIR          4
39 #define DT_BLK          6
40 #define DT_REG          8
41 #define DT_LNK          10
42 #define DT_SOCK         12
43 #define DT_WHT          14
44
45
46 /*
47  * Attribute flags.
48  * These are or-ed together to select what has been changed.
49  */
50 #define ATTR_MODE       1
51 #define ATTR_UID        2
52 #define ATTR_GID        4
53 #define ATTR_SIZE       8
54 #define ATTR_ATIME      16
55 #define ATTR_MTIME      32
56 #define ATTR_CTIME      64
57
58 struct iattr {
59         unsigned int ia_valid;
60         unsigned ia_mode;
61         unsigned ia_uid;
62         unsigned ia_gid;
63         unsigned ia_size;
64         unsigned ia_atime;
65         unsigned ia_mtime;
66         unsigned ia_ctime;
67         unsigned int ia_attr_flags;
68 };
69
70 #endif
71
72
73
74 #if defined CONFIG_YAFFS_WINCE
75
76 #include "ywinceenv.h"
77
78
79 #elif defined CONFIG_YAFFS_DIRECT
80
81 /* Direct interface */
82 #include "ydirectenv.h"
83
84 #elif defined CONFIG_YAFFS_UTIL
85
86 #include "yutilsenv.h"
87
88 #else
89 /* Should have specified a configuration type */
90 #error Unknown configuration
91
92 #endif
93
94 #if defined(CONFIG_YAFFS_DIRECT) || defined(CONFIG_YAFFS_WINCE)
95
96 #ifdef CONFIG_YAFFSFS_PROVIDE_VALUES
97
98 #ifndef O_RDONLY
99 #define O_RDONLY        00
100 #endif
101
102 #ifndef O_WRONLY
103 #define O_WRONLY        01
104 #endif
105
106 #ifndef O_RDWR
107 #define O_RDWR          02
108 #endif
109
110 #ifndef O_CREAT
111 #define O_CREAT         0100
112 #endif
113
114 #ifndef O_EXCL
115 #define O_EXCL          0200
116 #endif
117
118 #ifndef O_TRUNC
119 #define O_TRUNC         01000
120 #endif
121
122 #ifndef O_APPEND
123 #define O_APPEND        02000
124 #endif
125
126 #ifndef SEEK_SET
127 #define SEEK_SET        0
128 #endif
129
130 #ifndef SEEK_CUR
131 #define SEEK_CUR        1
132 #endif
133
134 #ifndef SEEK_END
135 #define SEEK_END        2
136 #endif
137
138 #ifndef EBUSY
139 #define EBUSY   16
140 #endif
141
142 #ifndef ENODEV
143 #define ENODEV  19
144 #endif
145
146 #ifndef EINVAL
147 #define EINVAL  22
148 #endif
149
150 #ifndef ENFILE
151 #define ENFILE  23
152 #endif
153
154 #ifndef EBADF
155 #define EBADF   9
156 #endif
157
158 #ifndef EACCES
159 #define EACCES  13
160 #endif
161
162 #ifndef EXDEV
163 #define EXDEV   18
164 #endif
165
166 #ifndef ENOENT
167 #define ENOENT  2
168 #endif
169
170 #ifndef ENOSPC
171 #define ENOSPC  28
172 #endif
173
174 #ifndef EROFS
175 #define EROFS   30
176 #endif
177
178 #ifndef ERANGE
179 #define ERANGE 34
180 #endif
181
182 #ifndef ENODATA
183 #define ENODATA 61
184 #endif
185
186 #ifndef ENOTEMPTY
187 #define ENOTEMPTY 39
188 #endif
189
190 #ifndef ENAMETOOLONG
191 #define ENAMETOOLONG 36
192 #endif
193
194 #ifndef ENOMEM
195 #define ENOMEM 12
196 #endif
197
198 #ifndef EFAULT
199 #define EFAULT 14
200 #endif
201
202 #ifndef EEXIST
203 #define EEXIST 17
204 #endif
205
206 #ifndef ENOTDIR
207 #define ENOTDIR 20
208 #endif
209
210 #ifndef EISDIR
211 #define EISDIR 21
212 #endif
213
214 #ifndef ELOOP
215 #define ELOOP   40
216 #endif
217
218
219 /* Mode flags */
220
221 #ifndef S_IFMT
222 #define S_IFMT          0170000
223 #endif
224
225 #ifndef S_IFSOCK
226 #define S_IFSOCK        0140000
227 #endif
228
229 #ifndef S_IFIFO
230 #define S_IFIFO         0010000
231 #endif
232
233 #ifndef S_IFCHR
234 #define S_IFCHR         0020000
235 #endif
236
237 #ifndef S_IFBLK
238 #define S_IFBLK         0060000
239 #endif
240
241 #ifndef S_IFLNK
242 #define S_IFLNK         0120000
243 #endif
244
245 #ifndef S_IFDIR
246 #define S_IFDIR         0040000
247 #endif
248
249 #ifndef S_IFREG
250 #define S_IFREG         0100000
251 #endif
252
253 #ifndef S_ISSOCK
254 #define S_ISSOCK(m)     (((m) & S_IFMT) == S_IFSOCK)
255 #endif
256 #ifndef S_ISLNK
257 #define S_ISLNK(m)      (((m) & S_IFMT) == S_IFLNK)
258 #endif
259 #ifndef S_ISDIR
260 #define S_ISDIR(m)      (((m) & S_IFMT) == S_IFDIR)
261 #endif
262 #ifndef S_ISREG
263 #define S_ISREG(m)      (((m) & S_IFMT) == S_IFREG)
264 #endif
265 #ifndef S_ISBLK
266 #define S_ISBLK(m)      (((m) & S_IFMT) == S_IFBLK)
267 #endif
268 #ifndef S_ISCHR
269 #define S_ISCHR(m)      (((m) & S_IFMT) == S_IFCHR)
270 #endif
271 #ifndef S_ISFIFO
272 #define S_ISFIFO(m)     (((m) & S_IFMT) == S_IFIFO)
273 #endif
274
275
276 #ifndef S_IRUSR
277 #define S_IRUSR         0000400
278 #endif
279
280 #ifndef S_IWUSR
281 #define S_IWUSR         0000200
282 #endif
283
284 #ifndef S_IXUSR
285 #define S_IXUSR         0000100
286 #endif
287
288 #ifndef S_IREAD
289 #define S_IREAD         0000400
290 #endif
291
292 #ifndef S_IWRITE
293 #define S_IWRITE        0000200
294 #endif
295
296 #ifndef S_IEXEC
297 #define S_IEXEC 0000100
298 #endif
299
300
301 #else
302 #include <errno.h>
303 #include <sys/stat.h>
304 #include <fcntl.h>
305 #endif
306
307 #endif
308
309 /* Create some less common define values if they don't exist */
310 #ifndef XATTR_CREATE
311 #define XATTR_CREATE 1
312 #endif
313
314 #ifndef XATTR_REPLACE
315 #define XATTR_REPLACE 2
316 #endif
317
318 #ifndef R_OK
319 #define R_OK    4
320 #define W_OK    2
321 #define X_OK    1
322 #define F_OK    0
323 #endif
324
325 #ifndef S_ISSOCK
326 #define S_ISSOCK(m)     (((m) & S_IFMT) == S_IFSOCK)
327 #endif
328
329 #ifndef Y_DUMP_STACK
330 #define Y_DUMP_STACK() do { } while (0)
331 #endif
332
333 #ifndef BUG
334 #define BUG() do {\
335         yaffs_trace(YAFFS_TRACE_BUG,\
336                 "==>> yaffs bug: " __FILE__ " %d",\
337                 __LINE__);\
338         Y_DUMP_STACK();\
339 } while (0)
340 #endif
341
342 #endif