Components/IFS/src/Arch/Host/include/IFS/Host/FileSystem.h
Go to the documentation of this file.
1 /****
2  * FileSystem.h
3  * IFS wrapper for Host (POSIX) file system
4  *
5  * Created on: 11 September 2018
6  *
7  * Copyright 2019 mikee47 <mike@sillyhouse.net>
8  *
9  * This file is part of the IFS Library
10  *
11  * This library is free software: you can redistribute it and/or modify it under the terms of the
12  * GNU General Public License as published by the Free Software Foundation, version 3 or later.
13  *
14  * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
15  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16  * See the GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License along with this library.
19  * If not, see <https://www.gnu.org/licenses/>.
20  *
21  ****/
22 
23 #pragma once
24 
25 #include <IFS/IFileSystem.h>
26 
27 namespace IFS
28 {
29 namespace Host
30 {
31 struct os_stat_t;
32 
36 class FileSystem : public IFileSystem
37 {
38 public:
39  FileSystem(const char* rootpath = nullptr) : rootpath(rootpath), mounted(!rootpath)
40  {
41  }
42 
43  ~FileSystem() override
44  {
45  }
46 
47  int mount() override;
48 
49  // IFileSystem methods
50  int getinfo(Info& info) override;
51  String getErrorString(int err) override;
52  int opendir(const char* path, DirHandle& dir) override;
53  int rewinddir(DirHandle dir) override;
54  int readdir(DirHandle dir, Stat& stat) override;
55  int closedir(DirHandle dir) override;
56  int mkdir(const char* path) override;
57  int stat(const char* path, Stat* stat) override;
58  int fstat(FileHandle file, Stat* stat) override;
59  int fsetxattr(FileHandle file, AttributeTag tag, const void* data, size_t size) override;
60  int fgetxattr(FileHandle file, AttributeTag tag, void* buffer, size_t size) override;
61  int fenumxattr(FileHandle file, AttributeEnumCallback callback, void* buffer, size_t bufsize) override;
62  int setxattr(const char* path, AttributeTag tag, const void* data, size_t size) override;
63  int getxattr(const char* path, AttributeTag tag, void* buffer, size_t size) override;
64  FileHandle open(const char* path, OpenFlags flags) override;
65  int close(FileHandle file) override;
66  int read(FileHandle file, void* data, size_t size) override;
67  int write(FileHandle file, const void* data, size_t size) override;
68  file_offset_t lseek(FileHandle file, file_offset_t offset, SeekOrigin origin) override;
69  int eof(FileHandle file) override;
70  file_offset_t tell(FileHandle file) override;
71  int ftruncate(FileHandle file, file_size_t new_size) override;
72  int flush(FileHandle file) override;
73  int rename(const char* oldpath, const char* newpath) override;
74  int remove(const char* path) override;
75  int fremove(FileHandle file) override
76  {
77  return Error::NotImplemented;
78  }
79  int format() override
80  {
81  return Error::ReadOnly;
82  }
83  int check() override
84  {
85  return Error::NotImplemented;
86  }
87 
88 private:
89  String resolvePath(const char* path);
90  void fillStat(const os_stat_t& s, Stat& stat);
91  String rootpath;
92  bool mounted;
93 };
94 
95 } // namespace Host
96 } // namespace IFS
int32_t file_offset_t
Definition: Components/IFS/src/include/IFS/Types.h:51
uint32_t file_size_t
Definition: Components/IFS/src/include/IFS/Types.h:50
SeekOrigin
Stream/file seek origins.
Definition: SeekOrigin.h:18
Manage a set of bit values using enumeration.
Definition: BitSet.h:45
Definition: Delegate.h:20
IFS implementation of Host filing system.
Definition: Components/IFS/src/Arch/Host/include/IFS/Host/FileSystem.h:37
String getErrorString(int err) override
get the text for a returned error code
file_offset_t lseek(FileHandle file, file_offset_t offset, SeekOrigin origin) override
change file read/write position
int remove(const char *path) override
remove (delete) a file by path
int fsetxattr(FileHandle file, AttributeTag tag, const void *data, size_t size) override
Set an extended attribute on an open file.
FileHandle open(const char *path, OpenFlags flags) override
open a file (or directory) by path
int getxattr(const char *path, AttributeTag tag, void *buffer, size_t size) override
Get an attribute from a file given its path.
int fremove(FileHandle file) override
remove (delete) a file by handle
Definition: Components/IFS/src/Arch/Host/include/IFS/Host/FileSystem.h:75
int mkdir(const char *path) override
Create a directory.
int fstat(FileHandle file, Stat *stat) override
get file information
int getinfo(Info &info) override
get filing system information
~FileSystem() override
Definition: Components/IFS/src/Arch/Host/include/IFS/Host/FileSystem.h:43
int opendir(const char *path, DirHandle &dir) override
open a directory for reading
int fenumxattr(FileHandle file, AttributeEnumCallback callback, void *buffer, size_t bufsize) override
Enumerate attributes.
int format() override
format the filing system
Definition: Components/IFS/src/Arch/Host/include/IFS/Host/FileSystem.h:79
int rename(const char *oldpath, const char *newpath) override
rename a file
int setxattr(const char *path, AttributeTag tag, const void *data, size_t size) override
Set an extended attribute for a file given its path.
int close(FileHandle file) override
close an open file
int flush(FileHandle file) override
flush any buffered data to physical media
int write(FileHandle file, const void *data, size_t size) override
write content to a file at current position and advance cursor
int read(FileHandle file, void *data, size_t size) override
read content from a file and advance cursor
int fgetxattr(FileHandle file, AttributeTag tag, void *buffer, size_t size) override
Get an extended attribute from an open file.
int mount() override
Mount file system, performing any required initialisation.
int closedir(DirHandle dir) override
close a directory object
FileSystem(const char *rootpath=nullptr)
Definition: Components/IFS/src/Arch/Host/include/IFS/Host/FileSystem.h:39
int stat(const char *path, Stat *stat) override
get file information
file_offset_t tell(FileHandle file) override
get current file position
int rewinddir(DirHandle dir) override
Reset directory read position to start.
int check() override
Perform a file system consistency check.
Definition: Components/IFS/src/Arch/Host/include/IFS/Host/FileSystem.h:83
int ftruncate(FileHandle file, file_size_t new_size) override
Truncate (reduce) the size of an open file.
int eof(FileHandle file) override
determine if current file position is at end of file
int readdir(DirHandle dir, Stat &stat) override
read a directory entry
Installable File System base class.
Definition: IFileSystem.h:100
The String class.
Definition: WString.h:137
Definition: Streams.h:25
Definition: DirectoryTemplate.h:37
struct ImplFileDir * DirHandle
Definition: IFileSystem.h:72
AttributeTag
Identifies a specific attribute.
Definition: Attribute.h:45
int16_t FileHandle
File handle.
Definition: Stat.h:40
Basic information about filing system.
Definition: IFileSystem.h:122
File Status structure.
Definition: Stat.h:52