提交 85218174 编写于 作者: A arvinzzz

refactor: vfs opt

  1. vfs重构优化,统一fs模块的对外接口,减少不必要的冗余调用,由fs组件直接提供posix对外接口
  2. vfs与libc关系整理
  3. fs接口实现规范化

BREAKING CHANGE:
删除API:
int LOS_Open(const char *path, int flags, ...);
int LOS_Close(int fd);
ssize_t LOS_Read(int fd, void *buff, size_t bytes);
ssize_t LOS_Write(int fd, const void *buff, size_t bytes);
off_t LOS_Lseek(int fd, off_t off, int whence);
int LOS_Stat(const char *path, struct stat *stat);
int LOS_Statfs(const char *path, struct statfs *buf);
int LOS_Unlink(const char *path);
int LOS_Rename(const char *oldpath, const char *newpath);
int LOS_Fsync(int fd);
DIR *LOS_Opendir(const char *path);
struct dirent *LOS_Readdir(DIR *dir);
int LOS_Closedir(DIR *dir);
int LOS_Mkdir(const char *path, mode_t mode);
int LOS_Rmdir(const char *path);
int LOS_Lstat(const char *path, struct stat *buffer);
int LOS_Fstat(int fd, struct stat *buf);
int LOS_Fcntl(int fd, int cmd, ...);
int LOS_Ioctl(int fd, int req, ...);
ssize_t LOS_Readv(int fd, const struct iovec *iovBuf, int iovcnt);
ssize_t LOS_Writev(int fd, const struct iovec *iovBuf, int iovcnt);
ssize_t LOS_Pread(int fd, void *buff, size_t bytes, off_t off);
ssize_t LOS_Pwrite(int fd, const void *buff, size_t bytes, off_t off);
int LOS_Isatty(int fd);
int LOS_Access(const char *path, int amode);
int LOS_Ftruncate(int fd, off_t length);
int LOS_FsUmount(const char *target);
int LOS_FsUmount2(const char *target, int flag);
int LOS_FsMount(const char *source, const char *target,
                const char *fsType, unsigned long mountflags,
                const void *data);
int OsFcntl(int fd, int cmd, va_list ap);
int OsIoctl(int fd, int req, va_list ap);

Close #I66F6I
Signed-off-by: Narvinzzz <zhaotianyu9@huawei.com>
上级 eb08c174
......@@ -32,7 +32,6 @@ config FS_FAT
default n
depends on FS_VFS
select SUPPORT_FATFS
select KAL_CMSIS
help
Answer Y to enable LiteOS support fat filesystem.
......@@ -30,6 +30,7 @@
config FS_VFS
bool "Enable FS VFS"
default y
select POSIX_FS_API
help
Answer Y to enable LiteOS support VFS.
......@@ -62,41 +62,6 @@ extern "C" {
#define LOSCFG_FS_FREE_HOOK(ptr) LOS_MemFree((VOID *)OS_SYS_MEM_ADDR, ptr)
#endif
int LOS_Open(const char *path, int flags, ...);
int LOS_Close(int fd);
ssize_t LOS_Read(int fd, void *buff, size_t bytes);
ssize_t LOS_Write(int fd, const void *buff, size_t bytes);
off_t LOS_Lseek(int fd, off_t off, int whence);
int LOS_Stat(const char *path, struct stat *stat);
int LOS_Statfs(const char *path, struct statfs *buf);
int LOS_Unlink(const char *path);
int LOS_Rename(const char *oldpath, const char *newpath);
int LOS_Fsync(int fd);
DIR *LOS_Opendir(const char *path);
struct dirent *LOS_Readdir(DIR *dir);
int LOS_Closedir(DIR *dir);
int LOS_Mkdir(const char *path, mode_t mode);
int LOS_Rmdir(const char *path);
int LOS_Lstat(const char *path, struct stat *buffer);
int LOS_Fstat(int fd, struct stat *buf);
int LOS_Fcntl(int fd, int cmd, ...);
int LOS_Ioctl(int fd, int req, ...);
ssize_t LOS_Readv(int fd, const struct iovec *iovBuf, int iovcnt);
ssize_t LOS_Writev(int fd, const struct iovec *iovBuf, int iovcnt);
ssize_t LOS_Pread(int fd, void *buff, size_t bytes, off_t off);
ssize_t LOS_Pwrite(int fd, const void *buff, size_t bytes, off_t off);
int LOS_Isatty(int fd);
int LOS_Access(const char *path, int amode);
int LOS_Ftruncate(int fd, off_t length);
int LOS_FsUmount(const char *target);
int LOS_FsUmount2(const char *target, int flag);
int LOS_FsMount(const char *source, const char *target,
const char *fsType, unsigned long mountflags,
const void *data);
int OsFcntl(int fd, int cmd, va_list ap);
int OsIoctl(int fd, int req, va_list ap);
struct PartitionCfg {
/* partition low-level read func */
int (*readFunc)(int partition, UINT32 *offset, void *buf, UINT32 size);
......
此差异已折叠。
......@@ -178,7 +178,7 @@ STATIC int VfsRemount(const char *source, const char *target,
return mp->mFs->fsMops->mount(mp, mountflags, data);
}
int LOS_FsMount(const char *source, const char *target,
int mount(const char *source, const char *target,
const char *fsType, unsigned long mountflags,
const void *data)
{
......@@ -242,7 +242,7 @@ errout:
return (int)LOS_NOK;
}
int LOS_FsUmount(const char *target)
int umount(const char *target)
{
struct MountPoint *mp = NULL;
const char *pathInMp = NULL;
......@@ -300,7 +300,7 @@ static void CloseFdsInMp(const struct MountPoint *mp)
}
}
int LOS_FsUmount2(const char *target, int flag)
int umount2(const char *target, int flag)
{
struct MountPoint *mp = NULL;
const char *pathInMp = NULL;
......
......@@ -35,7 +35,6 @@ choice
config LIBC_MUSL
bool "musl libc"
rsource "musl/Kconfig"
config LIBC_NEWLIB
bool "newlibc"
......
# Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
# Copyright (c) 2020-2022 Huawei Device Co., Ltd. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
......@@ -33,10 +33,7 @@ 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 = [
"fs.c",
"malloc.c",
]
sources = [ "malloc.c" ]
configs += [ "$LITEOSTOPDIR:warn_config" ]
deps = [ "//third_party/musl/porting/liteos_m/kernel" ]
......
# Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this list of
# conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice, this list
# of conditions and the following disclaimer in the documentation and/or other materials
# provided with the distribution.
#
# 3. Neither the name of the copyright holder nor the names of its contributors may be used
# to endorse or promote products derived from this software without specific prior written
# permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
if LIBC_MUSL
config LIBC_MUSL_FS
bool "Enable POSIX file system API support"
default y
depends on FS_VFS
help
This enables POSIX style file system related APIs.
endif # LIBC_MUSL
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#define _GNU_SOURCE
#include "los_config.h"
#include <errno.h>
#include <stdarg.h>
#include <dirent.h>
#include <sys/mount.h>
#include <sys/statfs.h>
#include <sys/stat.h>
#include <unistd.h>
#ifdef LOSCFG_LIBC_MUSL_FS
#include "los_fs.h"
int mount(const char *source, const char *target,
const char *filesystemtype, unsigned long mountflags,
const void *data)
{
return LOS_FsMount(source, target, filesystemtype, mountflags, data);
}
int umount(const char *target)
{
return LOS_FsUmount(target);
}
int umount2(const char *target, int flag)
{
return LOS_FsUmount2(target, flag);
}
int open(const char *path, int oflag, ...)
{
va_list vaList;
va_start(vaList, oflag);
int ret;
ret = LOS_Open(path, oflag, vaList);
va_end(vaList);
return ret;
}
int close(int fd)
{
return LOS_Close(fd);
}
ssize_t read(int fd, void *buf, size_t nbyte)
{
return LOS_Read(fd, buf, nbyte);
}
ssize_t write(int fd, const void *buf, size_t nbyte)
{
return LOS_Write(fd, buf, nbyte);
}
off_t lseek(int fd, off_t offset, int whence)
{
return LOS_Lseek(fd, offset, whence);
}
int unlink(const char *path)
{
return LOS_Unlink(path);
}
int fstat(int fd, struct stat *buf)
{
return LOS_Fstat(fd, buf);
}
int stat(const char *path, struct stat *buf)
{
return LOS_Stat(path, buf);
}
int fsync(int fd)
{
return LOS_Fsync(fd);
}
int mkdir(const char *path, mode_t mode)
{
return LOS_Mkdir(path, mode);
}
DIR *opendir(const char *dirName)
{
return LOS_Opendir(dirName);
}
struct dirent *readdir(DIR *dir)
{
return LOS_Readdir(dir);
}
int closedir(DIR *dir)
{
return LOS_Closedir(dir);
}
int rmdir(const char *path)
{
return LOS_Unlink(path);
}
int rename(const char *oldName, const char *newName)
{
return LOS_Rename(oldName, newName);
}
int statfs(const char *path, struct statfs *buf)
{
return LOS_Statfs(path, buf);
}
int ftruncate(int fd, off_t length)
{
return LOS_Ftruncate(fd, length);
}
ssize_t pread(int fd, void *buf, size_t nbyte, off_t offset)
{
return LOS_Pread(fd, buf, nbyte, offset);
}
ssize_t pwrite(int fd, const void *buf, size_t nbyte, off_t offset)
{
return LOS_Pwrite(fd, buf, nbyte, offset);
}
int access(const char *path, int mode)
{
struct stat st;
if (stat(path, &st) < 0) {
return -1;
}
if ((st.st_mode & S_IFDIR) || (st.st_mode & S_IFREG)) {
return 0;
}
if ((mode & W_OK) && !(st.st_mode & S_IWRITE)) {
return -1;
}
return 0;
}
int fcntl(int fd, int cmd, ...)
{
int ret;
va_list vaList;
va_start(vaList, cmd);
ret = OsFcntl(fd, cmd, vaList);
va_end(vaList);
return ret;
}
int ioctl(int fd, int req, ...)
{
int ret;
va_list vaList;
va_start(vaList, req);
ret = OsIoctl(fd, req, vaList);
va_end(vaList);
return ret;
}
#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;
}
int access(const char *path, int mode)
{
return -1;
}
int fcntl(int fd, int cmd, ...)
{
return -1;
}
int ioctl(int fd, int req, ...)
{
return -1;
}
#endif
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
* Copyright (c) 2020-2022 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
......@@ -34,7 +34,6 @@
#include "los_config.h"
#include "los_memory.h"
void *calloc(size_t nitems, size_t size)
{
size_t real_size;
......@@ -107,4 +106,3 @@ void *realloc(void *ptr, size_t size)
return LOS_MemRealloc(OS_SYS_MEM_ADDR, ptr, size);
}
# Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
# Copyright (c) 2020-2022 Huawei Device Co., Ltd. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
......@@ -33,7 +33,6 @@ module_switch = defined(LOSCFG_LIBC_NEWLIB)
module_name = get_path_info(rebase_path("."), "name")
kernel_module(module_name) {
sources = [
"porting/src/fs.c",
"porting/src/malloc.c",
"porting/src/network/htonl.c",
"porting/src/network/htons.c",
......@@ -44,7 +43,7 @@ kernel_module(module_name) {
]
configs += [ "$LITEOSTOPDIR:warn_config" ]
if (defined(LOSCFG_LIBC_NEWLIB_FS)) {
if (defined(LOSCFG_FS_VFS)) {
sources +=
[ "//third_party/musl/porting/liteos_m/kernel/src/misc/realpath.c" ]
}
......
/*
* Copyright (c) 2021-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#define _GNU_SOURCE
#include "los_config.h"
#include <errno.h>
#include <stdio.h>
#include <stdarg.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
#ifdef LOSCFG_LIBC_NEWLIB_FS
#include "los_fs.h"
#endif
#ifdef LOSCFG_LIBC_NEWLIB_FS
int mount(const char *source, const char *target,
const char *filesystemtype, unsigned long mountflags,
const void *data)
{
return LOS_FsMount(source, target, filesystemtype, mountflags, data);
}
int umount(const char *target)
{
return LOS_FsUmount(target);
}
int umount2(const char *target, int flag)
{
return LOS_FsUmount2(target, flag);
}
int _open(const char *path, int oflag, ...)
{
va_list vaList;
va_start(vaList, oflag);
int ret;
ret = LOS_Open(path, oflag);
va_end(vaList);
return ret;
}
int _close(int fd)
{
return LOS_Close(fd);
}
ssize_t _read(int fd, void *buf, size_t nbyte)
{
return LOS_Read(fd, buf, nbyte);
}
ssize_t _write(int fd, const void *buf, size_t nbyte)
{
return LOS_Write(fd, buf, nbyte);
}
off_t _lseek(int fd, off_t offset, int whence)
{
return LOS_Lseek(fd, offset, whence);
}
int _unlink(const char *path)
{
return LOS_Unlink(path);
}
int _fstat(int fd, struct stat *buf)
{
return LOS_Fstat(fd, buf);
}
int _stat(const char *path, struct stat *buf)
{
return LOS_Stat(path, buf);
}
int fsync(int fd)
{
return LOS_Fsync(fd);
}
int mkdir(const char *path, mode_t mode)
{
return LOS_Mkdir(path, mode);
}
DIR *opendir(const char *dirName)
{
return LOS_Opendir(dirName);
}
struct dirent *readdir(DIR *dir)
{
return LOS_Readdir(dir);
}
int closedir(DIR *dir)
{
return LOS_Closedir(dir);
}
int rmdir(const char *path)
{
return LOS_Unlink(path);
}
int rename(const char *oldName, const char *newName)
{
return LOS_Rename(oldName, newName);
}
int statfs(const char *path, struct statfs *buf)
{
return LOS_Statfs(path, buf);
}
int ftruncate(int fd, off_t length)
{
return LOS_Ftruncate(fd, length);
}
int fcntl(int fd, int cmd, ...)
{
int ret;
va_list vaList;
va_start(vaList, cmd);
ret = OsFcntl(fd, cmd, vaList);
va_end(vaList);
return ret;
}
int ioctl(int fd, int req, ...)
{
int ret;
va_list vaList;
va_start(vaList, req);
ret = OsIoctl(fd, req, vaList);
va_end(vaList);
return ret;
}
ssize_t pread(int fd, void *buf, size_t nbyte, off_t offset)
{
return LOS_Pread(fd, buf, nbyte, offset);
}
ssize_t pwrite(int fd, const void *buf, size_t nbyte, off_t offset)
{
return LOS_Pwrite(fd, buf, nbyte, offset);
}
int access(const char *path, int mode)
{
struct stat st;
if (stat(path, &st) < 0) {
return -1;
}
if ((st.st_mode & S_IFDIR) || (st.st_mode & S_IFREG)) {
return 0;
}
if ((mode & W_OK) && !(st.st_mode & S_IWRITE)) {
return -1;
}
return 0;
}
int remove(const char *filename)
{
int ret = unlink(filename);
if (ret == -EISDIR) {
ret = rmdir(filename);
}
return ret;
}
#else /* #ifdef LOSCFG_FS_VFS */
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 access(const char *path, int mode)
{
return -1;
}
int remove(const char *filename)
{
return -1;
}
int fcntl(int fd, int cmd, ...)
{
return -1;
}
int ioctl(int fd, int req, ...)
{
return -1;
}
#endif
......@@ -57,4 +57,3 @@ void _exit(int status)
while (1) {
}
}
......@@ -73,4 +73,11 @@ config POSIX_SIGNAL_API
help
Answer Y to enable LiteOS support POSIX Signal API.
config POSIX_FS_API
bool "Enable POSIX FS API"
default y
depends on FS_VFS
help
Answer Y to enable LiteOS support POSIX FS API.
endif # POSIX_API
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册