HostFileDevice.h
Go to the documentation of this file.
1 /****
2  * Sming Framework Project - Open Source framework for high efficiency native ESP8266 development.
3  * Created 2015 by Skurydin Alexey
4  * http://github.com/SmingHub/Sming
5  * All files of the Sming Core are provided under the LGPL v3 license.
6  *
7  * HostFileDevice.h
8  *
9  ****/
10 
11 #pragma once
12 
13 #include "BlockDevice.h"
14 
15 namespace Storage::Disk
16 {
20 class HostFileDevice : public BlockDevice
21 {
22 public:
29  HostFileDevice(const String& name, const String& filename, storage_size_t size);
30 
38  HostFileDevice(const String& name, const String& filename);
39 
41 
42  String getName() const override
43  {
44  return name.c_str();
45  }
46 
47  Type getType() const override
48  {
49  return Type::file;
50  }
51 
52 protected:
53  bool raw_sector_read(storage_size_t address, void* dst, size_t size) override;
54  bool raw_sector_write(storage_size_t address, const void* src, size_t size) override;
55  bool raw_sector_erase_range(storage_size_t address, size_t size) override;
56  bool raw_sync() override
57  {
58  return true;
59  }
60 
61 private:
62  CString name;
63  int file{-1};
64 };
65 
66 } // namespace Storage::Disk
const char * c_str() const
Definition: CString.h:104
bool raw_sector_erase_range(storage_size_t address, size_t size) override
The String class.
Definition: WString.h:136
String getName() const override
Obtain unique device name.
Definition: HostFileDevice.h:58
Type getType() const override
Obtain device type.
Definition: HostFileDevice.h:63
Type
Storage type.
Definition: Components/Storage/src/include/Storage/Device.h:42
Definition: Partition.h:77
Class to manage a NUL-terminated C-style string When storing persistent strings in RAM the regular St...
Definition: CString.h:26
bool raw_sector_read(storage_size_t address, void *dst, size_t size) override
HostFileDevice(const String &name, const String &filename, storage_size_t size)
Construct a file device with custom size.
bool raw_sector_write(storage_size_t address, const void *src, size_t size) override
bool raw_sync() override
Definition: HostFileDevice.h:72
uint32_t storage_size_t
Definition: Components/Storage/src/include/Storage/Types.h:19