AP_Filesystem: add allow_absolute_paths to open(), implement it for posix backend

This commit is contained in:
Willian Galvani 2022-03-14 11:33:32 -03:00 committed by Randy Mackay
parent ddfe3cf974
commit 8fc9191b4c
16 changed files with 20 additions and 18 deletions

View File

@ -106,10 +106,10 @@ const AP_Filesystem::Backend &AP_Filesystem::backend_by_fd(int &fd) const
return backends[idx];
}
int AP_Filesystem::open(const char *fname, int flags)
int AP_Filesystem::open(const char *fname, int flags, bool allow_absolute_paths)
{
const Backend &backend = backend_by_path(fname);
int fd = backend.fs.open(fname, flags);
int fd = backend.fs.open(fname, flags, allow_absolute_paths);
if (fd < 0) {
return -1;
}

View File

@ -80,7 +80,7 @@ public:
AP_Filesystem() {}
// functions that closely match the equivalent posix calls
int open(const char *fname, int flags);
int open(const char *fname, int flags, bool allow_absolute_paths = false);
int close(int fd);
int32_t read(int fd, void *buf, uint32_t count);
int32_t write(int fd, const void *buf, uint32_t count);

View File

@ -21,7 +21,7 @@ class AP_Filesystem_ESP32 : public AP_Filesystem_Backend
{
public:
// functions that closely match the equivalent posix calls
int open(const char *fname, int flags) override;
int open(const char *fname, int flags, bool allow_absolute_paths = false) override;
int close(int fd) override;
int32_t read(int fd, void *buf, uint32_t count) override;
int32_t write(int fd, const void *buf, uint32_t count) override;

View File

@ -279,7 +279,7 @@ static bool remount_file_system(void)
return true;
}
int AP_Filesystem_FATFS::open(const char *pathname, int flags)
int AP_Filesystem_FATFS::open(const char *pathname, int flags, bool allow_absolute_path)
{
int fileno;
int fatfs_modes;

View File

@ -20,7 +20,7 @@ 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 open(const char *fname, int flags, bool allow_absolute_paths = false) override;
int close(int fd) override;
int32_t read(int fd, void *buf, uint32_t count) override;
int32_t write(int fd, const void *buf, uint32_t count) override;

View File

@ -30,7 +30,7 @@ extern int errno;
#define IDLE_TIMEOUT_MS 30000
int AP_Filesystem_Mission::open(const char *fname, int flags)
int AP_Filesystem_Mission::open(const char *fname, int flags, bool allow_absolute_paths)
{
enum MAV_MISSION_TYPE mtype;

View File

@ -23,7 +23,7 @@ class AP_Filesystem_Mission : public AP_Filesystem_Backend
{
public:
// functions that closely match the equivalent posix calls
int open(const char *fname, int flags) override;
int open(const char *fname, int flags, bool allow_absolute_paths = false) override;
int close(int fd) override;
int32_t read(int fd, void *buf, uint32_t count) override;
int32_t lseek(int fd, int32_t offset, int whence) override;

View File

@ -26,7 +26,7 @@
extern const AP_HAL::HAL& hal;
extern int errno;
int AP_Filesystem_Param::open(const char *fname, int flags)
int AP_Filesystem_Param::open(const char *fname, int flags, bool allow_absolute_path)
{
if (!check_file_name(fname)) {
errno = ENOENT;

View File

@ -24,7 +24,7 @@ class AP_Filesystem_Param : public AP_Filesystem_Backend
{
public:
// functions that closely match the equivalent posix calls
int open(const char *fname, int flags) override;
int open(const char *fname, int flags, bool allow_absolute_paths = false) override;
int close(int fd) override;
int32_t read(int fd, void *buf, uint32_t count) override;
int32_t lseek(int fd, int32_t offset, int whence) override;

View File

@ -23,7 +23,7 @@
#if defined(HAL_HAVE_AP_ROMFS_EMBEDDED_H)
int AP_Filesystem_ROMFS::open(const char *fname, int flags)
int AP_Filesystem_ROMFS::open(const char *fname, int flags, bool allow_absolute_paths)
{
if ((flags & O_ACCMODE) != O_RDONLY) {
errno = EROFS;

View File

@ -21,7 +21,7 @@ class AP_Filesystem_ROMFS : public AP_Filesystem_Backend
{
public:
// functions that closely match the equivalent posix calls
int open(const char *fname, int flags) override;
int open(const char *fname, int flags, bool allow_absolute_paths = false) override;
int close(int fd) override;
int32_t read(int fd, void *buf, uint32_t count) override;
int32_t write(int fd, const void *buf, uint32_t count) override;

View File

@ -60,7 +60,7 @@ int8_t AP_Filesystem_Sys::file_in_sysfs(const char *fname) {
return -1;
}
int AP_Filesystem_Sys::open(const char *fname, int flags)
int AP_Filesystem_Sys::open(const char *fname, int flags, bool allow_absolute_paths)
{
if ((flags & O_ACCMODE) != O_RDONLY) {
errno = EROFS;

View File

@ -23,7 +23,7 @@ class AP_Filesystem_Sys : public AP_Filesystem_Backend
{
public:
// functions that closely match the equivalent posix calls
int open(const char *fname, int flags) override;
int open(const char *fname, int flags, bool allow_absolute_paths = false) override;
int close(int fd) override;
int32_t read(int fd, void *buf, uint32_t count) override;
int32_t lseek(int fd, int32_t offset, int whence) override;

View File

@ -43,7 +43,7 @@ class AP_Filesystem_Backend {
public:
// functions that closely match the equivalent posix calls
virtual int open(const char *fname, int flags) {
virtual int open(const char *fname, int flags, bool allow_absolute_paths = false) {
return -1;
}
virtual int close(int fd) { return -1; }

View File

@ -49,10 +49,12 @@ static const char *map_filename(const char *fname)
return fname;
}
int AP_Filesystem_Posix::open(const char *fname, int flags)
int AP_Filesystem_Posix::open(const char *fname, int flags, bool allow_absolute_paths)
{
FS_CHECK_ALLOWED(-1);
fname = map_filename(fname);
if (! allow_absolute_paths) {
fname = map_filename(fname);
}
// we automatically add O_CLOEXEC as we always want it for ArduPilot FS usage
return ::open(fname, flags | O_CLOEXEC, 0644);
}

View File

@ -29,7 +29,7 @@ class AP_Filesystem_Posix : public AP_Filesystem_Backend
{
public:
// functions that closely match the equivalent posix calls
int open(const char *fname, int flags) override;
int open(const char *fname, int flags, bool allow_absolute_paths = false) override;
int close(int fd) override;
int32_t read(int fd, void *buf, uint32_t count) override;
int32_t write(int fd, const void *buf, uint32_t count) override;