yaffs direct: Fix more EROFS handling
[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  * Define the MTD version in terms of Linux Kernel versions
22  * This allows yaffs to be used independantly of the kernel
23  * as well as with it.
24  */
25
26
27 #if defined CONFIG_YAFFS_WINCE
28
29 #include "ywinceenv.h"
30
31
32 #elif defined CONFIG_YAFFS_DIRECT
33
34 /* Direct interface */
35 #include "ydirectenv.h"
36
37 #elif defined CONFIG_YAFFS_UTIL
38
39 /* Stuff for YAFFS utilities */
40
41 #include "stdlib.h"
42 #include "stdio.h"
43 #include "string.h"
44
45
46 #define YMALLOC(x) malloc(x)
47 #define YFREE(x)   free(x)
48 #define YMALLOC_ALT(x) malloc(x)
49 #define YFREE_ALT(x) free(x)
50
51 #define YCHAR char
52 #define YUCHAR unsigned char
53 #define _Y(x)     x
54 #define yaffs_strcat(a, b)     strcat(a, b)
55 #define yaffs_strcpy(a, b)     strcpy(a, b)
56 #define yaffs_strncpy(a, b, c) strncpy(a, b, c)
57 #define yaffs_strnlen(s,m)             strnlen(s,m)
58 #define yaffs_sprintf          sprintf
59 #define yaffs_toupper(a)       toupper(a)
60
61 #define Y_INLINE inline
62
63 /* #define YINFO(s) YPRINTF(( __FILE__ " %d %s\n",__LINE__,s)) */
64 /* #define YALERT(s) YINFO(s) */
65
66 #define TENDSTR "\n"
67 #define TSTR(x) x
68 #define TOUT(p) printf p
69
70 #define YAFFS_LOSTNFOUND_NAME           "lost+found"
71 #define YAFFS_LOSTNFOUND_PREFIX         "obj"
72 /* #define YPRINTF(x) printf x */
73
74 #define YAFFS_ROOT_MODE                 0755
75 #define YAFFS_LOSTNFOUND_MODE           0700
76
77 #define yaffs_sum_cmp(x, y) ((x) == (y))
78 #define yaffs_strcmp(a, b) strcmp(a, b)
79
80 #else
81 /* Should have specified a configuration type */
82 #error Unknown configuration
83
84 #endif
85
86 #if defined(CONFIG_YAFFS_DIRECT) || defined(CONFIG_YAFFS_WINCE)
87
88 #ifdef CONFIG_YAFFSFS_PROVIDE_VALUES
89
90 #ifndef O_RDONLY
91 #define O_RDONLY        00
92 #endif
93
94 #ifndef O_WRONLY
95 #define O_WRONLY        01
96 #endif
97
98 #ifndef O_RDWR
99 #define O_RDWR          02
100 #endif
101
102 #ifndef O_CREAT         
103 #define O_CREAT         0100
104 #endif
105
106 #ifndef O_EXCL
107 #define O_EXCL          0200
108 #endif
109
110 #ifndef O_TRUNC
111 #define O_TRUNC         01000
112 #endif
113
114 #ifndef O_APPEND
115 #define O_APPEND        02000
116 #endif
117
118 #ifndef SEEK_SET
119 #define SEEK_SET        0
120 #endif
121
122 #ifndef SEEK_CUR
123 #define SEEK_CUR        1
124 #endif
125
126 #ifndef SEEK_END
127 #define SEEK_END        2
128 #endif
129
130 #ifndef EBUSY
131 #define EBUSY   16
132 #endif
133
134 #ifndef ENODEV
135 #define ENODEV  19
136 #endif
137
138 #ifndef EINVAL
139 #define EINVAL  22
140 #endif
141
142 #ifndef ENFILE
143 #define ENFILE  23
144 #endif
145
146 #ifndef EBADF
147 #define EBADF   9
148 #endif
149
150 #ifndef EACCES
151 #define EACCES  13
152 #endif
153
154 #ifndef EXDEV   
155 #define EXDEV   18
156 #endif
157
158 #ifndef ENOENT
159 #define ENOENT  2
160 #endif
161
162 #ifndef ENOSPC
163 #define ENOSPC  28
164 #endif
165
166 #ifndef EROFS
167 #define EROFS   30
168 #endif
169
170 #ifndef ERANGE
171 #define ERANGE 34
172 #endif
173
174 #ifndef ENODATA
175 #define ENODATA 61
176 #endif
177
178 #ifndef ENOTEMPTY
179 #define ENOTEMPTY 39
180 #endif
181
182 #ifndef ENAMETOOLONG
183 #define ENAMETOOLONG 36
184 #endif
185
186 #ifndef ENOMEM
187 #define ENOMEM 12
188 #endif
189
190 #ifndef EEXIST
191 #define EEXIST 17
192 #endif
193
194 #ifndef ENOTDIR
195 #define ENOTDIR 20
196 #endif
197
198 #ifndef EISDIR
199 #define EISDIR 21
200 #endif
201
202 #ifndef ELOOP
203 #define ELOOP   40
204 #endif
205
206
207 // Mode flags
208
209 #ifndef S_IFMT
210 #define S_IFMT          0170000
211 #endif
212
213 #ifndef S_IFLNK
214 #define S_IFLNK         0120000
215 #endif
216
217 #ifndef S_IFDIR
218 #define S_IFDIR         0040000
219 #endif
220
221 #ifndef S_IFREG
222 #define S_IFREG         0100000
223 #endif
224
225 #ifndef S_IREAD 
226 #define S_IREAD         0000400
227 #endif
228
229 #ifndef S_IWRITE
230 #define S_IWRITE        0000200
231 #endif
232
233 #ifndef S_IEXEC
234 #define S_IEXEC 0000100
235 #endif
236
237 #ifndef XATTR_CREATE
238 #define XATTR_CREATE 1
239 #endif
240
241 #ifndef XATTR_REPLACE
242 #define XATTR_REPLACE 2
243 #endif
244
245 #ifndef R_OK
246 #define R_OK    4
247 #define W_OK    2
248 #define X_OK    1
249 #define F_OK    0
250 #endif
251
252 #else
253 #include <errno.h>
254 #include <sys/stat.h>
255 #include <fcntl.h>
256 #endif
257
258 #endif
259
260 #ifndef Y_DUMP_STACK
261 #define Y_DUMP_STACK() do { } while (0)
262 #endif
263
264 #ifndef YBUG
265 #define YBUG() do {\
266         T(YAFFS_TRACE_BUG,\
267                 (TSTR("==>> yaffs bug: " __FILE__ " %d" TENDSTR),\
268                 __LINE__));\
269         Y_DUMP_STACK();\
270 } while (0)
271 #endif
272
273
274 #endif
275
276 /*
277  * YAFFS: Yet another Flash File System . A NAND-flash specific file system.
278  *
279  * Copyright (C) 2002-2010 Aleph One Ltd.
280  *   for Toby Churchill Ltd and Brightstar Engineering
281  *
282  * Created by Charles Manning <charles@aleph1.co.uk>
283  *
284  * This program is free software; you can redistribute it and/or modify
285  * it under the terms of the GNU Lesser General Public License version 2.1 as
286  * published by the Free Software Foundation.
287  *
288  * Note: Only YAFFS headers are LGPL, YAFFS C code is covered by GPL.
289  */
290
291 /*
292  * This file is just holds extra declarations of macros that would normally
293  * be provided in the Linux kernel. These macros have been written from
294  * scratch but are functionally equivalent to the Linux ones.
295  *
296  */
297
298 #ifndef __EXTRAS_H__
299 #define __EXTRAS_H__
300
301
302 /* Definition of types */
303 typedef unsigned char u8;
304 typedef unsigned short u16;
305 typedef unsigned u32;
306
307
308 #ifndef WIN32
309 #include <sys/stat.h>
310 #endif
311
312
313 #ifdef CONFIG_YAFFS_PROVIDE_DEFS
314 /* File types */
315
316
317 #define DT_UNKNOWN      0
318 #define DT_FIFO         1
319 #define DT_CHR          2
320 #define DT_DIR          4
321 #define DT_BLK          6
322 #define DT_REG          8
323 #define DT_LNK          10
324 #define DT_SOCK         12
325 #define DT_WHT          14
326
327
328 #ifndef WIN32
329 #include <sys/stat.h>
330 #endif
331
332 /*
333  * Attribute flags.  These should be or-ed together to figure out what
334  * has been changed!
335  */
336 #define ATTR_MODE       1
337 #define ATTR_UID        2
338 #define ATTR_GID        4
339 #define ATTR_SIZE       8
340 #define ATTR_ATIME      16
341 #define ATTR_MTIME      32
342 #define ATTR_CTIME      64
343
344 struct iattr {
345         unsigned int ia_valid;
346         unsigned ia_mode;
347         unsigned ia_uid;
348         unsigned ia_gid;
349         unsigned ia_size;
350         unsigned ia_atime;
351         unsigned ia_mtime;
352         unsigned ia_ctime;
353         unsigned int ia_attr_flags;
354 };
355
356 #endif
357
358
359
360 #endif