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

features/filesystem/bd/ProfilingBlockDevice.h

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

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

features/filesystem/bd/ReadOnlyBlockDevice.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ int ReadOnlyBlockDevice::deinit()
4545
return _bd->deinit();
4646
}
4747

48+
int ReadOnlyBlockDevice::sync()
49+
{
50+
return _bd->sync();
51+
}
52+
4853
int ReadOnlyBlockDevice::read(void *buffer, bd_addr_t addr, bd_size_t size)
4954
{
5055
return _bd->read(buffer, addr, size);

features/filesystem/bd/ReadOnlyBlockDevice.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@ class ReadOnlyBlockDevice : public BlockDevice
4949
*/
5050
virtual int deinit();
5151

52+
/** Ensure data on storage is in sync with the driver
53+
*
54+
* @return 0 on success or a negative error code on failure
55+
*/
56+
virtual int sync();
57+
5258
/** Read blocks from a block device
5359
*
5460
* @param buffer Buffer to read blocks into

features/filesystem/bd/SlicingBlockDevice.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@ int SlicingBlockDevice::deinit()
6464
return _bd->deinit();
6565
}
6666

67+
int SlicingBlockDevice::sync()
68+
{
69+
return _bd->sync();
70+
}
71+
6772
int SlicingBlockDevice::read(void *b, bd_addr_t addr, bd_size_t size)
6873
{
6974
MBED_ASSERT(is_valid_read(addr, size));

features/filesystem/bd/SlicingBlockDevice.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,12 @@ class SlicingBlockDevice : public BlockDevice
7777
*/
7878
virtual int deinit();
7979

80+
/** Ensure data on storage is in sync with the driver
81+
*
82+
* @return 0 on success or a negative error code on failure
83+
*/
84+
virtual int sync();
85+
8086
/** Read blocks from a block device
8187
*
8288
* @param buffer Buffer to read blocks into

features/filesystem/littlefs/LittleFileSystem.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,8 @@ static int lfs_bd_erase(const struct lfs_config *c, lfs_block_t block)
102102

103103
static int lfs_bd_sync(const struct lfs_config *c)
104104
{
105-
return 0;
105+
BlockDevice *bd = (BlockDevice *)c->context;
106+
return bd->sync();
106107
}
107108

108109

0 commit comments

Comments
 (0)