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_Sys.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_backend.h"
19
20
#include "AP_Filesystem_config.h"
21
22
#if AP_FILESYSTEM_SYS_ENABLED
23
24
class ExpandingString;
25
26
class AP_Filesystem_Sys : 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 lseek(int fd, int32_t offset, int whence) override;
34
int stat(const char *pathname, struct stat *stbuf) override;
35
void *opendir(const char *pathname) override;
36
struct dirent *readdir(void *dirp) override;
37
int closedir(void *dirp) override;
38
39
private:
40
// only allow up to 4 files at a time
41
static constexpr uint8_t max_open_file = 4;
42
int8_t file_in_sysfs(const char *fname);
43
44
struct DirReadTracker {
45
size_t file_offset;
46
struct dirent curr_file;
47
};
48
49
struct rfile {
50
bool open;
51
uint32_t file_ofs;
52
ExpandingString *str;
53
} file[max_open_file];
54
};
55
56
#endif // AP_FILESYSTEM_SYS_ENABLED
57
58