Skip to content

Commit 91a4f44

Browse files
committed
1 parent 9da2475 commit 91a4f44

File tree

14 files changed

+387
-196
lines changed

14 files changed

+387
-196
lines changed

LittleFileSystem.cpp

Lines changed: 66 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,17 @@
11
/* mbed Microcontroller Library
2-
* Copyright (c) 2006-2012 ARM Limited
2+
* Copyright (c) 2017 ARM Limited
33
*
4-
* Permission is hereby granted, free of charge, to any person obtaining a copy
5-
* of this software and associated documentation files (the "Software"), to deal
6-
* in the Software without restriction, including without limitation the rights
7-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8-
* copies of the Software, and to permit persons to whom the Software is
9-
* furnished to do so, subject to the following conditions:
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
107
*
11-
* The above copyright notice and this permission notice shall be included in
12-
* all copies or substantial portions of the Software.
8+
* http://www.apache.org/licenses/LICENSE-2.0
139
*
14-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20-
* SOFTWARE.
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
2115
*/
2216
#include "mbed.h"
2317
#include "LittleFileSystem.h"
@@ -29,7 +23,8 @@ extern "C" {
2923

3024

3125
////// Conversion functions //////
32-
static int lfs_toerror(int err) {
26+
static int lfs_toerror(int err)
27+
{
3328
switch (err) {
3429
case LFS_ERR_OK: return 0;
3530
case LFS_ERR_IO: return -EIO;
@@ -44,7 +39,8 @@ static int lfs_toerror(int err) {
4439
}
4540
}
4641

47-
static int lfs_fromflags(int flags) {
42+
static int lfs_fromflags(int flags)
43+
{
4844
return (
4945
(((flags & 3) == O_RDONLY) ? LFS_O_RDONLY : 0) |
5046
(((flags & 3) == O_WRONLY) ? LFS_O_WRONLY : 0) |
@@ -55,7 +51,8 @@ static int lfs_fromflags(int flags) {
5551
((flags & O_APPEND) ? LFS_O_APPEND : 0));
5652
}
5753

58-
static int lfs_fromwhence(int whence) {
54+
static int lfs_fromwhence(int whence)
55+
{
5956
switch (whence) {
6057
case SEEK_SET: return LFS_SEEK_SET;
6158
case SEEK_CUR: return LFS_SEEK_CUR;
@@ -64,7 +61,8 @@ static int lfs_fromwhence(int whence) {
6461
}
6562
}
6663

67-
static int lfs_tomode(int type) {
64+
static int lfs_tomode(int type)
65+
{
6866
int mode = S_IRWXU | S_IRWXG | S_IRWXO;
6967
switch (type) {
7068
case LFS_TYPE_DIR: return mode | S_IFDIR;
@@ -73,7 +71,8 @@ static int lfs_tomode(int type) {
7371
}
7472
}
7573

76-
static int lfs_totype(int type) {
74+
static int lfs_totype(int type)
75+
{
7776
switch (type) {
7877
case LFS_TYPE_DIR: return DT_DIR;
7978
case LFS_TYPE_REG: return DT_REG;
@@ -95,12 +94,14 @@ static int lfs_bd_prog(const struct lfs_config *c, lfs_block_t block,
9594
return bd->program(buffer, block*c->block_size + off, size);
9695
}
9796

98-
static int lfs_bd_erase(const struct lfs_config *c, lfs_block_t block) {
97+
static int lfs_bd_erase(const struct lfs_config *c, lfs_block_t block)
98+
{
9999
BlockDevice *bd = (BlockDevice *)c->context;
100100
return bd->erase(block*c->block_size, c->block_size);
101101
}
102102

103-
static int lfs_bd_sync(const struct lfs_config *c) {
103+
static int lfs_bd_sync(const struct lfs_config *c)
104+
{
104105
return 0;
105106
}
106107

@@ -126,7 +127,8 @@ LittleFileSystem::~LittleFileSystem() {
126127
unmount();
127128
}
128129

129-
int LittleFileSystem::mount(BlockDevice *bd) {
130+
int LittleFileSystem::mount(BlockDevice *bd)
131+
{
130132
_mutex.lock();
131133
LFS_INFO("mount(%p)", bd);
132134
_bd = bd;
@@ -167,7 +169,8 @@ int LittleFileSystem::mount(BlockDevice *bd) {
167169
return lfs_toerror(err);
168170
}
169171

170-
int LittleFileSystem::unmount() {
172+
int LittleFileSystem::unmount()
173+
{
171174
_mutex.lock();
172175
LFS_INFO("unmount(%s)", "");
173176
if (_bd) {
@@ -247,7 +250,8 @@ int LittleFileSystem::format(BlockDevice *bd,
247250
return 0;
248251
}
249252

250-
int LittleFileSystem::reformat(BlockDevice *bd) {
253+
int LittleFileSystem::reformat(BlockDevice *bd)
254+
{
251255
_mutex.lock();
252256
LFS_INFO("reformat(%p)", bd);
253257
if (_bd) {
@@ -289,7 +293,8 @@ int LittleFileSystem::reformat(BlockDevice *bd) {
289293
return 0;
290294
}
291295

292-
int LittleFileSystem::remove(const char *filename) {
296+
int LittleFileSystem::remove(const char *filename)
297+
{
293298
_mutex.lock();
294299
LFS_INFO("remove(\"%s\")", filename);
295300
int err = lfs_remove(&_lfs, filename);
@@ -298,7 +303,8 @@ int LittleFileSystem::remove(const char *filename) {
298303
return lfs_toerror(err);
299304
}
300305

301-
int LittleFileSystem::rename(const char *oldname, const char *newname) {
306+
int LittleFileSystem::rename(const char *oldname, const char *newname)
307+
{
302308
_mutex.lock();
303309
LFS_INFO("rename(\"%s\", \"%s\")", oldname, newname);
304310
int err = lfs_rename(&_lfs, oldname, newname);
@@ -307,7 +313,8 @@ int LittleFileSystem::rename(const char *oldname, const char *newname) {
307313
return lfs_toerror(err);
308314
}
309315

310-
int LittleFileSystem::mkdir(const char *name, mode_t mode) {
316+
int LittleFileSystem::mkdir(const char *name, mode_t mode)
317+
{
311318
_mutex.lock();
312319
LFS_INFO("mkdir(\"%s\", 0x%lx)", name, mode);
313320
int err = lfs_mkdir(&_lfs, name);
@@ -316,7 +323,8 @@ int LittleFileSystem::mkdir(const char *name, mode_t mode) {
316323
return lfs_toerror(err);
317324
}
318325

319-
int LittleFileSystem::stat(const char *name, struct stat *st) {
326+
int LittleFileSystem::stat(const char *name, struct stat *st)
327+
{
320328
struct lfs_info info;
321329
_mutex.lock();
322330
LFS_INFO("stat(\"%s\", %p)", name, st);
@@ -330,7 +338,8 @@ int LittleFileSystem::stat(const char *name, struct stat *st) {
330338

331339

332340
////// File operations //////
333-
int LittleFileSystem::file_open(fs_file_t *file, const char *path, int flags) {
341+
int LittleFileSystem::file_open(fs_file_t *file, const char *path, int flags)
342+
{
334343
lfs_file_t *f = new lfs_file_t;
335344
_mutex.lock();
336345
LFS_INFO("file_open(%p, \"%s\", 0x%x)", *file, path, flags);
@@ -345,7 +354,8 @@ int LittleFileSystem::file_open(fs_file_t *file, const char *path, int flags) {
345354
return lfs_toerror(err);
346355
}
347356

348-
int LittleFileSystem::file_close(fs_file_t file) {
357+
int LittleFileSystem::file_close(fs_file_t file)
358+
{
349359
lfs_file_t *f = (lfs_file_t *)file;
350360
_mutex.lock();
351361
LFS_INFO("file_close(%p)", file);
@@ -356,7 +366,8 @@ int LittleFileSystem::file_close(fs_file_t file) {
356366
return lfs_toerror(err);
357367
}
358368

359-
ssize_t LittleFileSystem::file_read(fs_file_t file, void *buffer, size_t len) {
369+
ssize_t LittleFileSystem::file_read(fs_file_t file, void *buffer, size_t len)
370+
{
360371
lfs_file_t *f = (lfs_file_t *)file;
361372
_mutex.lock();
362373
LFS_INFO("file_read(%p, %p, %d)", file, buffer, len);
@@ -366,7 +377,8 @@ ssize_t LittleFileSystem::file_read(fs_file_t file, void *buffer, size_t len) {
366377
return lfs_toerror(res);
367378
}
368379

369-
ssize_t LittleFileSystem::file_write(fs_file_t file, const void *buffer, size_t len) {
380+
ssize_t LittleFileSystem::file_write(fs_file_t file, const void *buffer, size_t len)
381+
{
370382
lfs_file_t *f = (lfs_file_t *)file;
371383
_mutex.lock();
372384
LFS_INFO("file_write(%p, %p, %d)", file, buffer, len);
@@ -376,7 +388,8 @@ ssize_t LittleFileSystem::file_write(fs_file_t file, const void *buffer, size_t
376388
return lfs_toerror(res);
377389
}
378390

379-
int LittleFileSystem::file_sync(fs_file_t file) {
391+
int LittleFileSystem::file_sync(fs_file_t file)
392+
{
380393
lfs_file_t *f = (lfs_file_t *)file;
381394
_mutex.lock();
382395
LFS_INFO("file_sync(%p)", file);
@@ -386,7 +399,8 @@ int LittleFileSystem::file_sync(fs_file_t file) {
386399
return lfs_toerror(err);
387400
}
388401

389-
off_t LittleFileSystem::file_seek(fs_file_t file, off_t offset, int whence) {
402+
off_t LittleFileSystem::file_seek(fs_file_t file, off_t offset, int whence)
403+
{
390404
lfs_file_t *f = (lfs_file_t *)file;
391405
_mutex.lock();
392406
LFS_INFO("file_seek(%p, %ld, %d)", file, offset, whence);
@@ -396,7 +410,8 @@ off_t LittleFileSystem::file_seek(fs_file_t file, off_t offset, int whence) {
396410
return lfs_toerror(res);
397411
}
398412

399-
off_t LittleFileSystem::file_tell(fs_file_t file) {
413+
off_t LittleFileSystem::file_tell(fs_file_t file)
414+
{
400415
lfs_file_t *f = (lfs_file_t *)file;
401416
_mutex.lock();
402417
LFS_INFO("file_tell(%p)", file);
@@ -406,7 +421,8 @@ off_t LittleFileSystem::file_tell(fs_file_t file) {
406421
return lfs_toerror(res);
407422
}
408423

409-
off_t LittleFileSystem::file_size(fs_file_t file) {
424+
off_t LittleFileSystem::file_size(fs_file_t file)
425+
{
410426
lfs_file_t *f = (lfs_file_t *)file;
411427
_mutex.lock();
412428
LFS_INFO("file_size(%p)", file);
@@ -418,7 +434,8 @@ off_t LittleFileSystem::file_size(fs_file_t file) {
418434

419435

420436
////// Dir operations //////
421-
int LittleFileSystem::dir_open(fs_dir_t *dir, const char *path) {
437+
int LittleFileSystem::dir_open(fs_dir_t *dir, const char *path)
438+
{
422439
lfs_dir_t *d = new lfs_dir_t;
423440
_mutex.lock();
424441
LFS_INFO("dir_open(%p, \"%s\")", *dir, path);
@@ -433,7 +450,8 @@ int LittleFileSystem::dir_open(fs_dir_t *dir, const char *path) {
433450
return lfs_toerror(err);
434451
}
435452

436-
int LittleFileSystem::dir_close(fs_dir_t dir) {
453+
int LittleFileSystem::dir_close(fs_dir_t dir)
454+
{
437455
lfs_dir_t *d = (lfs_dir_t *)dir;
438456
_mutex.lock();
439457
LFS_INFO("dir_close(%p)", dir);
@@ -444,7 +462,8 @@ int LittleFileSystem::dir_close(fs_dir_t dir) {
444462
return lfs_toerror(err);
445463
}
446464

447-
ssize_t LittleFileSystem::dir_read(fs_dir_t dir, struct dirent *ent) {
465+
ssize_t LittleFileSystem::dir_read(fs_dir_t dir, struct dirent *ent)
466+
{
448467
lfs_dir_t *d = (lfs_dir_t *)dir;
449468
struct lfs_info info;
450469
_mutex.lock();
@@ -459,7 +478,8 @@ ssize_t LittleFileSystem::dir_read(fs_dir_t dir, struct dirent *ent) {
459478
return lfs_toerror(res);
460479
}
461480

462-
void LittleFileSystem::dir_seek(fs_dir_t dir, off_t offset) {
481+
void LittleFileSystem::dir_seek(fs_dir_t dir, off_t offset)
482+
{
463483
lfs_dir_t *d = (lfs_dir_t *)dir;
464484
_mutex.lock();
465485
LFS_INFO("dir_seek(%p, %ld)", dir, offset);
@@ -468,7 +488,8 @@ void LittleFileSystem::dir_seek(fs_dir_t dir, off_t offset) {
468488
_mutex.unlock();
469489
}
470490

471-
off_t LittleFileSystem::dir_tell(fs_dir_t dir) {
491+
off_t LittleFileSystem::dir_tell(fs_dir_t dir)
492+
{
472493
lfs_dir_t *d = (lfs_dir_t *)dir;
473494
_mutex.lock();
474495
LFS_INFO("dir_tell(%p)", dir);
@@ -478,7 +499,8 @@ off_t LittleFileSystem::dir_tell(fs_dir_t dir) {
478499
return lfs_toerror(res);
479500
}
480501

481-
void LittleFileSystem::dir_rewind(fs_dir_t dir) {
502+
void LittleFileSystem::dir_rewind(fs_dir_t dir)
503+
{
482504
lfs_dir_t *d = (lfs_dir_t *)dir;
483505
_mutex.lock();
484506
LFS_INFO("dir_rewind(%p)", dir);

LittleFileSystem.h

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,17 @@
11
/* mbed Microcontroller Library
2-
* Copyright (c) 2006-2012 ARM Limited
2+
* Copyright (c) 2017 ARM Limited
33
*
4-
* Permission is hereby granted, free of charge, to any person obtaining a copy
5-
* of this software and associated documentation files (the "Software"), to deal
6-
* in the Software without restriction, including without limitation the rights
7-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8-
* copies of the Software, and to permit persons to whom the Software is
9-
* furnished to do so, subject to the following conditions:
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
107
*
11-
* The above copyright notice and this permission notice shall be included in
12-
* all copies or substantial portions of the Software.
8+
* http://www.apache.org/licenses/LICENSE-2.0
139
*
14-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20-
* SOFTWARE.
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
2115
*/
2216
#ifndef MBED_LFSFILESYSTEM_H
2317
#define MBED_LFSFILESYSTEM_H

0 commit comments

Comments
 (0)