*** empty log message ***
[yaffs2.git] / yportenv.h
1 /*\r
2  * YAFFS: Yet another FFS. A NAND-flash specific file system. \r
3  * yportenv.h: Portable services used by yaffs. This is done to allow\r
4  * simple migration from kernel space into app space for testing.\r
5  *\r
6  * Copyright (C) 2002 Aleph One Ltd.\r
7  *   for Toby Churchill Ltd and Brightstar Engineering\r
8  *\r
9  * Created by Charles Manning <charles@aleph1.co.uk>\r
10  *\r
11  * This program is free software; you can redistribute it and/or modify\r
12  * it under the terms of the GNU Lesser General Public License version 2.1 as\r
13  * published by the Free Software Foundation.\r
14  *\r
15  *\r
16  * Note: Only YAFFS headers are LGPL, YAFFS C code is covered by GPL.\r
17  *\r
18  * $Id: yportenv.h,v 1.1 2004-11-03 08:14:07 charles Exp $\r
19  *\r
20  */\r
21  \r
22 #ifndef __YPORTENV_H__\r
23 #define __YPORTENV_H__\r
24 \r
25 \r
26 #if defined CONFIG_YAFFS_WINCE\r
27 \r
28 // CONFIG_YAFFS_WINCE\r
29 #include "stdlib.h"\r
30 #include "stdio.h"\r
31 #include "string.h"\r
32 \r
33 #define CONFIG_YAFFS_CASE_INSENSITIVE\r
34 #define CONFIG_YAFFS_UNICODE\r
35 \r
36 #define YMALLOC(x) malloc(x)\r
37 #define YFREE(x)   free(x)\r
38 \r
39 \r
40 #define YINFO(s) YPRINTF(( __FILE__ " %d %s\n",__LINE__,s))\r
41 #define YALERT(s) YINFO(s)\r
42 \r
43 #include <windows.h>\r
44 \r
45 #define YPRINTF(x)      RETAILMSG(1,x)\r
46 \r
47 // Always pass the sum compare to overcome the case insensitivity issue\r
48 #define yaffs_SumCompare(x,y) ((x) == (y))\r
49 \r
50 #ifdef CONFIG_YAFFS_UNICODE\r
51 #define YCHAR                                   WCHAR\r
52 #define YUCHAR                                  WCHAR\r
53 #define _Y(a)                                   L##a\r
54 #define yaffs_toupper(a)                towupper(a)\r
55 #define yaffs_strcmp(a,b)               _wcsicmp(a,b)\r
56 #define yaffs_strcpy(a,b)               wcscpy(a,b)\r
57 #define yaffs_strncpy(a,b,c)    wcsncpy(a,b,c)\r
58 #define yaffs_strlen(s)                 wcslen(s)\r
59 #define yaffs_sprintf                   swprintf\r
60 #else\r
61 #define YCHAR                                   CHAR\r
62 #define YUCHAR                                  UCHAR\r
63 #define _Y(a)                                   a\r
64 #define yaffs_toupper(a)                toupper(a)\r
65 #define yaffs_strcmp(a,b)               _stricmp(a,b)\r
66 #define yaffs_strcpy(a,b)               strcpy(a,b)\r
67 #define yaffs_strncpy(a,b,c)    strncpy(a,b,c)\r
68 #define yaffs_strlen(s)                 strlen(s)\r
69 #define yaffs_sprintf                   sprintf\r
70 #endif\r
71 \r
72 #define YAFFS_LOSTNFOUND_NAME           _Y("Lost Clusters")\r
73 #define YAFFS_LOSTNFOUND_PREFIX         _Y("OBJ")\r
74 \r
75 \r
76 #define u_char unsigned char\r
77 #define loff_t int\r
78 #define S_IFDIR                                         04000\r
79 \r
80 #define S_ISFIFO(x) 0\r
81 #define S_ISCHR(x) 0\r
82 #define S_ISBLK(x) 0\r
83 #define S_ISSOCK(x) 0\r
84 \r
85 extern unsigned yfsd_U32FileTimeNow(void);\r
86 \r
87 #define CURRENT_TIME                             yfsd_U32FileTimeNow()\r
88 #define YAFFS_ROOT_MODE                         FILE_ATTRIBUTE_ARCHIVE\r
89 #define YAFFS_LOSTNFOUND_MODE           FILE_ATTRIBUTE_HIDDEN\r
90 \r
91 \r
92 #define TENDSTR L"\r\n"\r
93 #define TSTR(x) TEXT(x)\r
94 #define TOUT(x) RETAILMSG(1, x)\r
95 \r
96 \r
97 #elif  defined __KERNEL__\r
98 \r
99 \r
100 \r
101 // Linux kernel\r
102 #include "linux/kernel.h"\r
103 #include "linux/mm.h"\r
104 #include "linux/string.h"\r
105 #include "linux/slab.h"\r
106 \r
107 \r
108 #define YAFFS_LOSTNFOUND_NAME           "lost+found"\r
109 #define YAFFS_LOSTNFOUND_PREFIX         "obj"\r
110 \r
111 //#define YPRINTF(x) printk x\r
112 #define YMALLOC(x) kmalloc(x,GFP_KERNEL)\r
113 #define YFREE(x)   kfree(x)\r
114 \r
115 #define YAFFS_ROOT_MODE                         0666\r
116 #define YAFFS_LOSTNFOUND_MODE           0666\r
117 \r
118 \r
119 #define yaffs_SumCompare(x,y) ((x) == (y))\r
120 #define YCHAR                                   char\r
121 #define YUCHAR                                  unsigned char\r
122 #define _Y(a)                                   a\r
123 #define yaffs_toupper(a)                toupper(a)\r
124 #define yaffs_strcmp(a,b)               strcmp(a,b)\r
125 #define yaffs_strcpy(a,b)               strcpy(a,b)\r
126 #define yaffs_strncpy(a,b,c)    strncpy(a,b,c)\r
127 #define yaffs_strlen(s)                 strlen(s)\r
128 #define yaffs_sprintf                   sprintf\r
129 \r
130 #define TENDSTR "\n"\r
131 #define TSTR(x) KERN_DEBUG x\r
132 #define TOUT(p) printk p\r
133 \r
134 \r
135 #elif defined CONFIG_YAFFS_DIRECT\r
136 \r
137 // Direct interface\r
138 \r
139 #include "stdlib.h"\r
140 #include "stdio.h"\r
141 #include "string.h"\r
142 \r
143 #define YMALLOC(x) malloc(x)\r
144 #define YFREE(x)   free(x)\r
145 \r
146 \r
147 //#define YINFO(s) YPRINTF(( __FILE__ " %d %s\n",__LINE__,s))\r
148 //#define YALERT(s) YINFO(s)\r
149 \r
150 \r
151 #define TENDSTR "\n"\r
152 #define TSTR(x) x\r
153 #define TOUT(p) printf p\r
154 \r
155 \r
156 #define YAFFS_LOSTNFOUND_NAME           "lost+found"\r
157 #define YAFFS_LOSTNFOUND_PREFIX         "obj"\r
158 //#define YPRINTF(x) printf x\r
159 \r
160 #include "yaffscfg.h"\r
161 \r
162 #define CURRENT_TIME yaffsfs_CurrentTime()\r
163 #define YAFFS_ROOT_MODE                         0666\r
164 #define YAFFS_LOSTNFOUND_MODE           0666\r
165 \r
166 #define yaffs_SumCompare(x,y) ((x) == (y))\r
167 #define YCHAR                                   char\r
168 #define YUCHAR                                  unsigned char\r
169 #define _Y(a)                                   a\r
170 #define yaffs_toupper(a)                toupper(a)\r
171 #define yaffs_strcmp(a,b)               strcmp(a,b)\r
172 #define yaffs_strcpy(a,b)               strcpy(a,b)\r
173 #define yaffs_strncpy(a,b,c)    strncpy(a,b,c)\r
174 #define yaffs_strlen(s)                 strlen(s)\r
175 #define yaffs_sprintf                   sprintf\r
176 \r
177 #elif defined CONFIG_YAFFS_UTIL\r
178 \r
179 // Stuff for YAFFS utilities\r
180 \r
181 #include "stdlib.h"\r
182 #include "stdio.h"\r
183 #include "string.h"\r
184 \r
185 #define YMALLOC(x) malloc(x)\r
186 #define YFREE(x)   free(x)\r
187 \r
188 \r
189 //#define YINFO(s) YPRINTF(( __FILE__ " %d %s\n",__LINE__,s))\r
190 //#define YALERT(s) YINFO(s)\r
191 \r
192 \r
193 #define TENDSTR "\n"\r
194 #define TSTR(x) x\r
195 #define TOUT(p) printf p\r
196 \r
197 \r
198 #define YAFFS_LOSTNFOUND_NAME           "lost+found"\r
199 #define YAFFS_LOSTNFOUND_PREFIX         "obj"\r
200 //#define YPRINTF(x) printf x\r
201 \r
202 \r
203 #define CURRENT_TIME 0\r
204 #define YAFFS_ROOT_MODE                         0666\r
205 #define YAFFS_LOSTNFOUND_MODE           0666\r
206 \r
207 #define yaffs_SumCompare(x,y) ((x) == (y))\r
208 #define YCHAR                                   char\r
209 #define YUCHAR                                  unsigned char\r
210 #define _Y(a)                                   a\r
211 #define yaffs_toupper(a)                toupper(a)\r
212 #define yaffs_strcmp(a,b)               strcmp(a,b)\r
213 #define yaffs_strcpy(a,b)               strcpy(a,b)\r
214 #define yaffs_strncpy(a,b,c)    strncpy(a,b,c)\r
215 #define yaffs_strlen(s)                 strlen(s)\r
216 #define yaffs_sprintf                   sprintf\r
217 \r
218 #else\r
219 // Should have specified a configuration type\r
220 #error Unknown configuration\r
221 \r
222 #endif \r
223 \r
224 \r
225 extern unsigned yaffs_traceMask;\r
226 \r
227 #define YAFFS_TRACE_ERROR               0x0001\r
228 #define YAFFS_TRACE_OS                  0x0002\r
229 #define YAFFS_TRACE_ALLOCATE    0x0004\r
230 #define YAFFS_TRACE_SCAN                0x0008\r
231 #define YAFFS_TRACE_BAD_BLOCKS  0x0010\r
232 #define YAFFS_TRACE_ERASE               0x0020\r
233 #define YAFFS_TRACE_GC                  0x0040\r
234 #define YAFFS_TRACE_DELETION    0x0080\r
235 #define YAFFS_TRACE_TRACING             0x0100\r
236 #define YAFFS_TRACE_ALWAYS              0x0200\r
237 #define YAFFS_TRACE_WRITE               0x0400\r
238 #define YAFFS_TRACE_BUG                 0x8000\r
239 \r
240 #define T(mask,p) do{ if((mask) & (yaffs_traceMask | YAFFS_TRACE_ERROR)) TOUT(p);} while(0) \r
241 \r
242 //#undef YINFO\r
243 \r
244 \r
245 //#define YINFO(s) YPRINTF((KERN_DEBUG __FILE__ " %d %s\n",__LINE__,s))\r
246 //#define YALERT(s) YINFO(s)\r
247 #ifdef CONFIG_YAFFS_WINCE\r
248 #define YBUG() T(YAFFS_TRACE_BUG,(TSTR("==>> yaffs bug: %s %d" TENDSTR),TEXT(__FILE__),__LINE__))\r
249 #else\r
250 #define YBUG() T(YAFFS_TRACE_BUG,(TSTR("==>> yaffs bug: " __FILE__ " %d" TENDSTR),__LINE__))\r
251 #endif\r
252 #endif\r