sfs.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  1. /******************************************************************************
  2. ** File Name: sfs.h *
  3. ** Author: *
  4. ** DATE: 8/16/2006 *
  5. ** Copyright: 2006 Spreatrum, Incoporated. All Rights Reserved. *
  6. ** Description: *
  7. ** this file define the struct and API of SFS. *
  8. ** (FAT File System) *
  9. ** *
  10. ******************************************************************************
  11. ******************************************************************************
  12. ** Edit History *
  13. ** ------------------------------------------------------------------------- *
  14. ** DATE NAME DESCRIPTION *
  15. ** 8/16/2006 Create. Jason.wu *
  16. ******************************************************************************/
  17. #ifndef _SFS_H_
  18. #define _SFS_H_
  19. /**---------------------------------------------------------------------------*
  20. ** Dependencies *
  21. **---------------------------------------------------------------------------*/
  22. #include "sci_types.h"
  23. #include "vfs.h"
  24. /**---------------------------------------------------------------------------*
  25. ** Compiler Flag *
  26. **---------------------------------------------------------------------------*/
  27. #ifdef __cplusplus
  28. extern "C" {
  29. #endif
  30. #define SFS_IN
  31. #define SFS_OUT
  32. #define SFS_INOUT
  33. /*============================================================================
  34. Define basic data types:
  35. ==============================================================================*/
  36. typedef uint32 SFS_HANDLE;
  37. typedef enum SFS_ERROR_E_TAG
  38. {
  39. /**------------------------------------------------------------------*
  40. ** SFS error code(0-999) *
  41. **------------------------------------------------------------------*/
  42. // 0-1000 is reserved by sfs file system
  43. SFS_NO_ERROR = 0, //success
  44. SFS_ERROR_NONE = 0,
  45. SFS_ERROR_DEVICE = 1, //device error
  46. SFS_ERROR_SYSTEM = 2, //os error, memory overwrite, memory error.or other unlogic error.
  47. SFS_ERROR_INVALID_PARAM = 3, //param you give is invalid
  48. SFS_ERROR_NO_ENOUGH_RESOURCE = 4, //no use
  49. SFS_ERROR_IO_PENDING = 5, //when you call api in asynchronism ,api will return SFS_ERROR_IO_PENDING immediately.Real error message and return value will be given in callback funtion.
  50. SFS_ERROR_ACCESS = 6, //can not access the file ,maybe it is being used by other handler. or read data that not exist
  51. SFS_ERROR_NOT_EXIST = 7, // file or device not exist
  52. SFS_ERROR_HAS_EXIST = 8, // file or device has exist
  53. SFS_ERROR_HARDWARE_FAILED = 9, // no use
  54. SFS_ERROR_WRITE_CONFLICT = 10, // no use
  55. SFS_ERROR_NO_SPACE = 11,
  56. SFS_ERROR_NOT_EMPTY = 20, // folder not empty.
  57. SFS_ERROR_LONG_DEPTH = 21, // copy tree or move tree , has exceed too many folder.
  58. SFS_ERROR_FOLD_FULL = 22, // fold entry is not enough to add new file or fold in it
  59. SFS_ERROR_ABORT = 23, // copy or move process is cancelled.
  60. SFS_ERROR_NORES_HANDLE = 24, // no handle resource for open new file
  61. SFS_ERROR_BUSY = 25, // current sfs task is busy(formating or mountring)
  62. SFS_ERROR_INVALID_FORMAT = 26,
  63. SFS_ERROR_TOOMANYFILE = 27,
  64. /**------------------------------------------------------------------*
  65. ** DRM error code(1000-1199) *
  66. **------------------------------------------------------------------*/
  67. SFS_ERROR_DRM_ACCESS_DENIED = 1000, // @681, operation not allowed
  68. SFS_ERROR_DRM_NORMAL_FILE = 1001, // file is normal
  69. SFS_ERROR_DRM_NO_RIGHTS = 1002, // no rights
  70. SFS_ERROR_DRM_RIGHTS_EXPIRED = 1003, // rights expired
  71. SFS_ERROR_DRM_INVALID_RIGHTS = 1004, // rights file is invalid
  72. SFS_ERROR_DRM_INVALID_FORMAT = 1005, // DRM file format is invalid
  73. SFS_ERROR_INVALID_HANDLE = 1006
  74. /**------------------------------------------------------------------*
  75. ** reserved error code(1200-0xFFFFFFFF) *
  76. **------------------------------------------------------------------*/
  77. // if you want to add error code here please inform it to midware group. Jason.wu
  78. } SFS_ERROR_E;
  79. typedef enum SFS_DEVICE_FORMAT_E_TAG
  80. {
  81. SFS_FAT12_FORMAT = 0,
  82. SFS_FAT16_FORMAT = 1,
  83. SFS_FAT32_FORMAT = 2,
  84. SFS_AUTO_FORMAT = 6,
  85. SFS_OTHER_FORMAT = 7,
  86. SFS_UNKNOWN_FORMAT
  87. } SFS_DEVICE_FORMAT_E;
  88. /*
  89. Seek Macro define.
  90. */
  91. #define SFS_SEEK_BEGIN 0 /*Beginning of file */
  92. #define SFS_SEEK_CUR 1 /*Current position of file */
  93. #define SFS_SEEK_END 2 /*End of file */
  94. #define SFS_MAX_PATH 255
  95. /**---------------------------------------------------------------------------*
  96. ** Overlapped struct *
  97. completed-route :
  98. void CALLBACK FileIOCompletionRoutine(
  99. SFS_ERROR_E error, // error code of the relative opration.
  100. SFS_PARAM irp_param, // the param set by user.
  101. SFS_PARAM param1, // result of the relative operation.
  102. SFS_PARAM param1) // result of the relative operation.
  103. **---------------------------------------------------------------------------*/
  104. typedef uint32 SFS_PARAM;
  105. typedef void (*SFS_COMPLETETION_ROUTINE)(SFS_ERROR_E error, uint32 irp_param, uint32 param1, uint32 param2);
  106. typedef struct SFS_OVERLAPPED_tag
  107. {
  108. SFS_COMPLETETION_ROUTINE complete_route; //the point to callback function.
  109. SFS_PARAM param; //the param set by user,it canbe anything,it will be passed to callbackfun without modify
  110. } SFS_OVERLAPPED_T;
  111. /**------------------------------------------------------------------*
  112. ** SFS operation Mode(bit0-bit4) *
  113. ** only have 6 group can be used: *
  114. ** 1 SFS_MODE_READ *
  115. ** 2 SFS_MODE_WRITE *
  116. ** 3 SFS_MODE_READ|SFS_MODE_WRITE *
  117. ** 4 SFS_MODE_SHARE_READ *
  118. ** 5 SFS_MODE_SHARE_WRITE *
  119. ** 6 SFS_MODE_SHARE_READ|SFS_MODE_SHARE_WRITE *
  120. ** *
  121. **------------------------------------------------------------------*/
  122. #define SFS_MODE_READ ((uint32)(0x1 << 0))
  123. #define SFS_MODE_WRITE ((uint32)(0x1 << 1))
  124. #define SFS_MODE_SHARE_READ ((uint32)(0x1 << 2))
  125. #define SFS_MODE_SHARE_WRITE ((uint32)(0x1 << 3))
  126. /**------------------------------------------------------------------*
  127. ** SFS access Mode(bit4-bit7) *
  128. ** only have following choice: *
  129. **------------------------------------------------------------------*/
  130. #define SFS_MODE_CREATE_NEW ((uint32)(0x1 << 4))
  131. #define SFS_MODE_CREATE_ALWAYS ((uint32)(0x2 << 4))
  132. #define SFS_MODE_OPEN_EXISTING ((uint32)(0x3 << 4))
  133. #define SFS_MODE_OPEN_ALWAYS ((uint32)(0x4 << 4))
  134. #define SFS_MODE_APPEND ((uint32)(0x5 << 4))
  135. /**------------------------------------------------------------------*
  136. ** SFS DRM access Mode(bit8-bit12) *
  137. ** only have following choice: *
  138. **------------------------------------------------------------------*/
  139. #define SFS_MODE_DRM_READ ((uint32)(0x1 << 8))
  140. #define SFS_MODE_DRM_PLAY ((uint32)(0x2 << 8))
  141. #define SFS_MODE_DRM_DISPLAY ((uint32)(0x3 << 8))
  142. #define SFS_MODE_DRM_EXECUTE ((uint32)(0x4 << 8))
  143. #define SFS_MODE_DRM_PRINT ((uint32)(0x5 << 8))
  144. /*
  145. Find Data Define.
  146. The receives information about the found file.
  147. */
  148. typedef struct
  149. {
  150. uint8 mday; // day of the month - [1,31]
  151. uint8 mon; // months - [1,12]
  152. uint16 year; // years [1980,2107]
  153. } SFS_DATE_T;
  154. typedef struct
  155. {
  156. uint8 sec; // secondsafter the minute - [0,59]
  157. uint8 min; // minutesafter the hour - [0,59]
  158. uint8 hour; // hours since midnight - [0,23]
  159. } SFS_TIME_T;
  160. typedef struct SFS_FIND_DATA_TAG
  161. {
  162. SFS_DATE_T create_Date;
  163. SFS_TIME_T create_time;
  164. SFS_DATE_T modify_Date;
  165. SFS_TIME_T modify_time;
  166. SFS_DATE_T access_date;
  167. uint16 attr; // see FFS_ATTR_E.
  168. uint32 length;
  169. uint16 name[SFS_MAX_PATH + 1];
  170. uint8 short_name[13];
  171. } SFS_FIND_DATA_T;
  172. //fat attribute bits
  173. //the value of SFS_FIND_DATA_T->attr,you can use it to identify the file
  174. #define SFS_ATTR_NONE 0x0 /* no attribute bits */
  175. #define SFS_ATTR_RO 0x1 /* read-only */
  176. #define SFS_ATTR_HIDDEN 0x2 /* hidden */
  177. #define SFS_ATTR_SYS 0x4 /* system */
  178. #define SFS_ATTR_VOLUME 0x8 /* volume label */ //reserved : you can not use it
  179. #define SFS_ATTR_DIR 0x10 /* directory */ //can not used in SFS_SetAttr()
  180. #define SFS_ATTR_ARCH 0x20 /* archived */
  181. /**---------------------------------------------------------------------------*
  182. // Function Prototypes
  183. **---------------------------------------------------------------------------*/
  184. /*****************************************************************************/
  185. // Description: Create a directory
  186. // Author:
  187. // Param
  188. // path:The name of path you want to create ,must be unicode string
  189. // Return:
  190. // SFS_ERROR_NONE: Success
  191. // Other: Fail
  192. // Note:
  193. /*****************************************************************************/
  194. SFS_ERROR_E SFS_CreateDirectory(const uint16 *path);
  195. /*****************************************************************************/
  196. // Description: Create or open a file
  197. // Author: Jason.wu
  198. // Param
  199. // file_name :The name of path and file ,must be unicode string
  200. // access_mode:please refer to "Open/Create flag "
  201. // share_mode:reserved
  202. // file_attri:reserved
  203. // Return:
  204. // None zero: Success,this value is the handle of file
  205. // Zero: fail
  206. // Note:
  207. /*****************************************************************************/
  208. SFS_HANDLE SFS_CreateFile(
  209. const uint16 *file_name,
  210. uint32 access_mode,
  211. uint32 share_mode, //Must be NULL,File System have not realize it
  212. uint32 file_attri //Must be NULL,File System have not realize it
  213. );
  214. /*****************************************************************************/
  215. // Description: Write file
  216. // Author:
  217. // Param
  218. // sfs_handle:The handle returned by SFS_CreateFile
  219. // buffer:The data will be writen is stored in this buffer
  220. // bytes_to_write:the number you want to write ,unit is byte
  221. // bytes_written:the number you has be write infact
  222. // overlapped:asynchronism param,if you give this parm,the result value will be returned in callback funtion
  223. // Return:
  224. // SFS_ERROR_NONE: Success
  225. // SFS_ERROR_IO_PENDING:if you call it in asynchronism way,the real result will be given in callback funtion after SFS finish the command
  226. // Other: Fail
  227. // Note:
  228. /*****************************************************************************/
  229. SFS_ERROR_E SFS_WriteFile(
  230. SFS_HANDLE handle,
  231. const void *buffer,
  232. uint32 bytes_to_write,
  233. uint32 *bytes_written,
  234. SFS_OVERLAPPED_T *overlapped);
  235. /*****************************************************************************/
  236. // Description: Read file
  237. // Author:
  238. // Param
  239. // sfs_handle:The handle returned by SFS_CreateFile
  240. // buffer:The data has be read will stored in this buffer
  241. // bytes_to_read:the number you want to read ,unit is byte
  242. // bytes_read:the number you has be read infact
  243. // overlapped:asynchronism param,if you give this parm,the result value will be returned in callback funtion
  244. // Return:
  245. // SFS_ERROR_NONE: Success
  246. // SFS_ERROR_IO_PENDING:if you call it in asynchronism way,the real result will be given in callback funtion after SFS finish the command
  247. // Other: Fail
  248. // Note:
  249. /*****************************************************************************/
  250. SFS_ERROR_E SFS_ReadFile(
  251. SFS_HANDLE handle,
  252. void *buffer,
  253. uint32 bytes_to_read,
  254. uint32 *bytes_read,
  255. SFS_OVERLAPPED_T *overlapped);
  256. /*****************************************************************************/
  257. // Description: Flush file
  258. // Author:
  259. // Param
  260. // sfs_handle:The handle returned by SFS_CreateFile
  261. // overlapped:asynchronism param,if you give this parm,the result value will be returned in callback funtion
  262. // Return:
  263. // SFS_ERROR_NONE: Success
  264. // SFS_ERROR_IO_PENDING:if you call it in asynchronism way,the real result will be given in callback funtion after SFS finish the command
  265. // Other: Fail
  266. // Note:
  267. /*****************************************************************************/
  268. SFS_ERROR_E SFS_FlushFile(
  269. SFS_HANDLE handle,
  270. SFS_OVERLAPPED_T *overlapped);
  271. /*****************************************************************************/
  272. // Description: Close the handler returned by SFS_CreateFile
  273. // Author:
  274. // Param
  275. // sfs_handle:The handle returned by SFS_CreateFile
  276. // Return:
  277. // SFS_ERROR_NONE: Success
  278. // Other: Fail
  279. // Note:
  280. /*****************************************************************************/
  281. SFS_ERROR_E SFS_CloseFile(SFS_HANDLE handle);
  282. /**---------------------------------------------------------------------------*
  283. ** Compiler Flag *
  284. **---------------------------------------------------------------------------*/
  285. #ifdef __cplusplus
  286. }
  287. #endif
  288. #endif /*End FFS.h*/