ff_file.h 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  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_file.h
  28. * @ingroup FILEIO
  29. **/
  30. #ifndef _FF_FILE_H_
  31. #define _FF_FILE_H_
  32. #ifndef PLUS_FAT_H
  33. #error this header will be included from "ff_headers.h"
  34. #endif
  35. #define FF_SEEK_SET 0
  36. #define FF_SEEK_CUR 1
  37. #define FF_SEEK_END 2
  38. #if ( ffconfigOPTIMISE_UNALIGNED_ACCESS != 0 )
  39. #define FF_BUFSTATE_INVALID 0x00 /* Data in file handle buffer is invalid. */
  40. #define FF_BUFSTATE_VALID 0x01 /* Valid data in pBuf (Something has been read into it). */
  41. #define FF_BUFSTATE_WRITTEN 0x02 /* Data was written into pBuf, this must be saved when leaving sector. */
  42. #endif
  43. #if ( ffconfigDEV_SUPPORT != 0 )
  44. struct xDEV_NODE
  45. {
  46. uint8_t
  47. ucIsDevice;
  48. };
  49. #endif
  50. typedef struct _FF_FILE
  51. {
  52. FF_IOManager_t * pxIOManager; /* Ioman Pointer! */
  53. uint32_t ulFileSize; /* File's Size. */
  54. uint32_t ulObjectCluster; /* File's Start Cluster. */
  55. uint32_t ulChainLength; /* Total Length of the File's cluster chain. */
  56. uint32_t ulCurrentCluster; /* Prevents FAT Thrashing. */
  57. uint32_t ulAddrCurrentCluster; /* Address of the current cluster. */
  58. uint32_t ulEndOfChain; /* Address of the last cluster in the chain. */
  59. uint32_t ulFilePointer; /* Current Position Pointer. */
  60. uint32_t ulDirCluster; /* Cluster Number that the Dirent is in. */
  61. uint32_t ulValidFlags; /* Handle validation flags. */
  62. #if ( ffconfigOPTIMISE_UNALIGNED_ACCESS != 0 )
  63. uint8_t * pucBuffer; /* A buffer for providing fast unaligned access. */
  64. uint8_t ucState; /* State information about the buffer. */
  65. #endif
  66. uint8_t ucMode; /* Mode that File Was opened in. */
  67. uint16_t usDirEntry; /* Dirent Entry Number describing this file. */
  68. #if ( ffconfigDEV_SUPPORT != 0 )
  69. struct SFileCache * pxDevNode;
  70. #endif
  71. struct _FF_FILE * pxNext; /* Pointer to the next file object in the linked list. */
  72. } FF_FILE;
  73. #define FF_VALID_FLAG_INVALID 0x00000001
  74. #define FF_VALID_FLAG_DELETED 0x00000002
  75. /*---------- PROTOTYPES */
  76. /* PUBLIC (Interfaces): */
  77. #if ( ffconfigUNICODE_UTF16_SUPPORT != 0 )
  78. FF_FILE * FF_Open( FF_IOManager_t * pxIOManager,
  79. const FF_T_WCHAR * path,
  80. uint8_t Mode,
  81. FF_Error_t * pError );
  82. BaseType_t FF_isDirEmpty( FF_IOManager_t * pxIOManager,
  83. const FF_T_WCHAR * Path );
  84. FF_Error_t FF_RmFile( FF_IOManager_t * pxIOManager,
  85. const FF_T_WCHAR * path );
  86. FF_Error_t FF_RmDir( FF_IOManager_t * pxIOManager,
  87. const FF_T_WCHAR * path );
  88. FF_Error_t FF_Move( FF_IOManager_t * pxIOManager,
  89. const FF_T_WCHAR * szSourceFile,
  90. const FF_T_WCHAR * szDestinationFile,
  91. BaseType_t bDeleteIfExists );
  92. #else /* ffconfigUNICODE_UTF16_SUPPORT */
  93. FF_FILE * FF_Open( FF_IOManager_t * pxIOManager,
  94. const char * path,
  95. uint8_t Mode,
  96. FF_Error_t * pError );
  97. BaseType_t FF_isDirEmpty( FF_IOManager_t * pxIOManager,
  98. const char * Path );
  99. FF_Error_t FF_RmFile( FF_IOManager_t * pxIOManager,
  100. const char * path );
  101. FF_Error_t FF_RmDir( FF_IOManager_t * pxIOManager,
  102. const char * path );
  103. FF_Error_t FF_Move( FF_IOManager_t * pxIOManager,
  104. const char * szSourceFile,
  105. const char * szDestinationFile,
  106. BaseType_t bDeleteIfExists );
  107. #endif /* ffconfigUNICODE_UTF16_SUPPORT */
  108. #if ( ffconfigTIME_SUPPORT != 0 )
  109. enum
  110. {
  111. ETimeCreate = 1,
  112. ETimeMod = 2,
  113. ETimeAccess = 4,
  114. ETimeAll = 7
  115. };
  116. FF_Error_t FF_SetFileTime( FF_FILE * pFile,
  117. FF_SystemTime_t * pxTime,
  118. UBaseType_t uxWhat );
  119. #if ( ffconfigUNICODE_UTF16_SUPPORT != 0 )
  120. FF_Error_t FF_SetTime( FF_IOManager_t * pxIOManager,
  121. const FF_T_WCHAR * path,
  122. FF_SystemTime_t * pxTime,
  123. UBaseType_t uxWhat );
  124. #else
  125. FF_Error_t FF_SetTime( FF_IOManager_t * pxIOManager,
  126. const char * path,
  127. FF_SystemTime_t * pxTime,
  128. UBaseType_t uxWhat );
  129. #endif /* ffconfigUNICODE_UTF16_SUPPORT */
  130. #endif /* ffconfigTIME_SUPPORT */
  131. #if ( ffconfigUNICODE_UTF16_SUPPORT != 0 )
  132. FF_Error_t FF_SetPerm( FF_IOManager_t * pxIOManager,
  133. const FF_T_WCHAR * path,
  134. UBaseType_t aPerm );
  135. #else
  136. FF_Error_t FF_SetPerm( FF_IOManager_t * pxIOManager,
  137. const char * path,
  138. UBaseType_t aPerm );
  139. #endif
  140. FF_Error_t FF_SetEof( FF_FILE * pFile );
  141. FF_Error_t FF_Close( FF_FILE * pFile );
  142. int32_t FF_GetC( FF_FILE * pFile );
  143. int32_t FF_GetLine( FF_FILE * pFile,
  144. char * szLine,
  145. uint32_t ulLimit );
  146. int32_t FF_Read( FF_FILE * pFile,
  147. uint32_t ElementSize,
  148. uint32_t Count,
  149. uint8_t * buffer );
  150. int32_t FF_Write( FF_FILE * pFile,
  151. uint32_t ElementSize,
  152. uint32_t Count,
  153. uint8_t * buffer );
  154. BaseType_t FF_isEOF( FF_FILE * pFile );
  155. int32_t FF_BytesLeft( FF_FILE * pFile ); /* Returns # of bytes left to read. */
  156. /* FF_FileSize is an earlier version of FF_GetFileSize(). For files
  157. * equal to or larger than 2GB, the return value is negative.
  158. * Function is deprecated. Please use FF_GetFileSize(). */
  159. int32_t FF_FileSize( FF_FILE * pFile ); /* Returns # of bytes in a file. */
  160. /* Use the following function in case files may get larger than 2 GB.
  161. * Writes the size of a file to the parameter.
  162. * Returns 0 or error code. */
  163. FF_Error_t FF_GetFileSize( FF_FILE * pFile,
  164. uint32_t * pulSize );
  165. FF_Error_t FF_Seek( FF_FILE * pFile,
  166. int32_t Offset,
  167. BaseType_t xOrigin );
  168. int32_t FF_PutC( FF_FILE * pFile,
  169. uint8_t Value );
  170. static portINLINE uint32_t FF_Tell( FF_FILE * pFile )
  171. {
  172. return pFile ? pFile->ulFilePointer : 0;
  173. }
  174. uint8_t FF_GetModeBits( const char * Mode );
  175. FF_Error_t FF_CheckValid( FF_FILE * pFile ); /* Check if pFile is a valid FF_FILE pointer. */
  176. #if ( ffconfigREMOVABLE_MEDIA != 0 )
  177. int32_t FF_Invalidate( FF_IOManager_t * pxIOManager ); /* Invalidate all handles belonging to pxIOManager. */
  178. #endif
  179. /* Private : */
  180. #endif /* ifndef _FF_FILE_H_ */