2 * This file is part of Cleanflight and Betaflight.
4 * Cleanflight and Betaflight are free software. You can redistribute
5 * this software and/or modify this software under the terms of the
6 * GNU General Public License as published by the Free Software
7 * Foundation, either version 3 of the License, or (at your option)
10 * Cleanflight and Betaflight are distributed in the hope that they
11 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
12 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 * See the GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this software.
18 * If not, see <http://www.gnu.org/licenses/>.
26 #include "fat_standard.h"
28 typedef struct afatfsFile_t
*afatfsFilePtr_t
;
31 AFATFS_FILESYSTEM_STATE_UNKNOWN
,
32 AFATFS_FILESYSTEM_STATE_FATAL
,
33 AFATFS_FILESYSTEM_STATE_INITIALIZATION
,
34 AFATFS_FILESYSTEM_STATE_READY
35 } afatfsFilesystemState_e
;
38 AFATFS_OPERATION_IN_PROGRESS
,
39 AFATFS_OPERATION_SUCCESS
,
40 AFATFS_OPERATION_FAILURE
41 } afatfsOperationStatus_e
;
44 AFATFS_ERROR_NONE
= 0,
45 AFATFS_ERROR_GENERIC
= 1,
46 AFATFS_ERROR_BAD_MBR
= 2,
47 AFATFS_ERROR_BAD_FILESYSTEM_HEADER
= 3
50 typedef struct afatfsDirEntryPointer_t
{
51 uint32_t sectorNumberPhysical
;
53 } afatfsDirEntryPointer_t
;
55 typedef afatfsDirEntryPointer_t afatfsFinder_t
;
63 typedef void (*afatfsFileCallback_t
)(afatfsFilePtr_t file
);
64 typedef void (*afatfsCallback_t
)(void);
66 bool afatfs_fopen(const char *filename
, const char *mode
, afatfsFileCallback_t complete
);
67 bool afatfs_ftruncate(afatfsFilePtr_t file
, afatfsFileCallback_t callback
);
68 bool afatfs_fclose(afatfsFilePtr_t file
, afatfsCallback_t callback
);
69 bool afatfs_funlink(afatfsFilePtr_t file
, afatfsCallback_t callback
);
71 bool afatfs_feof(afatfsFilePtr_t file
);
72 void afatfs_fputc(afatfsFilePtr_t file
, uint8_t c
);
73 uint32_t afatfs_fwrite(afatfsFilePtr_t file
, const uint8_t *buffer
, uint32_t len
);
74 uint32_t afatfs_fread(afatfsFilePtr_t file
, uint8_t *buffer
, uint32_t len
);
75 afatfsOperationStatus_e
afatfs_fseek(afatfsFilePtr_t file
, int32_t offset
, afatfsSeek_e whence
);
76 bool afatfs_ftell(afatfsFilePtr_t file
, uint32_t *position
);
78 bool afatfs_mkdir(const char *filename
, afatfsFileCallback_t complete
);
79 bool afatfs_chdir(afatfsFilePtr_t dirHandle
);
81 void afatfs_findFirst(afatfsFilePtr_t directory
, afatfsFinder_t
*finder
);
82 afatfsOperationStatus_e
afatfs_findNext(afatfsFilePtr_t directory
, afatfsFinder_t
*finder
, fatDirectoryEntry_t
**dirEntry
);
83 void afatfs_findLast(afatfsFilePtr_t directory
);
85 bool afatfs_flush(void);
86 void afatfs_init(void);
87 bool afatfs_destroy(bool dirty
);
88 void afatfs_poll(void);
90 uint32_t afatfs_getFreeBufferSpace(void);
91 uint32_t afatfs_getContiguousFreeSpace(void);
92 bool afatfs_isFull(void);
94 afatfsFilesystemState_e
afatfs_getFilesystemState(void);
95 afatfsError_e
afatfs_getLastError(void);
96 bool afatfs_sectorCacheInSync(void);