add littlefs code
This commit is contained in:
@@ -128,56 +128,30 @@ int LfsMount(const char * source, const char * target, const char * fileSystemTy
|
||||
const void * data)
|
||||
{
|
||||
int ret;
|
||||
|
||||
|
||||
g_fsOp.fsVops = &lfs_vops;
|
||||
ret = lfs_mount(&g_lfs, (struct lfs_config*)data);
|
||||
ret = lfs_mount(&g_lfs, (struct lfs_config*)data);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int LfsUmount(const char * target)
|
||||
{
|
||||
int ret;
|
||||
|
||||
pthread_mutex_lock(&g_FslocalMutex);
|
||||
ret = lfs_unmount(&g_lfs);
|
||||
pthread_mutex_unlock(&g_FslocalMutex);
|
||||
|
||||
{
|
||||
return lfs_unmount(&g_lfs);
|
||||
}
|
||||
|
||||
int LfsUnlink(const char * fileName)
|
||||
{
|
||||
int ret;
|
||||
|
||||
pthread_mutex_lock(&g_FslocalMutex);
|
||||
ret = lfs_remove(&g_lfs, fileName);
|
||||
pthread_mutex_unlock(&g_FslocalMutex);
|
||||
|
||||
{
|
||||
return lfs_remove(&g_lfs, fileName);
|
||||
}
|
||||
|
||||
int LfsMkdir(const char * dirName, mode_t mode)
|
||||
{
|
||||
int ret;
|
||||
|
||||
pthread_mutex_lock(&g_FslocalMutex);
|
||||
ret = lfs_mkdir(&g_lfs, dirName);
|
||||
pthread_mutex_unlock(&g_FslocalMutex);
|
||||
|
||||
{
|
||||
return lfs_mkdir(&g_lfs, dirName);
|
||||
}
|
||||
|
||||
int LfsRmdir(const char * dirName)
|
||||
{
|
||||
int ret;
|
||||
|
||||
pthread_mutex_lock(&g_FslocalMutex);
|
||||
ret = lfs_remove(&g_lfs, dirName);
|
||||
pthread_mutex_unlock(&g_FslocalMutex);
|
||||
|
||||
{
|
||||
return lfs_remove(&g_lfs, dirName);
|
||||
}
|
||||
|
||||
@@ -189,9 +163,7 @@ DIR *LfsOpendir(const char * dirName)
|
||||
if (dir == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
ret = lfs_dir_open(&g_lfs, dir, dirName);
|
||||
ret = lfs_dir_open(&g_lfs, dir, dirName);
|
||||
|
||||
if (ret == 0) {
|
||||
@@ -205,7 +177,6 @@ struct dirent *LfsReaddir(DIR * dir)
|
||||
{
|
||||
int ret;
|
||||
struct lfs_info lfsInfo;
|
||||
|
||||
|
||||
ret = lfs_dir_read(&g_lfs, (lfs_dir_t *)dir, &lfsInfo);
|
||||
if (ret == 0) {
|
||||
@@ -216,31 +187,22 @@ struct dirent *LfsReaddir(DIR * dir)
|
||||
g_nameValue.d_type = DT_REG;
|
||||
}
|
||||
|
||||
g_nameValue.d_reclen = lfsInfo.size;
|
||||
g_nameValue.d_reclen = lfsInfo.size;
|
||||
|
||||
return &g_nameValue;
|
||||
}
|
||||
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int LfsClosedir(DIR * dir)
|
||||
{
|
||||
int ret;
|
||||
|
||||
pthread_mutex_lock(&g_FslocalMutex);
|
||||
ret = lfs_dir_close(&g_lfs, (lfs_dir_t *)dir);
|
||||
pthread_mutex_unlock(&g_FslocalMutex);
|
||||
|
||||
{
|
||||
return lfs_dir_close(&g_lfs, (lfs_dir_t *)dir);
|
||||
}
|
||||
|
||||
int LfsOpen(const char * path, int openFlag, int mode)
|
||||
{
|
||||
int fd = INVALID_FD;
|
||||
|
||||
|
||||
LittleFsHandleStruct *fsHandle = GetFreeFd(&fd);
|
||||
if (fd == INVALID_FD) {
|
||||
@@ -251,56 +213,36 @@ int LfsOpen(const char * path, int openFlag, int mode)
|
||||
if (err != 0) {
|
||||
goto errout;
|
||||
}
|
||||
|
||||
|
||||
return fd;
|
||||
errout:
|
||||
errout:
|
||||
return INVALID_FD;
|
||||
}
|
||||
|
||||
int LfsRead(int fd, void * buf, unsigned int len)
|
||||
{
|
||||
int ret = VFS_ERROR;
|
||||
{
|
||||
if (fd >= LITTLE_FS_MAX_OPEN_FILES && fd < 0) {
|
||||
if (fd >= LITTLE_FS_MAX_OPEN_FILES && fd < 0) {
|
||||
return VFS_ERROR;
|
||||
}
|
||||
|
||||
pthread_mutex_lock(&g_FslocalMutex);
|
||||
ret = lfs_file_read(&g_lfs, &(g_handle[fd].file), buf, len);
|
||||
pthread_mutex_unlock(&g_FslocalMutex);
|
||||
|
||||
|
||||
return lfs_file_read(&g_lfs, &(g_handle[fd].file), buf, len);
|
||||
}
|
||||
|
||||
int LfsWrite(int fd, const void * buf, unsigned int len)
|
||||
{
|
||||
int ret = VFS_ERROR;
|
||||
{
|
||||
if (fd >= LITTLE_FS_MAX_OPEN_FILES && fd < 0) {
|
||||
if (fd >= LITTLE_FS_MAX_OPEN_FILES && fd < 0) {
|
||||
return VFS_ERROR;
|
||||
}
|
||||
|
||||
pthread_mutex_lock(&g_FslocalMutex);
|
||||
ret = lfs_file_write(&g_lfs, &(g_handle[fd].file), buf, len);
|
||||
pthread_mutex_unlock(&g_FslocalMutex);
|
||||
|
||||
|
||||
return lfs_file_write(&g_lfs, &(g_handle[fd].file), buf, len);
|
||||
}
|
||||
|
||||
int LfsSeek(int fd, off_t offset, int whence)
|
||||
{
|
||||
int ret = VFS_ERROR;
|
||||
{
|
||||
if (fd >= LITTLE_FS_MAX_OPEN_FILES && fd < 0) {
|
||||
if (fd >= LITTLE_FS_MAX_OPEN_FILES && fd < 0) {
|
||||
return VFS_ERROR;
|
||||
}
|
||||
|
||||
pthread_mutex_lock(&g_FslocalMutex);
|
||||
ret = lfs_file_seek(&g_lfs, &(g_handle[fd].file), offset, whence);
|
||||
pthread_mutex_unlock(&g_FslocalMutex);
|
||||
|
||||
|
||||
return lfs_file_seek(&g_lfs, &(g_handle[fd].file), offset, whence);
|
||||
}
|
||||
|
||||
@@ -311,23 +253,15 @@ int LfsClose(int fd)
|
||||
if (fd >= LITTLE_FS_MAX_OPEN_FILES && fd < 0) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
ret = lfs_file_close(&g_lfs, &(g_handle[fd].file));
|
||||
g_handle[fd].useFlag = 0;
|
||||
g_handle[fd].useFlag = 0;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int LfsRename(const char * oldName, const char * newName)
|
||||
{
|
||||
int ret;
|
||||
|
||||
pthread_mutex_lock(&g_FslocalMutex);
|
||||
ret = lfs_rename(&g_lfs, oldName, newName);
|
||||
pthread_mutex_unlock(&g_FslocalMutex);
|
||||
|
||||
{
|
||||
return lfs_rename(&g_lfs, oldName, newName);
|
||||
}
|
||||
|
||||
@@ -335,24 +269,16 @@ int LfsStat(const char * path, struct stat * buf)
|
||||
{
|
||||
int ret;
|
||||
struct lfs_info info;
|
||||
|
||||
|
||||
ret = lfs_stat(&g_lfs, path, &info);
|
||||
if (ret == 0) {
|
||||
buf->st_size = info.size;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int LfsFsync(int fd)
|
||||
{
|
||||
int ret;
|
||||
|
||||
pthread_mutex_lock(&g_FslocalMutex);
|
||||
ret = lfs_file_sync(&g_lfs, &(g_handle[fd].file));
|
||||
pthread_mutex_unlock(&g_FslocalMutex);
|
||||
|
||||
{
|
||||
return lfs_file_sync(&g_lfs, &(g_handle[fd].file));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user