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