Skip to content

Commit aa92a92

Browse files
committed
littlefs: fix coding style
1 parent 7e160f1 commit aa92a92

File tree

14 files changed

+305
-279
lines changed

14 files changed

+305
-279
lines changed

features/storage/filesystem/littlefs/LittleFileSystem.cpp

Lines changed: 76 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ using namespace mbed;
2424

2525
extern "C" void lfs_crc(uint32_t *crc, const void *buffer, size_t size)
2626
{
27-
uint32_t initial_xor = *crc;
27+
uint32_t initial_xor = *crc;
2828
MbedCRC<POLY_32BIT_REV_ANSI, 32> ct(initial_xor, 0x0, true, false);
2929
ct.compute((void *)buffer, size, (uint32_t *) crc);
3030
}
@@ -33,79 +33,102 @@ extern "C" void lfs_crc(uint32_t *crc, const void *buffer, size_t size)
3333
static int lfs_toerror(int err)
3434
{
3535
switch (err) {
36-
case LFS_ERR_OK: return 0;
37-
case LFS_ERR_IO: return -EIO;
38-
case LFS_ERR_NOENT: return -ENOENT;
39-
case LFS_ERR_EXIST: return -EEXIST;
40-
case LFS_ERR_NOTDIR: return -ENOTDIR;
41-
case LFS_ERR_ISDIR: return -EISDIR;
42-
case LFS_ERR_INVAL: return -EINVAL;
43-
case LFS_ERR_NOSPC: return -ENOSPC;
44-
case LFS_ERR_NOMEM: return -ENOMEM;
45-
case LFS_ERR_CORRUPT: return -EILSEQ;
46-
default: return err;
36+
case LFS_ERR_OK:
37+
return 0;
38+
case LFS_ERR_IO:
39+
return -EIO;
40+
case LFS_ERR_NOENT:
41+
return -ENOENT;
42+
case LFS_ERR_EXIST:
43+
return -EEXIST;
44+
case LFS_ERR_NOTDIR:
45+
return -ENOTDIR;
46+
case LFS_ERR_ISDIR:
47+
return -EISDIR;
48+
case LFS_ERR_INVAL:
49+
return -EINVAL;
50+
case LFS_ERR_NOSPC:
51+
return -ENOSPC;
52+
case LFS_ERR_NOMEM:
53+
return -ENOMEM;
54+
case LFS_ERR_CORRUPT:
55+
return -EILSEQ;
56+
default:
57+
return err;
4758
}
4859
}
4960

5061
static int lfs_fromflags(int flags)
5162
{
5263
return (
53-
(((flags & 3) == O_RDONLY) ? LFS_O_RDONLY : 0) |
54-
(((flags & 3) == O_WRONLY) ? LFS_O_WRONLY : 0) |
55-
(((flags & 3) == O_RDWR) ? LFS_O_RDWR : 0) |
56-
((flags & O_CREAT) ? LFS_O_CREAT : 0) |
57-
((flags & O_EXCL) ? LFS_O_EXCL : 0) |
58-
((flags & O_TRUNC) ? LFS_O_TRUNC : 0) |
59-
((flags & O_APPEND) ? LFS_O_APPEND : 0));
64+
(((flags & 3) == O_RDONLY) ? LFS_O_RDONLY : 0) |
65+
(((flags & 3) == O_WRONLY) ? LFS_O_WRONLY : 0) |
66+
(((flags & 3) == O_RDWR) ? LFS_O_RDWR : 0) |
67+
((flags & O_CREAT) ? LFS_O_CREAT : 0) |
68+
((flags & O_EXCL) ? LFS_O_EXCL : 0) |
69+
((flags & O_TRUNC) ? LFS_O_TRUNC : 0) |
70+
((flags & O_APPEND) ? LFS_O_APPEND : 0));
6071
}
6172

6273
static int lfs_fromwhence(int whence)
6374
{
6475
switch (whence) {
65-
case SEEK_SET: return LFS_SEEK_SET;
66-
case SEEK_CUR: return LFS_SEEK_CUR;
67-
case SEEK_END: return LFS_SEEK_END;
68-
default: return whence;
76+
case SEEK_SET:
77+
return LFS_SEEK_SET;
78+
case SEEK_CUR:
79+
return LFS_SEEK_CUR;
80+
case SEEK_END:
81+
return LFS_SEEK_END;
82+
default:
83+
return whence;
6984
}
7085
}
7186

7287
static int lfs_tomode(int type)
7388
{
7489
int mode = S_IRWXU | S_IRWXG | S_IRWXO;
7590
switch (type) {
76-
case LFS_TYPE_DIR: return mode | S_IFDIR;
77-
case LFS_TYPE_REG: return mode | S_IFREG;
78-
default: return 0;
91+
case LFS_TYPE_DIR:
92+
return mode | S_IFDIR;
93+
case LFS_TYPE_REG:
94+
return mode | S_IFREG;
95+
default:
96+
return 0;
7997
}
8098
}
8199

82100
static int lfs_totype(int type)
83101
{
84102
switch (type) {
85-
case LFS_TYPE_DIR: return DT_DIR;
86-
case LFS_TYPE_REG: return DT_REG;
87-
default: return DT_UNKNOWN;
103+
case LFS_TYPE_DIR:
104+
return DT_DIR;
105+
case LFS_TYPE_REG:
106+
return DT_REG;
107+
default:
108+
return DT_UNKNOWN;
88109
}
89110
}
90111

91112

92113
////// Block device operations //////
93114
static int lfs_bd_read(const struct lfs_config *c, lfs_block_t block,
94-
lfs_off_t off, void *buffer, lfs_size_t size) {
115+
lfs_off_t off, void *buffer, lfs_size_t size)
116+
{
95117
BlockDevice *bd = (BlockDevice *)c->context;
96-
return bd->read(buffer, (bd_addr_t)block*c->block_size + off, size);
118+
return bd->read(buffer, (bd_addr_t)block * c->block_size + off, size);
97119
}
98120

99121
static int lfs_bd_prog(const struct lfs_config *c, lfs_block_t block,
100-
lfs_off_t off, const void *buffer, lfs_size_t size) {
122+
lfs_off_t off, const void *buffer, lfs_size_t size)
123+
{
101124
BlockDevice *bd = (BlockDevice *)c->context;
102-
return bd->program(buffer, (bd_addr_t)block*c->block_size + off, size);
125+
return bd->program(buffer, (bd_addr_t)block * c->block_size + off, size);
103126
}
104127

105128
static int lfs_bd_erase(const struct lfs_config *c, lfs_block_t block)
106129
{
107130
BlockDevice *bd = (BlockDevice *)c->context;
108-
return bd->erase((bd_addr_t)block*c->block_size, c->block_size);
131+
return bd->erase((bd_addr_t)block * c->block_size, c->block_size);
109132
}
110133

111134
static int lfs_bd_sync(const struct lfs_config *c)
@@ -119,19 +142,21 @@ static int lfs_bd_sync(const struct lfs_config *c)
119142

120143
// Filesystem implementation (See LittleFileSystem.h)
121144
LittleFileSystem::LittleFileSystem(const char *name, BlockDevice *bd,
122-
lfs_size_t read_size, lfs_size_t prog_size,
123-
lfs_size_t block_size, lfs_size_t lookahead)
124-
: FileSystem(name)
125-
, _read_size(read_size)
126-
, _prog_size(prog_size)
127-
, _block_size(block_size)
128-
, _lookahead(lookahead) {
145+
lfs_size_t read_size, lfs_size_t prog_size,
146+
lfs_size_t block_size, lfs_size_t lookahead)
147+
: FileSystem(name)
148+
, _read_size(read_size)
149+
, _prog_size(prog_size)
150+
, _block_size(block_size)
151+
, _lookahead(lookahead)
152+
{
129153
if (bd) {
130154
mount(bd);
131155
}
132156
}
133157

134-
LittleFileSystem::~LittleFileSystem() {
158+
LittleFileSystem::~LittleFileSystem()
159+
{
135160
// nop if unmounted
136161
unmount();
137162
}
@@ -168,7 +193,7 @@ int LittleFileSystem::mount(BlockDevice *bd)
168193
_config.block_size = _block_size;
169194
}
170195
_config.block_count = bd->size() / _config.block_size;
171-
_config.lookahead = 32 * ((_config.block_count+31)/32);
196+
_config.lookahead = 32 * ((_config.block_count + 31) / 32);
172197
if (_config.lookahead > _lookahead) {
173198
_config.lookahead = _lookahead;
174199
}
@@ -204,17 +229,18 @@ int LittleFileSystem::unmount()
204229

205230
_bd = NULL;
206231
}
207-
232+
208233
LFS_INFO("unmount -> %d", res);
209234
_mutex.unlock();
210235
return res;
211236
}
212237

213238
int LittleFileSystem::format(BlockDevice *bd,
214-
lfs_size_t read_size, lfs_size_t prog_size,
215-
lfs_size_t block_size, lfs_size_t lookahead) {
239+
lfs_size_t read_size, lfs_size_t prog_size,
240+
lfs_size_t block_size, lfs_size_t lookahead)
241+
{
216242
LFS_INFO("format(%p, %ld, %ld, %ld, %ld)",
217-
bd, read_size, prog_size, block_size, lookahead);
243+
bd, read_size, prog_size, block_size, lookahead);
218244
int err = bd->init();
219245
if (err) {
220246
LFS_INFO("format -> %d", err);
@@ -223,7 +249,7 @@ int LittleFileSystem::format(BlockDevice *bd,
223249

224250
lfs_t _lfs;
225251
struct lfs_config _config;
226-
252+
227253
memset(&_config, 0, sizeof(_config));
228254
_config.context = bd;
229255
_config.read = lfs_bd_read;
@@ -243,7 +269,7 @@ int LittleFileSystem::format(BlockDevice *bd,
243269
_config.block_size = block_size;
244270
}
245271
_config.block_count = bd->size() / _config.block_size;
246-
_config.lookahead = 32 * ((_config.block_count+31)/32);
272+
_config.lookahead = 32 * ((_config.block_count + 31) / 32);
247273
if (_config.lookahead > lookahead) {
248274
_config.lookahead = lookahead;
249275
}
@@ -288,7 +314,7 @@ int LittleFileSystem::reformat(BlockDevice *bd)
288314
}
289315

290316
int err = LittleFileSystem::format(bd,
291-
_read_size, _prog_size, _block_size, _lookahead);
317+
_read_size, _prog_size, _block_size, _lookahead);
292318
if (err) {
293319
LFS_INFO("reformat -> %d", err);
294320
_mutex.unlock();

features/storage/filesystem/littlefs/LittleFileSystem.h

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,13 @@ class LittleFileSystem : public mbed::FileSystem {
5151
* The lookahead buffer requires only 1 bit per block so it can be quite
5252
* large with little ram impact. Should be a multiple of 32.
5353
*/
54-
LittleFileSystem(const char *name=NULL, BlockDevice *bd=NULL,
55-
lfs_size_t read_size=MBED_LFS_READ_SIZE,
56-
lfs_size_t prog_size=MBED_LFS_PROG_SIZE,
57-
lfs_size_t block_size=MBED_LFS_BLOCK_SIZE,
58-
lfs_size_t lookahead=MBED_LFS_LOOKAHEAD);
54+
LittleFileSystem(const char *name = NULL, BlockDevice *bd = NULL,
55+
lfs_size_t read_size = MBED_LFS_READ_SIZE,
56+
lfs_size_t prog_size = MBED_LFS_PROG_SIZE,
57+
lfs_size_t block_size = MBED_LFS_BLOCK_SIZE,
58+
lfs_size_t lookahead = MBED_LFS_LOOKAHEAD);
5959
virtual ~LittleFileSystem();
60-
60+
6161
/** Formats a block device with the LittleFileSystem
6262
*
6363
* The block device to format should be mounted when this function is called.
@@ -82,10 +82,10 @@ class LittleFileSystem : public mbed::FileSystem {
8282
* large with little ram impact. Should be a multiple of 32.
8383
*/
8484
static int format(BlockDevice *bd,
85-
lfs_size_t read_size=MBED_LFS_READ_SIZE,
86-
lfs_size_t prog_size=MBED_LFS_PROG_SIZE,
87-
lfs_size_t block_size=MBED_LFS_BLOCK_SIZE,
88-
lfs_size_t lookahead=MBED_LFS_LOOKAHEAD);
85+
lfs_size_t read_size = MBED_LFS_READ_SIZE,
86+
lfs_size_t prog_size = MBED_LFS_PROG_SIZE,
87+
lfs_size_t block_size = MBED_LFS_BLOCK_SIZE,
88+
lfs_size_t lookahead = MBED_LFS_LOOKAHEAD);
8989

9090
/** Mounts a filesystem to a block device
9191
*
@@ -182,7 +182,7 @@ class LittleFileSystem : public mbed::FileSystem {
182182
*
183183
* @param file File handle
184184
* @param buffer The buffer to write from
185-
* @param size The number of bytes to write
185+
* @param size The number of bytes to write
186186
* @return The number of bytes written, negative error on failure
187187
*/
188188
virtual ssize_t file_write(mbed::fs_file_t file, const void *buffer, size_t size);
@@ -263,7 +263,7 @@ class LittleFileSystem : public mbed::FileSystem {
263263
* @param dir Dir handle
264264
*/
265265
virtual void dir_rewind(mbed::fs_dir_t dir);
266-
266+
267267
private:
268268
lfs_t _lfs; // _the actual filesystem
269269
struct lfs_config _config;

features/storage/filesystem/littlefs/TESTS/COMMON/atomic_usage.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,9 @@ static int file_scanf(File *file, const char *format, ...)
157157
int res = file->read(buf, sizeof(buf) - 1);
158158
TEST_ASSERT_OR_EXIT(res >= 0);
159159

160-
va_start (args, format);
161-
int count = vsscanf((char*)buf, format, args);
162-
va_end (args);
160+
va_start(args, format);
161+
int count = vsscanf((char *)buf, format, args);
162+
va_end(args);
163163
TEST_ASSERT_OR_EXIT(count >= 0);
164164

165165
return count;
@@ -176,9 +176,9 @@ static int file_printf(File *file, const char *format, ...)
176176
{
177177
uint8_t buf[BUFFER_SIZE];
178178
va_list args;
179-
va_start (args, format);
180-
int size = vsprintf((char*)buf, format, args);
181-
va_end (args);
179+
va_start(args, format);
180+
int size = vsprintf((char *)buf, format, args);
181+
va_end(args);
182182
TEST_ASSERT_OR_EXIT((size >= 0) && (size <= (int)sizeof(buf)));
183183

184184
if (file_write(file, buf, size)) {
@@ -254,7 +254,7 @@ static void check_file_rename(FileSystem *fs)
254254

255255
int files = 0;
256256
int valids = 0;
257-
const char * const filenames[] = {FILE_RENAME_A, FILE_RENAME_B};
257+
const char *const filenames[] = {FILE_RENAME_A, FILE_RENAME_B};
258258

259259
for (int i = 0; i < 2; i++) {
260260
File file;
@@ -300,7 +300,7 @@ static void setup_file_rename_replace(FileSystem *fs)
300300
uint32_t count = 0;
301301
uint8_t buf[BUFFER_SIZE];
302302
memset(buf, 0, sizeof(buf));
303-
const int length = sprintf((char*)buf, FILE_RENAME_REPLACE_FMT, count);
303+
const int length = sprintf((char *)buf, FILE_RENAME_REPLACE_FMT, count);
304304
TEST_ASSERT_OR_EXIT(length > 0);
305305

306306
res = file.write(buf, length);
@@ -602,7 +602,7 @@ static bool format_required(BlockDevice *bd)
602602

603603
// Get the test version
604604
uint32_t version = 0;
605-
res = sscanf((char*)buf, FILE_SETUP_COMPLETE_FMT, &version);
605+
res = sscanf((char *)buf, FILE_SETUP_COMPLETE_FMT, &version);
606606
if (res != 1) {
607607
return true;
608608
}

features/storage/filesystem/littlefs/TESTS/filesystem/dirs/main.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -300,8 +300,8 @@ void test_multi_block_directory()
300300
res = fs.mkdir("cactus", 0777);
301301
TEST_ASSERT_EQUAL(0, res);
302302
for (int i = 0; i < 128; i++) {
303-
sprintf((char*)buffer, "cactus/test%d", i);
304-
res = fs.mkdir((char*)buffer, 0777);
303+
sprintf((char *)buffer, "cactus/test%d", i);
304+
res = fs.mkdir((char *)buffer, 0777);
305305
TEST_ASSERT_EQUAL(0, res);
306306
}
307307
res = fs.unmount();
@@ -326,10 +326,10 @@ void test_multi_block_directory()
326326
res = ent.d_type;
327327
TEST_ASSERT_EQUAL(DT_DIR, res);
328328
for (int i = 0; i < 128; i++) {
329-
sprintf((char*)buffer, "test%d", i);
329+
sprintf((char *)buffer, "test%d", i);
330330
res = dir[0].read(&ent);
331331
TEST_ASSERT_EQUAL(1, res);
332-
res = strcmp(ent.d_name, (char*)buffer);
332+
res = strcmp(ent.d_name, (char *)buffer);
333333
TEST_ASSERT_EQUAL(0, res);
334334
}
335335
res = dir[0].read(&ent);

0 commit comments

Comments
 (0)