CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
Ardupilot

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.

GitHub Repository: Ardupilot/ardupilot
Path: blob/master/libraries/AP_Filesystem/AP_Filesystem_FATFS.h
Views: 1798
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
// return free disk space in bytes, -1 on error
40
int64_t disk_free(const char *path) override;
41
42
// return total disk space in bytes, -1 on error
43
int64_t disk_space(const char *path) override;
44
45
// set modification time on a file
46
bool set_mtime(const char *filename, const uint32_t mtime_sec) override;
47
48
// retry mount of filesystem if needed
49
bool retry_mount(void) override;
50
51
// unmount filesystem for reboot
52
void unmount(void) override;
53
54
// format sdcard. This is async, monitor get_format_status for progress
55
bool format(void) override;
56
AP_Filesystem_Backend::FormatStatus get_format_status() const override;
57
58
private:
59
void format_handler(void);
60
FormatStatus format_status;
61
};
62
63
#endif // #if AP_FILESYSTEM_FATFS_ENABLED
64
65