| 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 | #define MTD_VERSION(a, b, c) (((a) << 16) + ((b) << 8) + (c)) |
| 27 | |
| 28 | #if defined CONFIG_YAFFS_WINCE |
| 29 | |
| 30 | #include "ywinceenv.h" |
| 31 | |
| 32 | #elif defined __KERNEL__ |
| 33 | |
| 34 | #include "moduleconfig.h" |
| 35 | |
| 36 | /* Linux kernel */ |
| 37 | |
| 38 | #include <linux/version.h> |
| 39 | #define MTD_VERSION_CODE LINUX_VERSION_CODE |
| 40 | |
| 41 | #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 19)) |
| 42 | #include <linux/config.h> |
| 43 | #endif |
| 44 | |
| 45 | #include <linux/kernel.h> |
| 46 | #include <linux/mm.h> |
| 47 | #include <linux/sched.h> |
| 48 | #include <linux/string.h> |
| 49 | #include <linux/slab.h> |
| 50 | #include <linux/vmalloc.h> |
| 51 | #include <linux/xattr.h> |
| 52 | |
| 53 | #define YCHAR char |
| 54 | #define YUCHAR unsigned char |
| 55 | #define _Y(x) x |
| 56 | #define yaffs_strcat(a, b) strcat(a, b) |
| 57 | #define yaffs_strcpy(a, b) strcpy(a, b) |
| 58 | #define yaffs_strncpy(a, b, c) strncpy(a, b, c) |
| 59 | #define yaffs_strncmp(a, b, c) strncmp(a, b, c) |
| 60 | #define yaffs_strnlen(s,m) strnlen(s,m) |
| 61 | #define yaffs_sprintf sprintf |
| 62 | #define yaffs_toupper(a) toupper(a) |
| 63 | |
| 64 | #define Y_INLINE __inline__ |
| 65 | |
| 66 | #define YAFFS_LOSTNFOUND_NAME "lost+found" |
| 67 | #define YAFFS_LOSTNFOUND_PREFIX "obj" |
| 68 | |
| 69 | /* #define YPRINTF(x) printk x */ |
| 70 | #define YMALLOC(x) kmalloc(x, GFP_NOFS) |
| 71 | #define YFREE(x) kfree(x) |
| 72 | #define YMALLOC_ALT(x) vmalloc(x) |
| 73 | #define YFREE_ALT(x) vfree(x) |
| 74 | #define YMALLOC_DMA(x) YMALLOC(x) |
| 75 | |
| 76 | #define YYIELD() schedule() |
| 77 | #define Y_DUMP_STACK() dump_stack() |
| 78 | |
| 79 | #define YAFFS_ROOT_MODE 0755 |
| 80 | #define YAFFS_LOSTNFOUND_MODE 0700 |
| 81 | |
| 82 | #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0)) |
| 83 | #define Y_CURRENT_TIME CURRENT_TIME.tv_sec |
| 84 | #define Y_TIME_CONVERT(x) (x).tv_sec |
| 85 | #else |
| 86 | #define Y_CURRENT_TIME CURRENT_TIME |
| 87 | #define Y_TIME_CONVERT(x) (x) |
| 88 | #endif |
| 89 | |
| 90 | #define yaffs_sum_cmp(x, y) ((x) == (y)) |
| 91 | #define yaffs_strcmp(a, b) strcmp(a, b) |
| 92 | |
| 93 | #define TENDSTR "\n" |
| 94 | #define TSTR(x) KERN_DEBUG x |
| 95 | #define TCONT(x) x |
| 96 | #define TOUT(p) printk p |
| 97 | |
| 98 | #define compile_time_assertion(assertion) \ |
| 99 | ({ int x = __builtin_choose_expr(assertion, 0, (void)0); (void) x; }) |
| 100 | |
| 101 | #elif defined CONFIG_YAFFS_DIRECT |
| 102 | |
| 103 | #define MTD_VERSION_CODE MTD_VERSION(2, 6, 22) |
| 104 | |
| 105 | /* Direct interface */ |
| 106 | #include "ydirectenv.h" |
| 107 | |
| 108 | #elif defined CONFIG_YAFFS_UTIL |
| 109 | |
| 110 | /* Stuff for YAFFS utilities */ |
| 111 | |
| 112 | #include "stdlib.h" |
| 113 | #include "stdio.h" |
| 114 | #include "string.h" |
| 115 | |
| 116 | |
| 117 | #define YMALLOC(x) malloc(x) |
| 118 | #define YFREE(x) free(x) |
| 119 | #define YMALLOC_ALT(x) malloc(x) |
| 120 | #define YFREE_ALT(x) free(x) |
| 121 | |
| 122 | #define YCHAR char |
| 123 | #define YUCHAR unsigned char |
| 124 | #define _Y(x) x |
| 125 | #define yaffs_strcat(a, b) strcat(a, b) |
| 126 | #define yaffs_strcpy(a, b) strcpy(a, b) |
| 127 | #define yaffs_strncpy(a, b, c) strncpy(a, b, c) |
| 128 | #define yaffs_strnlen(s,m) strnlen(s,m) |
| 129 | #define yaffs_sprintf sprintf |
| 130 | #define yaffs_toupper(a) toupper(a) |
| 131 | |
| 132 | #define Y_INLINE inline |
| 133 | |
| 134 | /* #define YINFO(s) YPRINTF(( __FILE__ " %d %s\n",__LINE__,s)) */ |
| 135 | /* #define YALERT(s) YINFO(s) */ |
| 136 | |
| 137 | #define TENDSTR "\n" |
| 138 | #define TSTR(x) x |
| 139 | #define TOUT(p) printf p |
| 140 | |
| 141 | #define YAFFS_LOSTNFOUND_NAME "lost+found" |
| 142 | #define YAFFS_LOSTNFOUND_PREFIX "obj" |
| 143 | /* #define YPRINTF(x) printf x */ |
| 144 | |
| 145 | #define YAFFS_ROOT_MODE 0755 |
| 146 | #define YAFFS_LOSTNFOUND_MODE 0700 |
| 147 | |
| 148 | #define yaffs_sum_cmp(x, y) ((x) == (y)) |
| 149 | #define yaffs_strcmp(a, b) strcmp(a, b) |
| 150 | |
| 151 | #else |
| 152 | /* Should have specified a configuration type */ |
| 153 | #error Unknown configuration |
| 154 | |
| 155 | #endif |
| 156 | |
| 157 | #if defined(CONFIG_YAFFS_DIRECT) || defined(CONFIG_YAFFS_WINCE) |
| 158 | |
| 159 | #ifdef CONFIG_YAFFSFS_PROVIDE_VALUES |
| 160 | |
| 161 | #ifndef O_RDONLY |
| 162 | #define O_RDONLY 00 |
| 163 | #endif |
| 164 | |
| 165 | #ifndef O_WRONLY |
| 166 | #define O_WRONLY 01 |
| 167 | #endif |
| 168 | |
| 169 | #ifndef O_RDWR |
| 170 | #define O_RDWR 02 |
| 171 | #endif |
| 172 | |
| 173 | #ifndef O_CREAT |
| 174 | #define O_CREAT 0100 |
| 175 | #endif |
| 176 | |
| 177 | #ifndef O_EXCL |
| 178 | #define O_EXCL 0200 |
| 179 | #endif |
| 180 | |
| 181 | #ifndef O_TRUNC |
| 182 | #define O_TRUNC 01000 |
| 183 | #endif |
| 184 | |
| 185 | #ifndef O_APPEND |
| 186 | #define O_APPEND 02000 |
| 187 | #endif |
| 188 | |
| 189 | #ifndef SEEK_SET |
| 190 | #define SEEK_SET 0 |
| 191 | #endif |
| 192 | |
| 193 | #ifndef SEEK_CUR |
| 194 | #define SEEK_CUR 1 |
| 195 | #endif |
| 196 | |
| 197 | #ifndef SEEK_END |
| 198 | #define SEEK_END 2 |
| 199 | #endif |
| 200 | |
| 201 | #ifndef EBUSY |
| 202 | #define EBUSY 16 |
| 203 | #endif |
| 204 | |
| 205 | #ifndef ENODEV |
| 206 | #define ENODEV 19 |
| 207 | #endif |
| 208 | |
| 209 | #ifndef EINVAL |
| 210 | #define EINVAL 22 |
| 211 | #endif |
| 212 | |
| 213 | #ifndef EBADF |
| 214 | #define EBADF 9 |
| 215 | #endif |
| 216 | |
| 217 | #ifndef EACCES |
| 218 | #define EACCES 13 |
| 219 | #endif |
| 220 | |
| 221 | #ifndef EXDEV |
| 222 | #define EXDEV 18 |
| 223 | #endif |
| 224 | |
| 225 | #ifndef ENOENT |
| 226 | #define ENOENT 2 |
| 227 | #endif |
| 228 | |
| 229 | #ifndef ENOSPC |
| 230 | #define ENOSPC 28 |
| 231 | #endif |
| 232 | |
| 233 | #ifndef ERANGE |
| 234 | #define ERANGE 34 |
| 235 | #endif |
| 236 | |
| 237 | #ifndef ENODATA |
| 238 | #define ENODATA 61 |
| 239 | #endif |
| 240 | |
| 241 | #ifndef ENOTEMPTY |
| 242 | #define ENOTEMPTY 39 |
| 243 | #endif |
| 244 | |
| 245 | #ifndef ENAMETOOLONG |
| 246 | #define ENAMETOOLONG 36 |
| 247 | #endif |
| 248 | |
| 249 | #ifndef ENOMEM |
| 250 | #define ENOMEM 12 |
| 251 | #endif |
| 252 | |
| 253 | #ifndef EEXIST |
| 254 | #define EEXIST 17 |
| 255 | #endif |
| 256 | |
| 257 | #ifndef ENOTDIR |
| 258 | #define ENOTDIR 20 |
| 259 | #endif |
| 260 | |
| 261 | #ifndef EISDIR |
| 262 | #define EISDIR 21 |
| 263 | #endif |
| 264 | |
| 265 | |
| 266 | // Mode flags |
| 267 | |
| 268 | #ifndef S_IFMT |
| 269 | #define S_IFMT 0170000 |
| 270 | #endif |
| 271 | |
| 272 | #ifndef S_IFLNK |
| 273 | #define S_IFLNK 0120000 |
| 274 | #endif |
| 275 | |
| 276 | #ifndef S_IFDIR |
| 277 | #define S_IFDIR 0040000 |
| 278 | #endif |
| 279 | |
| 280 | #ifndef S_IFREG |
| 281 | #define S_IFREG 0100000 |
| 282 | #endif |
| 283 | |
| 284 | #ifndef S_IREAD |
| 285 | #define S_IREAD 0000400 |
| 286 | #endif |
| 287 | |
| 288 | #ifndef S_IWRITE |
| 289 | #define S_IWRITE 0000200 |
| 290 | #endif |
| 291 | |
| 292 | #ifndef S_IEXEC |
| 293 | #define S_IEXEC 0000100 |
| 294 | #endif |
| 295 | |
| 296 | #ifndef XATTR_CREATE |
| 297 | #define XATTR_CREATE 1 |
| 298 | #endif |
| 299 | |
| 300 | #ifndef XATTR_REPLACE |
| 301 | #define XATTR_REPLACE 2 |
| 302 | #endif |
| 303 | |
| 304 | #ifndef R_OK |
| 305 | #define R_OK 4 |
| 306 | #define W_OK 2 |
| 307 | #define X_OK 1 |
| 308 | #define F_OK 0 |
| 309 | #endif |
| 310 | |
| 311 | #else |
| 312 | #include <errno.h> |
| 313 | #include <sys/stat.h> |
| 314 | #include <fcntl.h> |
| 315 | #endif |
| 316 | |
| 317 | #endif |
| 318 | |
| 319 | #ifndef Y_DUMP_STACK |
| 320 | #define Y_DUMP_STACK() do { } while (0) |
| 321 | #endif |
| 322 | |
| 323 | #ifndef YBUG |
| 324 | #define YBUG() do {\ |
| 325 | T(YAFFS_TRACE_BUG,\ |
| 326 | (TSTR("==>> yaffs bug: " __FILE__ " %d" TENDSTR),\ |
| 327 | __LINE__));\ |
| 328 | Y_DUMP_STACK();\ |
| 329 | } while (0) |
| 330 | #endif |
| 331 | |
| 332 | |
| 333 | #endif |
| 334 | |