Merge pull request #5926 from geky/bd-sync

bd: Add sync function to the block device API
pull/5977/head
Cruz Monrreal 2018-01-30 14:55:59 -06:00 committed by GitHub
commit 101fc62495
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 95 additions and 1 deletions

View File

@ -59,6 +59,15 @@ public:
*/
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

View File

@ -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));

View File

@ -85,6 +85,12 @@ public:
*/
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

View File

@ -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);

View File

@ -70,6 +70,12 @@ public:
*/
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

View File

@ -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));

View File

@ -139,6 +139,12 @@ public:
*/
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

View File

@ -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);

View File

@ -56,6 +56,12 @@ public:
*/
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

View File

@ -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);

View File

@ -71,6 +71,12 @@ public:
*/
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

View File

@ -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);

View File

@ -49,6 +49,12 @@ public:
*/
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

View File

@ -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));

View File

@ -77,6 +77,12 @@ public:
*/
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

View File

@ -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();
}