Components/IFS/src/include/IFS/HYFS/FileSystem.h
Go to the documentation of this file.
1 
23 /*
24  *
25  * Files on SPIFFS are used in preference to FW.
26  *
27  * Formatting this system wipes SPIFFS to reset to a 'factory default' state.
28  *
29  * Images are created using a python script.
30  *
31  * @todo
32  * When a file is deleted, if it exists on FW then a zero-length file should be placed on SPIFFS
33  * with an attribute to indicate it has been deleted.
34  * An 'undelete' could be added which would remove this to restore the FW file. It probably wouldn't
35  * be useful on any other filing system though, and may not always succeed.
36  *
37  */
38 
39 #pragma once
40 
41 #include "../IFileSystem.h"
42 
43 #ifndef HYFS_HIDE_FLAGS
44 #define HYFS_HIDE_FLAGS 1
45 #endif
46 
47 #if HYFS_HIDE_FLAGS == 1
48 #include "WVector.h"
49 #endif
50 
51 namespace IFS
52 {
53 namespace HYFS
54 {
55 class FileSystem : public IFileSystem
56 {
57 public:
58  FileSystem(IFileSystem* fwfs, IFileSystem* ffs) : fwfs(fwfs), ffs(ffs)
59  {
60  }
61 
63  {
64  delete ffs;
65  delete fwfs;
66  }
67 
68  // IFileSystem methods
69  int mount() override;
70  int getinfo(Info& info) override;
71  String getErrorString(int err) override;
72  int setVolume(uint8_t index, IFileSystem* fileSystem) override;
73  int opendir(const char* path, DirHandle& dir) override;
74  int readdir(DirHandle dir, Stat& stat) override;
75  int rewinddir(DirHandle dir) override;
76  int closedir(DirHandle dir) override;
77  int mkdir(const char* path) override;
78  int stat(const char* path, Stat* stat) override;
79  int fstat(FileHandle file, Stat* stat) override;
80  int fcontrol(FileHandle file, ControlCode code, void* buffer, size_t bufSize) override;
81  int fsetxattr(FileHandle file, AttributeTag tag, const void* data, size_t size) override;
82  int fgetxattr(FileHandle file, AttributeTag tag, void* buffer, size_t size) override;
83  int fenumxattr(FileHandle file, AttributeEnumCallback callback, void* buffer, size_t bufsize) override;
84  int setxattr(const char* path, AttributeTag tag, const void* data, size_t size) override;
85  int getxattr(const char* path, AttributeTag tag, void* buffer, size_t size) override;
86  FileHandle open(const char* path, OpenFlags flags) override;
87  int close(FileHandle file) override;
88  int read(FileHandle file, void* data, size_t size) override;
89  int write(FileHandle file, const void* data, size_t size) override;
90  int lseek(FileHandle file, int offset, SeekOrigin origin) override;
91  int eof(FileHandle file) override;
92  int32_t tell(FileHandle file) override;
93  int ftruncate(FileHandle file, size_t new_size) override;
94  int flush(FileHandle file) override;
95  int rename(const char* oldpath, const char* newpath) override;
96  int remove(const char* path) override;
97  int fremove(FileHandle file) override;
98  int format() override;
99  int check() override;
100 
101 private:
102  int hideFWFile(const char* path, bool hide);
103  bool isFWFileHidden(const Stat& fwstat);
104 
105 private:
106  IFileSystem* fwfs;
107  IFileSystem* ffs;
108 #if HYFS_HIDE_FLAGS == 1
109  Vector<FileID> hiddenFwFiles;
110 #endif
111  bool mounted{false};
112 };
113 
114 } // namespace HYFS
115 
116 } // namespace IFS
Basic information about filing system.
Definition: IFileSystem.h:118
int flush(FileHandle file) override
flush any buffered data to physical media
int getxattr(const char *path, AttributeTag tag, void *buffer, size_t size) override
Get an attribute from a file given its path.
Definition: Components/IFS/src/include/IFS/HYFS/FileSystem.h:55
ControlCode
See IFS::IFileSystem::fcontrol
Definition: Control.h:31
int getinfo(Info &info) override
get filing system information
Installable File System base class.
Definition: IFileSystem.h:95
int fgetxattr(FileHandle file, AttributeTag tag, void *buffer, size_t size) override
Get an extended attribute from an open file.
int check() override
Perform a file system consistency check.
int lseek(FileHandle file, int offset, SeekOrigin origin) override
change file read/write position
int setVolume(uint8_t index, IFileSystem *fileSystem) override
Set volume for mountpoint.
struct ImplFileDir * DirHandle
Definition: IFileSystem.h:68
The String class.
Definition: WString.h:136
int format() override
format the filing system
~FileSystem()
Definition: Components/IFS/src/include/IFS/HYFS/FileSystem.h:62
int fsetxattr(FileHandle file, AttributeTag tag, const void *data, size_t size) override
Set an extended attribute on an open file.
int eof(FileHandle file) override
determine if current file position is at end of file
Definition: Delegate.h:20
SeekOrigin
Stream/file seek origins.
Definition: SeekOrigin.h:18
FileHandle open(const char *path, OpenFlags flags) override
open a file by path
int16_t FileHandle
File handle.
Definition: Stat.h:39
Definition: DirectoryTemplate.h:36
int mkdir(const char *path) override
Create a directory.
int closedir(DirHandle dir) override
close a directory object
FileSystem(IFileSystem *fwfs, IFileSystem *ffs)
Definition: Components/IFS/src/include/IFS/HYFS/FileSystem.h:58
int close(FileHandle file) override
close an open file
String getErrorString(int err) override
get the text for a returned error code
int fcontrol(FileHandle file, ControlCode code, void *buffer, size_t bufSize) override
Low-level and non-standard file control operations.
int rewinddir(DirHandle dir) override
Reset directory read position to start.
int write(FileHandle file, const void *data, size_t size) override
write content to a file at current position and advance cursor
int mount() override
Mount file system, performing any required initialisation.
File Status structure.
Definition: Stat.h:51
int opendir(const char *path, DirHandle &dir) override
open a directory for reading
int fstat(FileHandle file, Stat *stat) override
get file information
Manage a set of bit values using enumeration.
Definition: BitSet.h:43
int fremove(FileHandle file) override
remove (delete) a file by handle
AttributeTag
Identifies a specific attribute.
Definition: Attribute.h:45
int readdir(DirHandle dir, Stat &stat) override
read a directory entry
int read(FileHandle file, void *data, size_t size) override
read content from a file and advance cursor
int ftruncate(FileHandle file, size_t new_size) override
Truncate (reduce) the size of an open file.
int rename(const char *oldpath, const char *newpath) override
rename a file
int32_t tell(FileHandle file) override
get current file position
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 stat(const char *path, Stat *stat) override
get file information
int fenumxattr(FileHandle file, AttributeEnumCallback callback, void *buffer, size_t bufsize) override
Enumerate attributes.