feat: fs增加注册接口

方案描述:
增加注册机制, 并增加重复注册判断

BREAKING CHANGE:
fs增加注册接口
新增API:
int LOS_FsRegister(const char *fsType, const struct MountOps *fsMops,
                   const struct FileOps *fsFops, const struct FsManagement *fsMgt);

fix #I611L2
Signed-off-by: wangchen <wangchen240@huawei.com>
https://gitee.com/openharmony/kernel_liteos_m/issues/I611L2
This commit is contained in:
wangchen 2022-11-29 02:30:15 +00:00
parent 019dab8db4
commit 2f334bed21
4 changed files with 45 additions and 6 deletions

View File

@ -46,6 +46,7 @@
#include "sys/uio.h"
#include "unistd.h"
#include <stdarg.h>
#include "vfs_maps.h"
#ifdef __cplusplus
#if __cplusplus
@ -152,6 +153,28 @@ int LOS_DiskPartition(const char *dev, const char *fsType, int *lengthArray, int
*/
int LOS_PartitionFormat(const char *partName, char *fsType, void *data);
/*
* @brief new file system callbacks register.
* These callback functions are the adaptation layer implemented by the developer,
* used to interconnect the vfs with the new file system.
*
* LOS_FsRegister must be called after kernel initialization is complete.
*
* @param fsType file system type, don't register the same type fs more than once.
* @param fsMops mount operation of the fs.
* @param fsFops file operation of the fs.
* @param fsMgt management operation of the fs.
*
* @return Return LOS_OK if success.
* Return LOS_NOK if error.
* errno EINVAL: input errors, such as null pointers.
* errno ENOMEM: memory may malloc failed.
*
*/
int LOS_FsRegister(const char *fsType, const struct MountOps *fsMops,
const struct FileOps *fsFops, const struct FsManagement *fsMgt);
#ifdef __cplusplus
#if __cplusplus
extern "C" {

View File

@ -55,17 +55,19 @@ struct FsMap *VfsFsMapGet(const char *fsType)
return NULL;
}
int OsFsRegister(const char *fsType, struct MountOps *fsMops,
struct FileOps *fsFops, struct FsManagement *fsMgt)
int OsFsRegister(const char *fsType, const struct MountOps *fsMops,
const struct FileOps *fsFops, const struct FsManagement *fsMgt)
{
size_t len;
if ((fsMops == NULL) || (fsFops == NULL)) {
VFS_ERRNO_SET(EINVAL);
return (int)LOS_NOK;
}
struct FsMap *newfs = (struct FsMap *)LOSCFG_FS_MALLOC_HOOK(sizeof(struct FsMap));
if (newfs == NULL) {
PRINT_ERR("Fs register malloc failed, fsType %s.\n", fsType);
VFS_ERRNO_SET(ENOMEM);
return (int)LOS_NOK;
}
(void)memset_s(newfs, sizeof(struct FsMap), 0, sizeof(struct FsMap));
@ -74,6 +76,7 @@ int OsFsRegister(const char *fsType, struct MountOps *fsMops,
newfs->fsType = LOSCFG_FS_MALLOC_HOOK(len);
if (newfs->fsType == NULL) {
LOSCFG_FS_FREE_HOOK(newfs);
VFS_ERRNO_SET(ENOMEM);
return (int)LOS_NOK;
}
(void)strcpy_s((char *)newfs->fsType, len, fsType);
@ -90,3 +93,15 @@ int OsFsRegister(const char *fsType, struct MountOps *fsMops,
VfsUnlock();
return LOS_OK;
}
int LOS_FsRegister(const char *fsType, const struct MountOps *fsMops,
const struct FileOps *fsFops, const struct FsManagement *fsMgt)
{
if (VfsFsMapGet(fsType) != NULL) {
PRINT_ERR("fsType has been registered or fsType error\n");
VFS_ERRNO_SET(EINVAL);
return (int)LOS_NOK;
}
return OsFsRegister(fsType, fsMops, fsFops, fsMgt);
}

View File

@ -56,8 +56,8 @@ struct FsMap {
struct FsMap *next;
};
int OsFsRegister(const char *fsType, struct MountOps *fsMops,
struct FileOps *fsFops, struct FsManagement *fsMgt);
int OsFsRegister(const char *fsType, const struct MountOps *fsMops,
const struct FileOps *fsFops, const struct FsManagement *fsMgt);
struct FsMap *VfsFsMapGet(const char *fsType);
#ifdef __cplusplus

View File

@ -39,7 +39,6 @@ static_library("posix_test") {
"src/ctype/tolower_test.c",
"src/ctype/toupper_test.c",
"src/errno/strerror_test.c",
"src/fs/posix_fs_func_test.c",
"src/math/math_func_test.c",
"src/mqueue/mqueue_func_test.c",
"src/posix_test.c",
@ -65,7 +64,9 @@ static_library("posix_test") {
"//test/xts/tools/hctest/include",
"src",
]
if (defined(LOSCFG_SUPPORT_FATFS) || defined(LOSCFG_SUPPORT_LITTLEFS)) {
sources += [ "src/fs/posix_fs_func_test.c" ]
}
if (!defined(LOSCFG_COMPILER_ICCARM)) {
cflags = [ "-Wno-error" ]
} else {