diff --git a/Sming/Components/IFS b/Sming/Components/IFS index a29817b8e8..6457fef5ce 160000 --- a/Sming/Components/IFS +++ b/Sming/Components/IFS @@ -1 +1 @@ -Subproject commit a29817b8e8578e0709091ddfb204206ab1749fe0 +Subproject commit 6457fef5ceb7c200393cd8e3bf9d8f4ef608bfdc diff --git a/Sming/Components/Storage/src/ProgMem.cpp b/Sming/Components/Storage/src/ProgMem.cpp index 16e68e3410..34b4f25df0 100644 --- a/Sming/Components/Storage/src/ProgMem.cpp +++ b/Sming/Components/Storage/src/ProgMem.cpp @@ -29,7 +29,7 @@ Partition ProgMem::ProgMemPartitionTable::add(const String& name, const void* fl return Partition{}; } - return CustomPartitionTable::add(name, type, addr, size, Partition::Flag::readOnly); + return PartitionTable::add(name, type, addr, size, Partition::Flag::readOnly); } } // namespace Storage diff --git a/Sming/Components/Storage/src/include/Storage/CustomDevice.h b/Sming/Components/Storage/src/include/Storage/CustomDevice.h deleted file mode 100644 index ff39cb336a..0000000000 --- a/Sming/Components/Storage/src/include/Storage/CustomDevice.h +++ /dev/null @@ -1,33 +0,0 @@ -/* - * CustomDevice.h - */ - -#pragma once - -#include "Device.h" - -namespace Storage -{ -/** - * @brief Class to support dynamic partitions - */ -class CustomDevice : public Device -{ -public: - class CustomPartitionTable : public PartitionTable - { - public: - using PartitionTable::add; - using PartitionTable::clear; - }; - - /** - * @brief Provide read/write access to in-memory partition table - */ - CustomPartitionTable& partitions() - { - return static_cast(mPartitions); - } -}; - -} // namespace Storage diff --git a/Sming/Components/Storage/src/include/Storage/Device.h b/Sming/Components/Storage/src/include/Storage/Device.h index 4802fda5cb..d8f8058f64 100644 --- a/Sming/Components/Storage/src/include/Storage/Device.h +++ b/Sming/Components/Storage/src/include/Storage/Device.h @@ -64,6 +64,14 @@ class Device : public LinkedObjectTemplate return mPartitions; } + /** + * @brief Provide full access to partition table + */ + PartitionTable& editable_partitions() + { + return mPartitions; + } + /** * @brief Load partition table entries * @tableOffset Location of partition table to read diff --git a/Sming/Components/Storage/src/include/Storage/PartitionTable.h b/Sming/Components/Storage/src/include/Storage/PartitionTable.h index b618141d18..b54fcee3f3 100644 --- a/Sming/Components/Storage/src/include/Storage/PartitionTable.h +++ b/Sming/Components/Storage/src/include/Storage/PartitionTable.h @@ -98,12 +98,6 @@ class PartitionTable return mDevice; } -protected: - friend Device; - friend Iterator; - - void load(const esp_partition_info_t* entry, unsigned count); - /** * @brief Add new partition using given Info * @param info Must be allocated using `new`: Device will take ownership @@ -124,6 +118,12 @@ class PartitionTable mEntries.clear(); } +protected: + friend Device; + friend Iterator; + + void load(const esp_partition_info_t* entry, unsigned count); + Device& mDevice; Partition::Info::OwnedList mEntries; }; diff --git a/Sming/Components/Storage/src/include/Storage/ProgMem.h b/Sming/Components/Storage/src/include/Storage/ProgMem.h index 5a149940e2..025e8a5820 100644 --- a/Sming/Components/Storage/src/include/Storage/ProgMem.h +++ b/Sming/Components/Storage/src/include/Storage/ProgMem.h @@ -9,14 +9,14 @@ ****/ #pragma once -#include "CustomDevice.h" +#include "Device.h" namespace Storage { /** * @brief Storage device to access PROGMEM using flash API */ -class ProgMem : public CustomDevice +class ProgMem : public Device { public: String getName() const override @@ -51,7 +51,7 @@ class ProgMem : public CustomDevice return false; } - class ProgMemPartitionTable : public CustomPartitionTable + class ProgMemPartitionTable : public PartitionTable { public: /** @@ -73,7 +73,7 @@ class ProgMem : public CustomDevice } }; - ProgMemPartitionTable& partitions() + ProgMemPartitionTable& editable_partitions() { return static_cast(mPartitions); } diff --git a/Sming/Components/Storage/src/include/Storage/StreamDevice.h b/Sming/Components/Storage/src/include/Storage/StreamDevice.h index 18ca2d64cf..ebca8bfc2f 100644 --- a/Sming/Components/Storage/src/include/Storage/StreamDevice.h +++ b/Sming/Components/Storage/src/include/Storage/StreamDevice.h @@ -2,7 +2,7 @@ * StreamDevice.h */ -#include "CustomDevice.h" +#include "Device.h" #include namespace Storage @@ -11,10 +11,10 @@ namespace Storage * @brief Read-only partition on a stream object * @note Writes not possible as streams always append data, cannot do random writes */ -class StreamDevice : public CustomDevice +class StreamDevice : public Device { public: - StreamDevice(IDataSourceStream* stream, size_t size) : CustomDevice(nameOf(stream), size), mStream(stream) + StreamDevice(IDataSourceStream* stream, size_t size) : Device(nameOf(stream), size), mStream(stream) { } diff --git a/Sming/Components/Storage/src/include/Storage/SysMem.h b/Sming/Components/Storage/src/include/Storage/SysMem.h index 22a623a564..cb2e859573 100644 --- a/Sming/Components/Storage/src/include/Storage/SysMem.h +++ b/Sming/Components/Storage/src/include/Storage/SysMem.h @@ -10,14 +10,14 @@ #pragma once -#include "CustomDevice.h" +#include "Device.h" namespace Storage { /** * @brief Storage device to access system memory, e.g. RAM */ -class SysMem : public CustomDevice +class SysMem : public Device { public: String getName() const override @@ -70,7 +70,7 @@ class SysMem : public CustomDevice return true; } - class SysMemPartitionTable : public CustomPartitionTable + class SysMemPartitionTable : public PartitionTable { public: /** @@ -78,12 +78,12 @@ class SysMem : public CustomDevice */ Partition add(const String& name, const FSTR::ObjectBase& fstr, Partition::FullType type) { - return CustomPartitionTable::add(name, type, reinterpret_cast(fstr.data()), fstr.size(), - Partition::Flag::readOnly); + return PartitionTable::add(name, type, reinterpret_cast(fstr.data()), fstr.size(), + Partition::Flag::readOnly); } }; - SysMemPartitionTable& partitions() + SysMemPartitionTable& editable_partitions() { return static_cast(mPartitions); } diff --git a/Sming/Libraries/LittleFS b/Sming/Libraries/LittleFS index 55dbf00a0e..35e504c3ab 160000 --- a/Sming/Libraries/LittleFS +++ b/Sming/Libraries/LittleFS @@ -1 +1 @@ -Subproject commit 55dbf00a0e992f97d9dd1416f38f13b079e0ce84 +Subproject commit 35e504c3abbb29b1f5f8dc3e1dba6cde54b04897 diff --git a/docs/source/upgrading/4.6-4.7.rst b/docs/source/upgrading/4.6-4.7.rst index b5858ae5a4..c1eeae8966 100644 --- a/docs/source/upgrading/4.6-4.7.rst +++ b/docs/source/upgrading/4.6-4.7.rst @@ -6,36 +6,42 @@ From v4.6 to v4.7 Storage Partition methods ------------------------- -The ``Storage::Partition::getDevice()`` method has been removed. -This could be used to bypass protections offered by the partitioning API. +The ``Storage::Partition::getDevice()`` method has been removed because +it could be used to bypass protections offered by the partitioning API. Storage Device Partitions ------------------------- -The ``Storage::CustomDevice::createPartition()`` methods have been removed. - Instead, use partition table methods. +The ``CustomDevice`` class has been removed as it is simpler and more flexible to instead use PartitionTable methods. - For example:: +The :cpp:func:`Storage::Device::partitions` method returns a read-only (const) :cpp:class:`Storage::PartitionTable` object +for general use to avoid inadvertent modification. - part = device->createPartition("archive", Storage::Partition::SubType::Data::fwfs, startOffset, size); +Use the :cpp:func:`Storage::Device::editable_partitions` method to make partition table changes. - becomes:: +For example:: - part = device->partitions().add("archive", Storage::Partition::SubType::Data::fwfs, startOffset, size); + part = device->createPartition("archive", Storage::Partition::SubType::Data::fwfs, startOffset, size); - This also applies to derivatives :cpp:class:`Storage::SysMem` and :cpp:class:`Storage::ProgMem`. +becomes:: + part = device->editable_partitions().add("archive", Storage::Partition::SubType::Data::fwfs, startOffset, size); -Creating custom partition types require use of :cpp:struct:`Storage::Partition::FullType`. - For example:: - part = device->createPartitions("fs_app", Storage::Partition::Type::data, 100, startOffset, size); +Custom Partition Types +---------------------- - becomes:: +Creating custom partition types now require use of :cpp:struct:`Storage::Partition::FullType`. - part = device->partitions().add("fs_app", {Storage::Partition::Type::data, 100}, startOffset, size); +For example:: - Note how the ``type`` and ``subtype`` values are enclosed in braces (instantiating a ``FullType`` struct). - This avoids confusing the subtype value ``100`` with the start offset. + part = device->createPartition("fs_app", Storage::Partition::Type::data, 100, startOffset, size); + +becomes:: + + part = device->editable_partitions().add("fs_app", {Storage::Partition::Type::data, 100}, startOffset, size); + +Note how the ``type`` and ``subtype`` values are enclosed in braces (instantiating a ``FullType`` struct). +This avoids confusing the subtype value ``100`` with the start offset. diff --git a/samples/Basic_IFS/app/application.cpp b/samples/Basic_IFS/app/application.cpp index 79a7f8c25b..dc3f4f375c 100644 --- a/samples/Basic_IFS/app/application.cpp +++ b/samples/Basic_IFS/app/application.cpp @@ -139,7 +139,8 @@ bool initFileSystem() #ifdef ENABLE_FLASHSTRING_IMAGE // Create a partition wrapping some flashstring data - auto part = Storage::progMem.partitions().add(F("fwfsMem"), fwfsImage, Storage::Partition::SubType::Data::fwfs); + auto part = + Storage::progMem.editable_partitions().add(F("fwfsMem"), fwfsImage, Storage::Partition::SubType::Data::fwfs); #else auto part = Storage::findDefaultPartition(Storage::Partition::SubType::Data::fwfs); #endif diff --git a/samples/Basic_Storage/app/application.cpp b/samples/Basic_Storage/app/application.cpp index de77fcfd56..c66f0d5a35 100644 --- a/samples/Basic_Storage/app/application.cpp +++ b/samples/Basic_Storage/app/application.cpp @@ -80,19 +80,20 @@ void init() Serial.println(_F("** Reading tests, repeat 3 times to show effect of caching (if any)")); Serial.println(_F("** Reading SysMem device (flash)")); - part = Storage::sysMem.partitions().add(F("fs_app"), FS_app, {Storage::Partition::Type::data, 100}); + part = Storage::sysMem.editable_partitions().add(F("fs_app FLASH"), FS_app, {Storage::Partition::Type::data, 100}); printPart(part); printPart(part); printPart(part); Serial.println(_F("** Reading SysMem device (RAM)")); - part = Storage::sysMem.partitions().add(F("fs_app"), FS_app, {Storage::Partition::Type::data, 100}); + part = Storage::sysMem.editable_partitions().add(F("fs_app RAM"), FS_app, {Storage::Partition::Type::data, 100}); printPart(part); printPart(part); printPart(part); Serial.println(_F("** Reading ProgMem device")); - part = Storage::progMem.partitions().add(F("fs_app"), FS_app, {Storage::Partition::Type::data, 100}); + part = + Storage::progMem.editable_partitions().add(F("fs_app PROGMEM"), FS_app, {Storage::Partition::Type::data, 100}); printPart(part); printPart(part); printPart(part); diff --git a/tests/HostTests/modules/Spiffs.cpp b/tests/HostTests/modules/Spiffs.cpp index c2a08997a0..b71dce7f79 100644 --- a/tests/HostTests/modules/Spiffs.cpp +++ b/tests/HostTests/modules/Spiffs.cpp @@ -113,8 +113,8 @@ class SpiffsTest : public TestGroup } auto dev = new Storage::FileDevice(tag, hfs, f); Storage::registerDevice(dev); - auto part = dev->partitions().add(tag, Storage::Partition::SubType::Data::spiffs, 0, dev->getSize(), - Storage::Partition::Flag::readOnly); + auto part = dev->editable_partitions().add(tag, Storage::Partition::SubType::Data::spiffs, 0, dev->getSize(), + Storage::Partition::Flag::readOnly); auto fs = IFS::createSpiffsFilesystem(part); int err = fs->mount();