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