Represents a flash partition. More...

#include <Partition.h>

Collaboration diagram for Storage::Partition:

Classes

struct  FullType
 Express both partition type and subtype together. More...
 
struct  Info
 Partition information. More...
 
struct  SubType
 

Public Types

enum class  Type : uint8_t {
  app = 0x00 , data = 0x01 , storage = 0x02 , userMin = 0x40 ,
  userMax = 0xFE , invalid = 0xff , any = 0xff
}
 
enum class  Flag { encrypted = 0 , readOnly = 31 }
 
using Name = char[nameSize]
 
using Flags = BitSet< uint32_t, Flag >
 

Public Member Functions

 Partition ()
 
 Partition (const Partition &other)
 
 Partition (Device &device, const Info &info)
 
 operator bool () const
 
bool read (storage_size_t offset, void *dst, size_t size)
 Read data from the partition. More...
 
template<typename T >
std::enable_if< std::is_pod< T >::value, bool >::type read (storage_size_t offset, T &value)
 
bool write (storage_size_t offset, const void *src, size_t size)
 Write data to the partition. More...
 
bool erase_range (storage_size_t offset, storage_size_t size)
 Erase part of the partition. More...
 
Partition::Type type () const
 Obtain partition type. More...
 
uint8_t subType () const
 Obtain partition sub-type. More...
 
FullType fullType () const
 Obtain both type and subtype. More...
 
storage_size_t address () const
 Obtain partition starting address. More...
 
storage_size_t lastAddress () const
 Obtain address of last byte in this this partition. More...
 
storage_size_t size () const
 Obtain partition size. More...
 
String name () const
 Get partition name. More...
 
Flags flags () const
 Get partition flags. More...
 
bool isEncrypted () const
 Check state of partition encrypted flag. More...
 
bool isReadOnly () const
 Check state of partition readOnly flag. More...
 
bool getDeviceAddress (storage_size_t &address, storage_size_t size) const
 Get corresponding storage device address for a given partition offset. More...
 
String getDeviceName () const
 Get name of storage device for this partition. More...
 
bool contains (storage_size_t addr) const
 Determine if given address contained within this partition. More...
 
bool operator== (const Partition &other) const
 
bool operator== (const char *name) const
 
bool operator== (const String &name) const
 
template<typename T >
bool operator!= (const T &other) const
 
size_t getBlockSize () const
 Obtain smallest allocation unit for erase operations. More...
 
uint16_t getSectorSize () const
 Get sector size for block-addressable devices. More...
 
storage_size_t getSectorCount () const
 Obtain total number of sectors in this partition. More...
 
bool sync ()
 Flush any pending writes to the physical media. More...
 
const Disk::DiskPartdiskpart () const
 If this is a disk partition, return pointer to the additional information. More...
 
size_t printTo (Print &p) const
 
Confirm partition is of the expected type
bool verify (Type type, uint8_t subtype) const
 Strong C++ type value. More...
 
bool verify (uint8_t type, uint8_t subtype) const
 Weak 'type' value. More...
 
template<typename T >
bool verify (T subType) const
 Derive type from subtype, expressed as strong C++ enum. More...
 
Get partition type expressed as a string
String typeString () const
 
String longTypeString () const
 

Static Public Member Functions

static SubType::App apptypeOta (uint8_t i)
 Convenience function to get SubType value for the i-th OTA partition. More...
 

Static Public Attributes

static constexpr size_t nameSize {16}
 

Protected Attributes

DevicemDevice {nullptr}
 
const InfomPart {nullptr}
 

Detailed Description

Represents a flash partition.

Member Typedef Documentation

◆ Flags

◆ Name

Member Enumeration Documentation

◆ Flag

Enumerator
encrypted 
readOnly 

Write/erase prohibited.

◆ Type

enum Storage::Partition::Type : uint8_t
strong
Enumerator
app 
data 
storage 
userMin 
userMax 
invalid 
any 

Constructor & Destructor Documentation

◆ Partition() [1/3]

Storage::Partition::Partition ( )
inline

◆ Partition() [2/3]

Storage::Partition::Partition ( const Partition other)
inline

◆ Partition() [3/3]

Storage::Partition::Partition ( Device device,
const Info info 
)
inline

Member Function Documentation

◆ address()

storage_size_t Storage::Partition::address ( ) const
inline

Obtain partition starting address.

Return values
storage_size_tDevice address

◆ apptypeOta()

static SubType::App Storage::Partition::apptypeOta ( uint8_t  i)
inlinestatic

Convenience function to get SubType value for the i-th OTA partition.

◆ contains()

bool Storage::Partition::contains ( storage_size_t  addr) const
inline

Determine if given address contained within this partition.

◆ diskpart()

const Disk::DiskPart* Storage::Partition::diskpart ( ) const
inline

If this is a disk partition, return pointer to the additional information.

◆ erase_range()

bool Storage::Partition::erase_range ( storage_size_t  offset,
storage_size_t  size 
)

Erase part of the partition.

Parameters
offsetWhere to start erasing, relative to start of partition
sizeSize of region to erase, in bytes
Return values
booltrue on success, false on error
Note
Both offset and size must be aligned to flash sector size (4Kbytes)

◆ flags()

Flags Storage::Partition::flags ( ) const
inline

Get partition flags.

◆ fullType()

FullType Storage::Partition::fullType ( ) const
inline

Obtain both type and subtype.

◆ getBlockSize()

size_t Storage::Partition::getBlockSize ( ) const

Obtain smallest allocation unit for erase operations.

◆ getDeviceAddress()

bool Storage::Partition::getDeviceAddress ( storage_size_t address,
storage_size_t  size 
) const

Get corresponding storage device address for a given partition offset.

Parameters
addressIN: Zero-based offset within partition, OUT: Device address
sizeSize of data to be accessed
Return values
booltrue on success, false on failure Fails if the given offset/size combination is out of range, or the partition is undefined.

◆ getDeviceName()

String Storage::Partition::getDeviceName ( ) const

Get name of storage device for this partition.

Return values
String

◆ getSectorCount()

storage_size_t Storage::Partition::getSectorCount ( ) const
inline

Obtain total number of sectors in this partition.

◆ getSectorSize()

uint16_t Storage::Partition::getSectorSize ( ) const

Get sector size for block-addressable devices.

See also
See Storage::Device::getSectorSize

◆ isEncrypted()

bool Storage::Partition::isEncrypted ( ) const
inline

Check state of partition encrypted flag.

◆ isReadOnly()

bool Storage::Partition::isReadOnly ( ) const
inline

Check state of partition readOnly flag.

◆ lastAddress()

storage_size_t Storage::Partition::lastAddress ( ) const
inline

Obtain address of last byte in this this partition.

Return values
storage_size_tDevice address

◆ longTypeString()

String Storage::Partition::longTypeString ( ) const

◆ name()

String Storage::Partition::name ( ) const
inline

Get partition name.

◆ operator bool()

Storage::Partition::operator bool ( ) const
inlineexplicit

◆ operator!=()

template<typename T >
bool Storage::Partition::operator!= ( const T &  other) const
inline

◆ operator==() [1/3]

bool Storage::Partition::operator== ( const char *  name) const
inline

◆ operator==() [2/3]

bool Storage::Partition::operator== ( const Partition other) const
inline

◆ operator==() [3/3]

bool Storage::Partition::operator== ( const String name) const
inline

◆ printTo()

size_t Storage::Partition::printTo ( Print p) const

◆ read() [1/2]

template<typename T >
std::enable_if<std::is_pod<T>::value, bool>::type Storage::Partition::read ( storage_size_t  offset,
T &  value 
)
inline

◆ read() [2/2]

bool Storage::Partition::read ( storage_size_t  offset,
void *  dst,
size_t  size 
)

Read data from the partition.

Parameters
offsetWhere to start reading, relative to start of partition
dstBuffer to store data
sizeSize of data to be read, in bytes.
Return values
booltrue on success, false on error

◆ size()

storage_size_t Storage::Partition::size ( ) const
inline

Obtain partition size.

Return values
storage_size_tSize in bytes

◆ subType()

uint8_t Storage::Partition::subType ( ) const
inline

Obtain partition sub-type.

◆ sync()

bool Storage::Partition::sync ( )

Flush any pending writes to the physical media.

See also
See Storage::Device::sync

◆ type()

Partition::Type Storage::Partition::type ( ) const
inline

Obtain partition type.

◆ typeString()

String Storage::Partition::typeString ( ) const

◆ verify() [1/3]

template<typename T >
bool Storage::Partition::verify ( subType) const
inline

Derive type from subtype, expressed as strong C++ enum.

◆ verify() [2/3]

bool Storage::Partition::verify ( Type  type,
uint8_t  subtype 
) const

Strong C++ type value.

Parameters
typeExpected partition type
subtypeExpected partition sub-type
Return values
booltrue if type is OK, false if not. Logs debug messages on failure.

◆ verify() [3/3]

bool Storage::Partition::verify ( uint8_t  type,
uint8_t  subtype 
) const
inline

Weak 'type' value.

◆ write()

bool Storage::Partition::write ( storage_size_t  offset,
const void *  src,
size_t  size 
)

Write data to the partition.

Parameters
offsetWhere to start writing, relative to start of partition
srcData to write
sizeSize of data to be written, in bytes.
Return values
booltrue on success, false on error
Note
Flash region must be erased first

Member Data Documentation

◆ mDevice

Device* Storage::Partition::mDevice {nullptr}
protected

◆ mPart

const Info* Storage::Partition::mPart {nullptr}
protected

◆ nameSize

constexpr size_t Storage::Partition::nameSize {16}
staticconstexpr

The documentation for this class was generated from the following file: