add littlefs code
This commit is contained in:
parent
606bd9ca08
commit
3ae9d36049
|
@ -36,7 +36,7 @@ lfs_t g_lfs;
|
||||||
FileDirInfo g_lfsDir[LFS_MAX_OPEN_DIRS];
|
FileDirInfo g_lfsDir[LFS_MAX_OPEN_DIRS];
|
||||||
|
|
||||||
FileOpInfo g_fsOp;
|
FileOpInfo g_fsOp;
|
||||||
static LittleFsHandleStruct g_handle[LITTLE_FS_MAX_OPEN_FILES];
|
static LittleFsHandleStruct g_handle[LITTLE_FS_MAX_OPEN_FILES] = {0};
|
||||||
struct dirent g_nameValue;
|
struct dirent g_nameValue;
|
||||||
struct fsmap_t g_fsmap[MAX_FILE_SYSTEM_LEN];
|
struct fsmap_t g_fsmap[MAX_FILE_SYSTEM_LEN];
|
||||||
static pthread_mutex_t g_FslocalMutex = PTHREAD_MUTEX_INITIALIZER;
|
static pthread_mutex_t g_FslocalMutex = PTHREAD_MUTEX_INITIALIZER;
|
||||||
|
@ -87,7 +87,7 @@ int InitMountInfo(const char *fileSystemType, const struct MountOps *fsMops)
|
||||||
return VFS_ERROR;
|
return VFS_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
const struct fsmap_t *mount_finds(const char*fileSystemtype)
|
const struct fsmap_t *mount_findfs(const char*fileSystemtype)
|
||||||
{
|
{
|
||||||
struct fsmap_t *m = NULL;
|
struct fsmap_t *m = NULL;
|
||||||
|
|
||||||
|
@ -102,11 +102,25 @@ const struct fsmap_t *mount_finds(const char*fileSystemtype)
|
||||||
}
|
}
|
||||||
|
|
||||||
const struct MountOps g_fsMnt = {
|
const struct MountOps g_fsMnt = {
|
||||||
|
.Mount = LfsMount,
|
||||||
|
.Umount = LfsUmount,
|
||||||
};
|
};
|
||||||
|
|
||||||
struct FileOps lfs_vops = {
|
const struct FileOps lfs_vops = {
|
||||||
|
.Mkdir = LfsMkdir,
|
||||||
|
.Unlink = LfsUnlink,
|
||||||
|
.Rmdir = LfsRmdir,
|
||||||
|
.Opendir = LfsOpendir,
|
||||||
|
.Readdir = LfsReaddir,
|
||||||
|
.Closedir = LfsClosedir,
|
||||||
|
.Open = LfsOpen,
|
||||||
|
.Close = LfsClose,
|
||||||
|
.Write = LfsWrite,
|
||||||
|
.Read = LfsRead,
|
||||||
|
.Seek = LfsSeek,
|
||||||
|
.Rename = LfsRename,
|
||||||
|
.Getattr = LfsStat,
|
||||||
|
.Fsync = LfsFsync,
|
||||||
};
|
};
|
||||||
|
|
||||||
int LfsMount(const char * source, const char * target, const char * fileSystemType, unsigned long mountflags,
|
int LfsMount(const char * source, const char * target, const char * fileSystemType, unsigned long mountflags,
|
||||||
|
@ -186,7 +200,7 @@ DIR *LfsOpendir(const char * dirName)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct direct *LfsReaddir(DIR * dir)
|
struct dirent *LfsReaddir(DIR * dir)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
struct lfs_info lfsInfo;
|
struct lfs_info lfsInfo;
|
||||||
|
@ -211,12 +225,12 @@ struct direct *LfsReaddir(DIR * dir)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
int LfsCloseDir(DIR * dir)
|
int LfsClosedir(DIR * dir)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
pthread_mutex_lock(&g_FslocalMutex);
|
pthread_mutex_lock(&g_FslocalMutex);
|
||||||
ret = lfs_remove(&g_lfs, dirName);
|
ret = lfs_dir_close(&g_lfs, (lfs_dir_t *)dir);
|
||||||
pthread_mutex_unlock(&g_FslocalMutex);
|
pthread_mutex_unlock(&g_FslocalMutex);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -227,12 +241,12 @@ int LfsOpen(const char * path, int openFlag, int mode)
|
||||||
int fd = INVALID_FD;
|
int fd = INVALID_FD;
|
||||||
|
|
||||||
pthread_mutex_lock(&g_FslocalMutex);
|
pthread_mutex_lock(&g_FslocalMutex);
|
||||||
LittleFsHandleStruct *fsHandle = GetFreeDir(&fd);
|
LittleFsHandleStruct *fsHandle = GetFreeFd(&fd);
|
||||||
if (fd == INVALID_FD) {
|
if (fd == INVALID_FD) {
|
||||||
goto errout;
|
goto errout;
|
||||||
}
|
}
|
||||||
|
|
||||||
int err = lfs_file_open(lfs_t * lfs, lfs_file_t * file, const char * path, int flags);
|
int err = lfs_file_open(&g_lfs, &(fsHandle->file), path, openFlag);
|
||||||
if (err != 0) {
|
if (err != 0) {
|
||||||
goto errout;
|
goto errout;
|
||||||
}
|
}
|
||||||
|
@ -299,6 +313,7 @@ int LfsClose(int fd)
|
||||||
|
|
||||||
pthread_mutex_lock(&g_FslocalMutex);
|
pthread_mutex_lock(&g_FslocalMutex);
|
||||||
ret = lfs_file_close(&g_lfs, &(g_handle[fd].file));
|
ret = lfs_file_close(&g_lfs, &(g_handle[fd].file));
|
||||||
|
g_handle[fd].useFlag = 0;
|
||||||
pthread_mutex_unlock(&g_FslocalMutex);
|
pthread_mutex_unlock(&g_FslocalMutex);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -309,7 +324,7 @@ int LfsRename(const char * oldName, const char * newName)
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
pthread_mutex_lock(&g_FslocalMutex);
|
pthread_mutex_lock(&g_FslocalMutex);
|
||||||
ret = lfs_rename(oldName, newName);
|
ret = lfs_rename(&g_lfs, oldName, newName);
|
||||||
pthread_mutex_unlock(&g_FslocalMutex);
|
pthread_mutex_unlock(&g_FslocalMutex);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -322,7 +337,7 @@ int LfsStat(const char * path, struct stat * buf)
|
||||||
|
|
||||||
pthread_mutex_lock(&g_FslocalMutex);
|
pthread_mutex_lock(&g_FslocalMutex);
|
||||||
ret = lfs_stat(&g_lfs, path, &info);
|
ret = lfs_stat(&g_lfs, path, &info);
|
||||||
if (ret = 0) {
|
if (ret == 0) {
|
||||||
buf->st_size = info.size;
|
buf->st_size = info.size;
|
||||||
}
|
}
|
||||||
pthread_mutex_unlock(&g_FslocalMutex);
|
pthread_mutex_unlock(&g_FslocalMutex);
|
||||||
|
|
|
@ -55,7 +55,7 @@ typedef struct {
|
||||||
} LittleFsHandleStruct;
|
} LittleFsHandleStruct;
|
||||||
|
|
||||||
struct MountOps {
|
struct MountOps {
|
||||||
int {*Mount}(const char *source, const char *target, const char *filesystemtype, unsigned long mountflags,
|
int (*Mount)(const char *source, const char *target, const char *filesystemtype, unsigned long mountflags,
|
||||||
const void *data);
|
const void *data);
|
||||||
int (*Umount)(const char* target);
|
int (*Umount)(const char* target);
|
||||||
};
|
};
|
||||||
|
@ -71,9 +71,9 @@ struct FileOps {
|
||||||
int (*Unlink)(const char *fileName);
|
int (*Unlink)(const char *fileName);
|
||||||
int (*Rmdir)(const char *dirName);
|
int (*Rmdir)(const char *dirName);
|
||||||
int (*Mkdir)(const char *dirName, mode_t mode);
|
int (*Mkdir)(const char *dirName, mode_t mode);
|
||||||
struct direct *(*Readdir)(DIR *dir);
|
struct dirent *(*Readdir)(DIR *dir);
|
||||||
DIR *(*Opendir)(const char *dirName);
|
DIR *(*Opendir)(const char *dirName);
|
||||||
int (*Closedir)(Dir *dir);
|
int (*Closedir)(DIR *dir);
|
||||||
int (*Read)(int fd, void *buf, size_t len);
|
int (*Read)(int fd, void *buf, size_t len);
|
||||||
int (*Write)(int fd, const void *buf, size_t len);
|
int (*Write)(int fd, const void *buf, size_t len);
|
||||||
int (*Seek)(int fd, off_t offset, int whence);
|
int (*Seek)(int fd, off_t offset, int whence);
|
||||||
|
@ -116,7 +116,7 @@ int LfsMkdir(const char *dirName, mode_t mode);
|
||||||
int LfsRmdir(const char *dirName);
|
int LfsRmdir(const char *dirName);
|
||||||
DIR *LfsOpendir(const char *dirName);
|
DIR *LfsOpendir(const char *dirName);
|
||||||
struct dirent *LfsReaddir(DIR *dir);
|
struct dirent *LfsReaddir(DIR *dir);
|
||||||
int LfsCloseDir(DIR *dir);
|
int LfsClosedir(DIR *dir);
|
||||||
int LfsOpen(const char *path, int openFlag, int mode);
|
int LfsOpen(const char *path, int openFlag, int mode);
|
||||||
int LfsRead(int fd, void *buf, unsigned int len);
|
int LfsRead(int fd, void *buf, unsigned int len);
|
||||||
int LfsWrite(int fd, const void *buf, unsigned int len);
|
int LfsWrite(int fd, const void *buf, unsigned int len);
|
||||||
|
|
Loading…
Reference in New Issue