2019-08-01 02:07:26 -03:00
|
|
|
/*
|
|
|
|
FATFS backend for AP_Filesystem
|
|
|
|
*/
|
|
|
|
|
2020-03-11 03:48:09 -03:00
|
|
|
#pragma once
|
|
|
|
|
2019-08-01 02:07:26 -03:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <stddef.h>
|
|
|
|
#include <ff.h>
|
2020-03-11 03:48:09 -03:00
|
|
|
#include "AP_Filesystem_backend.h"
|
2019-08-01 02:07:26 -03:00
|
|
|
|
|
|
|
// Seek offset macros
|
|
|
|
#define SEEK_SET 0
|
|
|
|
#define SEEK_CUR 1
|
|
|
|
#define SEEK_END 2
|
|
|
|
|
|
|
|
#if FF_USE_LFN != 0
|
|
|
|
#define MAX_NAME_LEN FF_MAX_LFN
|
|
|
|
#else
|
|
|
|
#define MAX_NAME_LEN 13
|
|
|
|
#endif
|
|
|
|
|
2020-03-11 03:48:09 -03:00
|
|
|
class AP_Filesystem_FATFS : public AP_Filesystem_Backend
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
// functions that closely match the equivalent posix calls
|
|
|
|
int open(const char *fname, int flags) override;
|
|
|
|
int close(int fd) override;
|
2020-03-29 22:53:29 -03:00
|
|
|
int32_t read(int fd, void *buf, uint32_t count) override;
|
|
|
|
int32_t write(int fd, const void *buf, uint32_t count) override;
|
2020-03-11 03:48:09 -03:00
|
|
|
int fsync(int fd) override;
|
2020-03-29 22:53:29 -03:00
|
|
|
int32_t lseek(int fd, int32_t offset, int whence) override;
|
2020-03-11 03:48:09 -03:00
|
|
|
int stat(const char *pathname, struct stat *stbuf) override;
|
|
|
|
int unlink(const char *pathname) override;
|
|
|
|
int mkdir(const char *pathname) override;
|
|
|
|
void *opendir(const char *pathname) override;
|
|
|
|
struct dirent *readdir(void *dirp) override;
|
|
|
|
int closedir(void *dirp) override;
|
|
|
|
|
|
|
|
// return free disk space in bytes, -1 on error
|
|
|
|
int64_t disk_free(const char *path) override;
|
|
|
|
|
|
|
|
// return total disk space in bytes, -1 on error
|
|
|
|
int64_t disk_space(const char *path) override;
|
|
|
|
|
|
|
|
// set modification time on a file
|
2020-03-29 22:53:29 -03:00
|
|
|
bool set_mtime(const char *filename, const uint32_t mtime_sec) override;
|
2020-10-23 22:24:06 -03:00
|
|
|
|
|
|
|
// retry mount of filesystem if needed
|
|
|
|
bool retry_mount(void) override;
|
|
|
|
|
|
|
|
// unmount filesystem for reboot
|
|
|
|
void unmount(void) override;
|
2020-03-11 03:48:09 -03:00
|
|
|
};
|