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