Revert restriction of reading across page boundary (#14015)
[betaflight.git] / src / main / io / asyncfatfs / asyncfatfs.h
blob67906719e28d7052d28b24a392d8c6d50391baaf
1 /*
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)
8 * any later version.
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/>.
21 #pragma once
23 #include <stdint.h>
24 #include <stdbool.h>
26 #include "fat_standard.h"
28 typedef struct afatfsFile_t *afatfsFilePtr_t;
30 typedef enum {
31 AFATFS_FILESYSTEM_STATE_UNKNOWN,
32 AFATFS_FILESYSTEM_STATE_FATAL,
33 AFATFS_FILESYSTEM_STATE_INITIALIZATION,
34 AFATFS_FILESYSTEM_STATE_READY
35 } afatfsFilesystemState_e;
37 typedef enum {
38 AFATFS_OPERATION_IN_PROGRESS,
39 AFATFS_OPERATION_SUCCESS,
40 AFATFS_OPERATION_FAILURE
41 } afatfsOperationStatus_e;
43 typedef enum {
44 AFATFS_ERROR_NONE = 0,
45 AFATFS_ERROR_GENERIC = 1,
46 AFATFS_ERROR_BAD_MBR = 2,
47 AFATFS_ERROR_BAD_FILESYSTEM_HEADER = 3
48 } afatfsError_e;
50 typedef struct afatfsDirEntryPointer_t {
51 uint32_t sectorNumberPhysical;
52 int16_t entryIndex;
53 } afatfsDirEntryPointer_t;
55 typedef afatfsDirEntryPointer_t afatfsFinder_t;
57 typedef enum {
58 AFATFS_SEEK_SET,
59 AFATFS_SEEK_CUR,
60 AFATFS_SEEK_END
61 } afatfsSeek_e;
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);