2 * FreeRTOS+FAT build 191128 - Note: FreeRTOS+FAT is still in the lab!
\r
3 * Copyright (C) 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
\r
4 * Authors include James Walmsley, Hein Tibosch and Richard Barry
\r
6 * Permission is hereby granted, free of charge, to any person obtaining a copy of
\r
7 * this software and associated documentation files (the "Software"), to deal in
\r
8 * the Software without restriction, including without limitation the rights to
\r
9 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
\r
10 * the Software, and to permit persons to whom the Software is furnished to do so,
\r
11 * subject to the following conditions:
\r
13 * The above copyright notice and this permission notice shall be included in all
\r
14 * copies or substantial portions of the Software.
\r
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
\r
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
\r
18 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
\r
19 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
\r
20 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
\r
21 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\r
23 * https://www.FreeRTOS.org
\r
36 #error this header will be included from "ff_headers.h"
\r
39 #define FIND_FLAG_SHORTNAME_SET 0x01u
\r
40 #define FIND_FLAG_SHORTNAME_CHECKED 0x02u
\r
41 #define FIND_FLAG_SHORTNAME_FOUND 0x04u
\r
42 #define FIND_FLAG_FITS_SHORT 0x08u
\r
43 #define FIND_FLAG_SIZE_OK 0x10u
\r
44 #define FIND_FLAG_CREATE_FLAG 0x20u
\r
46 #define FIND_FLAG_FITS_SHORT_OK ( FIND_FLAG_FITS_SHORT | FIND_FLAG_SIZE_OK )
\r
50 uint32_t ulChainLength;
\r
51 uint32_t ulDirCluster;
\r
52 uint32_t ulCurrentClusterLCN;
\r
53 uint32_t ulCurrentClusterNum;
\r
54 FF_Buffer_t *pxBuffer;
\r
55 } FF_FetchContext_t;
\r
59 uint32_t ulFileSize;
\r
60 uint32_t ulObjectCluster;
\r
63 uint32_t ulCurrentCluster;
\r
64 uint32_t ulAddrCurrentCluster;
\r
65 uint32_t ulDirCluster;
\r
66 uint16_t usCurrentItem;
\r
67 /* End Book Keeping. */
\r
69 #if( ffconfigTIME_SUPPORT != 0 )
\r
70 FF_SystemTime_t xCreateTime; /* Date and Time Created. */
\r
71 FF_SystemTime_t xModifiedTime; /* Date and Time Modified. */
\r
72 FF_SystemTime_t xAccessedTime; /* Date of Last Access. */
\r
75 #if( ffconfigFINDAPI_ALLOW_WILDCARDS != 0 )
\r
76 #if( ffconfigUNICODE_UTF16_SUPPORT != 0 )
\r
77 FF_T_WCHAR pcWildCard[ ffconfigMAX_FILENAME ];
\r
79 char pcWildCard[ ffconfigMAX_FILENAME ];
\r
81 BaseType_t xInvertWildCard;
\r
84 #if( ffconfigUNICODE_UTF16_SUPPORT != 0 )
\r
85 FF_T_WCHAR pcFileName[ ffconfigMAX_FILENAME ];
\r
87 char pcFileName[ ffconfigMAX_FILENAME ];
\r
90 #if( ffconfigLFN_SUPPORT != 0 ) && ( ffconfigINCLUDE_SHORT_NAME != 0 )
\r
91 char pcShortName[ 13 ];
\r
94 #if( ffconfigDEV_SUPPORT != 0 )
\r
95 uint8_t ucIsDeviceDir;
\r
97 FF_FetchContext_t xFetchContext;
\r
103 * Some public API's, i.e. they're used but ff_stdio.c
\r
105 #if( ffconfigUNICODE_UTF16_SUPPORT != 0 )
\r
106 FF_Error_t FF_FindFirst( FF_IOManager_t *pxIOManager, FF_DirEnt_t *pxDirent, const FF_T_WCHAR *pcPath );
\r
107 FF_Error_t FF_MkDir( FF_IOManager_t *pxIOManager, const FF_T_WCHAR *pcPath );
\r
109 FF_Error_t FF_FindFirst( FF_IOManager_t *pxIOManager, FF_DirEnt_t *pxDirent, const char *pcPath );
\r
110 FF_Error_t FF_MkDir( FF_IOManager_t *pxIOManager, const char *pcPath );
\r
113 FF_Error_t FF_FindNext( FF_IOManager_t *pxIOManager, FF_DirEnt_t *pxDirent );
\r
115 static portINLINE void FF_RewindFind( FF_DirEnt_t *pxDirent )
\r
117 pxDirent->usCurrentItem = 0;
\r
121 * Some API's internal to the +FAT library.
\r
123 FF_Error_t FF_GetEntry( FF_IOManager_t *pxIOManager, uint16_t usEntry, uint32_t ulDirCluster, FF_DirEnt_t *pxDirent );
\r
124 FF_Error_t FF_PutEntry( FF_IOManager_t *pxIOManager, uint16_t usEntry, uint32_t ulDirCluster, FF_DirEnt_t *pxDirent, uint8_t *pucContents );
\r
125 int8_t FF_FindEntry( FF_IOManager_t *pxIOManager, uint32_t ulDirCluster, int8_t *Name, FF_DirEnt_t *pxDirent, BaseType_t LFNs );
\r
127 void FF_PopulateShortDirent( FF_IOManager_t *pxIOManager, FF_DirEnt_t *pxDirent, const uint8_t *pucEntryBuffer );
\r
128 FF_Error_t FF_PopulateLongDirent( FF_IOManager_t *pxIOManager, FF_DirEnt_t *pxDirent, uint16_t usEntry, FF_FetchContext_t *pFetchContext );
\r
130 FF_Error_t FF_InitEntryFetch( FF_IOManager_t *pxIOManager, uint32_t ulDirCluster, FF_FetchContext_t *pContext );
\r
131 FF_Error_t FF_FetchEntryWithContext( FF_IOManager_t *pxIOManager, uint32_t ulEntry, FF_FetchContext_t *pContext, uint8_t *pEntryBuffer );
\r
132 FF_Error_t FF_PushEntryWithContext( FF_IOManager_t *pxIOManager, uint32_t ulEntry, FF_FetchContext_t *pContext, uint8_t *pEntryBuffer );
\r
133 FF_Error_t FF_CleanupEntryFetch( FF_IOManager_t *pxIOManager, FF_FetchContext_t *pContext );
\r
135 int8_t FF_PushEntry( FF_IOManager_t *pxIOManager, uint32_t ulDirCluster, uint16_t usEntry, uint8_t *buffer, void *pParam );
\r
137 static portINLINE BaseType_t FF_isEndOfDir( const uint8_t *pucEntryBuffer )
\r
139 return pucEntryBuffer[ 0 ] == ( uint8_t ) 0;
\r
142 static portINLINE BaseType_t FF_isDeleted( const uint8_t *pucEntryBuffer )
\r
144 return pucEntryBuffer[ 0 ] == ( uint8_t ) FF_FAT_DELETED;
\r
147 struct _FF_FIND_PARAMS
\r
149 uint32_t ulDirCluster; /* The beginning cluster of this directory. */
\r
150 int32_t lFreeEntry; /* The first free entry big enough to add the file. */
\r
151 uint32_t ulFlags; /* See FIND_FLAG_xxx defines above. */
\r
152 char pcEntryBuffer[ 32 ]; /* LFN converted to short name. */
\r
153 uint8_t ucCaseAttrib;
\r
154 uint8_t ucFirstTilde;
\r
157 typedef struct _FF_FIND_PARAMS FF_FindParams_t;
\r
159 #if( ffconfigUNICODE_UTF16_SUPPORT != 0 )
\r
160 uint32_t FF_CreateFile( FF_IOManager_t *pxIOManager, FF_FindParams_t *findParams, FF_T_WCHAR *FileName,
\r
161 FF_DirEnt_t *pxDirent, FF_Error_t *pError );
\r
163 uint32_t FF_FindEntryInDir( FF_IOManager_t *pxIOManager, FF_FindParams_t *findParams, const FF_T_WCHAR *name,
\r
164 uint8_t pa_Attrib, FF_DirEnt_t *pxDirent, FF_Error_t *pError );
\r
166 uint32_t FF_FindDir( FF_IOManager_t *pxIOManager, const FF_T_WCHAR *pcPath, uint16_t pathLen, FF_Error_t *pError );
\r
167 void FF_CreateShortName( FF_FindParams_t *pxFindParams, const FF_T_WCHAR *pcLongName );
\r
169 uint32_t FF_CreateFile( FF_IOManager_t *pxIOManager, FF_FindParams_t *findParams, char *FileName,
\r
170 FF_DirEnt_t *pxDirent, FF_Error_t *pError );
\r
172 uint32_t FF_FindEntryInDir( FF_IOManager_t *pxIOManager, FF_FindParams_t *findParams, const char *name,
\r
173 uint8_t pa_Attrib, FF_DirEnt_t *pxDirent, FF_Error_t *pError );
\r
175 uint32_t FF_FindDir( FF_IOManager_t *pxIOManager, const char *pcPath, uint16_t pathLen, FF_Error_t *pError );
\r
176 void FF_CreateShortName( FF_FindParams_t *pxFindParams, const char *pcLongName );
\r
179 int32_t FF_FindShortName( FF_IOManager_t *pxIOManager, FF_FindParams_t *findParams );
\r
181 FF_Error_t FF_CreateDirent( FF_IOManager_t *pxIOManager, FF_FindParams_t *findParams, FF_DirEnt_t *pxDirent );
\r
182 FF_Error_t FF_ExtendDirectory( FF_IOManager_t *pxIOManager, uint32_t ulDirCluster );
\r
183 FF_Error_t FF_RmLFNs( FF_IOManager_t *pxIOManager, uint16_t usDirEntry, FF_FetchContext_t *pContext );
\r
185 #if( ffconfigHASH_CACHE != 0 )
\r
186 BaseType_t FF_CheckDirentHash( FF_IOManager_t *pxIOManager, uint32_t ulDirCluster, uint32_t ulHash );
\r
187 BaseType_t FF_DirHashed( FF_IOManager_t *pxIOManager, uint32_t ulDirCluster );
\r
188 void FF_AddDirentHash( FF_IOManager_t *pxIOManager, uint32_t ulDirCluster, uint32_t ulHash );
\r
189 FF_Error_t FF_HashDir( FF_IOManager_t *pxIOManager, uint32_t ulDirCluster );
\r
190 void FF_UnHashDir( FF_IOManager_t *pxIOManager, uint32_t ulDirCluster );
\r
193 struct SBuffStats {
\r
194 unsigned sectorMatch;
\r
195 unsigned sectorMiss;
\r
196 unsigned bufCounts;
\r
200 extern struct SBuffStats buffStats;
\r