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