Skip to content

Commit

Permalink
Remove CustomDevice, use editable_partitions() method
Browse files Browse the repository at this point in the history
  • Loading branch information
mikee47 committed Oct 24, 2022
1 parent 0a0478f commit 33a4512
Show file tree
Hide file tree
Showing 13 changed files with 60 additions and 77 deletions.
2 changes: 1 addition & 1 deletion Sming/Components/IFS
2 changes: 1 addition & 1 deletion Sming/Components/Storage/src/ProgMem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
33 changes: 0 additions & 33 deletions Sming/Components/Storage/src/include/Storage/CustomDevice.h

This file was deleted.

8 changes: 8 additions & 0 deletions Sming/Components/Storage/src/include/Storage/Device.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,14 @@ class Device : public LinkedObjectTemplate<Device>
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
Expand Down
12 changes: 6 additions & 6 deletions Sming/Components/Storage/src/include/Storage/PartitionTable.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
};
Expand Down
8 changes: 4 additions & 4 deletions Sming/Components/Storage/src/include/Storage/ProgMem.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -51,7 +51,7 @@ class ProgMem : public CustomDevice
return false;
}

class ProgMemPartitionTable : public CustomPartitionTable
class ProgMemPartitionTable : public PartitionTable
{
public:
/**
Expand All @@ -73,7 +73,7 @@ class ProgMem : public CustomDevice
}
};

ProgMemPartitionTable& partitions()
ProgMemPartitionTable& editable_partitions()
{
return static_cast<ProgMemPartitionTable&>(mPartitions);
}
Expand Down
6 changes: 3 additions & 3 deletions Sming/Components/Storage/src/include/Storage/StreamDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* StreamDevice.h
*/

#include "CustomDevice.h"
#include "Device.h"
#include <Data/Stream/DataSourceStream.h>

namespace Storage
Expand All @@ -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)
{
}

Expand Down
12 changes: 6 additions & 6 deletions Sming/Components/Storage/src/include/Storage/SysMem.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -70,20 +70,20 @@ class SysMem : public CustomDevice
return true;
}

class SysMemPartitionTable : public CustomPartitionTable
class SysMemPartitionTable : public PartitionTable
{
public:
/**
* @brief Add partition entry for FlashString data access
*/
Partition add(const String& name, const FSTR::ObjectBase& fstr, Partition::FullType type)
{
return CustomPartitionTable::add(name, type, reinterpret_cast<uint32_t>(fstr.data()), fstr.size(),
Partition::Flag::readOnly);
return PartitionTable::add(name, type, reinterpret_cast<uint32_t>(fstr.data()), fstr.size(),
Partition::Flag::readOnly);
}
};

SysMemPartitionTable& partitions()
SysMemPartitionTable& editable_partitions()
{
return static_cast<SysMemPartitionTable&>(mPartitions);
}
Expand Down
2 changes: 1 addition & 1 deletion Sming/Libraries/LittleFS
38 changes: 22 additions & 16 deletions docs/source/upgrading/4.6-4.7.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
3 changes: 2 additions & 1 deletion samples/Basic_IFS/app/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions samples/Basic_Storage/app/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions tests/HostTests/modules/Spiffs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 33a4512

Please sign in to comment.