Skip to content

Commit 101fc62

Browse files
authored
Merge pull request #5926 from geky/bd-sync
bd: Add sync function to the block device API
2 parents b08e1b3 + 6e5f243 commit 101fc62

16 files changed

+95
-1
lines changed

features/filesystem/bd/BlockDevice.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,15 @@ class BlockDevice
5959
*/
6060
virtual int deinit() = 0;
6161

62+
/** Ensure data on storage is in sync with the driver
63+
*
64+
* @return 0 on success or a negative error code on failure
65+
*/
66+
virtual int sync()
67+
{
68+
return 0;
69+
}
70+
6271
/** Read blocks from a block device
6372
*
6473
* If a failure occurs, it is not possible to determine how many bytes succeeded

features/filesystem/bd/ChainingBlockDevice.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,18 @@ int ChainingBlockDevice::deinit()
8484
return 0;
8585
}
8686

87+
int ChainingBlockDevice::sync()
88+
{
89+
for (size_t i = 0; i < _bd_count; i++) {
90+
int err = _bds[i]->sync();
91+
if (err) {
92+
return err;
93+
}
94+
}
95+
96+
return 0;
97+
}
98+
8799
int ChainingBlockDevice::read(void *b, bd_addr_t addr, bd_size_t size)
88100
{
89101
MBED_ASSERT(is_valid_read(addr, size));

features/filesystem/bd/ChainingBlockDevice.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,12 @@ class ChainingBlockDevice : public BlockDevice
8585
*/
8686
virtual int deinit();
8787

88+
/** Ensure data on storage is in sync with the driver
89+
*
90+
* @return 0 on success or a negative error code on failure
91+
*/
92+
virtual int sync();
93+
8894
/** Read blocks from a block device
8995
*
9096
* @param buffer Buffer to write blocks to

features/filesystem/bd/ExhaustibleBlockDevice.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ int ExhaustibleBlockDevice::deinit()
5353
return _bd->deinit();
5454
}
5555

56+
int ExhaustibleBlockDevice::sync()
57+
{
58+
return _bd->sync();
59+
}
60+
5661
int ExhaustibleBlockDevice::read(void *buffer, bd_addr_t addr, bd_size_t size)
5762
{
5863
return _bd->read(buffer, addr, size);

features/filesystem/bd/ExhaustibleBlockDevice.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,12 @@ class ExhaustibleBlockDevice : public BlockDevice
7070
*/
7171
virtual int deinit();
7272

73+
/** Ensure data on storage is in sync with the driver
74+
*
75+
* @return 0 on success or a negative error code on failure
76+
*/
77+
virtual int sync();
78+
7379
/** Read blocks from a block device
7480
*
7581
* @param buffer Buffer to read blocks into

features/filesystem/bd/MBRBlockDevice.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,11 @@ int MBRBlockDevice::deinit()
234234
return _bd->deinit();
235235
}
236236

237+
int MBRBlockDevice::sync()
238+
{
239+
return _bd->sync();
240+
}
241+
237242
int MBRBlockDevice::read(void *b, bd_addr_t addr, bd_size_t size)
238243
{
239244
MBED_ASSERT(is_valid_read(addr, size));

features/filesystem/bd/MBRBlockDevice.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,12 @@ class MBRBlockDevice : public BlockDevice
139139
*/
140140
virtual int deinit();
141141

142+
/** Ensure data on storage is in sync with the driver
143+
*
144+
* @return 0 on success or a negative error code on failure
145+
*/
146+
virtual int sync();
147+
142148
/** Read blocks from a block device
143149
*
144150
* @param buffer Buffer to read blocks into

features/filesystem/bd/ObservingBlockDevice.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ int ObservingBlockDevice::deinit()
5151
return _bd->deinit();
5252
}
5353

54+
int ObservingBlockDevice::sync()
55+
{
56+
return _bd->sync();
57+
}
58+
5459
int ObservingBlockDevice::read(void *buffer, bd_addr_t addr, bd_size_t size)
5560
{
5661
return _bd->read(buffer, addr, size);

features/filesystem/bd/ObservingBlockDevice.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,12 @@ class ObservingBlockDevice : public BlockDevice
5656
*/
5757
virtual int deinit();
5858

59+
/** Ensure data on storage is in sync with the driver
60+
*
61+
* @return 0 on success or a negative error code on failure
62+
*/
63+
virtual int sync();
64+
5965
/** Read blocks from a block device
6066
*
6167
* @param buffer Buffer to read blocks into

features/filesystem/bd/ProfilingBlockDevice.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ int ProfilingBlockDevice::deinit()
3535
return _bd->deinit();
3636
}
3737

38+
int ProfilingBlockDevice::sync()
39+
{
40+
return _bd->sync();
41+
}
42+
3843
int ProfilingBlockDevice::read(void *b, bd_addr_t addr, bd_size_t size)
3944
{
4045
int err = _bd->read(b, addr, size);

0 commit comments

Comments
 (0)