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