*** 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.7 2002-11-26 01:15:37 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 YMALLOC(x) malloc(x)
34 #define YFREE(x)   free(x)
35
36
37 #define YINFO(s) YPRINTF(( __FILE__ " %d %s\n",__LINE__,s))
38 #define YALERT(s) YINFO(s)
39
40 #include <windows.h>
41
42 #define YAFFS_LOSTNFOUND_NAME           "Lost Clusters"
43 #define YAFFS_LOSTNFOUND_PREFIX         "OBJ"
44
45 #define YPRINTF(x)
46
47 // Always pass the sum compare to overcome the case insensitivity issue
48 #define yaffs_SumCompare(x,y) ((x) == (y))
49 #define yaffs_strcmp(a,b) _stricmp(a,b)
50
51
52 #define u_char unsigned char
53 #define loff_t int
54 #define S_IFDIR                                         04000
55
56 #define S_ISFIFO(x) 0
57 #define S_ISCHR(x) 0
58 #define S_ISBLK(x) 0
59 #define S_ISSOCK(x) 0
60
61 extern unsigned yfsd_U32FileTimeNow(void);
62
63 #define CURRENT_TIME                             yfsd_U32FileTimeNow()
64 #define YAFFS_ROOT_MODE                         FILE_ATTRIBUTE_ARCHIVE
65 #define YAFFS_LOSTNFOUND_MODE           FILE_ATTRIBUTE_HIDDEN
66
67
68 #define TENDSTR L"\r\n"
69 #define TSTR(x) TEXT(x)
70 #define TOUT(x) RETAILMSG(1, x)
71
72
73 #elif  defined __KERNEL__
74
75
76
77 // Linux kernel
78 #include "linux/kernel.h"
79 #include "linux/mm.h"
80 #include "linux/string.h"
81 #include "linux/slab.h"
82
83
84 #define YAFFS_LOSTNFOUND_NAME           "lost+found"
85 #define YAFFS_LOSTNFOUND_PREFIX         "obj"
86
87 //#define YPRINTF(x) printk x
88 #define YMALLOC(x) kmalloc(x,GFP_KERNEL)
89 #define YFREE(x)   kfree(x)
90
91 #define YAFFS_ROOT_MODE                         0666
92 #define YAFFS_LOSTNFOUND_MODE           0666
93
94
95 #define yaffs_SumCompare(x,y) ((x) == (y))
96 #define yaffs_strcmp(a,b) strcmp(a,b)
97
98 #define TENDSTR "\n"
99 #define TSTR(x) KERN_DEBUG x
100 #define TOUT(p) printk p
101
102
103 #else
104
105 // Linux application
106 #include "stdlib.h"
107 #include "stdio.h"
108 #include "string.h"
109
110 #define YMALLOC(x) malloc(x)
111 #define YFREE(x)   free(x)
112
113
114 //#define YINFO(s) YPRINTF(( __FILE__ " %d %s\n",__LINE__,s))
115 //#define YALERT(s) YINFO(s)
116
117
118 #define TENDSTR "\n"
119 #define TSTR(x) x
120 #define TOUT(p) printf p
121
122
123 #define YAFFS_LOSTNFOUND_NAME           "lost+found"
124 #define YAFFS_LOSTNFOUND_PREFIX         "obj"
125 //#define YPRINTF(x) printf x
126
127 #define CURRENT_TIME 0
128 #define YAFFS_ROOT_MODE                         0666
129 #define YAFFS_LOSTNFOUND_MODE           0666
130
131 #define yaffs_SumCompare(x,y) ((x) == (y))
132 #define yaffs_strcmp(a,b) strcmp(a,b)
133
134 #endif 
135
136
137 extern unsigned yaffs_traceMask;
138
139 #define YAFFS_TRACE_ERROR               0x0001
140 #define YAFFS_TRACE_OS                  0x0002
141 #define YAFFS_TRACE_ALLOCATE    0x0004
142 #define YAFFS_TRACE_SCAN                0x0008
143 #define YAFFS_TRACE_BAD_BLOCKS  0x0010
144 #define YAFFS_TRACE_ERASE               0x0020
145 #define YAFFS_TRACE_TRACING             0x0100
146 #define YAFFS_TRACE_ALWAYS              0x0200
147 #define YAFFS_TRACE_BUG                 0x8000
148
149 #define T(mask,p) do{ if((mask) & (yaffs_traceMask | YAFFS_TRACE_ERROR)) TOUT(p);} while(0) 
150
151 //#undef YINFO
152
153
154 //#define YINFO(s) YPRINTF((KERN_DEBUG __FILE__ " %d %s\n",__LINE__,s))
155 //#define YALERT(s) YINFO(s)
156 #ifdef CONFIG_YAFFS_WINCE
157 #define YBUG() T(YAFFS_TRACE_BUG,(TSTR("==>> yaffs bug: %s %d" TENDSTR),TEXT(__FILE__),__LINE__))
158 #else
159 #define YBUG() T(YAFFS_TRACE_BUG,(TSTR("==>> yaffs bug: " __FILE__ " %d" TENDSTR),__LINE__))
160 #endif
161 #endif