Path: blob/master/libraries/AP_Filesystem/AP_Filesystem_ROMFS.h
9386 views
/*1This program is free software: you can redistribute it and/or modify2it under the terms of the GNU General Public License as published by3the Free Software Foundation, either version 3 of the License, or4(at your option) any later version.56This program is distributed in the hope that it will be useful,7but WITHOUT ANY WARRANTY; without even the implied warranty of8MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the9GNU General Public License for more details.1011You should have received a copy of the GNU General Public License12along with this program. If not, see <http://www.gnu.org/licenses/>.13*/1415#pragma once1617#include "AP_Filesystem_config.h"1819#if AP_FILESYSTEM_ROMFS_ENABLED2021#include <AP_HAL/Semaphores.h>2223#include "AP_Filesystem_backend.h"2425class AP_Filesystem_ROMFS : public AP_Filesystem_Backend26{27public:28// functions that closely match the equivalent posix calls29int open(const char *fname, int flags, bool allow_absolute_paths = false) override;30int close(int fd) override;31int32_t read(int fd, void *buf, uint32_t count) override;32int32_t write(int fd, const void *buf, uint32_t count) override;33int fsync(int fd) override;34int32_t lseek(int fd, int32_t offset, int whence) override;35int stat(const char *pathname, struct stat *stbuf) override;36int unlink(const char *pathname) override;37int mkdir(const char *pathname) override;38void *opendir(const char *pathname) override;39struct dirent *readdir(void *dirp) override;40int closedir(void *dirp) override;4142// return free disk space in bytes, -1 on error43int64_t disk_free(const char *path) override;4445// return total disk space in bytes, -1 on error46int64_t disk_space(const char *path) override;4748// set modification time on a file49bool set_mtime(const char *filename, const uint32_t mtime_sec) override;5051/*52load a full file. Use delete to free the data53*/54FileData *load_file(const char *filename) override;5556// unload data from load_file()57void unload_file(FileData *fd) override;5859private:60// protect searching for free file/dir records when opening/closing61HAL_Semaphore record_sem;6263// only allow up to 4 files at a time64static constexpr uint8_t max_open_file = 4;65static constexpr uint8_t max_open_dir = 4;66struct rfile {67const uint8_t *data;68uint32_t size;69uint32_t ofs;70} file[max_open_file];7172// allow up to 4 directory opens73struct rdir {74char *path;75uint16_t ofs;76struct dirent de;77} dir[max_open_dir];78};7980#endif // AP_FILESYSTEM_ROMFS_ENABLED818283