From 3ad47afec46123b231968b0612876736207a7018 Mon Sep 17 00:00:00 2001 From: wangchen <253227059@qq.com> Date: Thu, 17 Mar 2022 08:48:43 +0000 Subject: [PATCH] =?UTF-8?q?fix:=20=E9=80=9A=E8=BF=87menuconfig=E5=85=B3?= =?UTF-8?q?=E9=97=ADVFS=E9=80=89=E9=A1=B9=E5=90=8E=EF=BC=8C=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E7=BC=96=E8=AF=91=E6=97=A0=E6=B3=95=E9=80=9A=E8=BF=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 【背景】关闭VFS时,编译无法通过 【修改方案】 1,添加对fs依赖的模块中对fs开启情况的判断 【影响】 对现有的产品编译不会有影响。 re #I4X5DX Signed-off-by: wangchen --- components/shell/BUILD.gn | 4 +- components/shell/src/base/shcmd.c | 3 + kal/libc/musl/BUILD.gn | 9 +-- kal/libc/musl/fs.c | 128 +++++++++++++++++++++++++++++- kal/libc/newlib/porting/src/fs.c | 7 +- kal/posix/src/pipe.c | 1 - kernel/src/los_init.c | 5 +- 7 files changed, 145 insertions(+), 12 deletions(-) diff --git a/components/shell/BUILD.gn b/components/shell/BUILD.gn index f6422d60..e40052f0 100644 --- a/components/shell/BUILD.gn +++ b/components/shell/BUILD.gn @@ -42,11 +42,13 @@ kernel_module(module_name) { "src/cmds/mempt_shellcmd.c", "src/cmds/shell_shellcmd.c", "src/cmds/task_shellcmd.c", - "src/cmds/vfs_shellcmd.c", ] if (defined(LOSCFG_NET_LWIP_SACK)) { defines = [ "LWIP_SHELLCMD_ENABLE" ] } + if (defined(LOSCFG_FS_VFS)) { + sources += [ "src/cmds/vfs_shellcmd.c" ] + } } config("public") { diff --git a/components/shell/src/base/shcmd.c b/components/shell/src/base/shcmd.c index 703065e1..7f6b1c63 100755 --- a/components/shell/src/base/shcmd.c +++ b/components/shell/src/base/shcmd.c @@ -51,6 +51,7 @@ CmdItem g_shellcmdAll[] = { {CMD_TYPE_EX, "ifconfig", XARGS, (CmdCallBackFunc)lwip_ifconfig}, {CMD_TYPE_EX, "ping", XARGS, (CmdCallBackFunc)OsShellPing}, #endif +#if LOSCFG_FS_VFS {CMD_TYPE_EX, "touch", XARGS, (CmdCallBackFunc)OsShellCmdTouch}, {CMD_TYPE_EX, "ls", XARGS, (CmdCallBackFunc)OsShellCmdLs}, {CMD_TYPE_EX, "pwd", XARGS, (CmdCallBackFunc)OsShellCmdPwd}, @@ -60,6 +61,8 @@ CmdItem g_shellcmdAll[] = { {CMD_TYPE_EX, "rmdir", XARGS, (CmdCallBackFunc)OsShellCmdRmdir}, {CMD_TYPE_EX, "mkdir", XARGS, (CmdCallBackFunc)OsShellCmdMkdir}, {CMD_TYPE_EX, "cp", XARGS, (CmdCallBackFunc)OsShellCmdCp}, +#endif + {CMD_TYPE_EX, "help", 0, (CmdCallBackFunc)OsShellCmdHelp}, }; diff --git a/kal/libc/musl/BUILD.gn b/kal/libc/musl/BUILD.gn index 27c0cc57..7261499d 100644 --- a/kal/libc/musl/BUILD.gn +++ b/kal/libc/musl/BUILD.gn @@ -33,13 +33,12 @@ import("//third_party/musl/porting/liteos_m/kernel/musl.gni") module_switch = defined(LOSCFG_LIBC_MUSL) module_name = get_path_info(rebase_path("."), "name") kernel_module(module_name) { - sources = [ "malloc.c" ] + sources = [ + "fs.c", + "malloc.c", + ] configs += [ "$LITEOSTOPDIR:warn_config" ] - if (defined(LOSCFG_LIBC_MUSL_FS)) { - sources += [ "fs.c" ] - } - deps = [ "//third_party/musl/porting/liteos_m/kernel" ] } diff --git a/kal/libc/musl/fs.c b/kal/libc/musl/fs.c index e6e19716..9161d270 100644 --- a/kal/libc/musl/fs.c +++ b/kal/libc/musl/fs.c @@ -30,7 +30,6 @@ */ #include "los_config.h" -#include "los_fs.h" #include "stdarg.h" #include "dirent.h" #include "sys/mount.h" @@ -38,9 +37,16 @@ #include "sys/stat.h" #include "unistd.h" +#ifdef LOSCFG_LIBC_MUSL_FS +#include "los_fs.h" +#else +#include "sys/stat.h" +#endif + +#ifdef LOSCFG_LIBC_MUSL_FS int mount(const char *source, const char *target, - const char *filesystemtype, unsigned long mountflags, - const void *data) + const char *filesystemtype, unsigned long mountflags, + const void *data) { return LOS_FsMount(source, target, filesystemtype, mountflags, data); } @@ -154,3 +160,119 @@ ssize_t pwrite(int fd, const void *buf, size_t nbyte, off_t offset) { return LOS_Pwrite(fd, buf, nbyte, offset); } + +#else /* #ifdef LOSCFG_FS_VFS */ + +int mount(const char *source, const char *target, + const char *filesystemtype, unsigned long mountflags, + const void *data) +{ + return -1; +} + +int umount(const char *target) +{ + return -1; +} + +int umount2(const char *target, int flag) +{ + return -1; +} + +int open(const char *path, int oflag, ...) +{ + return -1; +} + +int close(int fd) +{ + return -1; +} + +ssize_t read(int fd, void *buf, size_t nbyte) +{ + return -1; +} + +ssize_t write(int fd, const void *buf, size_t nbyte) +{ + return -1; +} + +off_t lseek(int fd, off_t offset, int whence) +{ + return -1; +} + +int unlink(const char *path) +{ + return -1; +} + +int fstat(int fd, struct stat *buf) +{ + return -1; +} + +int stat(const char *path, struct stat *buf) +{ + return -1; +} + +int fsync(int fd) +{ + return -1; +} + +int mkdir(const char *path, mode_t mode) +{ + return -1; +} + +DIR *opendir(const char *dirName) +{ + return NULL; +} + +struct dirent *readdir(DIR *dir) +{ + return NULL; +} + +int closedir(DIR *dir) +{ + return -1; +} + +int rmdir(const char *path) +{ + return -1; +} + +int rename(const char *oldName, const char *newName) +{ + return -1; +} + +int statfs(const char *path, struct statfs *buf) +{ + return -1; +} + +int ftruncate(int fd, off_t length) +{ + return -1; +} + +ssize_t pread(int fd, void *buf, size_t nbyte, off_t offset) +{ + return -1; +} + +ssize_t pwrite(int fd, const void *buf, size_t nbyte, off_t offset) +{ + return -1; +} + +#endif diff --git a/kal/libc/newlib/porting/src/fs.c b/kal/libc/newlib/porting/src/fs.c index 4c8e1178..80e5f792 100644 --- a/kal/libc/newlib/porting/src/fs.c +++ b/kal/libc/newlib/porting/src/fs.c @@ -29,11 +29,16 @@ */ #include "los_config.h" -#include "los_fs.h" #include "stdio.h" #include "stdarg.h" #include +#ifdef LOSCFG_LIBC_NEWLIB_FS +#include "los_fs.h" +#else +#include "sys/stat.h" +#endif + #ifdef LOSCFG_LIBC_NEWLIB_FS int mount(const char *source, const char *target, const char *filesystemtype, unsigned long mountflags, diff --git a/kal/posix/src/pipe.c b/kal/posix/src/pipe.c index a5d59a73..04ff61cd 100644 --- a/kal/posix/src/pipe.c +++ b/kal/posix/src/pipe.c @@ -31,7 +31,6 @@ #include #include #include "securec.h" -#include "los_fs.h" #include "los_list.h" #include "los_mux.h" #include "los_sem.h" diff --git a/kernel/src/los_init.c b/kernel/src/los_init.c index 5aca0e52..be44330c 100644 --- a/kernel/src/los_init.c +++ b/kernel/src/los_init.c @@ -30,7 +30,6 @@ */ #include "stdarg.h" -#include "vfs_operations.h" #include "los_arch.h" #include "los_config.h" #include "los_debug.h" @@ -88,6 +87,10 @@ #include "los_box.h" #endif +#if (LOSCFG_FS_VFS == 1) +#include "vfs_operations.h" +#endif + /***************************************************************************** Function : LOS_Reboot Description : system exception, die in here, wait for watchdog.