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