mirror of https://github.com/ARMmbed/mbed-os.git
littlefs: fix coding style
parent
bc4101e5f3
commit
20646d3da1
|
@ -33,17 +33,28 @@ extern "C" void lfs_crc(uint32_t *crc, const void *buffer, size_t size)
|
|||
static int lfs_toerror(int err)
|
||||
{
|
||||
switch (err) {
|
||||
case LFS_ERR_OK: return 0;
|
||||
case LFS_ERR_IO: return -EIO;
|
||||
case LFS_ERR_NOENT: return -ENOENT;
|
||||
case LFS_ERR_EXIST: return -EEXIST;
|
||||
case LFS_ERR_NOTDIR: return -ENOTDIR;
|
||||
case LFS_ERR_ISDIR: return -EISDIR;
|
||||
case LFS_ERR_INVAL: return -EINVAL;
|
||||
case LFS_ERR_NOSPC: return -ENOSPC;
|
||||
case LFS_ERR_NOMEM: return -ENOMEM;
|
||||
case LFS_ERR_CORRUPT: return -EILSEQ;
|
||||
default: return err;
|
||||
case LFS_ERR_OK:
|
||||
return 0;
|
||||
case LFS_ERR_IO:
|
||||
return -EIO;
|
||||
case LFS_ERR_NOENT:
|
||||
return -ENOENT;
|
||||
case LFS_ERR_EXIST:
|
||||
return -EEXIST;
|
||||
case LFS_ERR_NOTDIR:
|
||||
return -ENOTDIR;
|
||||
case LFS_ERR_ISDIR:
|
||||
return -EISDIR;
|
||||
case LFS_ERR_INVAL:
|
||||
return -EINVAL;
|
||||
case LFS_ERR_NOSPC:
|
||||
return -ENOSPC;
|
||||
case LFS_ERR_NOMEM:
|
||||
return -ENOMEM;
|
||||
case LFS_ERR_CORRUPT:
|
||||
return -EILSEQ;
|
||||
default:
|
||||
return err;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -62,10 +73,14 @@ static int lfs_fromflags(int flags)
|
|||
static int lfs_fromwhence(int whence)
|
||||
{
|
||||
switch (whence) {
|
||||
case SEEK_SET: return LFS_SEEK_SET;
|
||||
case SEEK_CUR: return LFS_SEEK_CUR;
|
||||
case SEEK_END: return LFS_SEEK_END;
|
||||
default: return whence;
|
||||
case SEEK_SET:
|
||||
return LFS_SEEK_SET;
|
||||
case SEEK_CUR:
|
||||
return LFS_SEEK_CUR;
|
||||
case SEEK_END:
|
||||
return LFS_SEEK_END;
|
||||
default:
|
||||
return whence;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -73,31 +88,39 @@ static int lfs_tomode(int type)
|
|||
{
|
||||
int mode = S_IRWXU | S_IRWXG | S_IRWXO;
|
||||
switch (type) {
|
||||
case LFS_TYPE_DIR: return mode | S_IFDIR;
|
||||
case LFS_TYPE_REG: return mode | S_IFREG;
|
||||
default: return 0;
|
||||
case LFS_TYPE_DIR:
|
||||
return mode | S_IFDIR;
|
||||
case LFS_TYPE_REG:
|
||||
return mode | S_IFREG;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
static int lfs_totype(int type)
|
||||
{
|
||||
switch (type) {
|
||||
case LFS_TYPE_DIR: return DT_DIR;
|
||||
case LFS_TYPE_REG: return DT_REG;
|
||||
default: return DT_UNKNOWN;
|
||||
case LFS_TYPE_DIR:
|
||||
return DT_DIR;
|
||||
case LFS_TYPE_REG:
|
||||
return DT_REG;
|
||||
default:
|
||||
return DT_UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
////// Block device operations //////
|
||||
static int lfs_bd_read(const struct lfs_config *c, lfs_block_t block,
|
||||
lfs_off_t off, void *buffer, lfs_size_t size) {
|
||||
lfs_off_t off, void *buffer, lfs_size_t size)
|
||||
{
|
||||
BlockDevice *bd = (BlockDevice *)c->context;
|
||||
return bd->read(buffer, (bd_addr_t)block * c->block_size + off, size);
|
||||
}
|
||||
|
||||
static int lfs_bd_prog(const struct lfs_config *c, lfs_block_t block,
|
||||
lfs_off_t off, const void *buffer, lfs_size_t size) {
|
||||
lfs_off_t off, const void *buffer, lfs_size_t size)
|
||||
{
|
||||
BlockDevice *bd = (BlockDevice *)c->context;
|
||||
return bd->program(buffer, (bd_addr_t)block * c->block_size + off, size);
|
||||
}
|
||||
|
@ -125,13 +148,15 @@ LittleFileSystem::LittleFileSystem(const char *name, BlockDevice *bd,
|
|||
, _read_size(read_size)
|
||||
, _prog_size(prog_size)
|
||||
, _block_size(block_size)
|
||||
, _lookahead(lookahead) {
|
||||
, _lookahead(lookahead)
|
||||
{
|
||||
if (bd) {
|
||||
mount(bd);
|
||||
}
|
||||
}
|
||||
|
||||
LittleFileSystem::~LittleFileSystem() {
|
||||
LittleFileSystem::~LittleFileSystem()
|
||||
{
|
||||
// nop if unmounted
|
||||
unmount();
|
||||
}
|
||||
|
@ -212,7 +237,8 @@ int LittleFileSystem::unmount()
|
|||
|
||||
int LittleFileSystem::format(BlockDevice *bd,
|
||||
lfs_size_t read_size, lfs_size_t prog_size,
|
||||
lfs_size_t block_size, lfs_size_t lookahead) {
|
||||
lfs_size_t block_size, lfs_size_t lookahead)
|
||||
{
|
||||
LFS_INFO("format(%p, %ld, %ld, %ld, %ld)",
|
||||
bd, read_size, prog_size, block_size, lookahead);
|
||||
int err = bd->init();
|
||||
|
|
Loading…
Reference in New Issue