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_ROMFS.h
Views: 1798
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_Filesystem_backend.h"
23
24
class AP_Filesystem_ROMFS : public AP_Filesystem_Backend
25
{
26
public:
27
// functions that closely match the equivalent posix calls
28
int open(const char *fname, int flags, bool allow_absolute_paths = false) override;
29
int close(int fd) override;
30
int32_t read(int fd, void *buf, uint32_t count) override;
31
int32_t write(int fd, const void *buf, uint32_t count) override;
32
int fsync(int fd) override;
33
int32_t lseek(int fd, int32_t offset, int whence) override;
34
int stat(const char *pathname, struct stat *stbuf) override;
35
int unlink(const char *pathname) override;
36
int mkdir(const char *pathname) override;
37
void *opendir(const char *pathname) override;
38
struct dirent *readdir(void *dirp) override;
39
int closedir(void *dirp) 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
/*
51
load a full file. Use delete to free the data
52
*/
53
FileData *load_file(const char *filename) override;
54
55
// unload data from load_file()
56
void unload_file(FileData *fd) override;
57
58
private:
59
// only allow up to 4 files at a time
60
static constexpr uint8_t max_open_file = 4;
61
static constexpr uint8_t max_open_dir = 4;
62
struct rfile {
63
const uint8_t *data;
64
uint32_t size;
65
uint32_t ofs;
66
} file[max_open_file];
67
68
// allow up to 4 directory opens
69
struct rdir {
70
char *path;
71
uint16_t ofs;
72
struct dirent de;
73
} dir[max_open_dir];
74
};
75
76
#endif // AP_FILESYSTEM_ROMFS_ENABLED
77
78