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_posix.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_POSIX_ENABLED
21
22
#include <sys/types.h>
23
#include <sys/stat.h>
24
#include <fcntl.h>
25
#include <stddef.h>
26
#include <stdio.h>
27
#include <dirent.h>
28
#include <unistd.h>
29
#include <errno.h>
30
#include "AP_Filesystem_backend.h"
31
32
#ifndef AP_FILESYSTEM_POSIX_HAVE_UTIME
33
#define AP_FILESYSTEM_POSIX_HAVE_UTIME 1
34
#endif
35
36
#ifndef AP_FILESYSTEM_POSIX_HAVE_FSYNC
37
#define AP_FILESYSTEM_POSIX_HAVE_FSYNC 1
38
#endif
39
40
#ifndef AP_FILESYSTEM_POSIX_HAVE_STATFS
41
#define AP_FILESYSTEM_POSIX_HAVE_STATFS 1
42
#endif
43
44
#ifndef O_CLOEXEC
45
#define O_CLOEXEC 0
46
#endif
47
48
class AP_Filesystem_Posix : public AP_Filesystem_Backend
49
{
50
public:
51
// functions that closely match the equivalent posix calls
52
int open(const char *fname, int flags, bool allow_absolute_paths = false) override;
53
int close(int fd) override;
54
int32_t read(int fd, void *buf, uint32_t count) override;
55
int32_t write(int fd, const void *buf, uint32_t count) override;
56
int fsync(int fd) override;
57
int32_t lseek(int fd, int32_t offset, int whence) override;
58
int stat(const char *pathname, struct stat *stbuf) override;
59
int unlink(const char *pathname) override;
60
int mkdir(const char *pathname) override;
61
void *opendir(const char *pathname) override;
62
struct dirent *readdir(void *dirp) override;
63
int closedir(void *dirp) override;
64
int rename(const char *oldpath, const char *newpath) override;
65
66
// return free disk space in bytes, -1 on error
67
int64_t disk_free(const char *path) override;
68
69
// return total disk space in bytes, -1 on error
70
int64_t disk_space(const char *path) override;
71
72
// set modification time on a file
73
bool set_mtime(const char *filename, const uint32_t mtime_sec) override;
74
};
75
76
#endif // AP_FILESYSTEM_POSIX_ENABLED
77
78