Skip to content

bd: Add get_erase_value function to the block device API #5925

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 31, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion features/filesystem/bd/BlockDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,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 @@ -135,6 +136,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
Original file line number Diff line number Diff line change
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 @@ -190,6 +199,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
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,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 @@ -135,6 +136,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 @@ -148,6 +160,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
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,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
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,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 @@ -118,6 +119,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
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,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
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,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 @@ -189,6 +190,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
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,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
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,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 @@ -104,6 +105,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
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,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
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,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 @@ -121,6 +122,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
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,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
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,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 @@ -97,6 +98,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
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,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
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,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 @@ -127,6 +128,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