2020-03-27 17:29:27 -03:00
|
|
|
/*
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "AP_Filesystem_backend.h"
|
|
|
|
|
2020-12-30 02:23:26 -04:00
|
|
|
class ExpandingString;
|
|
|
|
|
2020-03-27 17:29:27 -03:00
|
|
|
class AP_Filesystem_Sys : public AP_Filesystem_Backend
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
// functions that closely match the equivalent posix calls
|
2022-03-14 11:33:32 -03:00
|
|
|
int open(const char *fname, int flags, bool allow_absolute_paths = false) override;
|
2020-03-27 17:29:27 -03:00
|
|
|
int close(int fd) override;
|
2020-03-29 22:53:29 -03:00
|
|
|
int32_t read(int fd, void *buf, uint32_t count) override;
|
|
|
|
int32_t lseek(int fd, int32_t offset, int whence) override;
|
2020-03-27 17:29:27 -03:00
|
|
|
int stat(const char *pathname, struct stat *stbuf) override;
|
2020-10-03 18:04:40 -03:00
|
|
|
void *opendir(const char *pathname) override;
|
|
|
|
struct dirent *readdir(void *dirp) override;
|
|
|
|
int closedir(void *dirp) override;
|
2020-03-27 17:29:27 -03:00
|
|
|
|
|
|
|
private:
|
|
|
|
// only allow up to 4 files at a time
|
|
|
|
static constexpr uint8_t max_open_file = 4;
|
2020-10-03 18:04:40 -03:00
|
|
|
int8_t file_in_sysfs(const char *fname);
|
2020-03-27 17:29:27 -03:00
|
|
|
|
2020-10-03 18:04:40 -03:00
|
|
|
struct DirReadTracker {
|
|
|
|
size_t file_offset;
|
|
|
|
struct dirent curr_file;
|
|
|
|
};
|
|
|
|
|
2020-03-27 17:29:27 -03:00
|
|
|
struct rfile {
|
|
|
|
bool open;
|
|
|
|
uint32_t file_ofs;
|
2020-12-30 02:23:26 -04:00
|
|
|
ExpandingString *str;
|
2020-03-27 17:29:27 -03:00
|
|
|
} file[max_open_file];
|
|
|
|
};
|