diff --git a/components/fs/fs.c b/components/fs/fs.c index 66ed8af6..e9a38e50 100644 --- a/components/fs/fs.c +++ b/components/fs/fs.c @@ -29,7 +29,9 @@ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "fs_operations.h" +#ifdef LOSCFG_SUPPORT_FATFS #include "fatfs.h" +#endif #include "dirent.h" #include "errno.h" #include "fcntl.h" @@ -158,16 +160,20 @@ static size_t GetCanonicalPath(const char *cwd, const char *path, char *buf, siz static void InitMountInfo(void) { +#if (LOSCFG_SUPPORT_FATFS == 1) extern struct MountOps g_fatfsMnt; extern struct FileOps g_fatfsFops; g_fsmap[0].fileSystemtype = strdup("fat"); g_fsmap[0].fsMops = &g_fatfsMnt; g_fsmap[0].fsFops = &g_fatfsFops; +#endif +#if (LOSCFG_SUPPORT_LITTLEFS == 1) extern struct MountOps g_lfsMnt; extern struct FileOps g_lfsFops; g_fsmap[1].fileSystemtype = strdup("littlefs"); g_fsmap[1].fsMops = &g_lfsMnt; g_fsmap[1].fsFops = &g_lfsFops; +#endif } static struct FsMap *MountFindfs(const char *fileSystemtype) diff --git a/components/fs/littlefs/BUILD.gn b/components/fs/littlefs/BUILD.gn index 02230191..e5a715d7 100644 --- a/components/fs/littlefs/BUILD.gn +++ b/components/fs/littlefs/BUILD.gn @@ -30,6 +30,8 @@ static_library("littlefs") { sources = [ "lfs_api.c", + "//third_party/littlefs/lfs.c", + "//third_party/littlefs/lfs_util.c", ] include_dirs = [ diff --git a/components/fs/littlefs/lfs_api.c b/components/fs/littlefs/lfs_api.c index 4388109f..a4c10e6d 100644 --- a/components/fs/littlefs/lfs_api.c +++ b/components/fs/littlefs/lfs_api.c @@ -39,7 +39,7 @@ struct FileOpInfo g_fsOp[LFS_MAX_MOUNT_SIZE] = {0}; static LittleFsHandleStruct g_handle[LITTLE_FS_MAX_OPEN_FILES] = {0}; struct dirent g_nameValue; static pthread_mutex_t g_FslocalMutex = PTHREAD_MUTEX_INITIALIZER; -static const char *const g_littlefsMntName[LFS_MAX_MOUNT_SIZE] = {"/a","/b","/c"}; +static const char *g_littlefsMntName[LFS_MAX_MOUNT_SIZE] = {"/a","/b","/c"}; LittleFsHandleStruct *LfsAllocFd(const char *fileName, int *fd) { @@ -165,6 +165,18 @@ struct FileOpInfo *AllocMountRes(const char* target, struct FileOps *fileOps) return NULL; } +int SetDefaultMountPath(int pathNameIndex, const char* target) +{ + if (pathNameIndex >= LFS_MAX_MOUNT_SIZE) { + return VFS_ERROR; + } + + pthread_mutex_lock(&g_FslocalMutex); + g_littlefsMntName[pathNameIndex] = strdup(target); + pthread_mutex_unlock(&g_FslocalMutex); + return VFS_OK; +} + struct FileOpInfo *GetMountRes(const char *target, int *mountIndex) { pthread_mutex_lock(&g_FslocalMutex); diff --git a/components/fs/littlefs/lfs_api.h b/components/fs/littlefs/lfs_api.h index 0222cf93..44af2f48 100644 --- a/components/fs/littlefs/lfs_api.h +++ b/components/fs/littlefs/lfs_api.h @@ -117,6 +117,7 @@ int LfsClose(int fd); int LfsRename(const char *oldName, const char *newName); int LfsStat(const char *path, struct stat *buf); int LfsFsync(int fd); +int SetDefaultMountPath(int pathNameIndex, const char* target); const struct FsMap *MountFindfs(const char *filesystemtype); diff --git a/kernel/include/los_config.h b/kernel/include/los_config.h index 011fe472..66c23244 100644 --- a/kernel/include/los_config.h +++ b/kernel/include/los_config.h @@ -583,6 +583,9 @@ extern UINT8 *m_aucSysMem0; #define LOSCFG_KERNEL_TRACE 0 #endif +#ifndef LOSCFG_SUPPORT_LITTLEFS +#define LOSCFG_SUPPORT_LITTLEFS 1 +#endif /** * @ingroup los_config * Configuration trace tool