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