Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Ardupilot
GitHub Repository: Ardupilot/ardupilot
Path: blob/master/libraries/AP_Filesystem/AP_Filesystem_ROMFS.h
9386 views
1
/*
2
This program is free software: you can redistribute it and/or modify
3
it under the terms of the GNU General Public License as published by
4
the Free Software Foundation, either version 3 of the License, or
5
(at your option) any later version.
6
7
This program is distributed in the hope that it will be useful,
8
but WITHOUT ANY WARRANTY; without even the implied warranty of
9
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
GNU General Public License for more details.
11
12
You should have received a copy of the GNU General Public License
13
along with this program. If not, see <http://www.gnu.org/licenses/>.
14
*/
15
16
#pragma once
17
18
#include "AP_Filesystem_config.h"
19
20
#if AP_FILESYSTEM_ROMFS_ENABLED
21
22
#include <AP_HAL/Semaphores.h>
23
24
#include "AP_Filesystem_backend.h"
25
26
class AP_Filesystem_ROMFS : public AP_Filesystem_Backend
27
{
28
public:
29
// functions that closely match the equivalent posix calls
30
int open(const char *fname, int flags, bool allow_absolute_paths = false) override;
31
int close(int fd) override;
32
int32_t read(int fd, void *buf, uint32_t count) override;
33
int32_t write(int fd, const void *buf, uint32_t count) override;
34
int fsync(int fd) override;
35
int32_t lseek(int fd, int32_t offset, int whence) override;
36
int stat(const char *pathname, struct stat *stbuf) override;
37
int unlink(const char *pathname) override;
38
int mkdir(const char *pathname) override;
39
void *opendir(const char *pathname) override;
40
struct dirent *readdir(void *dirp) override;
41
int closedir(void *dirp) override;
42
43
// return free disk space in bytes, -1 on error
44
int64_t disk_free(const char *path) override;
45
46
// return total disk space in bytes, -1 on error
47
int64_t disk_space(const char *path) override;
48
49
// set modification time on a file
50
bool set_mtime(const char *filename, const uint32_t mtime_sec) override;
51
52
/*
53
load a full file. Use delete to free the data
54
*/
55
FileData *load_file(const char *filename) override;
56
57
// unload data from load_file()
58
void unload_file(FileData *fd) override;
59
60
private:
61
// protect searching for free file/dir records when opening/closing
62
HAL_Semaphore record_sem;
63
64
// only allow up to 4 files at a time
65
static constexpr uint8_t max_open_file = 4;
66
static constexpr uint8_t max_open_dir = 4;
67
struct rfile {
68
const uint8_t *data;
69
uint32_t size;
70
uint32_t ofs;
71
} file[max_open_file];
72
73
// allow up to 4 directory opens
74
struct rdir {
75
char *path;
76
uint16_t ofs;
77
struct dirent de;
78
} dir[max_open_dir];
79
};
80
81
#endif // AP_FILESYSTEM_ROMFS_ENABLED
82
83