|
@@ -1,40 +1,30 @@
|
|
|
-/*
|
|
|
|
|
- * File : dfs_lfs.c
|
|
|
|
|
- * This file is part of Suzhou Allen
|
|
|
|
|
- * COPYRIGHT (C) 2006 - 2017, Allen Development Team
|
|
|
|
|
- *
|
|
|
|
|
- * Change Logs:
|
|
|
|
|
- * Date Author Notes
|
|
|
|
|
- * 2018��2��11�� Urey first version
|
|
|
|
|
- */
|
|
|
|
|
-#include <rtthread.h>
|
|
|
|
|
#include <rtdevice.h>
|
|
#include <rtdevice.h>
|
|
|
|
|
+#include <rtthread.h>
|
|
|
|
|
|
|
|
-#include <dfs_fs.h>
|
|
|
|
|
#include <dfs_file.h>
|
|
#include <dfs_file.h>
|
|
|
|
|
+#include <dfs_fs.h>
|
|
|
|
|
|
|
|
#include "lfs.h"
|
|
#include "lfs.h"
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
#include <stdio.h>
|
|
|
#include <string.h>
|
|
#include <string.h>
|
|
|
|
|
|
|
|
-
|
|
|
|
|
-#define RT_DFS_LFS_DRIVES 1
|
|
|
|
|
|
|
+#define RT_DFS_LFS_DRIVES 1
|
|
|
|
|
|
|
|
#ifndef LFS_READ_SIZE
|
|
#ifndef LFS_READ_SIZE
|
|
|
-# define LFS_READ_SIZE 128
|
|
|
|
|
|
|
+#define LFS_READ_SIZE 128
|
|
|
#endif
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef LFS_PROG_SIZE
|
|
#ifndef LFS_PROG_SIZE
|
|
|
-# define LFS_PROG_SIZE 256
|
|
|
|
|
|
|
+#define LFS_PROG_SIZE 256
|
|
|
#endif
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef LFS_BLOCK_SIZE
|
|
#ifndef LFS_BLOCK_SIZE
|
|
|
-# define LFS_BLOCK_SIZE 512
|
|
|
|
|
|
|
+#define LFS_BLOCK_SIZE 512
|
|
|
#endif
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef LFS_LOOKAHEAD
|
|
#ifndef LFS_LOOKAHEAD
|
|
|
-# define LFS_LOOKAHEAD 512
|
|
|
|
|
|
|
+#define LFS_LOOKAHEAD 512
|
|
|
#endif
|
|
#endif
|
|
|
|
|
|
|
|
typedef struct _dfs_lfs_s
|
|
typedef struct _dfs_lfs_s
|
|
@@ -45,19 +35,19 @@ typedef struct _dfs_lfs_s
|
|
|
|
|
|
|
|
typedef struct _dfs_lfs_fd_s
|
|
typedef struct _dfs_lfs_fd_s
|
|
|
{
|
|
{
|
|
|
- struct lfs *lfs;
|
|
|
|
|
|
|
+ struct lfs* lfs;
|
|
|
union
|
|
union
|
|
|
{
|
|
{
|
|
|
struct lfs_file file;
|
|
struct lfs_file file;
|
|
|
- struct lfs_dir dir;
|
|
|
|
|
|
|
+ struct lfs_dir dir;
|
|
|
} u;
|
|
} u;
|
|
|
} dfs_lfs_fd_t;
|
|
} dfs_lfs_fd_t;
|
|
|
|
|
|
|
|
-static struct _dfs_lfs_s* _lfs_mount_tbl[RT_DFS_LFS_DRIVES] = {0};
|
|
|
|
|
|
|
+static struct _dfs_lfs_s* _lfs_mount_tbl[RT_DFS_LFS_DRIVES] = { 0 };
|
|
|
|
|
|
|
|
// Read a region in a block. Negative error codes are propogated
|
|
// Read a region in a block. Negative error codes are propogated
|
|
|
// to the user.
|
|
// to the user.
|
|
|
-int _lfs_flash_read(const struct lfs_config *c, lfs_block_t block, lfs_off_t off, void *buffer, lfs_size_t size)
|
|
|
|
|
|
|
+static int _lfs_flash_read(const struct lfs_config* c, lfs_block_t block, lfs_off_t off, void* buffer, lfs_size_t size)
|
|
|
{
|
|
{
|
|
|
struct rt_mtd_nor_device* mtd_nor;
|
|
struct rt_mtd_nor_device* mtd_nor;
|
|
|
|
|
|
|
@@ -65,7 +55,7 @@ int _lfs_flash_read(const struct lfs_config *c, lfs_block_t block, lfs_off_t off
|
|
|
RT_ASSERT(c->context != RT_NULL);
|
|
RT_ASSERT(c->context != RT_NULL);
|
|
|
|
|
|
|
|
mtd_nor = (struct rt_mtd_nor_device*)c->context;
|
|
mtd_nor = (struct rt_mtd_nor_device*)c->context;
|
|
|
- rt_mtd_nor_read(mtd_nor,block * c->block_size + off,buffer,size);
|
|
|
|
|
|
|
+ rt_mtd_nor_read(mtd_nor, block * c->block_size + off, buffer, size);
|
|
|
|
|
|
|
|
return LFS_ERR_OK;
|
|
return LFS_ERR_OK;
|
|
|
}
|
|
}
|
|
@@ -73,7 +63,7 @@ int _lfs_flash_read(const struct lfs_config *c, lfs_block_t block, lfs_off_t off
|
|
|
// Program a region in a block. The block must have previously
|
|
// Program a region in a block. The block must have previously
|
|
|
// been erased. Negative error codes are propogated to the user.
|
|
// been erased. Negative error codes are propogated to the user.
|
|
|
// May return LFS_ERR_CORRUPT if the block should be considered bad.
|
|
// May return LFS_ERR_CORRUPT if the block should be considered bad.
|
|
|
-int _lfs_flash_prog(const struct lfs_config *c, lfs_block_t block, lfs_off_t off, const void *buffer, lfs_size_t size)
|
|
|
|
|
|
|
+static int _lfs_flash_prog(const struct lfs_config* c, lfs_block_t block, lfs_off_t off, const void* buffer, lfs_size_t size)
|
|
|
{
|
|
{
|
|
|
struct rt_mtd_nor_device* mtd_nor;
|
|
struct rt_mtd_nor_device* mtd_nor;
|
|
|
|
|
|
|
@@ -81,7 +71,7 @@ int _lfs_flash_prog(const struct lfs_config *c, lfs_block_t block, lfs_off_t off
|
|
|
RT_ASSERT(c->context != RT_NULL);
|
|
RT_ASSERT(c->context != RT_NULL);
|
|
|
|
|
|
|
|
mtd_nor = (struct rt_mtd_nor_device*)c->context;
|
|
mtd_nor = (struct rt_mtd_nor_device*)c->context;
|
|
|
- rt_mtd_nor_write(mtd_nor,block*c->block_size + off,buffer,size);
|
|
|
|
|
|
|
+ rt_mtd_nor_write(mtd_nor, block * c->block_size + off, buffer, size);
|
|
|
|
|
|
|
|
return LFS_ERR_OK;
|
|
return LFS_ERR_OK;
|
|
|
}
|
|
}
|
|
@@ -90,7 +80,7 @@ int _lfs_flash_prog(const struct lfs_config *c, lfs_block_t block, lfs_off_t off
|
|
|
// The state of an erased block is undefined. Negative error codes
|
|
// The state of an erased block is undefined. Negative error codes
|
|
|
// are propogated to the user.
|
|
// are propogated to the user.
|
|
|
// May return LFS_ERR_CORRUPT if the block should be considered bad.
|
|
// May return LFS_ERR_CORRUPT if the block should be considered bad.
|
|
|
-int _lfs_flash_erase(const struct lfs_config *c, lfs_block_t block)
|
|
|
|
|
|
|
+static int _lfs_flash_erase(const struct lfs_config* c, lfs_block_t block)
|
|
|
{
|
|
{
|
|
|
struct rt_mtd_nor_device* mtd_nor;
|
|
struct rt_mtd_nor_device* mtd_nor;
|
|
|
|
|
|
|
@@ -98,14 +88,14 @@ int _lfs_flash_erase(const struct lfs_config *c, lfs_block_t block)
|
|
|
RT_ASSERT(c->context != RT_NULL);
|
|
RT_ASSERT(c->context != RT_NULL);
|
|
|
|
|
|
|
|
mtd_nor = (struct rt_mtd_nor_device*)c->context;
|
|
mtd_nor = (struct rt_mtd_nor_device*)c->context;
|
|
|
- rt_mtd_nor_erase_block(mtd_nor,block * c->block_size,c->block_size);
|
|
|
|
|
|
|
+ rt_mtd_nor_erase_block(mtd_nor, block * c->block_size, c->block_size);
|
|
|
|
|
|
|
|
return LFS_ERR_OK;
|
|
return LFS_ERR_OK;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// Sync the state of the underlying block device. Negative error codes
|
|
// Sync the state of the underlying block device. Negative error codes
|
|
|
// are propogated to the user.
|
|
// are propogated to the user.
|
|
|
-int _lfs_flash_sync(const struct lfs_config *c)
|
|
|
|
|
|
|
+static int _lfs_flash_sync(const struct lfs_config* c)
|
|
|
{
|
|
{
|
|
|
return LFS_ERR_OK;
|
|
return LFS_ERR_OK;
|
|
|
}
|
|
}
|
|
@@ -120,9 +110,9 @@ static int get_disk(rt_device_t dev_id)
|
|
|
|
|
|
|
|
if (dev_id == RT_NULL)
|
|
if (dev_id == RT_NULL)
|
|
|
{
|
|
{
|
|
|
- for (index = 0; index < RT_DFS_LFS_DRIVES; index ++)
|
|
|
|
|
|
|
+ for (index = 0; index < RT_DFS_LFS_DRIVES; index++)
|
|
|
{
|
|
{
|
|
|
- if(_lfs_mount_tbl[index] == RT_NULL)
|
|
|
|
|
|
|
+ if (_lfs_mount_tbl[index] == RT_NULL)
|
|
|
{
|
|
{
|
|
|
return index;
|
|
return index;
|
|
|
}
|
|
}
|
|
@@ -130,10 +120,10 @@ static int get_disk(rt_device_t dev_id)
|
|
|
}
|
|
}
|
|
|
else
|
|
else
|
|
|
{
|
|
{
|
|
|
- for (index = 0; index < RT_DFS_LFS_DRIVES; index ++)
|
|
|
|
|
|
|
+ for (index = 0; index < RT_DFS_LFS_DRIVES; index++)
|
|
|
{
|
|
{
|
|
|
if ((_lfs_mount_tbl[index] != RT_NULL)
|
|
if ((_lfs_mount_tbl[index] != RT_NULL)
|
|
|
- && (_lfs_mount_tbl[index]->cfg.context == (void *)dev_id))
|
|
|
|
|
|
|
+ && (_lfs_mount_tbl[index]->cfg.context == (void*)dev_id))
|
|
|
{
|
|
{
|
|
|
return index;
|
|
return index;
|
|
|
}
|
|
}
|
|
@@ -151,35 +141,71 @@ static int lfs_result_to_dfs(int result)
|
|
|
{
|
|
{
|
|
|
case LFS_ERR_OK:
|
|
case LFS_ERR_OK:
|
|
|
break;
|
|
break;
|
|
|
- case LFS_ERR_IO : status = -EIO; break; // Error during device operation
|
|
|
|
|
- case LFS_ERR_NOENT : status = -ENOENT; break; // No directory entry
|
|
|
|
|
- case LFS_ERR_EXIST : status = -EEXIST; break; // Entry already exists
|
|
|
|
|
- case LFS_ERR_NOTDIR : status = -ENOTDIR; break; // Entry is not a dir
|
|
|
|
|
- case LFS_ERR_ISDIR : status = -EISDIR; break; // Entry is a dir
|
|
|
|
|
- case LFS_ERR_NOTEMPTY : status = -ENOTEMPTY;break; // Dir is not empty
|
|
|
|
|
- case LFS_ERR_BADF : status = -EBADF; break; // Bad file number
|
|
|
|
|
- case LFS_ERR_INVAL : status = -EINVAL; break; // Invalid parameter
|
|
|
|
|
- case LFS_ERR_NOSPC : status = -ENOSPC; break; // No space left on device
|
|
|
|
|
- case LFS_ERR_NOMEM : status = -ENOMEM; break; // No more memory available
|
|
|
|
|
- case LFS_ERR_CORRUPT : status = -52; break; // Corrupted
|
|
|
|
|
- default : status = -EIO; break;
|
|
|
|
|
|
|
+
|
|
|
|
|
+ case LFS_ERR_IO:
|
|
|
|
|
+ status = -EIO;
|
|
|
|
|
+ break; // Error during device operation
|
|
|
|
|
+
|
|
|
|
|
+ case LFS_ERR_NOENT:
|
|
|
|
|
+ status = -ENOENT;
|
|
|
|
|
+ break; // No directory entry
|
|
|
|
|
+
|
|
|
|
|
+ case LFS_ERR_EXIST:
|
|
|
|
|
+ status = -EEXIST;
|
|
|
|
|
+ break; // Entry already exists
|
|
|
|
|
+
|
|
|
|
|
+ case LFS_ERR_NOTDIR:
|
|
|
|
|
+ status = -ENOTDIR;
|
|
|
|
|
+ break; // Entry is not a dir
|
|
|
|
|
+
|
|
|
|
|
+ case LFS_ERR_ISDIR:
|
|
|
|
|
+ status = -EISDIR;
|
|
|
|
|
+ break; // Entry is a dir
|
|
|
|
|
+
|
|
|
|
|
+ case LFS_ERR_NOTEMPTY:
|
|
|
|
|
+ status = -ENOTEMPTY;
|
|
|
|
|
+ break; // Dir is not empty
|
|
|
|
|
+
|
|
|
|
|
+ case LFS_ERR_BADF:
|
|
|
|
|
+ status = -EBADF;
|
|
|
|
|
+ break; // Bad file number
|
|
|
|
|
+
|
|
|
|
|
+ case LFS_ERR_INVAL:
|
|
|
|
|
+ status = -EINVAL;
|
|
|
|
|
+ break; // Invalid parameter
|
|
|
|
|
+
|
|
|
|
|
+ case LFS_ERR_NOSPC:
|
|
|
|
|
+ status = -ENOSPC;
|
|
|
|
|
+ break; // No space left on device
|
|
|
|
|
+
|
|
|
|
|
+ case LFS_ERR_NOMEM:
|
|
|
|
|
+ status = -ENOMEM;
|
|
|
|
|
+ break; // No more memory available
|
|
|
|
|
+
|
|
|
|
|
+ case LFS_ERR_CORRUPT:
|
|
|
|
|
+ status = -52;
|
|
|
|
|
+ break; // Corrupted
|
|
|
|
|
+
|
|
|
|
|
+ default:
|
|
|
|
|
+ status = -EIO;
|
|
|
|
|
+ break;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
return status;
|
|
return status;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-void _dfs_lfs_load_config(dfs_lfs_t *dfs_lfs,struct rt_mtd_nor_device *mtd_nor)
|
|
|
|
|
|
|
+static void _dfs_lfs_load_config(dfs_lfs_t* dfs_lfs, struct rt_mtd_nor_device* mtd_nor)
|
|
|
{
|
|
{
|
|
|
- dfs_lfs->cfg.context = (void *)mtd_nor;
|
|
|
|
|
|
|
+ dfs_lfs->cfg.context = (void*)mtd_nor;
|
|
|
|
|
|
|
|
- //MTD device can access 1 byte....
|
|
|
|
|
|
|
+ // MTD device can access 1 byte....
|
|
|
dfs_lfs->cfg.read_size = 1;
|
|
dfs_lfs->cfg.read_size = 1;
|
|
|
if (dfs_lfs->cfg.read_size < LFS_READ_SIZE)
|
|
if (dfs_lfs->cfg.read_size < LFS_READ_SIZE)
|
|
|
{
|
|
{
|
|
|
dfs_lfs->cfg.read_size = LFS_READ_SIZE;
|
|
dfs_lfs->cfg.read_size = LFS_READ_SIZE;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- //MTD device can access 1 byte....
|
|
|
|
|
|
|
+ // MTD device can access 1 byte....
|
|
|
dfs_lfs->cfg.prog_size = 1;
|
|
dfs_lfs->cfg.prog_size = 1;
|
|
|
if (dfs_lfs->cfg.prog_size < LFS_PROG_SIZE)
|
|
if (dfs_lfs->cfg.prog_size < LFS_PROG_SIZE)
|
|
|
{
|
|
{
|
|
@@ -200,16 +226,16 @@ void _dfs_lfs_load_config(dfs_lfs_t *dfs_lfs,struct rt_mtd_nor_device *mtd_nor)
|
|
|
dfs_lfs->cfg.lookahead = LFS_LOOKAHEAD;
|
|
dfs_lfs->cfg.lookahead = LFS_LOOKAHEAD;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- dfs_lfs->cfg.read = &_lfs_flash_read;
|
|
|
|
|
- dfs_lfs->cfg.prog = &_lfs_flash_prog;
|
|
|
|
|
- dfs_lfs->cfg.erase = &_lfs_flash_erase;
|
|
|
|
|
- dfs_lfs->cfg.sync = &_lfs_flash_sync;
|
|
|
|
|
|
|
+ dfs_lfs->cfg.read = &_lfs_flash_read;
|
|
|
|
|
+ dfs_lfs->cfg.prog = &_lfs_flash_prog;
|
|
|
|
|
+ dfs_lfs->cfg.erase = &_lfs_flash_erase;
|
|
|
|
|
+ dfs_lfs->cfg.sync = &_lfs_flash_sync;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-static int dfs_lfs_mount(struct dfs_filesystem *dfs, unsigned long rwflag, const void *data)
|
|
|
|
|
|
|
+static int dfs_lfs_mount(struct dfs_filesystem* dfs, unsigned long rwflag, const void* data)
|
|
|
{
|
|
{
|
|
|
int result;
|
|
int result;
|
|
|
- dfs_lfs_t *dfs_lfs;
|
|
|
|
|
|
|
+ dfs_lfs_t* dfs_lfs;
|
|
|
int index;
|
|
int index;
|
|
|
|
|
|
|
|
/* Check Device Type */
|
|
/* Check Device Type */
|
|
@@ -231,28 +257,26 @@ static int dfs_lfs_mount(struct dfs_filesystem *dfs, unsigned long rwflag, const
|
|
|
if (dfs_lfs == RT_NULL)
|
|
if (dfs_lfs == RT_NULL)
|
|
|
{
|
|
{
|
|
|
rt_kprintf("ERROR:no memory!\n");
|
|
rt_kprintf("ERROR:no memory!\n");
|
|
|
-
|
|
|
|
|
_lfs_mount_tbl[index] = RT_NULL;
|
|
_lfs_mount_tbl[index] = RT_NULL;
|
|
|
return -ENOMEM;
|
|
return -ENOMEM;
|
|
|
}
|
|
}
|
|
|
- rt_memset(dfs_lfs,0,sizeof(dfs_lfs_t));
|
|
|
|
|
|
|
+ rt_memset(dfs_lfs, 0, sizeof(dfs_lfs_t));
|
|
|
|
|
|
|
|
{ /* init cfg data */
|
|
{ /* init cfg data */
|
|
|
- struct rt_mtd_nor_device *mtd_nor = (struct rt_mtd_nor_device *)dfs->dev_id;
|
|
|
|
|
-
|
|
|
|
|
- _dfs_lfs_load_config(dfs_lfs,mtd_nor);
|
|
|
|
|
|
|
+ struct rt_mtd_nor_device* mtd_nor = (struct rt_mtd_nor_device*)dfs->dev_id;
|
|
|
|
|
|
|
|
|
|
+ _dfs_lfs_load_config(dfs_lfs, mtd_nor);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/* mount lfs*/
|
|
/* mount lfs*/
|
|
|
- result = lfs_mount(&dfs_lfs->lfs,&dfs_lfs->cfg);
|
|
|
|
|
|
|
+ result = lfs_mount(&dfs_lfs->lfs, &dfs_lfs->cfg);
|
|
|
if (result == LFS_ERR_OK)
|
|
if (result == LFS_ERR_OK)
|
|
|
{
|
|
{
|
|
|
/* save device */
|
|
/* save device */
|
|
|
_lfs_mount_tbl[index] = dfs_lfs;
|
|
_lfs_mount_tbl[index] = dfs_lfs;
|
|
|
|
|
|
|
|
/* mount succeed! */
|
|
/* mount succeed! */
|
|
|
- dfs->data = (void *)dfs_lfs;
|
|
|
|
|
|
|
+ dfs->data = (void*)dfs_lfs;
|
|
|
|
|
|
|
|
return RT_EOK;
|
|
return RT_EOK;
|
|
|
}
|
|
}
|
|
@@ -263,15 +287,15 @@ static int dfs_lfs_mount(struct dfs_filesystem *dfs, unsigned long rwflag, const
|
|
|
return -EIO;
|
|
return -EIO;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-static int dfs_lfs_unmount(struct dfs_filesystem *dfs)
|
|
|
|
|
|
|
+static int dfs_lfs_unmount(struct dfs_filesystem* dfs)
|
|
|
{
|
|
{
|
|
|
int index;
|
|
int index;
|
|
|
- dfs_lfs_t *dfs_lfs = RT_NULL;
|
|
|
|
|
|
|
+ dfs_lfs_t* dfs_lfs = RT_NULL;
|
|
|
|
|
|
|
|
RT_ASSERT(dfs != RT_NULL);
|
|
RT_ASSERT(dfs != RT_NULL);
|
|
|
RT_ASSERT(dfs->data != RT_NULL);
|
|
RT_ASSERT(dfs->data != RT_NULL);
|
|
|
|
|
|
|
|
- dfs_lfs = (dfs_lfs_t *)dfs->data;
|
|
|
|
|
|
|
+ dfs_lfs = (dfs_lfs_t*)dfs->data;
|
|
|
|
|
|
|
|
/* find the device index and then umount it */
|
|
/* find the device index and then umount it */
|
|
|
index = get_disk(dfs->dev_id);
|
|
index = get_disk(dfs->dev_id);
|
|
@@ -292,7 +316,7 @@ static int dfs_lfs_unmount(struct dfs_filesystem *dfs)
|
|
|
|
|
|
|
|
static int dfs_lfs_mkfs(rt_device_t dev_id)
|
|
static int dfs_lfs_mkfs(rt_device_t dev_id)
|
|
|
{
|
|
{
|
|
|
- dfs_lfs_t *dfs_lfs = RT_NULL;
|
|
|
|
|
|
|
+ dfs_lfs_t* dfs_lfs = RT_NULL;
|
|
|
int result;
|
|
int result;
|
|
|
int index;
|
|
int index;
|
|
|
|
|
|
|
@@ -331,18 +355,19 @@ static int dfs_lfs_mkfs(rt_device_t dev_id)
|
|
|
_lfs_mount_tbl[index] = RT_NULL;
|
|
_lfs_mount_tbl[index] = RT_NULL;
|
|
|
return -ENOMEM;
|
|
return -ENOMEM;
|
|
|
}
|
|
}
|
|
|
- rt_memset(dfs_lfs,0,sizeof(dfs_lfs_t));
|
|
|
|
|
|
|
+ rt_memset(dfs_lfs, 0, sizeof(dfs_lfs_t));
|
|
|
|
|
|
|
|
{ /* init cfg data */
|
|
{ /* init cfg data */
|
|
|
- struct rt_mtd_nor_device *mtd_nor = (struct rt_mtd_nor_device *)dev_id;
|
|
|
|
|
|
|
+ struct rt_mtd_nor_device* mtd_nor =
|
|
|
|
|
+ (struct rt_mtd_nor_device*)dev_id;
|
|
|
|
|
|
|
|
- _dfs_lfs_load_config(dfs_lfs,mtd_nor);
|
|
|
|
|
|
|
+ _dfs_lfs_load_config(dfs_lfs, mtd_nor);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
else
|
|
else
|
|
|
{
|
|
{
|
|
|
- dfs_lfs = _lfs_mount_tbl[index];
|
|
|
|
|
|
|
+ dfs_lfs = _lfs_mount_tbl[index];
|
|
|
_lfs_mount_tbl[index] = RT_NULL;
|
|
_lfs_mount_tbl[index] = RT_NULL;
|
|
|
|
|
|
|
|
/* unmount it */
|
|
/* unmount it */
|
|
@@ -350,7 +375,7 @@ static int dfs_lfs_mkfs(rt_device_t dev_id)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/* format flash device */
|
|
/* format flash device */
|
|
|
- result = lfs_format(&dfs_lfs->lfs,&dfs_lfs->cfg);
|
|
|
|
|
|
|
+ result = lfs_format(&dfs_lfs->lfs, &dfs_lfs->cfg);
|
|
|
if (result != LFS_ERR_OK)
|
|
if (result != LFS_ERR_OK)
|
|
|
{
|
|
{
|
|
|
return lfs_result_to_dfs(result);
|
|
return lfs_result_to_dfs(result);
|
|
@@ -360,15 +385,15 @@ static int dfs_lfs_mkfs(rt_device_t dev_id)
|
|
|
return RT_EOK;
|
|
return RT_EOK;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-static int _dfs_lfs_statfs_count(void *p, lfs_block_t b)
|
|
|
|
|
|
|
+static int _dfs_lfs_statfs_count(void* p, lfs_block_t b)
|
|
|
{
|
|
{
|
|
|
- *(lfs_size_t *) p += 1;
|
|
|
|
|
|
|
+ *(lfs_size_t*)p += 1;
|
|
|
return 0;
|
|
return 0;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-static int dfs_lfs_statfs(struct dfs_filesystem *dfs, struct statfs *buf)
|
|
|
|
|
|
|
+static int dfs_lfs_statfs(struct dfs_filesystem* dfs, struct statfs* buf)
|
|
|
{
|
|
{
|
|
|
- dfs_lfs_t *dfs_lfs ;
|
|
|
|
|
|
|
+ dfs_lfs_t* dfs_lfs;
|
|
|
int result;
|
|
int result;
|
|
|
lfs_size_t in_use = 0;
|
|
lfs_size_t in_use = 0;
|
|
|
|
|
|
|
@@ -376,7 +401,7 @@ static int dfs_lfs_statfs(struct dfs_filesystem *dfs, struct statfs *buf)
|
|
|
RT_ASSERT(dfs != RT_NULL);
|
|
RT_ASSERT(dfs != RT_NULL);
|
|
|
RT_ASSERT(dfs->data != RT_NULL);
|
|
RT_ASSERT(dfs->data != RT_NULL);
|
|
|
|
|
|
|
|
- dfs_lfs = (dfs_lfs_t *)dfs->data;
|
|
|
|
|
|
|
+ dfs_lfs = (dfs_lfs_t*)dfs->data;
|
|
|
|
|
|
|
|
/* Get total sectors and free sectors */
|
|
/* Get total sectors and free sectors */
|
|
|
result = lfs_traverse(&dfs_lfs->lfs, _dfs_lfs_statfs_count, &in_use);
|
|
result = lfs_traverse(&dfs_lfs->lfs, _dfs_lfs_statfs_count, &in_use);
|
|
@@ -387,25 +412,25 @@ static int dfs_lfs_statfs(struct dfs_filesystem *dfs, struct statfs *buf)
|
|
|
|
|
|
|
|
buf->f_bsize = dfs_lfs->cfg.block_size;
|
|
buf->f_bsize = dfs_lfs->cfg.block_size;
|
|
|
buf->f_blocks = dfs_lfs->cfg.block_count;
|
|
buf->f_blocks = dfs_lfs->cfg.block_count;
|
|
|
- buf->f_bfree = dfs_lfs->cfg.block_count - in_use;
|
|
|
|
|
|
|
+ buf->f_bfree = dfs_lfs->cfg.block_count - in_use;
|
|
|
|
|
|
|
|
return RT_EOK;
|
|
return RT_EOK;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-static int dfs_lfs_unlink(struct dfs_filesystem *dfs, const char *path)
|
|
|
|
|
|
|
+static int dfs_lfs_unlink(struct dfs_filesystem* dfs, const char* path)
|
|
|
{
|
|
{
|
|
|
- dfs_lfs_t *dfs_lfs;
|
|
|
|
|
|
|
+ dfs_lfs_t* dfs_lfs;
|
|
|
int result;
|
|
int result;
|
|
|
|
|
|
|
|
RT_ASSERT(dfs != RT_NULL);
|
|
RT_ASSERT(dfs != RT_NULL);
|
|
|
RT_ASSERT(dfs->data != RT_NULL);
|
|
RT_ASSERT(dfs->data != RT_NULL);
|
|
|
- dfs_lfs = (dfs_lfs_t *)dfs->data;
|
|
|
|
|
|
|
+ dfs_lfs = (dfs_lfs_t*)dfs->data;
|
|
|
|
|
|
|
|
- result = lfs_remove(&dfs_lfs->lfs,path);
|
|
|
|
|
|
|
+ result = lfs_remove(&dfs_lfs->lfs, path);
|
|
|
return lfs_result_to_dfs(result);
|
|
return lfs_result_to_dfs(result);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-static void _dfs_lfs_tostat(struct stat *st, struct lfs_info *info)
|
|
|
|
|
|
|
+static void _dfs_lfs_tostat(struct stat* st, struct lfs_info* info)
|
|
|
{
|
|
{
|
|
|
memset(st, 0, sizeof(struct stat));
|
|
memset(st, 0, sizeof(struct stat));
|
|
|
|
|
|
|
@@ -424,21 +449,20 @@ static void _dfs_lfs_tostat(struct stat *st, struct lfs_info *info)
|
|
|
st->st_mode |= S_IFREG;
|
|
st->st_mode |= S_IFREG;
|
|
|
break;
|
|
break;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-int dfs_lfs_stat(struct dfs_filesystem *dfs, const char *path, struct stat *st)
|
|
|
|
|
|
|
+int dfs_lfs_stat(struct dfs_filesystem* dfs, const char* path, struct stat* st)
|
|
|
{
|
|
{
|
|
|
- dfs_lfs_t *dfs_lfs;
|
|
|
|
|
|
|
+ dfs_lfs_t* dfs_lfs;
|
|
|
int result;
|
|
int result;
|
|
|
struct lfs_info info;
|
|
struct lfs_info info;
|
|
|
|
|
|
|
|
RT_ASSERT(dfs != RT_NULL);
|
|
RT_ASSERT(dfs != RT_NULL);
|
|
|
RT_ASSERT(dfs->data != RT_NULL);
|
|
RT_ASSERT(dfs->data != RT_NULL);
|
|
|
- dfs_lfs = (dfs_lfs_t *)dfs->data;
|
|
|
|
|
|
|
+ dfs_lfs = (dfs_lfs_t*)dfs->data;
|
|
|
|
|
|
|
|
result = lfs_stat(&dfs_lfs->lfs, path, &info);
|
|
result = lfs_stat(&dfs_lfs->lfs, path, &info);
|
|
|
- if(result != LFS_ERR_OK)
|
|
|
|
|
|
|
+ if (result != LFS_ERR_OK)
|
|
|
{
|
|
{
|
|
|
return lfs_result_to_dfs(result);
|
|
return lfs_result_to_dfs(result);
|
|
|
}
|
|
}
|
|
@@ -447,24 +471,23 @@ int dfs_lfs_stat(struct dfs_filesystem *dfs, const char *path, struct stat *st)
|
|
|
return 0;
|
|
return 0;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-static int dfs_lfs_rename(struct dfs_filesystem *dfs, const char *from, const char *to)
|
|
|
|
|
|
|
+static int dfs_lfs_rename(struct dfs_filesystem* dfs, const char* from, const char* to)
|
|
|
{
|
|
{
|
|
|
- dfs_lfs_t *dfs_lfs;
|
|
|
|
|
|
|
+ dfs_lfs_t* dfs_lfs;
|
|
|
int result;
|
|
int result;
|
|
|
|
|
|
|
|
RT_ASSERT(dfs != RT_NULL);
|
|
RT_ASSERT(dfs != RT_NULL);
|
|
|
RT_ASSERT(dfs->data != RT_NULL);
|
|
RT_ASSERT(dfs->data != RT_NULL);
|
|
|
- dfs_lfs = (dfs_lfs_t *)dfs->data;
|
|
|
|
|
|
|
+ dfs_lfs = (dfs_lfs_t*)dfs->data;
|
|
|
|
|
|
|
|
result = lfs_rename(&dfs_lfs->lfs, from, to);
|
|
result = lfs_rename(&dfs_lfs->lfs, from, to);
|
|
|
return lfs_result_to_dfs(result);
|
|
return lfs_result_to_dfs(result);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
/******************************************************************************
|
|
/******************************************************************************
|
|
|
* file operations
|
|
* file operations
|
|
|
******************************************************************************/
|
|
******************************************************************************/
|
|
|
-static int dfs_lfs_open(struct dfs_fd *file)
|
|
|
|
|
|
|
+static int dfs_lfs_open(struct dfs_fd* file)
|
|
|
{
|
|
{
|
|
|
struct dfs_filesystem* dfs;
|
|
struct dfs_filesystem* dfs;
|
|
|
dfs_lfs_t* dfs_lfs;
|
|
dfs_lfs_t* dfs_lfs;
|
|
@@ -473,12 +496,13 @@ static int dfs_lfs_open(struct dfs_fd *file)
|
|
|
|
|
|
|
|
RT_ASSERT(file != RT_NULL);
|
|
RT_ASSERT(file != RT_NULL);
|
|
|
RT_ASSERT(file->data != RT_NULL);
|
|
RT_ASSERT(file->data != RT_NULL);
|
|
|
- dfs = (struct dfs_filesystem *) file->data;
|
|
|
|
|
- dfs_lfs = (dfs_lfs_t *)dfs->data;
|
|
|
|
|
|
|
+
|
|
|
|
|
+ dfs = (struct dfs_filesystem*)file->data;
|
|
|
|
|
+ dfs_lfs = (dfs_lfs_t*)dfs->data;
|
|
|
|
|
|
|
|
if (file->flags & O_DIRECTORY)
|
|
if (file->flags & O_DIRECTORY)
|
|
|
{
|
|
{
|
|
|
- dfs_lfs_fd_t* dfs_lfs_fd = rt_malloc(sizeof(dfs_lfs_fd_t));
|
|
|
|
|
|
|
+ dfs_lfs_fd_t* dfs_lfs_fd = rt_malloc(sizeof(dfs_lfs_fd_t));
|
|
|
if (dfs_lfs_fd == RT_NULL)
|
|
if (dfs_lfs_fd == RT_NULL)
|
|
|
{
|
|
{
|
|
|
rt_kprintf("ERROR:no memory!\n");
|
|
rt_kprintf("ERROR:no memory!\n");
|
|
@@ -486,12 +510,12 @@ static int dfs_lfs_open(struct dfs_fd *file)
|
|
|
|
|
|
|
|
goto _error_dir;
|
|
goto _error_dir;
|
|
|
}
|
|
}
|
|
|
- rt_memset(dfs_lfs_fd,0,sizeof(dfs_lfs_fd_t));
|
|
|
|
|
|
|
+ rt_memset(dfs_lfs_fd, 0, sizeof(dfs_lfs_fd_t));
|
|
|
dfs_lfs_fd->lfs = &dfs_lfs->lfs;
|
|
dfs_lfs_fd->lfs = &dfs_lfs->lfs;
|
|
|
|
|
|
|
|
if (file->flags & O_CREAT)
|
|
if (file->flags & O_CREAT)
|
|
|
{
|
|
{
|
|
|
- result = lfs_mkdir(dfs_lfs_fd->lfs,file->path);
|
|
|
|
|
|
|
+ result = lfs_mkdir(dfs_lfs_fd->lfs, file->path);
|
|
|
if (result != LFS_ERR_OK)
|
|
if (result != LFS_ERR_OK)
|
|
|
{
|
|
{
|
|
|
goto _error_dir;
|
|
goto _error_dir;
|
|
@@ -505,11 +529,11 @@ static int dfs_lfs_open(struct dfs_fd *file)
|
|
|
}
|
|
}
|
|
|
else
|
|
else
|
|
|
{
|
|
{
|
|
|
- file->data = (void *)dfs_lfs_fd;
|
|
|
|
|
|
|
+ file->data = (void*)dfs_lfs_fd;
|
|
|
return RT_EOK;
|
|
return RT_EOK;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-_error_dir:
|
|
|
|
|
|
|
+ _error_dir:
|
|
|
if (dfs_lfs_fd != RT_NULL)
|
|
if (dfs_lfs_fd != RT_NULL)
|
|
|
{
|
|
{
|
|
|
rt_free(dfs_lfs_fd);
|
|
rt_free(dfs_lfs_fd);
|
|
@@ -519,25 +543,31 @@ _error_dir:
|
|
|
}
|
|
}
|
|
|
else
|
|
else
|
|
|
{
|
|
{
|
|
|
- dfs_lfs_fd_t* dfs_lfs_fd = rt_malloc(sizeof(dfs_lfs_fd_t));
|
|
|
|
|
- if(dfs_lfs_fd == RT_NULL)
|
|
|
|
|
|
|
+ dfs_lfs_fd_t* dfs_lfs_fd = rt_malloc(sizeof(dfs_lfs_fd_t));
|
|
|
|
|
+ if (dfs_lfs_fd == RT_NULL)
|
|
|
{
|
|
{
|
|
|
rt_kprintf("ERROR:no memory!\n");
|
|
rt_kprintf("ERROR:no memory!\n");
|
|
|
result = -ENOMEM;
|
|
result = -ENOMEM;
|
|
|
|
|
|
|
|
goto _error_file;
|
|
goto _error_file;
|
|
|
}
|
|
}
|
|
|
- rt_memset(dfs_lfs_fd,0,sizeof(dfs_lfs_fd_t));
|
|
|
|
|
|
|
+ rt_memset(dfs_lfs_fd, 0, sizeof(dfs_lfs_fd_t));
|
|
|
dfs_lfs_fd->lfs = &dfs_lfs->lfs;
|
|
dfs_lfs_fd->lfs = &dfs_lfs->lfs;
|
|
|
|
|
|
|
|
-
|
|
|
|
|
- if ((file->flags & 3) == O_RDONLY) flags |= LFS_O_RDONLY;
|
|
|
|
|
- if ((file->flags & 3) == O_WRONLY) flags |= LFS_O_WRONLY;
|
|
|
|
|
- if ((file->flags & 3) == O_RDWR) flags |= LFS_O_RDWR;
|
|
|
|
|
- if (file->flags & O_CREAT) flags |= LFS_O_CREAT;
|
|
|
|
|
- if (file->flags & O_EXCL) flags |= LFS_O_EXCL;
|
|
|
|
|
- if (file->flags & O_TRUNC) flags |= LFS_O_TRUNC;
|
|
|
|
|
- if (file->flags & O_APPEND) flags |= LFS_O_APPEND;
|
|
|
|
|
|
|
+ if ((file->flags & 3) == O_RDONLY)
|
|
|
|
|
+ flags |= LFS_O_RDONLY;
|
|
|
|
|
+ if ((file->flags & 3) == O_WRONLY)
|
|
|
|
|
+ flags |= LFS_O_WRONLY;
|
|
|
|
|
+ if ((file->flags & 3) == O_RDWR)
|
|
|
|
|
+ flags |= LFS_O_RDWR;
|
|
|
|
|
+ if (file->flags & O_CREAT)
|
|
|
|
|
+ flags |= LFS_O_CREAT;
|
|
|
|
|
+ if (file->flags & O_EXCL)
|
|
|
|
|
+ flags |= LFS_O_EXCL;
|
|
|
|
|
+ if (file->flags & O_TRUNC)
|
|
|
|
|
+ flags |= LFS_O_TRUNC;
|
|
|
|
|
+ if (file->flags & O_APPEND)
|
|
|
|
|
+ flags |= LFS_O_APPEND;
|
|
|
|
|
|
|
|
result = lfs_file_open(dfs_lfs_fd->lfs, &dfs_lfs_fd->u.file, file->path, flags);
|
|
result = lfs_file_open(dfs_lfs_fd->lfs, &dfs_lfs_fd->u.file, file->path, flags);
|
|
|
if (result != LFS_ERR_OK)
|
|
if (result != LFS_ERR_OK)
|
|
@@ -546,11 +576,11 @@ _error_dir:
|
|
|
}
|
|
}
|
|
|
else
|
|
else
|
|
|
{
|
|
{
|
|
|
- file->data = (void *)dfs_lfs_fd;
|
|
|
|
|
|
|
+ file->data = (void*)dfs_lfs_fd;
|
|
|
return RT_EOK;
|
|
return RT_EOK;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-_error_file:
|
|
|
|
|
|
|
+ _error_file:
|
|
|
if (dfs_lfs_fd != RT_NULL)
|
|
if (dfs_lfs_fd != RT_NULL)
|
|
|
{
|
|
{
|
|
|
rt_free(dfs_lfs_fd);
|
|
rt_free(dfs_lfs_fd);
|
|
@@ -560,14 +590,14 @@ _error_file:
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-static int dfs_lfs_close(struct dfs_fd *file)
|
|
|
|
|
|
|
+static int dfs_lfs_close(struct dfs_fd* file)
|
|
|
{
|
|
{
|
|
|
int result;
|
|
int result;
|
|
|
dfs_lfs_fd_t* dfs_lfs_fd;
|
|
dfs_lfs_fd_t* dfs_lfs_fd;
|
|
|
RT_ASSERT(file != RT_NULL);
|
|
RT_ASSERT(file != RT_NULL);
|
|
|
RT_ASSERT(file->data != RT_NULL);
|
|
RT_ASSERT(file->data != RT_NULL);
|
|
|
|
|
|
|
|
- dfs_lfs_fd = (dfs_lfs_fd_t *)file->data;
|
|
|
|
|
|
|
+ dfs_lfs_fd = (dfs_lfs_fd_t*)file->data;
|
|
|
|
|
|
|
|
if (file->type == FT_DIRECTORY)
|
|
if (file->type == FT_DIRECTORY)
|
|
|
{
|
|
{
|
|
@@ -575,7 +605,7 @@ static int dfs_lfs_close(struct dfs_fd *file)
|
|
|
}
|
|
}
|
|
|
else
|
|
else
|
|
|
{
|
|
{
|
|
|
- result = lfs_file_close(dfs_lfs_fd->lfs,&dfs_lfs_fd->u.file);
|
|
|
|
|
|
|
+ result = lfs_file_close(dfs_lfs_fd->lfs, &dfs_lfs_fd->u.file);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
rt_free(dfs_lfs_fd);
|
|
rt_free(dfs_lfs_fd);
|
|
@@ -583,17 +613,19 @@ static int dfs_lfs_close(struct dfs_fd *file)
|
|
|
return lfs_result_to_dfs(result);
|
|
return lfs_result_to_dfs(result);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-static int dfs_lfs_ioctl(struct dfs_fd *file, int cmd, void *args)
|
|
|
|
|
|
|
+static int dfs_lfs_ioctl(struct dfs_fd* file, int cmd, void* args)
|
|
|
{
|
|
{
|
|
|
return -ENOSYS;
|
|
return -ENOSYS;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-int dfs_lfs_read(struct dfs_fd *file, void *buf, size_t len)
|
|
|
|
|
|
|
+int dfs_lfs_read(struct dfs_fd* file, void* buf, size_t len)
|
|
|
{
|
|
{
|
|
|
lfs_ssize_t ssize;
|
|
lfs_ssize_t ssize;
|
|
|
dfs_lfs_fd_t* dfs_lfs_fd;
|
|
dfs_lfs_fd_t* dfs_lfs_fd;
|
|
|
|
|
+
|
|
|
RT_ASSERT(file != RT_NULL);
|
|
RT_ASSERT(file != RT_NULL);
|
|
|
RT_ASSERT(file->data != RT_NULL);
|
|
RT_ASSERT(file->data != RT_NULL);
|
|
|
|
|
+
|
|
|
dfs_lfs_fd = (dfs_lfs_fd_t*)file->data;
|
|
dfs_lfs_fd = (dfs_lfs_fd_t*)file->data;
|
|
|
|
|
|
|
|
if (file->type == FT_DIRECTORY)
|
|
if (file->type == FT_DIRECTORY)
|
|
@@ -601,7 +633,7 @@ int dfs_lfs_read(struct dfs_fd *file, void *buf, size_t len)
|
|
|
return -EISDIR;
|
|
return -EISDIR;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if (lfs_file_tell(dfs_lfs_fd->lfs,&dfs_lfs_fd->u.file) != file->pos)
|
|
|
|
|
|
|
+ if (lfs_file_tell(dfs_lfs_fd->lfs, &dfs_lfs_fd->u.file) != file->pos)
|
|
|
{
|
|
{
|
|
|
lfs_soff_t soff = lfs_file_seek(dfs_lfs_fd->lfs, &dfs_lfs_fd->u.file, file->pos, LFS_SEEK_SET);
|
|
lfs_soff_t soff = lfs_file_seek(dfs_lfs_fd->lfs, &dfs_lfs_fd->u.file, file->pos, LFS_SEEK_SET);
|
|
|
if (soff < 0)
|
|
if (soff < 0)
|
|
@@ -610,19 +642,19 @@ int dfs_lfs_read(struct dfs_fd *file, void *buf, size_t len)
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- ssize = lfs_file_read(dfs_lfs_fd->lfs, &dfs_lfs_fd->u.file,buf,len);
|
|
|
|
|
|
|
+ ssize = lfs_file_read(dfs_lfs_fd->lfs, &dfs_lfs_fd->u.file, buf, len);
|
|
|
if (ssize < 0)
|
|
if (ssize < 0)
|
|
|
{
|
|
{
|
|
|
return lfs_result_to_dfs(ssize);
|
|
return lfs_result_to_dfs(ssize);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/* update position */
|
|
/* update position */
|
|
|
- file->pos = dfs_lfs_fd->u.file.pos;
|
|
|
|
|
|
|
+ file->pos = dfs_lfs_fd->u.file.pos;
|
|
|
|
|
|
|
|
return ssize;
|
|
return ssize;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-int dfs_lfs_write(struct dfs_fd *file, const void *buf, size_t len)
|
|
|
|
|
|
|
+int dfs_lfs_write(struct dfs_fd* file, const void* buf, size_t len)
|
|
|
{
|
|
{
|
|
|
lfs_ssize_t ssize;
|
|
lfs_ssize_t ssize;
|
|
|
dfs_lfs_fd_t* dfs_lfs_fd;
|
|
dfs_lfs_fd_t* dfs_lfs_fd;
|
|
@@ -634,8 +666,8 @@ int dfs_lfs_write(struct dfs_fd *file, const void *buf, size_t len)
|
|
|
return -EISDIR;
|
|
return -EISDIR;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- dfs_lfs_fd = (dfs_lfs_fd_t *)file->data;
|
|
|
|
|
- if (lfs_file_tell(dfs_lfs_fd->lfs,&dfs_lfs_fd->u.file) != file->pos)
|
|
|
|
|
|
|
+ dfs_lfs_fd = (dfs_lfs_fd_t*)file->data;
|
|
|
|
|
+ if (lfs_file_tell(dfs_lfs_fd->lfs, &dfs_lfs_fd->u.file) != file->pos)
|
|
|
{
|
|
{
|
|
|
lfs_soff_t soff = lfs_file_seek(dfs_lfs_fd->lfs, &dfs_lfs_fd->u.file, file->pos, LFS_SEEK_SET);
|
|
lfs_soff_t soff = lfs_file_seek(dfs_lfs_fd->lfs, &dfs_lfs_fd->u.file, file->pos, LFS_SEEK_SET);
|
|
|
if (soff < 0)
|
|
if (soff < 0)
|
|
@@ -651,32 +683,32 @@ int dfs_lfs_write(struct dfs_fd *file, const void *buf, size_t len)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/* update position and file size */
|
|
/* update position and file size */
|
|
|
- file->pos = dfs_lfs_fd->u.file.pos;
|
|
|
|
|
|
|
+ file->pos = dfs_lfs_fd->u.file.pos;
|
|
|
file->size = dfs_lfs_fd->u.file.size;
|
|
file->size = dfs_lfs_fd->u.file.size;
|
|
|
return ssize;
|
|
return ssize;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-int dfs_lfs_flush(struct dfs_fd *file)
|
|
|
|
|
|
|
+int dfs_lfs_flush(struct dfs_fd* file)
|
|
|
{
|
|
{
|
|
|
int result;
|
|
int result;
|
|
|
dfs_lfs_fd_t* dfs_lfs_fd;
|
|
dfs_lfs_fd_t* dfs_lfs_fd;
|
|
|
RT_ASSERT(file != RT_NULL);
|
|
RT_ASSERT(file != RT_NULL);
|
|
|
RT_ASSERT(file->data != RT_NULL);
|
|
RT_ASSERT(file->data != RT_NULL);
|
|
|
|
|
|
|
|
- dfs_lfs_fd = (dfs_lfs_fd_t *)file->data;
|
|
|
|
|
|
|
+ dfs_lfs_fd = (dfs_lfs_fd_t*)file->data;
|
|
|
|
|
|
|
|
- result = lfs_file_sync(dfs_lfs_fd->lfs,&dfs_lfs_fd->u.file);
|
|
|
|
|
|
|
+ result = lfs_file_sync(dfs_lfs_fd->lfs, &dfs_lfs_fd->u.file);
|
|
|
|
|
|
|
|
return lfs_result_to_dfs(result);
|
|
return lfs_result_to_dfs(result);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-int dfs_lfs_lseek(struct dfs_fd *file, rt_off_t offset)
|
|
|
|
|
|
|
+int dfs_lfs_lseek(struct dfs_fd* file, rt_off_t offset)
|
|
|
{
|
|
{
|
|
|
dfs_lfs_fd_t* dfs_lfs_fd;
|
|
dfs_lfs_fd_t* dfs_lfs_fd;
|
|
|
RT_ASSERT(file != RT_NULL);
|
|
RT_ASSERT(file != RT_NULL);
|
|
|
RT_ASSERT(file->data != RT_NULL);
|
|
RT_ASSERT(file->data != RT_NULL);
|
|
|
|
|
|
|
|
- dfs_lfs_fd = (dfs_lfs_fd_t *)file->data;
|
|
|
|
|
|
|
+ dfs_lfs_fd = (dfs_lfs_fd_t*)file->data;
|
|
|
|
|
|
|
|
if (file->type == FT_REGULAR)
|
|
if (file->type == FT_REGULAR)
|
|
|
{
|
|
{
|
|
@@ -702,17 +734,16 @@ int dfs_lfs_lseek(struct dfs_fd *file, rt_off_t offset)
|
|
|
return (file->pos);
|
|
return (file->pos);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
-int dfs_lfs_getdents(struct dfs_fd *file, struct dirent *dirp, uint32_t count)
|
|
|
|
|
|
|
+int dfs_lfs_getdents(struct dfs_fd* file, struct dirent* dirp, uint32_t count)
|
|
|
{
|
|
{
|
|
|
dfs_lfs_fd_t* dfs_lfs_fd;
|
|
dfs_lfs_fd_t* dfs_lfs_fd;
|
|
|
int result;
|
|
int result;
|
|
|
int index;
|
|
int index;
|
|
|
- struct dirent *d;
|
|
|
|
|
|
|
+ struct dirent* d;
|
|
|
struct lfs_info info;
|
|
struct lfs_info info;
|
|
|
|
|
|
|
|
RT_ASSERT(file->data != RT_NULL);
|
|
RT_ASSERT(file->data != RT_NULL);
|
|
|
- dfs_lfs_fd = (dfs_lfs_fd_t *)(file->data);
|
|
|
|
|
|
|
+ dfs_lfs_fd = (dfs_lfs_fd_t*)(file->data);
|
|
|
|
|
|
|
|
/* make integer count */
|
|
/* make integer count */
|
|
|
count = (count / sizeof(struct dirent)) * sizeof(struct dirent);
|
|
count = (count / sizeof(struct dirent)) * sizeof(struct dirent);
|
|
@@ -735,11 +766,12 @@ int dfs_lfs_getdents(struct dfs_fd *file, struct dirent *dirp, uint32_t count)
|
|
|
d->d_type = DT_UNKNOWN;
|
|
d->d_type = DT_UNKNOWN;
|
|
|
switch (info.type)
|
|
switch (info.type)
|
|
|
{
|
|
{
|
|
|
- case LFS_TYPE_DIR:
|
|
|
|
|
- d->d_type |= DT_DIR;
|
|
|
|
|
|
|
+ case LFS_TYPE_DIR:
|
|
|
|
|
+ d->d_type |= DT_DIR;
|
|
|
break;
|
|
break;
|
|
|
- case LFS_TYPE_REG:
|
|
|
|
|
- d->d_type |= DT_REG;
|
|
|
|
|
|
|
+
|
|
|
|
|
+ case LFS_TYPE_REG:
|
|
|
|
|
+ d->d_type |= DT_REG;
|
|
|
break;
|
|
break;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -747,7 +779,7 @@ int dfs_lfs_getdents(struct dfs_fd *file, struct dirent *dirp, uint32_t count)
|
|
|
d->d_reclen = (rt_uint16_t)sizeof(struct dirent);
|
|
d->d_reclen = (rt_uint16_t)sizeof(struct dirent);
|
|
|
rt_strncpy(d->d_name, info.name, rt_strlen(info.name) + 1);
|
|
rt_strncpy(d->d_name, info.name, rt_strlen(info.name) + 1);
|
|
|
|
|
|
|
|
- index ++;
|
|
|
|
|
|
|
+ index++;
|
|
|
if (index * sizeof(struct dirent) >= count)
|
|
if (index * sizeof(struct dirent) >= count)
|
|
|
{
|
|
{
|
|
|
break;
|
|
break;
|
|
@@ -764,8 +796,7 @@ int dfs_lfs_getdents(struct dfs_fd *file, struct dirent *dirp, uint32_t count)
|
|
|
return index * sizeof(struct dirent);
|
|
return index * sizeof(struct dirent);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-static const struct dfs_file_ops _dfs_lfs_fops =
|
|
|
|
|
-{
|
|
|
|
|
|
|
+static const struct dfs_file_ops _dfs_lfs_fops = {
|
|
|
dfs_lfs_open,
|
|
dfs_lfs_open,
|
|
|
dfs_lfs_close,
|
|
dfs_lfs_close,
|
|
|
dfs_lfs_ioctl,
|
|
dfs_lfs_ioctl,
|
|
@@ -774,11 +805,10 @@ static const struct dfs_file_ops _dfs_lfs_fops =
|
|
|
dfs_lfs_flush,
|
|
dfs_lfs_flush,
|
|
|
dfs_lfs_lseek,
|
|
dfs_lfs_lseek,
|
|
|
dfs_lfs_getdents,
|
|
dfs_lfs_getdents,
|
|
|
-// RT_NULL, /* poll interface */
|
|
|
|
|
|
|
+ // RT_NULL, /* poll interface */
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
-static const struct dfs_filesystem_ops _dfs_lfs_ops =
|
|
|
|
|
-{
|
|
|
|
|
|
|
+static const struct dfs_filesystem_ops _dfs_lfs_ops = {
|
|
|
"lfs",
|
|
"lfs",
|
|
|
DFS_FS_FLAG_DEFAULT,
|
|
DFS_FS_FLAG_DEFAULT,
|
|
|
&_dfs_lfs_fops,
|
|
&_dfs_lfs_fops,
|
|
@@ -801,4 +831,3 @@ int dfs_lfs_init(void)
|
|
|
return 0;
|
|
return 0;
|
|
|
}
|
|
}
|
|
|
INIT_COMPONENT_EXPORT(dfs_lfs_init);
|
|
INIT_COMPONENT_EXPORT(dfs_lfs_init);
|
|
|
-
|
|
|