Skip to content

Commit 840c777

Browse files
committed
STORAGE: Pull request 3762 review feedback changes.
- Fixing code formatting errors with astyle tool. - Replaced use of TOOLCHAIN_xxx macros with compiler emitted macros. - Added const to BlockDevice::get_xxx_size() member functions. - Added documentation for FAT filesystem thread support. - Added documentation for fat_filesystem_set_errno(). - Added documentation clarifying the reasons for errno/stat symbol definitions in retarget.h. - Removed FAT filesystem from mbed 2 testing. - Fixed FATMisc.h Copyright (c) 2016 year to 2017 as its a new file. - Removed #ifndef NDEBUG from HeapBlockDevice.cpp. - Removed unnecessary todo comment in retarget.cpp.
1 parent b8e31c8 commit 840c777

22 files changed

+254
-225
lines changed

features/TESTS/filesystem/heap_block_device/main.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ using namespace utest::v1;
2727
* stack tracking statistics are enabled. If this is the case, build dummy
2828
* tests.
2929
*/
30-
#if ! defined(TOOLCHAIN_IAR) && ! defined(TARGET_KL25Z) && ! defined(MBED_STACK_STATS_ENABLED)
30+
#if ! defined(__ICCARM__) && ! defined(TARGET_KL25Z) && ! defined(MBED_STACK_STATS_ENABLED)
3131

3232
#define BLOCK_SIZE 512
3333
#define HEAP_BLOCK_DEVICE_TEST_01 test_read_write
@@ -64,7 +64,7 @@ void test_read_write() {
6464
TEST_ASSERT_EQUAL(0, err);
6565
}
6666

67-
#else /* ! defined(TOOLCHAIN_IAR) && ! defined(TARGET_KL25Z) && ! defined(MBED_STACK_STATS_ENABLED) */
67+
#else /* ! defined(__ICCARM__) && ! defined(TARGET_KL25Z) && ! defined(MBED_STACK_STATS_ENABLED) */
6868

6969
#define HEAP_BLOCK_DEVICE_TEST_01 heap_block_device_test_dummy
7070

@@ -78,7 +78,7 @@ static control_t heap_block_device_test_dummy()
7878
return CaseNext;
7979
}
8080

81-
#endif /* ! defined(TOOLCHAIN_IAR) && ! defined(TARGET_KL25Z) && ! defined(MBED_STACK_STATS_ENABLED) */
81+
#endif /* ! defined(__ICCARM__) && ! defined(TARGET_KL25Z) && ! defined(MBED_STACK_STATS_ENABLED) */
8282

8383
// Test setup
8484
utest::v1::status_t test_setup(const size_t number_of_cases) {

features/filesystem/bd/BlockDevice.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ bd_error_t BlockDevice::write(const void *buffer, bd_addr_t addr, bd_size_t size
3232
return program(buffer, addr, size);
3333
}
3434

35-
bd_size_t BlockDevice::get_write_size()
35+
bd_size_t BlockDevice::get_write_size() const
3636
{
3737
return get_erase_size();
3838
}
@@ -52,24 +52,24 @@ static bool is_aligned(uint64_t x, uint64_t alignment)
5252
bool BlockDevice::is_valid_read(bd_addr_t addr, bd_size_t size)
5353
{
5454
return (
55-
is_aligned(addr, get_read_size()) &&
56-
is_aligned(size, get_read_size()) &&
57-
addr + size <= this->size());
55+
is_aligned(addr, get_read_size()) &&
56+
is_aligned(size, get_read_size()) &&
57+
addr + size <= this->size());
5858
}
5959

6060
bool BlockDevice::is_valid_erase(bd_addr_t addr, bd_size_t size)
6161
{
6262
return (
63-
is_aligned(addr, get_erase_size()) &&
64-
is_aligned(size, get_erase_size()) &&
65-
addr + size <= this->size());
63+
is_aligned(addr, get_erase_size()) &&
64+
is_aligned(size, get_erase_size()) &&
65+
addr + size <= this->size());
6666
}
6767

6868
bool BlockDevice::is_valid_program(bd_addr_t addr, bd_size_t size)
6969
{
7070
return (
71-
is_aligned(addr, get_program_size()) &&
72-
is_aligned(size, get_program_size()) &&
73-
addr + size <= this->size());
71+
is_aligned(addr, get_program_size()) &&
72+
is_aligned(size, get_program_size()) &&
73+
addr + size <= this->size());
7474
}
7575

features/filesystem/bd/BlockDevice.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ typedef uint64_t bd_size_t;
5050

5151
/** A hardware device capable of writing and reading blocks
5252
*/
53-
class BlockDevice {
53+
class BlockDevice
54+
{
5455
public:
5556
/** Lifetime of a block device
5657
*/
@@ -119,29 +120,29 @@ class BlockDevice {
119120
*
120121
* @return Size of a readable block in bytes
121122
*/
122-
virtual bd_size_t get_read_size() = 0;
123+
virtual bd_size_t get_read_size() const = 0;
123124

124125
/** Get the size of a writeable block
125126
*
126127
* @return Size of a writeable block in bytes
127128
* @note Must be a multiple of the read size, this is
128129
* equivalent to the erase size of the device
129130
*/
130-
virtual bd_size_t get_write_size();
131+
virtual bd_size_t get_write_size() const;
131132

132133
/** Get the size of a programable block
133134
*
134135
* @return Size of a programable block in bytes
135136
* @note Must be a multiple of the read size
136137
*/
137-
virtual bd_size_t get_program_size() = 0;
138+
virtual bd_size_t get_program_size() const = 0;
138139

139140
/** Get the size of a eraseable block
140141
*
141142
* @return Size of a eraseable block in bytes
142143
* @note Must be a multiple of the program size
143144
*/
144-
virtual bd_size_t get_erase_size() = 0;
145+
virtual bd_size_t get_erase_size() const = 0;
145146

146147
/** Get the total size of the underlying device
147148
*

features/filesystem/bd/ChainingBlockDevice.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ bd_error_t ChainingBlockDevice::init()
3535
_erase_size = 0;
3636
_size = 0;
3737

38-
// Initialize children block devices, find all sizes and
38+
// Initialize children block devices, find all sizes and
3939
// assert that block sizes are similar. We can't do this in
4040
// the constructor since some block devices may need to be
4141
// initialized before they know their block size/count
@@ -183,17 +183,17 @@ bd_error_t ChainingBlockDevice::erase(bd_addr_t addr, bd_size_t size)
183183
return 0;
184184
}
185185

186-
bd_size_t ChainingBlockDevice::get_read_size()
186+
bd_size_t ChainingBlockDevice::get_read_size() const
187187
{
188188
return _read_size;
189189
}
190190

191-
bd_size_t ChainingBlockDevice::get_program_size()
191+
bd_size_t ChainingBlockDevice::get_program_size() const
192192
{
193193
return _program_size;
194194
}
195195

196-
bd_size_t ChainingBlockDevice::get_erase_size()
196+
bd_size_t ChainingBlockDevice::get_erase_size() const
197197
{
198198
return _erase_size;
199199
}

features/filesystem/bd/ChainingBlockDevice.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@
4444
* BlockDevice *bds[] = {&mem1, &mem2};
4545
* ChainingBlockDevice chainmem(bds);
4646
*/
47-
class ChainingBlockDevice : public BlockDevice {
47+
class ChainingBlockDevice : public BlockDevice
48+
{
4849
public:
4950
/** Lifetime of the memory block device
5051
*
@@ -62,7 +63,8 @@ class ChainingBlockDevice : public BlockDevice {
6263
template <size_t Size>
6364
ChainingBlockDevice(BlockDevice *(&bds)[Size])
6465
: _bds(bds), _bd_count(sizeof(bds) / sizeof(bds[0]))
65-
, _read_size(0), _program_size(0), _erase_size(0), _size(0) {
66+
, _read_size(0), _program_size(0), _erase_size(0), _size(0)
67+
{
6668
}
6769

6870
/** Lifetime of the memory block device
@@ -118,21 +120,21 @@ class ChainingBlockDevice : public BlockDevice {
118120
*
119121
* @return Size of a readable block in bytes
120122
*/
121-
virtual bd_size_t get_read_size();
123+
virtual bd_size_t get_read_size() const;
122124

123125
/** Get the size of a programable block
124126
*
125127
* @return Size of a programable block in bytes
126128
* @note Must be a multiple of the read size
127129
*/
128-
virtual bd_size_t get_program_size();
130+
virtual bd_size_t get_program_size() const;
129131

130132
/** Get the size of a eraseable block
131133
*
132134
* @return Size of a eraseable block in bytes
133135
* @note Must be a multiple of the program size
134136
*/
135-
virtual bd_size_t get_erase_size();
137+
virtual bd_size_t get_erase_size() const;
136138

137139
/** Get the total size of the underlying device
138140
*

features/filesystem/bd/HeapBlockDevice.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ HeapBlockDevice::HeapBlockDevice(bd_size_t size, bd_size_t block)
2424
MBED_ASSERT(_count * _erase_size == size);
2525
}
2626

27-
HeapBlockDevice::HeapBlockDevice(bd_size_t size,
28-
bd_size_t read, bd_size_t program, bd_size_t erase)
27+
HeapBlockDevice::HeapBlockDevice(bd_size_t size, bd_size_t read, bd_size_t program, bd_size_t erase)
2928
: _read_size(read), _program_size(program), _erase_size(erase)
3029
, _count(size / erase), _blocks(0)
3130
{
@@ -63,17 +62,17 @@ bd_error_t HeapBlockDevice::deinit()
6362
return BD_ERROR_OK;
6463
}
6564

66-
bd_size_t HeapBlockDevice::get_read_size()
65+
bd_size_t HeapBlockDevice::get_read_size() const
6766
{
6867
return _read_size;
6968
}
7069

71-
bd_size_t HeapBlockDevice::get_program_size()
70+
bd_size_t HeapBlockDevice::get_program_size() const
7271
{
7372
return _program_size;
7473
}
7574

76-
bd_size_t HeapBlockDevice::get_erase_size()
75+
bd_size_t HeapBlockDevice::get_erase_size() const
7776
{
7877
return _erase_size;
7978
}
@@ -142,7 +141,6 @@ bd_error_t HeapBlockDevice::erase(bd_addr_t addr, bd_size_t size)
142141
return BD_ERROR_PARAMETER;
143142
}
144143

145-
#ifndef NDEBUG
146144
while (size > 0) {
147145
bd_addr_t hi = addr / _erase_size;
148146

@@ -153,7 +151,6 @@ bd_error_t HeapBlockDevice::erase(bd_addr_t addr, bd_size_t size)
153151
addr += _erase_size;
154152
size -= _erase_size;
155153
}
156-
#endif
157154

158155
return 0;
159156
}

features/filesystem/bd/HeapBlockDevice.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@
4545
* bd.deinit();
4646
* }
4747
*/
48-
class HeapBlockDevice : public BlockDevice {
48+
class HeapBlockDevice : public BlockDevice
49+
{
4950
public:
5051

5152
/** Lifetime of the memory block device
@@ -100,19 +101,19 @@ class HeapBlockDevice : public BlockDevice {
100101
*
101102
* @return Size of a readable block in bytes
102103
*/
103-
virtual bd_size_t get_read_size();
104+
virtual bd_size_t get_read_size() const;
104105

105106
/** Get the size of a programable block
106107
*
107108
* @return Size of a programable block in bytes
108109
*/
109-
virtual bd_size_t get_program_size();
110+
virtual bd_size_t get_program_size() const;
110111

111112
/** Get the size of a eraseable block
112113
*
113114
* @return Size of a eraseable block in bytes
114115
*/
115-
virtual bd_size_t get_erase_size();
116+
virtual bd_size_t get_erase_size() const;
116117

117118
/** Get the total size of the underlying device
118119
*

features/filesystem/bd/SlicingBlockDevice.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,17 +104,17 @@ bd_error_t SlicingBlockDevice::erase(bd_addr_t addr, bd_size_t size)
104104
return _bd->erase(addr + _start, size);
105105
}
106106

107-
bd_size_t SlicingBlockDevice::get_read_size()
107+
bd_size_t SlicingBlockDevice::get_read_size() const
108108
{
109109
return _bd->get_read_size();
110110
}
111111

112-
bd_size_t SlicingBlockDevice::get_program_size()
112+
bd_size_t SlicingBlockDevice::get_program_size() const
113113
{
114114
return _bd->get_program_size();
115115
}
116116

117-
bd_size_t SlicingBlockDevice::get_erase_size()
117+
bd_size_t SlicingBlockDevice::get_erase_size() const
118118
{
119119
return _bd->get_erase_size();
120120
}

features/filesystem/bd/SlicingBlockDevice.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@
4545
* // Create a block device that maps to the middle 32 blocks
4646
* SlicingBlockDevice slice3(&mem, 16*512, -16*512);
4747
*/
48-
class SlicingBlockDevice : public BlockDevice {
48+
class SlicingBlockDevice : public BlockDevice
49+
{
4950
public:
5051
/** Lifetime of the memory block device
5152
*
@@ -117,21 +118,21 @@ class SlicingBlockDevice : public BlockDevice {
117118
*
118119
* @return Size of a readable block in bytes
119120
*/
120-
virtual bd_size_t get_read_size();
121+
virtual bd_size_t get_read_size() const;
121122

122123
/** Get the size of a programable block
123124
*
124125
* @return Size of a programable block in bytes
125126
* @note Must be a multiple of the read size
126127
*/
127-
virtual bd_size_t get_program_size();
128+
virtual bd_size_t get_program_size() const;
128129

129130
/** Get the size of a eraseable block
130131
*
131132
* @return Size of a eraseable block in bytes
132133
* @note Must be a multiple of the program size
133134
*/
134-
virtual bd_size_t get_erase_size();
135+
virtual bd_size_t get_erase_size() const;
135136

136137
/** Get the total size of the underlying device
137138
*

features/filesystem/fat/FATDirHandle.cpp

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,13 @@
2626

2727
using namespace mbed;
2828

29-
FATDirHandle::FATDirHandle(const FATFS_DIR &the_dir, PlatformMutex * mutex): _mutex(mutex) {
29+
FATDirHandle::FATDirHandle(const FATFS_DIR &the_dir, PlatformMutex * mutex): _mutex(mutex)
30+
{
3031
dir = the_dir;
3132
}
3233

33-
int FATDirHandle::closedir() {
34+
int FATDirHandle::closedir()
35+
{
3436
lock();
3537
FRESULT retval = f_closedir(&dir);
3638
fat_filesystem_set_errno(retval);
@@ -39,7 +41,8 @@ int FATDirHandle::closedir() {
3941
return retval;
4042
}
4143

42-
struct dirent *FATDirHandle::readdir() {
44+
struct dirent *FATDirHandle::readdir()
45+
{
4346
FILINFO finfo;
4447

4548
lock();
@@ -76,33 +79,38 @@ struct dirent *FATDirHandle::readdir() {
7679
#endif /* _USE_LFN */
7780
}
7881

79-
void FATDirHandle::rewinddir() {
82+
void FATDirHandle::rewinddir()
83+
{
8084
lock();
8185
dir.index = 0;
8286
fat_filesystem_set_errno(FR_OK);
8387
unlock();
8488
}
8589

86-
off_t FATDirHandle::telldir() {
90+
off_t FATDirHandle::telldir()
91+
{
8792
lock();
8893
off_t offset = dir.index;
8994
fat_filesystem_set_errno(FR_OK);
9095
unlock();
9196
return offset;
9297
}
9398

94-
void FATDirHandle::seekdir(off_t location) {
99+
void FATDirHandle::seekdir(off_t location)
100+
{
95101
lock();
96102
dir.index = location;
97103
fat_filesystem_set_errno(FR_OK);
98104
unlock();
99105
}
100106

101-
void FATDirHandle::lock() {
107+
void FATDirHandle::lock()
108+
{
102109
_mutex->lock();
103110
}
104111

105-
void FATDirHandle::unlock() {
112+
void FATDirHandle::unlock()
113+
{
106114
_mutex->unlock();
107115
}
108116

0 commit comments

Comments
 (0)