Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

420 lines
14 KiB

  1. /*
  2. * $Log: V:/Flite/archives/TrueFFS5/Src/FLBASE.H_V $
  3. *
  4. * Rev 1.19 Apr 15 2002 07:36:18 oris
  5. * Moved all include directive to head of file.
  6. * Moved OS names definitions to mtdsa.h
  7. * Changed flBusConfig environment array to dword variables instead of single byte.
  8. * Added support for VERIFY_ERASED_SECTOR compilation flag.
  9. *
  10. * Rev 1.18 Feb 19 2002 20:59:28 oris
  11. * Changed order of include directives.
  12. *
  13. * Rev 1.17 Jan 29 2002 20:08:08 oris
  14. * Added NAMING_CONVENTION prefix and extern "C" for cpp files to all public routines:
  15. * tffsset, tffscmp and tffsset.
  16. *
  17. * Rev 1.16 Jan 20 2002 20:26:42 oris
  18. * Added casting to byte to FL_GET_PARTITION_FROM_HANDLE and to FL_GET_SOCKET_FROM_HANDLE
  19. *
  20. * Rev 1.15 Jan 17 2002 23:00:42 oris
  21. * Removed MAX and MIN definitions and replaced them with TFFSMIN and TFFSMAX.
  22. * Added extern for the following environment variables:
  23. * extern dword flSectorsVerifiedPerFolding;
  24. * extern byte flSuspendMode;
  25. * extern byte flBusConfig[SOCKETS];
  26. * Changed the following environment variables
  27. * extern byte flVerifyWrite[SOCKETS][MAX_TL_PARTITIONS<<1] - 4 for disk partition 3 for binary and one for the rest.
  28. * extern byte flPolicy[SOCKETS][MAX_TL_PARTITIONS] - 1 for each disk partition.
  29. * Changed all environment variables to byte (except for flSectorsVerifiedPerFolding)
  30. * Added FL_UPS for flVerifyWrite
  31. * Added FL_SUSPEND_WRITE and FL_SUSPEND_IO for flSuspendMode.
  32. * Added define CUR_OS_WINCE for boot SDK customization.
  33. * Exchanged CUR_OS_VX_WORKS and CUR_NO_OS
  34. * Added FL_GET_SOCKET_FROM_HANDLE and FL_GET_PARTITION_FROM_HANDLE instead of HANDLE_VOLUME_MASK and HANDLE_PARTITION_MASK.
  35. *
  36. * Rev 1.14 Nov 21 2001 11:38:52 oris
  37. * Removed FL_MULTI_DOC_NOT_ACTIVE , FL_MULTI_DOC_ACTIVE , FL_DO_NOT_MARK_DELETE , FL_MARK_DELETE , FL_WITHOUT_VERIFY_WRITE , FL_WITH_VERIFY_WRITE definition (unsing FL_ON and FL_OFF instead).
  38. *
  39. * Rev 1.13 Nov 08 2001 10:49:14 oris
  40. * Moved environment variable states definitions from blockdev.h
  41. * Added flVerifyWrite environment variable that controls the verify write mode at run-time.
  42. *
  43. * Rev 1.12 Sep 15 2001 23:45:40 oris
  44. * Changed BIG_ENDIAN to FL_BIG_ENDIAN
  45. * Changed checkStatus definition in order not to get compilation warnings.
  46. *
  47. * Rev 1.11 Jul 29 2001 16:44:16 oris
  48. * Added CUR_OS_NO definition
  49. *
  50. * Rev 1.10 May 21 2001 16:09:52 oris
  51. * Removed flsleep prototype and moved tffscpy tffscmp and tffsset prototypes under USE_STD_FUNC copmpilation flag.
  52. *
  53. * Rev 1.9 May 21 2001 13:51:06 oris
  54. * Reorganized and added the CUS_OS_DOS, CUS_OS_PSOS and CUS_OS_VX_WORKS defintions.
  55. *
  56. * Rev 1.8 May 16 2001 21:17:38 oris
  57. * Added the FL_ prefix to the following defines: ON, OFF
  58. * Changed c variable name to cval (avoid name clashes).
  59. * Added flMtlDefragMode environment variable forward definition.
  60. *
  61. * Rev 1.7 Apr 30 2001 18:00:32 oris
  62. * Added new environment variable flMarkDeleteOnFlash declaration.
  63. *
  64. * Rev 1.6 Apr 10 2001 23:53:54 oris
  65. * Added flAddLongToFarPointer declaration for the standalone version.
  66. *
  67. * Rev 1.5 Apr 09 2001 15:01:56 oris
  68. * UNAL4(arg) definition was changed.
  69. *
  70. * Rev 1.4 Apr 01 2001 07:51:46 oris
  71. * copywrite notice.
  72. * Moved MIN,MAX,BYTE_ADD_FAR,WORD_ADD_FAR macroes from base2400.c.
  73. * Moved protection attributes definition to flflash.h.
  74. * Aliggned left all # directives.
  75. * Added FAR0 to cpyBuffer,setBuffer,cmpBuffer,flmemcpy,flmemset and flmemcmp
  76. *
  77. * Rev 1.3 Feb 18 2001 14:18:02 oris
  78. * remove osak version redundent definition.
  79. *
  80. * Rev 1.2 Feb 14 2001 02:12:08 oris
  81. * Added flMaxUnitChain environment variable.
  82. * Changed flUseMultiDoc and flPolicy variables type and names.
  83. *
  84. * Rev 1.1 Feb 05 2001 18:45:20 oris
  85. * Removed flcustm.h include directive since it is already included in mtdsa.h
  86. * Added flchkdef.h include directive for sanity check on compilation flags.
  87. *
  88. * Rev 1.0 Feb 04 2001 11:14:30 oris
  89. * Initial revision.
  90. *
  91. */
  92. /***********************************************************************************/
  93. /* M-Systems Confidential */
  94. /* Copyright (C) M-Systems Flash Disk Pioneers Ltd. 1995-2001 */
  95. /* All Rights Reserved */
  96. /***********************************************************************************/
  97. /* NOTICE OF M-SYSTEMS OEM */
  98. /* SOFTWARE LICENSE AGREEMENT */
  99. /* */
  100. /* THE USE OF THIS SOFTWARE IS GOVERNED BY A SEPARATE LICENSE */
  101. /* AGREEMENT BETWEEN THE OEM AND M-SYSTEMS. REFER TO THAT AGREEMENT */
  102. /* FOR THE SPECIFIC TERMS AND CONDITIONS OF USE, */
  103. /* OR CONTACT M-SYSTEMS FOR LICENSE ASSISTANCE: */
  104. /* E-MAIL = [email protected] */
  105. /***********************************************************************************/
  106. #ifndef FLBASE_H
  107. #define FLBASE_H
  108. /***************************************************************************/
  109. /* */
  110. /* Include customization files */
  111. /* Note the following files are used for : */
  112. /* mtdsa.h - Complete customization - standaloe applications */
  113. /* like Binary SDK */
  114. /* flsystem.h - System customization - TrueFFS applications like drivers */
  115. /* flchkdef.h - Customized defintion check of TrueFFS applications. */
  116. /* */
  117. /***************************************************************************/
  118. #include "mtdsa.h"
  119. #ifndef MTD_STANDALONE
  120. #include "flcustom.h"
  121. #include "flsystem.h"
  122. #include "flchkdef.h"
  123. #endif /* MTD_STANDALONE */
  124. #include "flstatus.h"
  125. /* Number of translation layer partitions
  126. *
  127. * Defines Maximum Number of Traslation layer partitons on a physical device
  128. *
  129. * The actual number of partitions depends on the format placed on each device.
  130. */
  131. #define MAX_TL_PARTITIONS 4
  132. /* Sector size
  133. *
  134. * Define the log2 of sector size for the FAT & translation layers. Note
  135. * that the default 512 bytes is the de-facto standard and practically
  136. * the only one that provides real PC interoperability.
  137. */
  138. #define SECTOR_SIZE_BITS 9
  139. /* standard type definitions */
  140. typedef int FLBoolean;
  141. /* Boolean constants */
  142. #ifndef FALSE
  143. #define FALSE 0
  144. #endif
  145. #ifndef TRUE
  146. #define TRUE 1
  147. #endif
  148. #ifndef FL_ON
  149. #define FL_ON 1
  150. #endif
  151. #ifndef FL_OFF
  152. #define FL_OFF 0
  153. #endif
  154. /* Geral purpose macroes */
  155. #define BYTE_ADD_FAR(x,y) ((byte FAR1 *)addToFarPointer(x,y))
  156. #define WORD_ADD_FAR(x,y) ((word FAR1 *)addToFarPointer(x,y))
  157. /* Drive handle masks */
  158. #define FL_GET_SOCKET_FROM_HANDLE(ioreq) (byte)(ioreq->irHandle & 0x0f)
  159. #define FL_GET_PARTITION_FROM_HANDLE(ioreq) (byte)((ioreq->irHandle & 0xf0) >> 4)
  160. #define INVALID_VOLUME_NUMBER 0xff
  161. #define TL_SIGNATURE 6
  162. /* General types definitions */
  163. typedef unsigned char byte; /* 8 bit unsigned variable */
  164. typedef unsigned short word; /* 16 bit unsigned variable */
  165. typedef unsigned long dword; /* 32 bit unsigned variable */
  166. typedef signed char Sbyte; /* 8 bit signed variable */
  167. typedef signed short Sword; /* 16 bit signed variable */
  168. typedef signed long Sdword; /* 32 bit signed variable */
  169. #define SECTOR_SIZE (1 << SECTOR_SIZE_BITS)
  170. #define BITS_PER_BITE 8
  171. /* General purpose Macroes adjusted according to the above customization files. */
  172. /* define SectorNo range according to media maximum size */
  173. #if (MAX_VOLUME_MBYTES * 0x100000l) / SECTOR_SIZE > 0x10000l
  174. typedef unsigned long SectorNo;
  175. #define UNASSIGNED_SECTOR 0xffffffffl
  176. #else
  177. typedef unsigned short SectorNo;
  178. #define UNASSIGNED_SECTOR 0xffff
  179. #endif
  180. /* x86 pointer far level dictated several of the TrueFFS pointers types. */
  181. #if FAR_LEVEL > 0
  182. #define FAR0 far
  183. #else
  184. #define FAR0
  185. #endif
  186. #if FAR_LEVEL > 1
  187. #define FAR1 far
  188. #else
  189. #define FAR1
  190. #endif
  191. #if FAR_LEVEL > 2
  192. #define FAR2 far
  193. #else
  194. #define FAR2
  195. #endif
  196. /* Call a procedure returning status and fail if it fails. This works only in */
  197. /* routines that return Status: */
  198. #define checkStatus(exp) { FLStatus fl__status = (exp);if (fl__status != flOK) return fl__status; }
  199. #define vol (*pVol)
  200. #define TFFSMIN(a,b) ((a>b) ? b:a)
  201. #define TFFSMAX(a,b) ((a<b) ? b:a)
  202. /***************************************************************************/
  203. /* Big \ Little endien architecture conversion macroes. */
  204. /***************************************************************************/
  205. #ifndef FL_BIG_ENDIAN
  206. typedef unsigned short LEushort;
  207. typedef unsigned long LEulong;
  208. #define LE2(arg) arg
  209. #define toLE2(to,arg) (to) = (arg)
  210. #define LE4(arg) arg
  211. #define toLE4(to,arg) (to) = (arg)
  212. #define COPY2(to,arg) (to) = (arg)
  213. #define COPY4(to,arg) (to) = (arg)
  214. typedef unsigned char Unaligned[2];
  215. typedef Unaligned Unaligned4[2];
  216. #define UNAL2(arg) fromUNAL(arg)
  217. #define toUNAL2(to,arg) toUNAL(to,arg)
  218. #define UNAL4(arg) fromUNALLONG((Unaligned const FAR0 *)(arg))
  219. #define toUNAL4(to,arg) toUNALLONG(to,arg)
  220. extern void toUNAL(unsigned char FAR0 *unal, unsigned short n);
  221. extern unsigned short fromUNAL(unsigned char const FAR0 *unal);
  222. extern void toUNALLONG(Unaligned FAR0 *unal, unsigned long n);
  223. extern unsigned long fromUNALLONG(Unaligned const FAR0 *unal);
  224. #else
  225. typedef unsigned char LEushort[2];
  226. typedef unsigned char LEulong[4];
  227. #define LE2(arg) fromLEushort(arg)
  228. #define toLE2(to,arg) toLEushort(to,arg)
  229. #define LE4(arg) fromLEulong(arg)
  230. #define toLE4(to,arg) toLEulong(to,arg)
  231. #define COPY2(to,arg) copyShort(to,arg)
  232. #define COPY4(to,arg) copyLong(to,arg)
  233. #define Unaligned LEushort
  234. #define Unaligned4 LEulong
  235. extern void toLEushort(unsigned char FAR0 *le, unsigned short n);
  236. extern unsigned short fromLEushort(unsigned char const FAR0 *le);
  237. extern void toLEulong(unsigned char FAR0 *le, unsigned long n);
  238. extern unsigned long fromLEulong(unsigned char const FAR0 *le);
  239. extern void copyShort(unsigned char FAR0 *to,
  240. unsigned char const FAR0 *from);
  241. extern void copyLong(unsigned char FAR0 *to,
  242. unsigned char const FAR0 *from);
  243. #define UNAL2 LE2
  244. #define toUNAL2 toLE2
  245. #define UNAL4 LE4
  246. #define toUNAL4 toLE4
  247. #endif /* FL_BIG_ENDIAN */
  248. typedef LEulong LEmin;
  249. #ifndef MTD_STANDALONE
  250. #include "flsysfun.h"
  251. #endif /* MTD_STANDALONE */
  252. /*************************************************/
  253. /* Use routines instead of 'c' standard librarys */
  254. /*************************************************/
  255. #if (defined(VERIFY_WRITE) || defined(VERIFY_ERASED_SECTOR))
  256. extern byte flVerifyWrite[SOCKETS][MAX_TL_PARTITIONS<<1];
  257. /* Vefrify write */
  258. #define FL_UPS 2
  259. /*
  260. * See also FL_ON and FL_OFF
  261. */
  262. #endif /* VERIFY_WRITE || VERIFY_ERASED_SECTOR */
  263. #ifdef ENVIRONMENT_VARS
  264. typedef void FAR0 * (NAMING_CONVENTION FAR0* cpyBuffer)(void FAR0 * ,const void FAR0 * ,size_t);
  265. typedef void FAR0 * (NAMING_CONVENTION FAR0* setBuffer)(void FAR0 * ,int ,size_t);
  266. typedef int (NAMING_CONVENTION FAR0* cmpBuffer)(const void FAR0 * ,const void FAR0 * ,size_t);
  267. #ifdef __cplusplus
  268. extern "C"
  269. {
  270. #endif /* __cplusplus */
  271. extern cpyBuffer tffscpy;
  272. #ifdef __cplusplus
  273. }
  274. #endif /* __cplusplus */
  275. #ifdef __cplusplus
  276. extern "C"
  277. {
  278. #endif /* __cplusplus */
  279. extern cmpBuffer tffscmp;
  280. #ifdef __cplusplus
  281. }
  282. #endif /* __cplusplus */
  283. #ifdef __cplusplus
  284. extern "C"
  285. {
  286. #endif /* __cplusplus */
  287. extern setBuffer tffsset;
  288. #ifdef __cplusplus
  289. }
  290. #endif /* __cplusplus */
  291. extern void FAR0* NAMING_CONVENTION FAR0 flmemcpy(void FAR0* dest,const void FAR0 *src,size_t count);
  292. extern void FAR0* NAMING_CONVENTION FAR0 flmemset(void FAR0* dest,int cval,size_t count);
  293. extern int NAMING_CONVENTION FAR0 flmemcmp(const void FAR0* dest,const void FAR0 *src,size_t count);
  294. /**********************************************/
  295. /* Declare the TrueFFS environment variables */
  296. /**********************************************/
  297. extern byte flUse8Bit;
  298. extern byte flUseNFTLCache;
  299. extern byte flUseisRAM;
  300. extern byte flUseMultiDoc;
  301. extern byte flMTLdefragMode;
  302. extern byte flMaxUnitChain;
  303. extern byte flMarkDeleteOnFlash;
  304. extern byte flPolicy[SOCKETS][MAX_TL_PARTITIONS];
  305. extern byte flSuspendMode;
  306. #if (defined(VERIFY_WRITE) || defined(VERIFY_ERASED_SECTOR))
  307. extern dword flSectorsVerifiedPerFolding;
  308. #endif /* VERIFY_WRITE || VERIFY_ERASED_SECTOR */
  309. /* Policies definitions (FL_SET_POLICY) */
  310. #define FL_DEFAULT_POLICY 0
  311. #define FL_COMPLETE_ASAP 1
  312. /* Mtl policies defintions (FL_MTL_POLICY) */
  313. #define FL_MTL_DEFRAGMENT_ALL_DEVICES 0
  314. #define FL_MTL_DEFRAGMENT_SEQUANTIAL 1
  315. /* Suspend mode other then FL_OF */
  316. #define FL_SUSPEND_WRITE 1
  317. #define FL_SUSPEND_IO 3
  318. extern void flSetEnvVar(void);
  319. #endif /* ENVIRONMENT_VARS */
  320. #ifndef FL_NO_USE_FUNC
  321. extern dword flBusConfig[SOCKETS];
  322. #endif /* FL_NO_USE_FUNC */
  323. #ifdef MTD_STANDALONE
  324. /* When the using the application standalone mode (mtdsa.h), the following routines can be */
  325. /* used provided they are implemented in mtdsa.c file. */
  326. extern void flDelayMsecs(unsigned long msec);
  327. extern void FAR0* flAddLongToFarPointer(void FAR0 *ptr, unsigned long offset);
  328. #ifndef USE_STD_FUNC
  329. /**********************************************/
  330. /* Declare tffscpy, tffsset, tffscmp routines */
  331. /* Not using the standard 'c' libraries. */
  332. /**********************************************/
  333. extern void tffscpy(void FAR1 *dst, void FAR1 *src, unsigned len);
  334. extern int tffscmp(void FAR1 *s1, void FAR1 *s2, unsigned len);
  335. extern void tffsset(void FAR1 *dst, unsigned char value, unsigned len);
  336. #endif /* USE_STD_FUNC */
  337. #endif /* MTD_STANDALONE */
  338. #endif