Components/IFS/src/include/IFS/HYFS/FileSystem.h
Go to the documentation of this file.
1 /****
2  * HybridFileSystem.h
3  * Hybrid file system which layers SPIFFS over FW.
4  *
5  * Created on: 22 Jul 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 /*
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  file_offset_t lseek(FileHandle file, file_offset_t offset, SeekOrigin origin) override;
91  int eof(FileHandle file) override;
92  file_offset_t tell(FileHandle file) override;
93  int ftruncate(FileHandle file, file_size_t new_size) override;
94  int flush(FileHandle file) override;
95  int fgetextents(FileHandle file, Storage::Partition* part, Extent* list, uint16_t extcount) override;
96  int rename(const char* oldpath, const char* newpath) override;
97  int remove(const char* path) override;
98  int fremove(FileHandle file) override;
99  int format() override;
100  int check() override;
101 
102 private:
103  int hideFWFile(const char* path, bool hide);
104  bool isFWFileHidden(const Stat& fwstat);
105 
106 private:
107  IFileSystem* fwfs;
108  IFileSystem* ffs;
109 #if HYFS_HIDE_FLAGS == 1
110  Vector<FileID> hiddenFwFiles;
111 #endif
112  bool mounted{false};
113 };
114 
115 } // namespace HYFS
116 
117 } // 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
Definition: Components/IFS/src/include/IFS/HYFS/FileSystem.h:56
int rewinddir(DirHandle dir) override
Reset directory read position to start.
int format() override
format the filing system
int read(FileHandle file, void *data, size_t size) override
read content from a file and advance cursor
int ftruncate(FileHandle file, file_size_t new_size) override
Truncate (reduce) the size of an open file.
int close(FileHandle file) override
close an open file
int setVolume(uint8_t index, IFileSystem *fileSystem) override
Set volume for mountpoint.
String getErrorString(int err) override
get the text for a returned error code
int fenumxattr(FileHandle file, AttributeEnumCallback callback, void *buffer, size_t bufsize) override
Enumerate attributes.
int mount() override
Mount file system, performing any required initialisation.
int fcontrol(FileHandle file, ControlCode code, void *buffer, size_t bufSize) override
Low-level and non-standard file control operations.
int fsetxattr(FileHandle file, AttributeTag tag, const void *data, size_t size) override
Set an extended attribute on an open file.
int mkdir(const char *path) override
Create a directory.
~FileSystem()
Definition: Components/IFS/src/include/IFS/HYFS/FileSystem.h:62
int rename(const char *oldpath, const char *newpath) override
rename a file
int getinfo(Info &info) override
get filing system information
int fgetxattr(FileHandle file, AttributeTag tag, void *buffer, size_t size) override
Get an extended attribute from an open file.
FileSystem(IFileSystem *fwfs, IFileSystem *ffs)
Definition: Components/IFS/src/include/IFS/HYFS/FileSystem.h:58
int check() override
Perform a file system consistency check.
int closedir(DirHandle dir) override
close a directory object
file_offset_t lseek(FileHandle file, file_offset_t offset, SeekOrigin origin) override
change file read/write position
int readdir(DirHandle dir, Stat &stat) override
read a directory entry
int eof(FileHandle file) override
determine if current file position is at end of file
int write(FileHandle file, const void *data, size_t size) override
write content to a file at current position and advance cursor
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 opendir(const char *path, DirHandle &dir) override
open a directory for reading
int flush(FileHandle file) override
flush any buffered data to physical media
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 stat(const char *path, Stat *stat) override
get file information
file_offset_t tell(FileHandle file) override
get current file position
int remove(const char *path) override
remove (delete) a file by path
int fgetextents(FileHandle file, Storage::Partition *part, Extent *list, uint16_t extcount) override
Get extents for a file.
int fstat(FileHandle file, Stat *stat) override
get file information
int fremove(FileHandle file) override
remove (delete) a file by handle
Installable File System base class.
Definition: IFileSystem.h:100
Represents a flash partition.
Definition: Partition.h:86
The String class.
Definition: WString.h:137
Definition: DirectoryTemplate.h:37
ControlCode
See IFS::IFileSystem::fcontrol
Definition: Components/IFS/src/include/IFS/Control.h:31
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
Defines the location of a contiguous run of file data.
Definition: Extent.h:40
Basic information about filing system.
Definition: IFileSystem.h:122
File Status structure.
Definition: Stat.h:52