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