Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Ardupilot
GitHub Repository: Ardupilot/ardupilot
Path: blob/master/libraries/AP_Filesystem/AP_Filesystem_FATFS.h
9447 views
1
/*
2
FATFS backend for AP_Filesystem
3
*/
4
5
#pragma once
6
7
#include <sys/types.h>
8
#include <sys/stat.h>
9
#include <fcntl.h>
10
#include <errno.h>
11
#include <stddef.h>
12
#include "AP_Filesystem_backend.h"
13
14
#if AP_FILESYSTEM_FATFS_ENABLED
15
16
// Seek offset macros
17
#define SEEK_SET 0
18
#define SEEK_CUR 1
19
#define SEEK_END 2
20
21
class AP_Filesystem_FATFS : public AP_Filesystem_Backend
22
{
23
public:
24
// functions that closely match the equivalent posix calls
25
int open(const char *fname, int flags, bool allow_absolute_paths = false) override;
26
int close(int fd) override;
27
int32_t read(int fd, void *buf, uint32_t count) override;
28
int32_t write(int fd, const void *buf, uint32_t count) override;
29
int fsync(int fd) override;
30
int32_t lseek(int fd, int32_t offset, int whence) override;
31
int stat(const char *pathname, struct stat *stbuf) override;
32
int unlink(const char *pathname) override;
33
int mkdir(const char *pathname) override;
34
void *opendir(const char *pathname) override;
35
int rename(const char *oldpath, const char *newpath) override;
36
struct dirent *readdir(void *dirp) override;
37
int closedir(void *dirp) override;
38
39
uint32_t bytes_until_fsync(int fd) override;
40
41
// return free disk space in bytes, -1 on error
42
int64_t disk_free(const char *path) override;
43
44
// return total disk space in bytes, -1 on error
45
int64_t disk_space(const char *path) override;
46
47
// set modification time on a file
48
bool set_mtime(const char *filename, const uint32_t mtime_sec) override;
49
50
// retry mount of filesystem if needed
51
bool retry_mount(void) override;
52
53
// unmount filesystem for reboot
54
void unmount(void) override;
55
56
// format sdcard. This is async, monitor get_format_status for progress
57
bool format(void) override;
58
AP_Filesystem_Backend::FormatStatus get_format_status() const override;
59
60
static void set_io_size(uint32_t _io_size) { io_size = _io_size; }
61
static uint32_t get_io_size() { return io_size; }
62
63
private:
64
static uint32_t io_size;
65
void format_handler(void);
66
FormatStatus format_status;
67
};
68
69
#endif // #if AP_FILESYSTEM_FATFS_ENABLED
70
71