Blackbox device type 'file' (SITL) considered working when file handler is available
[inav.git] / src / main / io / asyncfatfs / asyncfatfs.h
blob521bd48fba7ae300a7b71c04d8a8cb96863e2c08
1 /*
2 * This file is part of Cleanflight.
4 * Cleanflight is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * Cleanflight is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with Cleanflight. If not, see <http://www.gnu.org/licenses/>.
18 #pragma once
20 #include <stdint.h>
21 #include <stdbool.h>
23 #include "fat_standard.h"
25 typedef struct afatfsFile_t *afatfsFilePtr_t;
27 typedef enum {
28 AFATFS_FILESYSTEM_STATE_UNKNOWN,
29 AFATFS_FILESYSTEM_STATE_FATAL,
30 AFATFS_FILESYSTEM_STATE_INITIALIZATION,
31 AFATFS_FILESYSTEM_STATE_READY,
32 } afatfsFilesystemState_e;
34 typedef enum {
35 AFATFS_OPERATION_IN_PROGRESS,
36 AFATFS_OPERATION_SUCCESS,
37 AFATFS_OPERATION_FAILURE,
38 } afatfsOperationStatus_e;
40 typedef enum {
41 AFATFS_ERROR_NONE = 0,
42 AFATFS_ERROR_GENERIC = 1,
43 AFATFS_ERROR_BAD_MBR = 2,
44 AFATFS_ERROR_BAD_FILESYSTEM_HEADER = 3
45 } afatfsError_e;
47 typedef struct afatfsDirEntryPointer_t {
48 uint32_t sectorNumberPhysical;
49 int16_t entryIndex;
50 } afatfsDirEntryPointer_t;
52 typedef afatfsDirEntryPointer_t afatfsFinder_t;
54 typedef enum {
55 AFATFS_SEEK_SET,
56 AFATFS_SEEK_CUR,
57 AFATFS_SEEK_END,
58 } afatfsSeek_e;
60 typedef void (*afatfsFileCallback_t)(afatfsFilePtr_t file);
61 typedef void (*afatfsCallback_t)(void);
63 bool afatfs_fopen(const char *filename, const char *mode, afatfsFileCallback_t complete);
64 bool afatfs_ftruncate(afatfsFilePtr_t file, afatfsFileCallback_t callback);
65 bool afatfs_fclose(afatfsFilePtr_t file, afatfsCallback_t callback);
66 void afatfs_fcloseSync(afatfsFilePtr_t file);
67 bool afatfs_funlink(afatfsFilePtr_t file, afatfsCallback_t callback);
69 bool afatfs_feof(afatfsFilePtr_t file);
70 void afatfs_fputc(afatfsFilePtr_t file, uint8_t c);
71 uint32_t afatfs_fwrite(afatfsFilePtr_t file, const uint8_t *buffer, uint32_t len);
72 uint32_t afatfs_fwriteSync(afatfsFilePtr_t file, uint8_t *data, uint32_t length);
73 uint32_t afatfs_fread(afatfsFilePtr_t file, uint8_t *buffer, uint32_t len);
74 uint32_t afatfs_freadSync(afatfsFilePtr_t file, uint8_t *buffer, uint32_t length);
75 afatfsOperationStatus_e afatfs_fseek(afatfsFilePtr_t file, int32_t offset, afatfsSeek_e whence);
76 afatfsOperationStatus_e afatfs_fseekSync(afatfsFilePtr_t file, int32_t offset, afatfsSeek_e whence);
77 bool afatfs_ftell(afatfsFilePtr_t file, uint32_t *position);
78 uint32_t afatfs_fileSize(afatfsFilePtr_t file);
80 bool afatfs_mkdir(const char *filename, afatfsFileCallback_t complete);
81 bool afatfs_chdir(afatfsFilePtr_t dirHandle);
83 void afatfs_findFirst(afatfsFilePtr_t directory, afatfsFinder_t *finder);
84 afatfsOperationStatus_e afatfs_findNext(afatfsFilePtr_t directory, afatfsFinder_t *finder, fatDirectoryEntry_t **dirEntry);
85 void afatfs_findLast(afatfsFilePtr_t directory);
87 bool afatfs_flush(void);
88 void afatfs_init(void);
89 bool afatfs_destroy(bool dirty);
90 void afatfs_poll(void);
92 uint32_t afatfs_getFreeBufferSpace(void);
93 uint32_t afatfs_getContiguousFreeSpace(void);
94 bool afatfs_isFull(void);
96 afatfsFilesystemState_e afatfs_getFilesystemState(void);
97 afatfsError_e afatfs_getLastError(void);