Skip to content

bd: Add sync function to the block device API #5926

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 30, 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
9 changes: 9 additions & 0 deletions features/filesystem/bd/BlockDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,15 @@ class BlockDevice
*/
virtual int deinit() = 0;

/** Ensure data on storage is in sync with the driver
*
* @return 0 on success or a negative error code on failure
*/
virtual int sync()
{
return 0;
}

/** Read blocks from a block device
*
* If a failure occurs, it is not possible to determine how many bytes succeeded
Expand Down
12 changes: 12 additions & 0 deletions features/filesystem/bd/ChainingBlockDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,18 @@ int ChainingBlockDevice::deinit()
return 0;
}

int ChainingBlockDevice::sync()
{
for (size_t i = 0; i < _bd_count; i++) {
int err = _bds[i]->sync();
if (err) {
return err;
}
}

return 0;
}

int ChainingBlockDevice::read(void *b, bd_addr_t addr, bd_size_t size)
{
MBED_ASSERT(is_valid_read(addr, size));
Expand Down
6 changes: 6 additions & 0 deletions features/filesystem/bd/ChainingBlockDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ class ChainingBlockDevice : public BlockDevice
*/
virtual int deinit();

/** Ensure data on storage is in sync with the driver
*
* @return 0 on success or a negative error code on failure
*/
virtual int sync();

/** Read blocks from a block device
*
* @param buffer Buffer to write blocks to
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 @@ -53,6 +53,11 @@ int ExhaustibleBlockDevice::deinit()
return _bd->deinit();
}

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

int ExhaustibleBlockDevice::read(void *buffer, bd_addr_t addr, bd_size_t size)
{
return _bd->read(buffer, addr, size);
Expand Down
6 changes: 6 additions & 0 deletions features/filesystem/bd/ExhaustibleBlockDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ class ExhaustibleBlockDevice : public BlockDevice
*/
virtual int deinit();

/** Ensure data on storage is in sync with the driver
*
* @return 0 on success or a negative error code on failure
*/
virtual int sync();

/** Read blocks from a block device
*
* @param buffer Buffer to read blocks into
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 @@ -234,6 +234,11 @@ int MBRBlockDevice::deinit()
return _bd->deinit();
}

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

int MBRBlockDevice::read(void *b, bd_addr_t addr, bd_size_t size)
{
MBED_ASSERT(is_valid_read(addr, size));
Expand Down
6 changes: 6 additions & 0 deletions features/filesystem/bd/MBRBlockDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,12 @@ class MBRBlockDevice : public BlockDevice
*/
virtual int deinit();

/** Ensure data on storage is in sync with the driver
*
* @return 0 on success or a negative error code on failure
*/
virtual int sync();

/** Read blocks from a block device
*
* @param buffer Buffer to read blocks into
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 @@ -51,6 +51,11 @@ int ObservingBlockDevice::deinit()
return _bd->deinit();
}

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

int ObservingBlockDevice::read(void *buffer, bd_addr_t addr, bd_size_t size)
{
return _bd->read(buffer, addr, size);
Expand Down
6 changes: 6 additions & 0 deletions features/filesystem/bd/ObservingBlockDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ class ObservingBlockDevice : public BlockDevice
*/
virtual int deinit();

/** Ensure data on storage is in sync with the driver
*
* @return 0 on success or a negative error code on failure
*/
virtual int sync();

/** Read blocks from a block device
*
* @param buffer Buffer to read blocks into
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 @@ -35,6 +35,11 @@ int ProfilingBlockDevice::deinit()
return _bd->deinit();
}

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

int ProfilingBlockDevice::read(void *b, bd_addr_t addr, bd_size_t size)
{
int err = _bd->read(b, addr, size);
Expand Down
6 changes: 6 additions & 0 deletions features/filesystem/bd/ProfilingBlockDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ class ProfilingBlockDevice : public BlockDevice
*/
virtual int deinit();

/** Ensure data on storage is in sync with the driver
*
* @return 0 on success or a negative error code on failure
*/
virtual int sync();

/** Read blocks from a block device
*
* @param buffer Buffer to read blocks into
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 @@ -45,6 +45,11 @@ int ReadOnlyBlockDevice::deinit()
return _bd->deinit();
}

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

int ReadOnlyBlockDevice::read(void *buffer, bd_addr_t addr, bd_size_t size)
{
return _bd->read(buffer, addr, size);
Expand Down
6 changes: 6 additions & 0 deletions features/filesystem/bd/ReadOnlyBlockDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ class ReadOnlyBlockDevice : public BlockDevice
*/
virtual int deinit();

/** Ensure data on storage is in sync with the driver
*
* @return 0 on success or a negative error code on failure
*/
virtual int sync();

/** Read blocks from a block device
*
* @param buffer Buffer to read blocks into
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 @@ -64,6 +64,11 @@ int SlicingBlockDevice::deinit()
return _bd->deinit();
}

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

int SlicingBlockDevice::read(void *b, bd_addr_t addr, bd_size_t size)
{
MBED_ASSERT(is_valid_read(addr, size));
Expand Down
6 changes: 6 additions & 0 deletions features/filesystem/bd/SlicingBlockDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ class SlicingBlockDevice : public BlockDevice
*/
virtual int deinit();

/** Ensure data on storage is in sync with the driver
*
* @return 0 on success or a negative error code on failure
*/
virtual int sync();

/** Read blocks from a block device
*
* @param buffer Buffer to read blocks into
Expand Down
3 changes: 2 additions & 1 deletion features/filesystem/littlefs/LittleFileSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ static int lfs_bd_erase(const struct lfs_config *c, lfs_block_t block)

static int lfs_bd_sync(const struct lfs_config *c)
{
return 0;
BlockDevice *bd = (BlockDevice *)c->context;
return bd->sync();
}


Expand Down