ff_dir.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. /*
  2. * FreeRTOS+FAT V2.3.3
  3. * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining a copy of
  6. * this software and associated documentation files (the "Software"), to deal in
  7. * the Software without restriction, including without limitation the rights to
  8. * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
  9. * the Software, and to permit persons to whom the Software is furnished to do so,
  10. * subject to the following conditions:
  11. *
  12. * The above copyright notice and this permission notice shall be included in all
  13. * copies or substantial portions of the Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  17. * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  18. * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  19. * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  20. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  21. *
  22. * https://www.FreeRTOS.org
  23. * https://github.com/FreeRTOS
  24. *
  25. */
  26. /**
  27. * @file ff_dir.h
  28. * @ingroup DIR
  29. **/
  30. #ifndef _FF_DIR_H_
  31. #define _FF_DIR_H_
  32. #ifndef PLUS_FAT_H
  33. #error this header will be included from "ff_headers.h"
  34. #endif
  35. #define FIND_FLAG_SHORTNAME_SET 0x01u
  36. #define FIND_FLAG_SHORTNAME_CHECKED 0x02u
  37. #define FIND_FLAG_SHORTNAME_FOUND 0x04u
  38. #define FIND_FLAG_FITS_SHORT 0x08u
  39. #define FIND_FLAG_SIZE_OK 0x10u
  40. #define FIND_FLAG_CREATE_FLAG 0x20u
  41. #define FIND_FLAG_FITS_SHORT_OK ( FIND_FLAG_FITS_SHORT | FIND_FLAG_SIZE_OK )
  42. typedef struct
  43. {
  44. uint32_t ulChainLength;
  45. uint32_t ulDirCluster;
  46. uint32_t ulCurrentClusterLCN;
  47. uint32_t ulCurrentClusterNum;
  48. FF_Buffer_t * pxBuffer;
  49. } FF_FetchContext_t;
  50. typedef struct
  51. {
  52. uint32_t ulFileSize;
  53. uint32_t ulObjectCluster;
  54. /* Book Keeping. */
  55. uint32_t ulCurrentCluster;
  56. uint32_t ulAddrCurrentCluster;
  57. uint32_t ulDirCluster;
  58. uint16_t usCurrentItem;
  59. /* End Book Keeping. */
  60. #if ( ffconfigTIME_SUPPORT != 0 )
  61. FF_SystemTime_t xCreateTime; /* Date and Time Created. */
  62. FF_SystemTime_t xModifiedTime; /* Date and Time Modified. */
  63. FF_SystemTime_t xAccessedTime; /* Date of Last Access. */
  64. #endif
  65. #if ( ffconfigFINDAPI_ALLOW_WILDCARDS != 0 )
  66. #if ( ffconfigUNICODE_UTF16_SUPPORT != 0 )
  67. FF_T_WCHAR pcWildCard[ ffconfigMAX_FILENAME ];
  68. #else
  69. char pcWildCard[ ffconfigMAX_FILENAME ];
  70. #endif
  71. BaseType_t xInvertWildCard;
  72. #endif
  73. #if ( ffconfigUNICODE_UTF16_SUPPORT != 0 )
  74. FF_T_WCHAR pcFileName[ ffconfigMAX_FILENAME ];
  75. #else
  76. char pcFileName[ ffconfigMAX_FILENAME ];
  77. #endif
  78. #if ( ffconfigLFN_SUPPORT != 0 ) && ( ffconfigINCLUDE_SHORT_NAME != 0 )
  79. char pcShortName[ 13 ];
  80. #endif
  81. uint8_t ucAttrib;
  82. #if ( ffconfigDEV_SUPPORT != 0 )
  83. uint8_t ucIsDeviceDir;
  84. #endif
  85. FF_FetchContext_t xFetchContext;
  86. } FF_DirEnt_t;
  87. /*
  88. * Some public API's, i.e. they're used but ff_stdio.c
  89. */
  90. #if ( ffconfigUNICODE_UTF16_SUPPORT != 0 )
  91. FF_Error_t FF_FindFirst( FF_IOManager_t * pxIOManager,
  92. FF_DirEnt_t * pxDirent,
  93. const FF_T_WCHAR * pcPath );
  94. FF_Error_t FF_MkDir( FF_IOManager_t * pxIOManager,
  95. const FF_T_WCHAR * pcPath );
  96. #else
  97. FF_Error_t FF_FindFirst( FF_IOManager_t * pxIOManager,
  98. FF_DirEnt_t * pxDirent,
  99. const char * pcPath );
  100. FF_Error_t FF_MkDir( FF_IOManager_t * pxIOManager,
  101. const char * pcPath );
  102. #endif /* if ( ffconfigUNICODE_UTF16_SUPPORT != 0 ) */
  103. FF_Error_t FF_FindNext( FF_IOManager_t * pxIOManager,
  104. FF_DirEnt_t * pxDirent );
  105. static portINLINE void FF_RewindFind( FF_DirEnt_t * pxDirent )
  106. {
  107. pxDirent->usCurrentItem = 0;
  108. }
  109. /*
  110. * Some API's internal to the +FAT library.
  111. */
  112. FF_Error_t FF_GetEntry( FF_IOManager_t * pxIOManager,
  113. uint16_t usEntry,
  114. uint32_t ulDirCluster,
  115. FF_DirEnt_t * pxDirent );
  116. FF_Error_t FF_PutEntry( FF_IOManager_t * pxIOManager,
  117. uint16_t usEntry,
  118. uint32_t ulDirCluster,
  119. FF_DirEnt_t * pxDirent,
  120. uint8_t * pucContents );
  121. int8_t FF_FindEntry( FF_IOManager_t * pxIOManager,
  122. uint32_t ulDirCluster,
  123. int8_t * Name,
  124. FF_DirEnt_t * pxDirent,
  125. BaseType_t LFNs );
  126. void FF_PopulateShortDirent( FF_IOManager_t * pxIOManager,
  127. FF_DirEnt_t * pxDirent,
  128. const uint8_t * pucEntryBuffer );
  129. FF_Error_t FF_PopulateLongDirent( FF_IOManager_t * pxIOManager,
  130. FF_DirEnt_t * pxDirent,
  131. uint16_t usEntry,
  132. FF_FetchContext_t * pFetchContext );
  133. FF_Error_t FF_InitEntryFetch( FF_IOManager_t * pxIOManager,
  134. uint32_t ulDirCluster,
  135. FF_FetchContext_t * pContext );
  136. FF_Error_t FF_FetchEntryWithContext( FF_IOManager_t * pxIOManager,
  137. uint32_t ulEntry,
  138. FF_FetchContext_t * pContext,
  139. uint8_t * pEntryBuffer );
  140. FF_Error_t FF_PushEntryWithContext( FF_IOManager_t * pxIOManager,
  141. uint32_t ulEntry,
  142. FF_FetchContext_t * pContext,
  143. uint8_t * pEntryBuffer );
  144. FF_Error_t FF_CleanupEntryFetch( FF_IOManager_t * pxIOManager,
  145. FF_FetchContext_t * pContext );
  146. int8_t FF_PushEntry( FF_IOManager_t * pxIOManager,
  147. uint32_t ulDirCluster,
  148. uint16_t usEntry,
  149. uint8_t * buffer,
  150. void * pParam );
  151. static portINLINE BaseType_t FF_isEndOfDir( const uint8_t * pucEntryBuffer )
  152. {
  153. return pucEntryBuffer[ 0 ] == ( uint8_t ) 0;
  154. }
  155. static portINLINE BaseType_t FF_isDeleted( const uint8_t * pucEntryBuffer )
  156. {
  157. return pucEntryBuffer[ 0 ] == ( uint8_t ) FF_FAT_DELETED;
  158. }
  159. struct _FF_FIND_PARAMS
  160. {
  161. uint32_t ulDirCluster; /* The beginning cluster of this directory. */
  162. int32_t lFreeEntry; /* The first free entry big enough to add the file. */
  163. uint32_t ulFlags; /* See FIND_FLAG_xxx defines above. */
  164. char pcEntryBuffer[ 32 ]; /* LFN converted to short name. */
  165. uint8_t ucCaseAttrib;
  166. uint8_t ucFirstTilde;
  167. };
  168. typedef struct _FF_FIND_PARAMS FF_FindParams_t;
  169. #if ( ffconfigUNICODE_UTF16_SUPPORT != 0 )
  170. uint32_t FF_CreateFile( FF_IOManager_t * pxIOManager,
  171. FF_FindParams_t * findParams,
  172. FF_T_WCHAR * FileName,
  173. FF_DirEnt_t * pxDirent,
  174. FF_Error_t * pError );
  175. uint32_t FF_FindEntryInDir( FF_IOManager_t * pxIOManager,
  176. FF_FindParams_t * findParams,
  177. const FF_T_WCHAR * name,
  178. uint8_t pa_Attrib,
  179. FF_DirEnt_t * pxDirent,
  180. FF_Error_t * pError );
  181. uint32_t FF_FindDir( FF_IOManager_t * pxIOManager,
  182. const FF_T_WCHAR * pcPath,
  183. uint16_t pathLen,
  184. FF_Error_t * pError );
  185. void FF_CreateShortName( FF_FindParams_t * pxFindParams,
  186. const FF_T_WCHAR * pcLongName );
  187. #else /* if ( ffconfigUNICODE_UTF16_SUPPORT != 0 ) */
  188. uint32_t FF_CreateFile( FF_IOManager_t * pxIOManager,
  189. FF_FindParams_t * findParams,
  190. char * FileName,
  191. FF_DirEnt_t * pxDirent,
  192. FF_Error_t * pError );
  193. uint32_t FF_FindEntryInDir( FF_IOManager_t * pxIOManager,
  194. FF_FindParams_t * findParams,
  195. const char * name,
  196. uint8_t pa_Attrib,
  197. FF_DirEnt_t * pxDirent,
  198. FF_Error_t * pError );
  199. uint32_t FF_FindDir( FF_IOManager_t * pxIOManager,
  200. const char * pcPath,
  201. uint16_t pathLen,
  202. FF_Error_t * pError );
  203. void FF_CreateShortName( FF_FindParams_t * pxFindParams,
  204. const char * pcLongName );
  205. #endif /* if ( ffconfigUNICODE_UTF16_SUPPORT != 0 ) */
  206. int32_t FF_FindShortName( FF_IOManager_t * pxIOManager,
  207. FF_FindParams_t * findParams );
  208. FF_Error_t FF_CreateDirent( FF_IOManager_t * pxIOManager,
  209. FF_FindParams_t * findParams,
  210. FF_DirEnt_t * pxDirent );
  211. FF_Error_t FF_ExtendDirectory( FF_IOManager_t * pxIOManager,
  212. uint32_t ulDirCluster );
  213. FF_Error_t FF_RmLFNs( FF_IOManager_t * pxIOManager,
  214. uint16_t usDirEntry,
  215. FF_FetchContext_t * pContext );
  216. #if ( ffconfigHASH_CACHE != 0 )
  217. BaseType_t FF_CheckDirentHash( FF_IOManager_t * pxIOManager,
  218. uint32_t ulDirCluster,
  219. uint32_t ulHash );
  220. BaseType_t FF_DirHashed( FF_IOManager_t * pxIOManager,
  221. uint32_t ulDirCluster );
  222. void FF_AddDirentHash( FF_IOManager_t * pxIOManager,
  223. uint32_t ulDirCluster,
  224. uint32_t ulHash );
  225. FF_Error_t FF_HashDir( FF_IOManager_t * pxIOManager,
  226. uint32_t ulDirCluster );
  227. void FF_UnHashDir( FF_IOManager_t * pxIOManager,
  228. uint32_t ulDirCluster );
  229. #endif /* if ( ffconfigHASH_CACHE != 0 ) */
  230. struct SBuffStats
  231. {
  232. unsigned sectorMatch;
  233. unsigned sectorMiss;
  234. unsigned bufCounts;
  235. unsigned bufCalls;
  236. };
  237. extern struct SBuffStats buffStats;
  238. #endif /* ifndef _FF_DIR_H_ */