Skip to content

Commit

Permalink
Merge pull request #7058 from davidsaada/david_exhaustible_bd_fix
Browse files Browse the repository at this point in the history
Fix two issues in ExhaustibleBlockDevice
  • Loading branch information
Cruz Monrreal committed Jun 15, 2018
2 parents d66dfcb + 4af2c9d commit 74a75d5
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions features/filesystem/bd/ExhaustibleBlockDevice.cpp
Expand Up @@ -68,7 +68,6 @@ int ExhaustibleBlockDevice::program(const void *buffer, bd_addr_t addr, bd_size_
MBED_ASSERT(is_valid_program(addr, size));

if (_erase_array[addr / get_erase_size()] == 0) {
// TODO possibly something more destructive here
return 0;
}

Expand All @@ -79,17 +78,25 @@ int ExhaustibleBlockDevice::erase(bd_addr_t addr, bd_size_t size)
{
MBED_ASSERT(is_valid_erase(addr, size));

// use an erase cycle
if (_erase_array[addr / get_erase_size()] > 0) {
_erase_array[addr / get_erase_size()] -= 1;
}
bd_size_t eu_size = get_erase_size();
while (size) {
// use an erase cycle
if (_erase_array[addr / eu_size] > 0) {
_erase_array[addr / eu_size] -= 1;
}

if (_erase_array[addr / get_erase_size()] == 0) {
// TODO possibly something more destructive here
return 0;
if (_erase_array[addr / eu_size] > 0) {
int err = _bd->erase(addr, eu_size);
if (err) {
return err;
}
}

addr += eu_size;
size -= eu_size;
}

return _bd->erase(addr, size);
return 0;
}

bd_size_t ExhaustibleBlockDevice::get_read_size() const
Expand Down

0 comments on commit 74a75d5

Please sign in to comment.