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 "../FWFS/FileSystem.h"
42 #include "../SPIFFS/FileSystem.h"
43 #include "../Types.h"
44 
45 #ifndef HYFS_HIDE_FLAGS
46 #define HYFS_HIDE_FLAGS 1
47 #endif
48 
49 #if HYFS_HIDE_FLAGS == 1
50 #include "WVector.h"
51 #endif
52 
53 namespace IFS
54 {
55 namespace HYFS
56 {
57 class FileSystem : public IFileSystem
58 {
59 public:
60  FileSystem(IObjectStore* fwStore, Storage::Partition ffsPartition) : fwfs(fwStore), ffs(ffsPartition)
61  {
62  }
63 
64  // IFileSystem methods
65  int mount() override;
66  int getinfo(Info& info) override;
67  String getErrorString(int err) override;
68  int opendir(const char* path, DirHandle& dir) override;
69  int readdir(DirHandle dir, Stat& stat) override;
70  int rewinddir(DirHandle dir) override;
71  int closedir(DirHandle dir) override;
72  int mkdir(const char* path) override;
73  int stat(const char* path, Stat* stat) override;
74  int fstat(FileHandle file, Stat* stat) override;
75  int fcontrol(FileHandle file, ControlCode code, void* buffer, size_t bufSize) override;
76  int setacl(FileHandle file, const ACL& acl) override;
77  int setattr(const char* path, FileAttributes attr) override;
78  int settime(FileHandle file, time_t mtime) override;
79  int setcompression(FileHandle file, const Compression& compression) override;
80  FileHandle open(const char* path, OpenFlags flags) override;
81  FileHandle fopen(const Stat& stat, OpenFlags flags) override;
82  int close(FileHandle file) override;
83  int read(FileHandle file, void* data, size_t size) override;
84  int write(FileHandle file, const void* data, size_t size) override;
85  int lseek(FileHandle file, int offset, SeekOrigin origin) override;
86  int eof(FileHandle file) override;
87  int32_t tell(FileHandle file) override;
88  int ftruncate(FileHandle file, size_t new_size) override;
89  int flush(FileHandle file) override;
90  int rename(const char* oldpath, const char* newpath) override;
91  int remove(const char* path) override;
92  int fremove(FileHandle file) override;
93  int format() override;
94  int check() override;
95 
96 private:
97  int hideFWFile(const char* path, bool hide);
98  bool isFWFileHidden(const Stat& fwstat);
99 
100 private:
101  FWFS::FileSystem fwfs;
102  SPIFFS::FileSystem ffs;
103 #if HYFS_HIDE_FLAGS == 1
104  Vector<FileID> hiddenFwFiles;
105 #endif
106 };
107 
108 } // namespace HYFS
109 
110 } // namespace IFS
Basic information about filing system.
Definition: IFileSystem.h:123
int flush(FileHandle file) override
flush any buffered data to physical media
struct FileDir * DirHandle
Definition: IFileSystem.h:65
Definition: Components/IFS/src/include/IFS/HYFS/FileSystem.h:57
ControlCode
See IFS::IFileSystem::fcontrol
Definition: Control.h:31
int getinfo(Info &info) override
get filing system information
Definition: ObjectStore.h:108
Installable File System base class.
Definition: IFileSystem.h:100
int check() override
Perform a file system consistency check.
int lseek(FileHandle file, int offset, SeekOrigin origin) override
change file read/write position
The String class.
Definition: WString.h:136
int format() override
format the filing system
int setattr(const char *path, FileAttributes attr) override
Set file attributes.
int eof(FileHandle file) override
determine if current file position is at end of file
SeekOrigin
Stream/file seek origins.
Definition: SeekOrigin.h:18
FileHandle open(const char *path, OpenFlags flags) override
open a file by name/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(IObjectStore *fwStore, Storage::Partition ffsPartition)
Definition: Components/IFS/src/include/IFS/HYFS/FileSystem.h:60
int close(FileHandle file) override
close an open file
String getErrorString(int err) override
get the text for a returned error code
Implementation of firmware filing system using IFS.
Definition: Components/IFS/src/include/IFS/FWFS/FileSystem.h:86
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 setcompression(FileHandle file, const Compression &compression) override
Set file compression information.
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
int setacl(FileHandle file, const ACL &acl) override
Set access control information for file.
Represents a flash partition.
Definition: Partition.h:77
FileHandle fopen(const Stat &stat, OpenFlags flags) override
open a file from it&#39;s stat structure
int fremove(FileHandle file) override
remove (delete) a file by handle
Definition: Access.h:34
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
int settime(FileHandle file, time_t mtime) override
Set modificatino tiem for file.
int32_t tell(FileHandle file) override
get current file position
Definition: Components/IFS/src/include/IFS/SPIFFS/FileSystem.h:63
int stat(const char *path, Stat *stat) override
get file information
A compression descriptor.
Definition: Compression.h:38