distortos  v0.7.0
object-oriented C++ RTOS for microcontrollers
Littlefs1FileSystem.hpp
Go to the documentation of this file.
1 
12 #ifndef INCLUDE_DISTORTOS_FILESYSTEM_LITTLEFS1_LITTLEFS1FILESYSTEM_HPP_
13 #define INCLUDE_DISTORTOS_FILESYSTEM_LITTLEFS1_LITTLEFS1FILESYSTEM_HPP_
14 
16 
17 #include "distortos/Mutex.hpp"
18 
19 #include "lfs1.h"
20 
21 namespace distortos
22 {
23 
24 namespace devices
25 {
26 
27 class MemoryTechnologyDevice;
28 
29 } // namespace devices
30 
38 {
39  friend class Littlefs1Directory;
40  friend class Littlefs1File;
41 
42 public:
43 
57  constexpr explicit Littlefs1FileSystem(devices::MemoryTechnologyDevice& memoryTechnologyDevice,
58  const size_t readBlockSize = {}, const size_t programBlockSize = {}, const size_t eraseBlockSize = {},
59  const size_t blocksCount = {}, const size_t lookahead = 32 * 16) :
61  fileSystem_{},
62  mutex_{Mutex::Type::recursive, Mutex::Protocol::priorityInheritance},
65  readBuffer_{},
66  memoryTechnologyDevice_{memoryTechnologyDevice},
67  readBlockSize_{readBlockSize},
68  programBlockSize_{programBlockSize},
69  eraseBlockSize_{eraseBlockSize},
70  blocksCount_{blocksCount},
71  lookahead_{lookahead},
72  mounted_{}
73  {
74 
75  }
76 
85  ~Littlefs1FileSystem() override;
86 
100  int format() override;
101 
122  int getFileStatus(const char* path, struct stat& status) override;
123 
142  int getStatus(struct statvfs& status) override;
143 
159  void lock() override;
160 
178  int makeDirectory(const char* path, mode_t mode) override;
179 
193  int mount() override;
194 
213  std::pair<int, std::unique_ptr<Directory>> openDirectory(const char* path) override;
214 
236  std::pair<int, std::unique_ptr<File>> openFile(const char* path, int flags) override;
237 
254  int remove(const char* path) override;
255 
273  int rename(const char* path, const char* newPath) override;
274 
285  void unlock() override;
286 
303  int unmount() override;
304 
305 private:
306 
308  lfs1_config configuration_;
309 
311  lfs1_t fileSystem_;
312 
315 
317  std::unique_ptr<uint8_t[]> lookaheadBuffer_;
318 
320  std::unique_ptr<uint8_t[]> programBuffer_;
321 
323  std::unique_ptr<uint8_t[]> readBuffer_;
324 
327 
330 
333 
336 
338  size_t blocksCount_;
339 
341  size_t lookahead_;
342 
344  bool mounted_;
345 };
346 
347 } // namespace distortos
348 
349 #endif // INCLUDE_DISTORTOS_FILESYSTEM_LITTLEFS1_LITTLEFS1FILESYSTEM_HPP_
Definition: Littlefs1Directory.hpp:30
int rename(const char *path, const char *newPath) override
Renames file or directory.
Definition: Littlefs1FileSystem.cpp:436
size_t lookahead_
number of blocks to lookahead during block allocation
Definition: Littlefs1FileSystem.hpp:341
bool mounted_
tells whether the file system is currently mounted on associated memory technology device (true) or n...
Definition: Littlefs1FileSystem.hpp:344
size_t readBlockSize_
read block size, bytes, 0 to use default value of device
Definition: Littlefs1FileSystem.hpp:329
FileSystem class header.
void lock() override
Locks the file system for exclusive use by current thread.
Definition: Littlefs1FileSystem.cpp:303
lfs1_config configuration_
configuration of littlefs
Definition: Littlefs1FileSystem.hpp:308
void unlock() override
Unlocks the file system which was previously locked by current thread.
Definition: Littlefs1FileSystem.cpp:448
Definition: MemoryTechnologyDevice.hpp:30
devices::MemoryTechnologyDevice & memoryTechnologyDevice_
reference to associated memory technology device
Definition: Littlefs1FileSystem.hpp:326
Mutex class header.
std::pair< int, std::unique_ptr< Directory > > openDirectory(const char *path) override
Opens directory.
Definition: Littlefs1FileSystem.cpp:387
int getFileStatus(const char *path, struct stat &status) override
Returns status of file.
Definition: Littlefs1FileSystem.cpp:259
int format() override
Formats associated device with the file system.
Definition: Littlefs1FileSystem.cpp:200
size_t programBlockSize_
program block size, bytes, 0 to use default value of device
Definition: Littlefs1FileSystem.hpp:332
int unmount() override
Unmounts file system from associated device.
Definition: Littlefs1FileSystem.cpp:454
std::unique_ptr< uint8_t[]> readBuffer_
read buffer
Definition: Littlefs1FileSystem.hpp:323
int remove(const char *path) override
Removes file or directory.
Definition: Littlefs1FileSystem.cpp:425
Top-level namespace of distortos project.
Definition: buttons.hpp:33
std::unique_ptr< uint8_t[]> lookaheadBuffer_
lookahead buffer
Definition: Littlefs1FileSystem.hpp:317
Mutex is the basic synchronization primitive.
Definition: Mutex.hpp:30
Definition: Littlefs1File.hpp:34
Definition: Littlefs1FileSystem.hpp:37
std::unique_ptr< uint8_t[]> programBuffer_
program buffer
Definition: Littlefs1FileSystem.hpp:320
int makeDirectory(const char *path, mode_t mode) override
Makes a directory.
Definition: Littlefs1FileSystem.cpp:309
int getStatus(struct statvfs &status) override
Returns status of file system.
Definition: Littlefs1FileSystem.cpp:280
lfs1_t fileSystem_
littlefs-v1 file system
Definition: Littlefs1FileSystem.hpp:311
~Littlefs1FileSystem() override
Littlefs1FileSystem's destructor.
Definition: Littlefs1FileSystem.cpp:195
Definition: statvfs.h:56
Definition: FileSystem.hpp:34
int mount() override
Mounts file system on associated device.
Definition: Littlefs1FileSystem.cpp:320
std::pair< int, std::unique_ptr< File > > openFile(const char *path, int flags) override
Opens file.
Definition: Littlefs1FileSystem.cpp:406
constexpr Littlefs1FileSystem(devices::MemoryTechnologyDevice &memoryTechnologyDevice, const size_t readBlockSize={}, const size_t programBlockSize={}, const size_t eraseBlockSize={}, const size_t blocksCount={}, const size_t lookahead=32 *16)
Littlefs1FileSystem's constructor.
Definition: Littlefs1FileSystem.hpp:57
size_t eraseBlockSize_
erase block size, bytes, 0 to use default value of device
Definition: Littlefs1FileSystem.hpp:335
distortos::Mutex mutex_
mutex for serializing access to the object
Definition: Littlefs1FileSystem.hpp:314
size_t blocksCount_
number of erase blocks used for file system, 0 to use max value of device
Definition: Littlefs1FileSystem.hpp:338