Skip to content

Commit

Permalink
Merge pull request #5925 from geky/bd-erase-value
Browse files Browse the repository at this point in the history
bd: Add get_erase_value function to the block device API
  • Loading branch information
cmonr committed Jan 31, 2018
2 parents c06a42b + e6949db commit 5cd30b9
Show file tree
Hide file tree
Showing 15 changed files with 152 additions and 8 deletions.
17 changes: 16 additions & 1 deletion features/filesystem/bd/BlockDevice.h
Expand Up @@ -94,7 +94,8 @@ class BlockDevice

/** Erase blocks on a block device
*
* The state of an erased block is undefined until it has been programmed
* The state of an erased block is undefined until it has been programmed,
* unless get_erase_value returns a non-negative byte value
*
* @param addr Address of block to begin erasing
* @param size Size to erase in bytes, must be a multiple of erase block size
Expand Down Expand Up @@ -144,6 +145,20 @@ class BlockDevice
return get_program_size();
}

/** Get the value of storage when erased
*
* If get_erase_value returns a non-negative byte value, the underlying
* storage is set to that value when erased, and storage containing
* that value can be programmed without another erase.
*
* @return The value of storage when erased, or -1 if you can't
* rely on the value of erased storage
*/
virtual int get_erase_value() const
{
return -1;
}

/** Get the total size of the underlying device
*
* @return Size of the underlying device in bytes
Expand Down
14 changes: 14 additions & 0 deletions features/filesystem/bd/ChainingBlockDevice.cpp
Expand Up @@ -20,6 +20,7 @@
ChainingBlockDevice::ChainingBlockDevice(BlockDevice **bds, size_t bd_count)
: _bds(bds), _bd_count(bd_count)
, _read_size(0), _program_size(0), _erase_size(0), _size(0)
, _erase_value(-1)
{
}

Expand All @@ -33,6 +34,7 @@ int ChainingBlockDevice::init()
_read_size = 0;
_program_size = 0;
_erase_size = 0;
_erase_value = -1;
_size = 0;

// Initialize children block devices, find all sizes and
Expand Down Expand Up @@ -66,6 +68,13 @@ int ChainingBlockDevice::init()
MBED_ASSERT(_erase_size > erase && is_aligned(_erase_size, erase));
}

int value = _bds[i]->get_erase_value();
if (i == 0 || value == _erase_value) {
_erase_value = value;
} else {
_erase_value = -1;
}

_size += _bds[i]->size();
}

Expand Down Expand Up @@ -202,6 +211,11 @@ bd_size_t ChainingBlockDevice::get_erase_size() const
return _erase_size;
}

int ChainingBlockDevice::get_erase_value() const
{
return _erase_value;
}

bd_size_t ChainingBlockDevice::size() const
{
return _size;
Expand Down
15 changes: 14 additions & 1 deletion features/filesystem/bd/ChainingBlockDevice.h
Expand Up @@ -113,7 +113,8 @@ class ChainingBlockDevice : public BlockDevice

/** Erase blocks on a block device
*
* The state of an erased block is undefined until it has been programmed
* The state of an erased block is undefined until it has been programmed,
* unless get_erase_value returns a non-negative byte value
*
* @param addr Address of block to begin erasing
* @param size Size to erase in bytes, must be a multiple of erase block size
Expand Down Expand Up @@ -141,6 +142,17 @@ class ChainingBlockDevice : public BlockDevice
*/
virtual bd_size_t get_erase_size() const;

/** Get the value of storage when erased
*
* If get_erase_value returns a non-negative byte value, the underlying
* storage is set to that value when erased, and storage containing
* that value can be programmed without another erase.
*
* @return The value of storage when erased, or -1 if you can't
* rely on the value of erased storage
*/
virtual int get_erase_value() const;

/** Get the total size of the underlying device
*
* @return Size of the underlying device in bytes
Expand All @@ -154,6 +166,7 @@ class ChainingBlockDevice : public BlockDevice
bd_size_t _program_size;
bd_size_t _erase_size;
bd_size_t _size;
int _erase_value;
};


Expand Down
5 changes: 5 additions & 0 deletions features/filesystem/bd/ExhaustibleBlockDevice.cpp
Expand Up @@ -107,6 +107,11 @@ bd_size_t ExhaustibleBlockDevice::get_erase_size() const
return _bd->get_erase_size();
}

int ExhaustibleBlockDevice::get_erase_value() const
{
return _bd->get_erase_value();
}

bd_size_t ExhaustibleBlockDevice::size() const
{
return _bd->size();
Expand Down
14 changes: 13 additions & 1 deletion features/filesystem/bd/ExhaustibleBlockDevice.h
Expand Up @@ -98,7 +98,8 @@ class ExhaustibleBlockDevice : public BlockDevice

/** Erase blocks on a block device
*
* The state of an erased block is undefined until it has been programmed
* The state of an erased block is undefined until it has been programmed,
* unless get_erase_value returns a non-negative byte value
*
* @param addr Address of block to begin erasing
* @param size Size to erase in bytes, must be a multiple of erase block size
Expand All @@ -124,6 +125,17 @@ class ExhaustibleBlockDevice : public BlockDevice
*/
virtual bd_size_t get_erase_size() const;

/** Get the value of storage when erased
*
* If get_erase_value returns a non-negative byte value, the underlying
* storage is set to that value when erased, and storage containing
* that value can be programmed without another erase.
*
* @return The value of storage when erased, or -1 if you can't
* rely on the value of erased storage
*/
virtual int get_erase_value() const;

/** Get the total size of the underlying device
*
* @return Size of the underlying device in bytes
Expand Down
5 changes: 5 additions & 0 deletions features/filesystem/bd/MBRBlockDevice.cpp
Expand Up @@ -272,6 +272,11 @@ bd_size_t MBRBlockDevice::get_erase_size() const
return _bd->get_erase_size();
}

int MBRBlockDevice::get_erase_value() const
{
return _bd->get_erase_value();
}

bd_size_t MBRBlockDevice::size() const
{
return _size;
Expand Down
14 changes: 13 additions & 1 deletion features/filesystem/bd/MBRBlockDevice.h
Expand Up @@ -167,7 +167,8 @@ class MBRBlockDevice : public BlockDevice

/** Erase blocks on a block device
*
* The state of an erased block is undefined until it has been programmed
* The state of an erased block is undefined until it has been programmed,
* unless get_erase_value returns a non-negative byte value
*
* @param addr Address of block to begin erasing
* @param size Size to erase in bytes, must be a multiple of erase block size
Expand Down Expand Up @@ -195,6 +196,17 @@ class MBRBlockDevice : public BlockDevice
*/
virtual bd_size_t get_erase_size() const;

/** Get the value of storage when erased
*
* If get_erase_value returns a non-negative byte value, the underlying
* storage is set to that value when erased, and storage containing
* that value can be programmed without another erase.
*
* @return The value of storage when erased, or -1 if you can't
* rely on the value of erased storage
*/
virtual int get_erase_value() const;

/** Get the total size of the underlying device
*
* @return Size of the underlying device in bytes
Expand Down
5 changes: 5 additions & 0 deletions features/filesystem/bd/ObservingBlockDevice.cpp
Expand Up @@ -96,6 +96,11 @@ bd_size_t ObservingBlockDevice::get_erase_size() const
return _bd->get_erase_size();
}

int ObservingBlockDevice::get_erase_value() const
{
return _bd->get_erase_value();
}

bd_size_t ObservingBlockDevice::size() const
{
return _bd->size();
Expand Down
14 changes: 13 additions & 1 deletion features/filesystem/bd/ObservingBlockDevice.h
Expand Up @@ -84,7 +84,8 @@ class ObservingBlockDevice : public BlockDevice

/** Erase blocks on a block device
*
* The state of an erased block is undefined until it has been programmed
* The state of an erased block is undefined until it has been programmed,
* unless get_erase_value returns a non-negative byte value
*
* @param addr Address of block to begin erasing
* @param size Size to erase in bytes, must be a multiple of erase block size
Expand All @@ -110,6 +111,17 @@ class ObservingBlockDevice : public BlockDevice
*/
virtual bd_size_t get_erase_size() const;

/** Get the value of storage when erased
*
* If get_erase_value returns a non-negative byte value, the underlying
* storage is set to that value when erased, and storage containing
* that value can be programmed without another erase.
*
* @return The value of storage when erased, or -1 if you can't
* rely on the value of erased storage
*/
virtual int get_erase_value() const;

/** Get the total size of the underlying device
*
* @return Size of the underlying device in bytes
Expand Down
5 changes: 5 additions & 0 deletions features/filesystem/bd/ProfilingBlockDevice.cpp
Expand Up @@ -82,6 +82,11 @@ bd_size_t ProfilingBlockDevice::get_erase_size() const
return _bd->get_erase_size();
}

int ProfilingBlockDevice::get_erase_value() const
{
return _bd->get_erase_value();
}

bd_size_t ProfilingBlockDevice::size() const
{
return _bd->size();
Expand Down
14 changes: 13 additions & 1 deletion features/filesystem/bd/ProfilingBlockDevice.h
Expand Up @@ -99,7 +99,8 @@ class ProfilingBlockDevice : public BlockDevice

/** Erase blocks on a block device
*
* The state of an erased block is undefined until it has been programmed
* The state of an erased block is undefined until it has been programmed,
* unless get_erase_value returns a non-negative byte value
*
* @param addr Address of block to begin erasing
* @param size Size to erase in bytes, must be a multiple of erase block size
Expand Down Expand Up @@ -127,6 +128,17 @@ class ProfilingBlockDevice : public BlockDevice
*/
virtual bd_size_t get_erase_size() const;

/** Get the value of storage when erased
*
* If get_erase_value returns a non-negative byte value, the underlying
* storage is set to that value when erased, and you can program storage
* containing that value without another erase.
*
* @return The value of storage when erased, or -1 if you can't
* rely on the value of erased storage
*/
virtual int get_erase_value() const;

/** Get the total size of the underlying device
*
* @return Size of the underlying device in bytes
Expand Down
5 changes: 5 additions & 0 deletions features/filesystem/bd/ReadOnlyBlockDevice.cpp
Expand Up @@ -82,6 +82,11 @@ bd_size_t ReadOnlyBlockDevice::get_erase_size() const
return _bd->get_erase_size();
}

int ReadOnlyBlockDevice::get_erase_value() const
{
return _bd->get_erase_value();
}

bd_size_t ReadOnlyBlockDevice::size() const
{
return _bd->size();
Expand Down
14 changes: 13 additions & 1 deletion features/filesystem/bd/ReadOnlyBlockDevice.h
Expand Up @@ -77,7 +77,8 @@ class ReadOnlyBlockDevice : public BlockDevice

/** Erase blocks on a block device
*
* The state of an erased block is undefined until it has been programmed
* The state of an erased block is undefined until it has been programmed,
* unless get_erase_value returns a non-negative byte value
*
* @param addr Address of block to begin erasing
* @param size Size to erase in bytes, must be a multiple of erase block size
Expand All @@ -103,6 +104,17 @@ class ReadOnlyBlockDevice : public BlockDevice
*/
virtual bd_size_t get_erase_size() const;

/** Get the value of storage when erased
*
* If get_erase_value returns a non-negative byte value, the underlying
* storage is set to that value when erased, and storage containing
* that value can be programmed without another erase.
*
* @return The value of storage when erased, or -1 if you can't
* rely on the value of erased storage
*/
virtual int get_erase_value() const;

/** Get the total size of the underlying device
*
* @return Size of the underlying device in bytes
Expand Down
5 changes: 5 additions & 0 deletions features/filesystem/bd/SlicingBlockDevice.cpp
Expand Up @@ -102,6 +102,11 @@ bd_size_t SlicingBlockDevice::get_erase_size() const
return _bd->get_erase_size();
}

int SlicingBlockDevice::get_erase_value() const
{
return _bd->get_erase_value();
}

bd_size_t SlicingBlockDevice::size() const
{
return _stop - _start;
Expand Down
14 changes: 13 additions & 1 deletion features/filesystem/bd/SlicingBlockDevice.h
Expand Up @@ -105,7 +105,8 @@ class SlicingBlockDevice : public BlockDevice

/** Erase blocks on a block device
*
* The state of an erased block is undefined until it has been programmed
* The state of an erased block is undefined until it has been programmed,
* unless get_erase_value returns a non-negative byte value
*
* @param addr Address of block to begin erasing
* @param size Size to erase in bytes, must be a multiple of erase block size
Expand Down Expand Up @@ -133,6 +134,17 @@ class SlicingBlockDevice : public BlockDevice
*/
virtual bd_size_t get_erase_size() const;

/** Get the value of storage when erased
*
* If get_erase_value returns a non-negative byte value, the underlying
* storage is set to that value when erased, and storage containing
* that value can be programmed without another erase.
*
* @return The value of storage when erased, or -1 if you can't
* rely on the value of erased storage
*/
virtual int get_erase_value() const;

/** Get the total size of the underlying device
*
* @return Size of the underlying device in bytes
Expand Down

0 comments on commit 5cd30b9

Please sign in to comment.