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:
parent
019dab8db4
commit
2f334bed21
|
@ -46,6 +46,7 @@
|
||||||
#include "sys/uio.h"
|
#include "sys/uio.h"
|
||||||
#include "unistd.h"
|
#include "unistd.h"
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
|
#include "vfs_maps.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
#if __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);
|
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
|
#ifdef __cplusplus
|
||||||
#if __cplusplus
|
#if __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
|
|
@ -55,17 +55,19 @@ struct FsMap *VfsFsMapGet(const char *fsType)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
int OsFsRegister(const char *fsType, struct MountOps *fsMops,
|
int OsFsRegister(const char *fsType, const struct MountOps *fsMops,
|
||||||
struct FileOps *fsFops, struct FsManagement *fsMgt)
|
const struct FileOps *fsFops, const struct FsManagement *fsMgt)
|
||||||
{
|
{
|
||||||
size_t len;
|
size_t len;
|
||||||
if ((fsMops == NULL) || (fsFops == NULL)) {
|
if ((fsMops == NULL) || (fsFops == NULL)) {
|
||||||
|
VFS_ERRNO_SET(EINVAL);
|
||||||
return (int)LOS_NOK;
|
return (int)LOS_NOK;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct FsMap *newfs = (struct FsMap *)LOSCFG_FS_MALLOC_HOOK(sizeof(struct FsMap));
|
struct FsMap *newfs = (struct FsMap *)LOSCFG_FS_MALLOC_HOOK(sizeof(struct FsMap));
|
||||||
if (newfs == NULL) {
|
if (newfs == NULL) {
|
||||||
PRINT_ERR("Fs register malloc failed, fsType %s.\n", fsType);
|
PRINT_ERR("Fs register malloc failed, fsType %s.\n", fsType);
|
||||||
|
VFS_ERRNO_SET(ENOMEM);
|
||||||
return (int)LOS_NOK;
|
return (int)LOS_NOK;
|
||||||
}
|
}
|
||||||
(void)memset_s(newfs, sizeof(struct FsMap), 0, sizeof(struct FsMap));
|
(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);
|
newfs->fsType = LOSCFG_FS_MALLOC_HOOK(len);
|
||||||
if (newfs->fsType == NULL) {
|
if (newfs->fsType == NULL) {
|
||||||
LOSCFG_FS_FREE_HOOK(newfs);
|
LOSCFG_FS_FREE_HOOK(newfs);
|
||||||
|
VFS_ERRNO_SET(ENOMEM);
|
||||||
return (int)LOS_NOK;
|
return (int)LOS_NOK;
|
||||||
}
|
}
|
||||||
(void)strcpy_s((char *)newfs->fsType, len, fsType);
|
(void)strcpy_s((char *)newfs->fsType, len, fsType);
|
||||||
|
@ -90,3 +93,15 @@ int OsFsRegister(const char *fsType, struct MountOps *fsMops,
|
||||||
VfsUnlock();
|
VfsUnlock();
|
||||||
return LOS_OK;
|
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);
|
||||||
|
}
|
||||||
|
|
|
@ -56,8 +56,8 @@ struct FsMap {
|
||||||
struct FsMap *next;
|
struct FsMap *next;
|
||||||
};
|
};
|
||||||
|
|
||||||
int OsFsRegister(const char *fsType, struct MountOps *fsMops,
|
int OsFsRegister(const char *fsType, const struct MountOps *fsMops,
|
||||||
struct FileOps *fsFops, struct FsManagement *fsMgt);
|
const struct FileOps *fsFops, const struct FsManagement *fsMgt);
|
||||||
struct FsMap *VfsFsMapGet(const char *fsType);
|
struct FsMap *VfsFsMapGet(const char *fsType);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|
|
@ -39,7 +39,6 @@ static_library("posix_test") {
|
||||||
"src/ctype/tolower_test.c",
|
"src/ctype/tolower_test.c",
|
||||||
"src/ctype/toupper_test.c",
|
"src/ctype/toupper_test.c",
|
||||||
"src/errno/strerror_test.c",
|
"src/errno/strerror_test.c",
|
||||||
"src/fs/posix_fs_func_test.c",
|
|
||||||
"src/math/math_func_test.c",
|
"src/math/math_func_test.c",
|
||||||
"src/mqueue/mqueue_func_test.c",
|
"src/mqueue/mqueue_func_test.c",
|
||||||
"src/posix_test.c",
|
"src/posix_test.c",
|
||||||
|
@ -65,7 +64,9 @@ static_library("posix_test") {
|
||||||
"//test/xts/tools/hctest/include",
|
"//test/xts/tools/hctest/include",
|
||||||
"src",
|
"src",
|
||||||
]
|
]
|
||||||
|
if (defined(LOSCFG_SUPPORT_FATFS) || defined(LOSCFG_SUPPORT_LITTLEFS)) {
|
||||||
|
sources += [ "src/fs/posix_fs_func_test.c" ]
|
||||||
|
}
|
||||||
if (!defined(LOSCFG_COMPILER_ICCARM)) {
|
if (!defined(LOSCFG_COMPILER_ICCARM)) {
|
||||||
cflags = [ "-Wno-error" ]
|
cflags = [ "-Wno-error" ]
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue