diff --git a/bsd/dev/usb/storage/umass_fs.h b/bsd/dev/usb/storage/umass_fs.h deleted file mode 120000 index 878547e7..00000000 --- a/bsd/dev/usb/storage/umass_fs.h +++ /dev/null @@ -1 +0,0 @@ -../../../../../../third_party/NuttX/include/nuttx/usb/storage.h \ No newline at end of file diff --git a/compat/posix/src/mqueue.c b/compat/posix/src/mqueue.c index 38adb40f..9916b641 100644 --- a/compat/posix/src/mqueue.c +++ b/compat/posix/src/mqueue.c @@ -38,7 +38,7 @@ #include "los_memory.h" #include "los_vm_map.h" #include "los_process_pri.h" -#include "fs_file.h" +#include "fs/file.h" #include "user_copy.h" diff --git a/fs/vfs/disk/Makefile b/drivers/block/disk/Makefile similarity index 98% rename from fs/vfs/disk/Makefile rename to drivers/block/disk/Makefile index d61cb100..1a2ddf61 100644 --- a/fs/vfs/disk/Makefile +++ b/drivers/block/disk/Makefile @@ -31,7 +31,7 @@ include $(LITEOSTOPDIR)/config.mk MODULE_NAME := $(notdir $(shell pwd)) -LOCAL_SRCS := $(wildcard *.c) +LOCAL_SRCS := $(wildcard src/*.c) LOCAL_INCLUDE := \ diff --git a/fs/include/disk.h b/drivers/block/disk/include/disk.h similarity index 99% rename from fs/include/disk.h rename to drivers/block/disk/include/disk.h index b9d64f45..851aa563 100644 --- a/fs/include/disk.h +++ b/drivers/block/disk/include/disk.h @@ -37,7 +37,7 @@ #ifndef _DISK_H #define _DISK_H -#include "fs/fs.h" +#include "fs/driver.h" #include "los_base.h" #include "pthread.h" diff --git a/fs/vfs/include/disk/disk_pri.h b/drivers/block/disk/include/disk_pri.h similarity index 100% rename from fs/vfs/include/disk/disk_pri.h rename to drivers/block/disk/include/disk_pri.h diff --git a/fs/vfs/include/driver/driver.h b/drivers/block/disk/include/driver.h similarity index 99% rename from fs/vfs/include/driver/driver.h rename to drivers/block/disk/include/driver.h index 87648eea..d2dcf27f 100644 --- a/fs/vfs/include/driver/driver.h +++ b/drivers/block/disk/include/driver.h @@ -37,7 +37,7 @@ ****************************************************************************/ #include "vfs_config.h" -#include "fs/fs.h" +#include "fs/file.h" #ifdef __cplusplus diff --git a/fs/vfs/disk/disk.c b/drivers/block/disk/src/disk.c similarity index 99% rename from fs/vfs/disk/disk.c rename to drivers/block/disk/src/disk.c index d03ce62d..756d3cc1 100644 --- a/fs/vfs/disk/disk.c +++ b/drivers/block/disk/src/disk.c @@ -35,7 +35,7 @@ #include "unistd.h" #include "sys/mount.h" #include "linux/spinlock.h" -#include "fs/path_cache.h" +#include "path_cache.h" los_disk g_sysDisk[SYS_MAX_DISK]; los_part g_sysPart[SYS_MAX_PART]; diff --git a/fs/vfs/disk/disk_shellcmd.c b/drivers/block/disk/src/disk_shellcmd.c similarity index 99% rename from fs/vfs/disk/disk_shellcmd.c rename to drivers/block/disk/src/disk_shellcmd.c index d92d6251..38227121 100644 --- a/fs/vfs/disk/disk_shellcmd.c +++ b/drivers/block/disk/src/disk_shellcmd.c @@ -36,7 +36,7 @@ #include "disk.h" #include "shcmd.h" #include "shell.h" -#include "fs/path_cache.h" +#include "path_cache.h" INT32 osShellCmdPartInfo(INT32 argc, const CHAR **argv) { diff --git a/fs/vfs/bch/Makefile b/drivers/char/bch/Makefile similarity index 100% rename from fs/vfs/bch/Makefile rename to drivers/char/bch/Makefile diff --git a/fs/vfs/include/driver/blockproxy.h b/drivers/char/bch/include/blockproxy.h similarity index 100% rename from fs/vfs/include/driver/blockproxy.h rename to drivers/char/bch/include/blockproxy.h diff --git a/drivers/char/mem/src/mem.c b/drivers/char/mem/src/mem.c index c16ca27c..4030a29c 100644 --- a/drivers/char/mem/src/mem.c +++ b/drivers/char/mem/src/mem.c @@ -31,6 +31,7 @@ #include "fcntl.h" #include "linux/kernel.h" +#include "fs/driver.h" static int MemOpen(struct file *filep) { @@ -42,17 +43,17 @@ static int MemClose(struct file *filep) return 0; } -static ssize_t MemRead(FAR struct file *filep, FAR char *buffer, size_t buflen) +static ssize_t MemRead(struct file *filep, char *buffer, size_t buflen) { return 0; } -static ssize_t MemWrite(FAR struct file *filep, FAR const char *buffer, size_t buflen) +static ssize_t MemWrite(struct file *filep, const char *buffer, size_t buflen) { return 0; } -static ssize_t MemMap(FAR struct file *filep, FAR LosVmMapRegion *region) +static ssize_t MemMap(struct file *filep, LosVmMapRegion *region) { #ifdef LOSCFG_KERNEL_VM size_t size = region->range.size; diff --git a/drivers/char/quickstart/src/quickstart.c b/drivers/char/quickstart/src/quickstart.c index 84db844a..5f55bc14 100644 --- a/drivers/char/quickstart/src/quickstart.c +++ b/drivers/char/quickstart/src/quickstart.c @@ -33,7 +33,8 @@ #include "fcntl.h" #include "linux/kernel.h" #include "los_process_pri.h" -#include "fs/fs.h" +#include "fs/file.h" +#include "fs/driver.h" EVENT_CB_S g_qsEvent; static SysteminitHook g_systemInitFunc[QS_STAGE_CNT] = {0}; diff --git a/drivers/char/random/src/random.c b/drivers/char/random/src/random.c index 5fb95f5f..365249e1 100644 --- a/drivers/char/random/src/random.c +++ b/drivers/char/random/src/random.c @@ -32,6 +32,7 @@ #include "los_random.h" #include "fcntl.h" #include "linux/kernel.h" +#include "fs/driver.h" static unsigned long g_randomMax = 0x7FFFFFFF; @@ -91,7 +92,7 @@ ssize_t RanRead(struct file *filep, char *buffer, size_t buflen) return (buflen - len); /* return a successful len */ } -static ssize_t RanMap(FAR struct file *filep, FAR LosVmMapRegion *region) +static ssize_t RanMap(struct file *filep, LosVmMapRegion *region) { PRINTK("%s %d, mmap is not support\n", __FUNCTION__, __LINE__); return 0; diff --git a/drivers/char/random/src/random_hw.c b/drivers/char/random/src/random_hw.c index f7c6780e..ffaa495a 100644 --- a/drivers/char/random/src/random_hw.c +++ b/drivers/char/random/src/random_hw.c @@ -33,6 +33,7 @@ #include "fcntl.h" #include "hisoc/random.h" #include "linux/kernel.h" +#include "fs/driver.h" static RandomOperations g_randomOp; void RandomOperationsInit(const RandomOperations *r) @@ -89,7 +90,7 @@ static ssize_t RandomHwRead(struct file *filep, char *buffer, size_t buflen) return ret; } -static ssize_t RandomMap(FAR struct file *filep, FAR LosVmMapRegion *region) +static ssize_t RandomMap(struct file *filep, LosVmMapRegion *region) { PRINTK("%s %d, mmap is not support\n", __FUNCTION__, __LINE__); return 0; diff --git a/fs/vfs/multi_partition/Makefile b/drivers/mtd/multi_partition/Makefile similarity index 97% rename from fs/vfs/multi_partition/Makefile rename to drivers/mtd/multi_partition/Makefile index d5e625c4..79000fdf 100644 --- a/fs/vfs/multi_partition/Makefile +++ b/drivers/mtd/multi_partition/Makefile @@ -35,6 +35,7 @@ LOCAL_SRCS := $(wildcard src/*.c) LOCAL_INCLUDE := \ -I $(LITEOSTOPDIR)/fs/jffs2/include \ + -I $(LITEOSTOPDIR)/drivers/mtd/multi_partition/include \ -I $(LITEOSTOPDIR)/../../device/hisilicon/drivers/include/mtd/common/include ifeq ($(LOSCFG_PLATFORM_QEMU_ARM_VIRT_CA7), y) diff --git a/fs/vfs/include/driver/mtd_dev.h b/drivers/mtd/multi_partition/include/mtd_dev.h similarity index 100% rename from fs/vfs/include/driver/mtd_dev.h rename to drivers/mtd/multi_partition/include/mtd_dev.h diff --git a/fs/vfs/include/driver/mtd_list.h b/drivers/mtd/multi_partition/include/mtd_list.h similarity index 100% rename from fs/vfs/include/driver/mtd_list.h rename to drivers/mtd/multi_partition/include/mtd_list.h diff --git a/fs/vfs/include/multi_partition/mtd_partition.h b/drivers/mtd/multi_partition/include/mtd_partition.h similarity index 100% rename from fs/vfs/include/multi_partition/mtd_partition.h rename to drivers/mtd/multi_partition/include/mtd_partition.h diff --git a/fs/vfs/multi_partition/src/mtd_partition.c b/drivers/mtd/multi_partition/src/mtd_partition.c similarity index 99% rename from fs/vfs/multi_partition/src/mtd_partition.c rename to drivers/mtd/multi_partition/src/mtd_partition.c index bbdb9a36..9a92fcd1 100644 --- a/fs/vfs/multi_partition/src/mtd_partition.c +++ b/drivers/mtd/multi_partition/src/mtd_partition.c @@ -36,7 +36,7 @@ #include "mtd_list.h" #include "los_config.h" #include "los_mux.h" - +#include "fs/driver.h" #include "mtd_common.h" #ifdef LOSCFG_PLATFORM_QEMU_ARM_VIRT_CA7 diff --git a/fs/vfs/multi_partition/src/mtd_shellcmd.c b/drivers/mtd/multi_partition/src/mtd_shellcmd.c similarity index 100% rename from fs/vfs/multi_partition/src/mtd_shellcmd.c rename to drivers/mtd/multi_partition/src/mtd_shellcmd.c diff --git a/fs/fat/os_adapt/fat_shellcmd.c b/fs/fat/os_adapt/fat_shellcmd.c index 35dcbdd1..74e25a89 100644 --- a/fs/fat/os_adapt/fat_shellcmd.c +++ b/fs/fat/os_adapt/fat_shellcmd.c @@ -37,7 +37,6 @@ #include "errno.h" #include "shcmd.h" #include "shell.h" -#include "fs/fs.h" #include "fatfs.h" int osShellCmdFormat(int argc, char **argv) @@ -77,45 +76,5 @@ int osShellCmdFormat(int argc, char **argv) return 0; } -#ifdef LOSCFG_FS_FAT_VIRTUAL_PARTITION -int osShellCmdVirstatfs(int argc, char** argv) -{ - struct statfs sfs; - unsigned long long totalSize, freeSize; - int result; - (void)memset_s(&sfs, sizeof(sfs), 0, sizeof(sfs)); - if (argc != 1) { - perror("virstatfs error"); - PRINTK("Usage :\n"); - PRINTK(" virstatfs \n"); - PRINTK(" virtual_entry : the path of the virtual partition entry\n"); - PRINTK("Example:\n"); - PRINTK(" virstatfs /mnt/sd/virpart0\n"); - return FAT_ERROR; - } - - result = virstatfs(argv[0], &sfs); - if (result < 0) { - set_errno(-result); - perror("virstatfs failed"); - return FAT_ERROR; - } - totalSize = (unsigned long long)sfs.f_bsize * sfs.f_blocks; - freeSize = (unsigned long long)sfs.f_bsize * sfs.f_bfree; - - PRINTK("Virtual partition \"%s\" Info:\n", argv[0]); - PRINTK(" f_type = %d\n cluster_size = %d\n total_clusters = 0x%llx\n ", - sfs.f_type, sfs.f_bsize, sfs.f_blocks); - PRINTK("free_clusters = 0x%llx\n avail_clusters = 0x%llx\n f_namelen = %d\n", - sfs.f_bfree, sfs.f_bavail, sfs.f_namelen); - PRINTK("\n%s\n total size: %4llu Bytes\n free size: %4llu Bytes\n", argv[0], totalSize, freeSize); - - return 0; -} -#endif - -#if defined(LOSCFG_FS_FAT_VIRTUAL_PARTITION) && defined(LOSCFG_SHELL_CMD_DEBUG) - SHELLCMD_ENTRY(virstatfs_shellcmd, CMD_TYPE_EX, "virstatfs", XARGS, (CmdCallBackFunc)osShellCmdVirstatfs); -#endif SHELLCMD_ENTRY(format_shellcmd, CMD_TYPE_EX, "format", XARGS, (CmdCallBackFunc)osShellCmdFormat); #endif diff --git a/fs/fat/os_adapt/fatfs.c b/fs/fat/os_adapt/fatfs.c index f60fc1b6..952d989d 100644 --- a/fs/fat/os_adapt/fatfs.c +++ b/fs/fat/os_adapt/fatfs.c @@ -32,15 +32,13 @@ #include "fatfs.h" #ifdef LOSCFG_FS_FAT #include "ff.h" -#include "fs/vfs_util.h" #include "disk_pri.h" #include "diskio.h" #include "fs/fs.h" #include "fs/dirent_fs.h" -#include "fs_other.h" #include "fs/mount.h" -#include "fs/vnode.h" -#include "fs/path_cache.h" +#include "vnode.h" +#include "path_cache.h" #ifdef LOSCFG_FS_FAT_VIRTUAL_PARTITION #include "virpartff.h" #include "errcode_fat.h" @@ -55,6 +53,7 @@ #include #include #include +#include "los_hash.h" struct VnodeOps fatfs_vops; /* forward define */ @@ -214,10 +213,10 @@ int fatfs_hash_cmp(struct Vnode *vp, void *arg) static DWORD fatfs_hash(QWORD sect, DWORD dptr, DWORD sclst) { - DWORD hash = FNV1_32_INIT; - hash = fnv_32_buf(§, sizeof(QWORD), hash); - hash = fnv_32_buf(&dptr, sizeof(DWORD), hash); - hash = fnv_32_buf(&sclst, sizeof(DWORD), hash); + DWORD hash = FNV1_32A_INIT; + hash = LOS_HashFNV32aBuf(§, sizeof(QWORD), hash); + hash = LOS_HashFNV32aBuf(&dptr, sizeof(DWORD), hash); + hash = LOS_HashFNV32aBuf(&sclst, sizeof(DWORD), hash); return hash; } diff --git a/fs/fat/os_adapt/fatfs.h b/fs/fat/os_adapt/fatfs.h index 4c1f7821..a9d280e5 100644 --- a/fs/fat/os_adapt/fatfs.h +++ b/fs/fat/os_adapt/fatfs.h @@ -33,7 +33,7 @@ #define _FATFS_H #include "ff.h" -#include "fs/fs.h" +#include "fs/file.h" #include "disk.h" #include "unistd.h" #include "string.h" @@ -107,6 +107,12 @@ extern "C" { #define FDEBUG(...) #endif +/* Format options (3rd argument of format) */ +#define FMT_FAT 0x01 +#define FMT_FAT32 0x02 +#define FMT_ANY 0x07 +#define FMT_ERASE 0x08 + int fatfs_2_vfs(int result); int fatfs_lookup(struct Vnode *parent, const char *name, int len, struct Vnode **vpp); int fatfs_create(struct Vnode *parent, const char *name, int mode, struct Vnode **vpp); diff --git a/fs/fat/virpart/include/virpart.h b/fs/fat/virpart/include/virpart.h index 4341c829..841295e0 100644 --- a/fs/fat/virpart/include/virpart.h +++ b/fs/fat/virpart/include/virpart.h @@ -32,9 +32,19 @@ #ifndef _VIRPART_H #define _VIRPART_H -#include "ff.h" +#include "integer.h" #include "disk.h" +#define _MAX_ENTRYLENGTH 16 /* MAX virtual partition name length */ +#define _MAX_VIRVOLUMES 5 /* MAX virtual partition number */ +typedef struct virtual_partition_info +{ + char *devpartpath; /* need set virtual partition, e.g. /dev/mmcblk0p0 */ + int virpartnum; /* virtual partition numbers, MAX number is 5 */ + double virpartpercent[_MAX_VIRVOLUMES]; /* every virtual partition percent,e.g 0.6,0.3,0.1 */ + char virpartname[_MAX_VIRVOLUMES][_MAX_ENTRYLENGTH + 1]; /* every virtual partition name, MAX length is 16 */ +} virpartinfo; + extern char g_devPartName[DISK_NAME + 1]; INT FatFsBindVirPart(void *handle, BYTE vol); @@ -43,4 +53,4 @@ INT FatFsUnbindVirPart(void *handle); INT FatFsMakeVirPart(void *handle, BYTE vol); -#endif /* _VIRPART_H */ \ No newline at end of file +#endif /* _VIRPART_H */ diff --git a/fs/fat/virpart/src/virpart.c b/fs/fat/virpart/src/virpart.c index 9d0238c2..87372d83 100644 --- a/fs/fat/virpart/src/virpart.c +++ b/fs/fat/virpart/src/virpart.c @@ -34,15 +34,16 @@ #include "fatfs.h" #include "errcode_fat.h" #include "disk.h" +#include "fs/mount.h" #ifdef LOSCFG_FS_FAT_CACHE #include "bcache.h" #endif -#ifdef LOSCFG_FS_FAT_VIRTUAL_PARTITION - #include "virpartff.h" +#ifdef LOSCFG_FS_FAT_VIRTUAL_PARTITION + char g_devPartName[DISK_NAME + 1] = {0}; static INT FatFsCheckPercent(virpartinfo *virtualinfo) diff --git a/fs/include/compiler.h b/fs/include/compiler.h deleted file mode 120000 index 125c7f61..00000000 --- a/fs/include/compiler.h +++ /dev/null @@ -1 +0,0 @@ -../../../../third_party/NuttX/include/nuttx/compiler.h \ No newline at end of file diff --git a/fs/include/debug.h b/fs/include/debug.h deleted file mode 120000 index b109ec9b..00000000 --- a/fs/include/debug.h +++ /dev/null @@ -1 +0,0 @@ -../../../../third_party/NuttX/include/debug.h \ No newline at end of file diff --git a/fs/include/fs/automount.h b/fs/include/fs/automount.h deleted file mode 120000 index e890caca..00000000 --- a/fs/include/fs/automount.h +++ /dev/null @@ -1 +0,0 @@ -../../../../../third_party/NuttX/include/nuttx/fs/automount.h \ No newline at end of file diff --git a/fs/include/fs/driver.h b/fs/include/fs/driver.h new file mode 100644 index 00000000..b23ebdea --- /dev/null +++ b/fs/include/fs/driver.h @@ -0,0 +1,298 @@ +/**************************************************************************** + * include/fs/fs.h + * + * Copyright (C) 2007-2009, 2011-2013, 2015-2018 Gregory Nutt. All rights + * reserved. + * Author: Gregory Nutt + * + * 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 NuttX 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 OWNER 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. + * + ****************************************************************************/ + +#ifndef _FS_DRIVER_H_ +#define _FS_DRIVER_H_ + +#include +#include "vnode.h" +#include "fs/file.h" + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +/* This structure provides information about the state of a block driver */ + +struct geometry +{ + bool geo_available; /* true: The device is available */ + bool geo_mediachanged; /* true: The media has changed since last query */ + bool geo_writeenabled; /* true: It is okay to write to this device */ + unsigned long long geo_nsectors; /* Number of sectors on the device */ + size_t geo_sectorsize; /* Size of one sector */ +}; + +/* This structure is provided by block devices when they register with the + * system. It is used by file systems to perform filesystem transfers. It + * differs from the normal driver vtable in several ways -- most notably in + * that it deals in struct Vnode vs. struct filep. + */ + +struct block_operations +{ + int (*open)(struct Vnode *vnode); + int (*close)(struct Vnode *vnode); + ssize_t (*read)(struct Vnode *vnode, unsigned char *buffer, + unsigned long long start_sector, unsigned int nsectors); + ssize_t (*write)(struct Vnode *vnode, const unsigned char *buffer, + unsigned long long start_sector, unsigned int nsectors); + int (*geometry)(struct Vnode *vnode, struct geometry *geometry); + int (*ioctl)(struct Vnode *vnode, int cmd, unsigned long arg); + int (*unlink)(struct Vnode *vnode); +}; + +struct drv_data +{ + const void *ops; + mode_t mode; + void *priv; +}; + +/**************************************************************************** + * Name: register_driver + * + * Description: + * Register a character driver vnode the pseudo file system. + * + * Input Parameters: + * path - The path to the vnode to create + * fops - The file operations structure + * mode - Access privileges (not used) + * priv - Private, user data that will be associated with the vnode. + * + * Returned Value: + * Zero on success (with the vnode point in 'vnode'); A negated errno + * value is returned on a failure (all error values returned by + * vnode_reserve): + * + * EINVAL - 'path' is invalid for this operation + * EEXIST - An vnode already exists at 'path' + * ENOMEM - Failed to allocate in-memory resources for the operation + * + * Attention: + * This function should be called after los_vfs_init has been called. + * The parameter path must point a valid string, which end with the terminating null byte. + * The total length of parameter path must less than the value defined by PATH_MAX. + * The prefix of the parameter path must be /dev/. + * The fops must pointed the right functions, otherwise the system will crash when the device is being operated. + * + ****************************************************************************/ + +int register_driver(const char *path, + const struct file_operations_vfs *fops, mode_t mode, + void *priv); + +/**************************************************************************** + * Name: register_blockdriver + * + * Description: + * Register a block driver vnode the pseudo file system. + * + * Attention: + * This function should be called after los_vfs_init has been called. + * The parameter path must point a valid string, which end with the terminating null byte. + * The length of parameter path must be less than the value defined by PATH_MAX. + * The prefix of the parameter path must be '/dev/'. + * The bops must pointed the right functions, otherwise the system will crash when the device is being operated. + * + * Input Parameters: + * path - The path to the vnode to create + * bops - The block driver operations structure + * mode - Access privileges (not used) + * priv - Private, user data that will be associated with the vnode. + * + * Returned Value: + * Zero on success (with the vnode point in 'vnode'); A negated errno + * value is returned on a failure (all error values returned by + * vnode_reserve): + * + * EINVAL - 'path' is invalid for this operation + * EEXIST - An vnode already exists at 'path' + * ENOMEM - Failed to allocate in-memory resources for the operation + * + ****************************************************************************/ + +int register_blockdriver(const char *path, + const struct block_operations *bops, + mode_t mode, void *priv); + +/**************************************************************************** + * Name: unregister_driver + * + * Description: + * Remove the character driver vnode at 'path' from the pseudo-file system + * + * Returned Value: + * Zero on success (with the vnode point in 'vnode'); A negated errno + * value is returned on a failure (all error values returned by + * vnode_reserve): + * + * EBUSY - Resource is busy ,not permit for this operation. + * ENOENT - 'path' is invalid for this operation. + * + * Attention: + * This function should be called after register_blockdriver has been called. + * The parameter path must point a valid string, which end with the terminating null byte. + * The total length of parameter path must less than the value defined by PATH_MAX. + * The block device node referred by parameter path must be really exist. + ****************************************************************************/ + +int unregister_driver(const char *path); + +/**************************************************************************** + * Name: unregister_blockdriver + * + * Description: + * Remove the block driver vnode at 'path' from the pseudo-file system + * + * Input Parameters: + * path - The path that the vnode to be destroyed. + * + * Returned Value: + * Zero on success (with the vnode point in 'vnode'); A negated errno + * value is returned on a failure (all error values returned by + * vnode_reserve): + * + * EBUSY - Resource is busy ,not permit for this operation. + * ENOENT - 'path' is invalid for this operation. + * + * Attention: + * This function should be called after register_blockdriver has been called. + * The parameter path must point a valid string, which end with the terminating null byte. + * The total length of parameter path must less than the value defined by PATH_MAX. + * The block device node referred by parameter path must be really exist. + * + ****************************************************************************/ + +int unregister_blockdriver(const char *path); + + +/**************************************************************************** + * Name: open_blockdriver + * + * Description: + * Return the vnode of the block driver specified by 'pathname' + * + * Input Parameters: + * pathname - the full path to the block driver to be opened + * mountflags - if MS_RDONLY is not set, then driver must support write + * operations (see include/sys/mount.h) + * ppvnode - address of the location to return the vnode reference + * + * Returned Value: + * Returns zero on success or a negated errno on failure: + * + * EINVAL - pathname or pvnode is NULL + * ENOENT - No block driver of this name is registered + * ENOTBLK - The vnode associated with the pathname is not a block driver + * EACCESS - The MS_RDONLY option was not set but this driver does not + * support write access + * + * Aattention: + * The parameter path must point a valid string, which end with the terminating null byte. + * The total length of parameter path must less than the value defined by PATH_MAX. + * The parameter ppvnode must point a valid memory, which size must be enough for storing struct Vnode. + + ****************************************************************************/ + +#if CONFIG_NFILE_DESCRIPTORS > 0 +int open_blockdriver(const char *pathname, int mountflags, + struct Vnode **ppvnode); +#endif + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Name: find_blockdriver + * + * Description: + * Return the inode of the block driver specified by 'pathname' + * + * Input Parameters: + * pathname - The full path to the block driver to be located + * mountflags - If MS_RDONLY is not set, then driver must support write + * operations (see include/sys/mount.h) + * ppinode - Address of the location to return the inode reference + * + * Returned Value: + * Returns zero on success or a negated errno on failure: + * + * ENOENT - No block driver of this name is registered + * ENOTBLK - The inode associated with the pathname is not a block driver + * EACCESS - The MS_RDONLY option was not set but this driver does not + * support write access + * + ****************************************************************************/ + +int find_blockdriver(const char *pathname, int mountflags, + struct Vnode **vpp); + + +/**************************************************************************** + * Name: close_blockdriver + * + * Description: + * Call the close method and release the vnode + * + * Input Parameters: + * vnode - reference to the vnode of a block driver opened by open_blockdriver + * + * Returned Value: + * Returns zero on success or a negated errno on failure: + * + * EINVAL - vnode is NULL + * ENOTBLK - The vnode is not a block driver + * + * Attention: + * This function should be called after open_blockdriver has been called. + * + ****************************************************************************/ + +#if CONFIG_NFILE_DESCRIPTORS > 0 +int close_blockdriver(struct Vnode *vnode); +#endif + +#ifdef __cplusplus +#if __cplusplus +} +#endif /* __cplusplus */ +#endif /* __cplusplus */ +#endif /* _FS_DRIVER_H_ */ diff --git a/fs/include/fs/file.h b/fs/include/fs/file.h deleted file mode 120000 index 29ac3712..00000000 --- a/fs/include/fs/file.h +++ /dev/null @@ -1 +0,0 @@ -../../../../../third_party/NuttX/include/nuttx/fs/file.h \ No newline at end of file diff --git a/fs/include/fs/file.h b/fs/include/fs/file.h new file mode 100644 index 00000000..cb05f0bc --- /dev/null +++ b/fs/include/fs/file.h @@ -0,0 +1,594 @@ +/**************************************************************************** + * include/fs/file.h + * + * Copyright (C) 2007-2009, 2011-2013, 2015-2018 Gregory Nutt. All rights + * reserved. + * Author: Gregory Nutt + * + * 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 NuttX 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 OWNER 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. + * + ****************************************************************************/ + +#ifndef __INCLUDE_FS_FILE_H +#define __INCLUDE_FS_FILE_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include "vfs_config.h" + +#include "sys/types.h" +#include "sys/stat.h" +#include "semaphore.h" +#include "poll.h" +#include "los_vm_map.h" +#include "los_atomic.h" + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +#ifndef VFS_ERROR +#define VFS_ERROR -1 +#endif + +#ifndef OK +#define OK 0 +#endif + +/* This is the underlying representation of an open file. A file + * descriptor is an index into an array of such types. The type associates + * the file descriptor to the file state and to a set of vnode operations. + */ + +struct Vnode; + +struct file +{ + unsigned int f_magicnum; /* file magic number */ + int f_oflags; /* Open mode flags */ + struct Vnode *f_vnode; /* Driver interface */ + loff_t f_pos; /* File position */ + unsigned long f_refcount; /* reference count */ + char *f_path; /* File fullpath */ + void *f_priv; /* Per file driver private data */ + const char *f_relpath; /* realpath */ + struct page_mapping *f_mapping; /* mapping file to memory */ + void *f_dir; /* DIR struct for iterate the directory if open a directory */ + const struct file_operations_vfs *ops; + int fd; +}; + +/* This defines a list of files indexed by the file descriptor */ + +#if CONFIG_NFILE_DESCRIPTORS > 0 +struct filelist +{ + sem_t fl_sem; /* Manage access to the file list */ + struct file fl_files[CONFIG_NFILE_DESCRIPTORS]; +}; + +extern struct filelist tg_filelist; +#endif + +/* This structure is provided by devices when they are registered with the + * system. It is used to call back to perform device specific operations. + */ + +struct file_operations_vfs +{ + /* The device driver open method differs from the mountpoint open method */ + + int (*open)(struct file *filep); + + /* The following methods must be identical in signature and position because + * the struct file_operations and struct mountp_operations are treated like + * unions. + */ + + int (*close)(struct file *filep); + ssize_t (*read)(struct file *filep, char *buffer, size_t buflen); + ssize_t (*write)(struct file *filep, const char *buffer, size_t buflen); + off_t (*seek)(struct file *filep, off_t offset, int whence); + int (*ioctl)(struct file *filep, int cmd, unsigned long arg); + int (*mmap)(struct file* filep, struct VmMapRegion *region); + /* The two structures need not be common after this point */ + +#ifndef CONFIG_DISABLE_POLL + int (*poll)(struct file *filep, poll_table *fds); +#endif + int (*stat)(struct file *filep, struct stat* st); + int (*fallocate)(struct file* filep, int mode, off_t offset, off_t len); + int (*fallocate64)(struct file *filep, int mode, off64_t offset, off64_t len); + int (*fsync)(struct file *filep); + ssize_t (*readpage)(struct file *filep, char *buffer, size_t buflen); + int (*unlink)(struct Vnode *vnode); +}; + +/* file mapped in VMM pages */ +struct page_mapping { + LOS_DL_LIST page_list; /* all pages */ + SPIN_LOCK_S list_lock; /* lock protecting it */ + LosMux mux_lock; /* mutex lock */ + unsigned long nrpages; /* number of total pages */ + unsigned long flags; + Atomic ref; /* reference counting */ + struct file *host; /* owner of this mapping */ +}; + +/* map: full_path(owner) <-> mapping */ +struct file_map { + LOS_DL_LIST head; + LosMux lock; /* lock to protect this mapping */ + struct page_mapping mapping; + int name_len; + char *rename; + char owner[0]; /* owner: full path of file */ +}; + +/**************************************************************************** + * Name: files_initlist + * + * Description: + * Initializes the list of files for a new task + * + ****************************************************************************/ + +#if CONFIG_NFILE_DESCRIPTORS > 0 +void files_initlist(struct filelist *list); +#endif + +/**************************************************************************** + * Name: files_releaselist + * + * Description: + * Release a reference to the file list + * + ****************************************************************************/ + +#if CONFIG_NFILE_DESCRIPTORS > 0 +void files_releaselist(struct filelist *list); +#endif + +/**************************************************************************** + * Name: file_dup2 + * + * Description: + * Assign an vnode to a specific files structure. This is the heart of + * dup2. + * + * Equivalent to the non-standard fs_dupfd2() function except that it + * accepts struct file instances instead of file descriptors and it does + * not set the errno variable. + * + * Returned Value: + * Zero (OK) is returned on success; a negated errno value is return on + * any failure. + * + ****************************************************************************/ + +#if CONFIG_NFILE_DESCRIPTORS > 0 +int file_dup2(struct file *filep1, struct file *filep2); +#endif + +/**************************************************************************** + * Name: fs_dupfd OR dup + * + * Description: + * Clone a file descriptor 'fd' to an arbitrary descriptor number (any value + * greater than or equal to 'minfd'). If socket descriptors are + * implemented, then this is called by dup() for the case of file + * descriptors. If socket descriptors are not implemented, then this + * function IS dup(). + * + * This alternative naming is used when dup could operate on both file and + * socket descriptors to avoid drawing unused socket support into the link. + * + * Returned Value: + * fs_dupfd is sometimes an OS internal function and sometimes is a direct + * substitute for dup(). So it must return an errno value as though it + * were dup(). + * + ****************************************************************************/ + +#if CONFIG_NFILE_DESCRIPTORS > 0 +int fs_dupfd(int fd, int minfd); +#endif + +/**************************************************************************** + * Name: file_dup + * + * Description: + * Equivalent to the non-standard fs_dupfd() function except that it + * accepts a struct file instance instead of a file descriptor and does + * not set the errno variable. + * + * Returned Value: + * Zero (OK) is returned on success; a negated errno value is returned on + * any failure. + * + ****************************************************************************/ + +int file_dup(struct file *filep, int minfd); + +/**************************************************************************** + * Name: fs_dupfd2 OR dup2 + * + * Description: + * Clone a file descriptor to a specific descriptor number. If socket + * descriptors are implemented, then this is called by dup2() for the + * case of file descriptors. If socket descriptors are not implemented, + * then this function IS dup2(). + * + * This alternative naming is used when dup2 could operate on both file and + * socket descriptors to avoid drawing unused socket support into the link. + * + * Returned Value: + * fs_dupfd2 is sometimes an OS internal function and sometimes is a direct + * substitute for dup2(). So it must return an errno value as though it + * were dup2(). + * + ****************************************************************************/ + +#if CONFIG_NFILE_DESCRIPTORS > 0 +int fs_dupfd2(int fd1, int fd2); +#endif + +/**************************************************************************** + * Name: fs_ioctl + * + * Description: + * Perform device specific operations. + * + * Input Parameters: + * fd File/socket descriptor of device + * req The ioctl command + * arg The argument of the ioctl cmd + * + * Returned Value: + * >=0 on success (positive non-zero values are cmd-specific) + * -1 on failure with errno set properly: + * + * EBADF + * 'fd' is not a valid descriptor. + * EFAULT + * 'arg' references an inaccessible memory area. + * EINVAL + * 'cmd' or 'arg' is not valid. + * ENOTTY + * 'fd' is not associated with a character special device. + * ENOTTY + * The specified request does not apply to the kind of object that the + * descriptor 'fd' references. + * + ****************************************************************************/ +#ifdef CONFIG_LIBC_IOCTL_VARIADIC +int fs_ioctl(int fd, int req, unsigned long arg); +#endif + +/**************************************************************************** + * Name: lib_sendfile + * + * Description: + * Transfer a file + * + ****************************************************************************/ + +#ifdef CONFIG_NET_SENDFILE +ssize_t lib_sendfile(int outfd, int infd, off_t *offset, size_t count); +#endif + +/**************************************************************************** + * Name: fs_getfilep + * + * Description: + * Given a file descriptor, return the corresponding instance of struct + * file. NOTE that this function will currently fail if it is provided + * with a socket descriptor. + * + * Input Parameters: + * fd - The file descriptor + * filep - The location to return the struct file instance + * + * Returned Value: + * Zero (OK) is returned on success; a negated errno value is returned on + * any failure. + * + ****************************************************************************/ + +#if CONFIG_NFILE_DESCRIPTORS > 0 +int fs_getfilep(int fd, struct file **filep); +#endif + +/**************************************************************************** + * Name: file_read + * + * Description: + * file_read() is an internal OS interface. It is functionally similar to + * the standard read() interface except: + * + * - It does not modify the errno variable, + * - It is not a cancellation point, + * - It does not handle socket descriptors, and + * - It accepts a file structure instance instead of file descriptor. + * + * Input Parameters: + * filep - File structure instance + * buf - User-provided to save the data + * nbytes - The maximum size of the user-provided buffer + * + * Returned Value: + * The positive non-zero number of bytes read on success, 0 on if an + * end-of-file condition, or a negated errno value on any failure. + * + ****************************************************************************/ + +#if CONFIG_NFILE_DESCRIPTORS > 0 +ssize_t file_read(struct file *filep, void *buf, size_t nbytes); +#endif + +/**************************************************************************** + * Name: file_write + * + * Description: + * Equivalent to the standard write() function except that is accepts a + * struct file instance instead of a file descriptor. Currently used + * only by aio_write(); + * + ****************************************************************************/ + +#if CONFIG_NFILE_DESCRIPTORS > 0 +ssize_t file_write(struct file *filep, const void *buf, size_t nbytes); +#endif + +/**************************************************************************** + * Name: file_pread + * + * Description: + * Equivalent to the standard pread function except that is accepts a + * struct file instance instead of a file descriptor. Currently used + * only by aio_read(); + * + ****************************************************************************/ + +#if CONFIG_NFILE_DESCRIPTORS > 0 +ssize_t file_pread(struct file *filep, void *buf, size_t nbytes, + off_t offset); +#endif + +/**************************************************************************** + * Name: file_pwrite + * + * Description: + * Equivalent to the standard pwrite function except that is accepts a + * struct file instance instead of a file descriptor. Currently used + * only by aio_write(); + * + ****************************************************************************/ + +#if CONFIG_NFILE_DESCRIPTORS > 0 +ssize_t file_pwrite(struct file *filep, const void *buf, + size_t nbytes, off_t offset); +#endif + +/**************************************************************************** + * Name: file_seek + * + * Description: + * Equivalent to the standard lseek() function except that is accepts a + * struct file instance instead of a file descriptor. Currently used + * only by net_sendfile() + * + ****************************************************************************/ + +#if CONFIG_NFILE_DESCRIPTORS > 0 +off_t file_seek(struct file *filep, off_t offset, int whence); +#endif + +/**************************************************************************** + * Name: file_fsync + * + * Description: + * Equivalent to the standard fsync() function except that is accepts a + * struct file instance instead of a file descriptor and it does not set + * the errno variable. + * + ****************************************************************************/ + +#if CONFIG_NFILE_DESCRIPTORS > 0 +int file_fsync(struct file *filep); +#endif + +/**************************************************************************** + * Name: file_vfcntl + * + * Description: + * Similar to the standard vfcntl function except that is accepts a struct + * struct file instance instead of a file descriptor. + * + * Input Parameters: + * filep - Instance for struct file for the opened file. + * cmd - Indentifies the operation to be performed. + * ap - Variable argument following the command. + * + * Returned Value: + * The nature of the return value depends on the command. Non-negative + * values indicate success. Failures are reported as negated errno + * values. + * + ****************************************************************************/ + +#if CONFIG_NFILE_DESCRIPTORS > 0 +int file_vfcntl(struct file *filep, int cmd, va_list ap); +#endif + +/**************************************************************************** + * Name: file_seek64 + * + * Description: + * Equivalent to the standard lseek64() function except that is accepts a + * struct file instance instead of a file descriptor. Currently used + * only by net_sendfile() + * + ****************************************************************************/ + +#if CONFIG_NFILE_DESCRIPTORS > 0 +off64_t file_seek64(struct file *filep, off64_t offset, int whence); +#endif + +/**************************************************************************** + * Name: files_allocate + * + * Description: + * Allocate a struct files instance and associate it with an vnode instance. + * Returns the file descriptor == index into the files array. + * + ****************************************************************************/ + +int files_allocate(struct Vnode *vnode, int oflags, off_t pos,void *priv, int minfd); + +/**************************************************************************** + * Name: files_close + * + * Description: + * Close an vnode (if open) + * + * Assumuptions: + * Caller holds the list semaphore because the file descriptor will be freed. + * + ****************************************************************************/ + +int files_close(int fd); + +/**************************************************************************** + * Name: files_release + * + * Assumuptions: + * Similar to files_close(). Called only from open() logic on error + * conditions. + * + ****************************************************************************/ + +void files_release(int fd); + +/**************************************************************************** + * Name: files_initialize + * + * Description: + * This is called from the FS initialization logic to configure the files. + * + ****************************************************************************/ + +void WEAK files_initialize(void); + +int vfs_normalize_path(const char *directory, const char *filename, char **pathname); +int vfs_normalize_pathat(int fd, const char *filename, char **pathname); + +struct filelist *sched_getfiles(void); + +/* fs/fs_sendfile.c *************************************************/ +/**************************************************************************** + * Name: sendfile + * + * Description: + * Copy data between one file descriptor and another. + * + ****************************************************************************/ +ssize_t sendfile(int outfd, int infd, off_t *offset, size_t count); + +/** + * @ingroup fs + * @brief get the path by a given file fd. + * + * @par Description: + * The function is used for getting the path by a given file fd. + * + * @attention + *
    + *
  • Only support file fd, not any dir fd.
  • + *
+ * + * @param fd [IN] Type #int file fd. + * @param path [IN] Type #char ** address of the location to return the path reference. + * + * @retval #0 get path success + * @retval #~0 get path failed + * + * @par Dependency: + *
  • fs.h: the header file that contains the API declaration.
+ * @see + * + * @since 2020-1-8 + */ + +int get_path_from_fd(int fd, char **path); + +bool get_bit(int i); + +int AllocProcessFd(void); + +int AllocLowestProcessFd(int minFd); + +int AllocSpecifiedProcessFd(int procFd); + +int AllocAndAssocProcessFd(int sysFd, int minFd); + +int AllocAndAssocSystemFd(int procFd, int minFd); + +void AssociateSystemFd(int procFd, int sysFd); + +int DisassociateProcessFd(int procFd); + +int GetAssociatedSystemFd(int procFd); + +int CheckProcessFd(int procFd); + +void FreeProcessFd(int procFd); + +int CopyFdToProc(int fd, unsigned int targetPid); + +int CloseProcFd(int fd, unsigned int targetPid); + +void lsfd(void); + +void set_sd_sync_fn(int (*sync_fn)(int)); + +struct Vnode *files_get_openfile(int fd); + +void poll_wait(struct file *filp, wait_queue_head_t *wait_address, poll_table *p); + +int follow_symlink(int dirfd, const char *path, struct Vnode **vnode, char **fullpath); +#ifdef __cplusplus +#if __cplusplus +} +#endif /* __cplusplus */ +#endif /* __cplusplus */ +#endif /* __INCLUDE_FS_FILE_H */ diff --git a/fs/include/fs/fs_operation.h b/fs/include/fs/fs_operation.h index 0f1e6967..fec8cfa6 100644 --- a/fs/include/fs/fs_operation.h +++ b/fs/include/fs/fs_operation.h @@ -32,7 +32,7 @@ #ifndef FS_OPERATION_H #define FS_OPERATION_H -#include "fs/fs.h" +#include "fs/file.h" #ifdef __cplusplus #if __cplusplus @@ -269,64 +269,6 @@ extern void ls(const char *pathname); extern int los_set_systime_status(BOOL b_status); -/** - * @ingroup fs - * @check the three latest files in path - * - * @par Description: - * The fscheck() function check the latest three files in path and subdirectories. - * The function will fix the FAT when the file size info of directory is not matched with FAT. - * - * @attention - *
    - *
  • This function only support for FAT32.
  • - *
- * - * @param path [IN] Type #const char * The path of the directory to be checked. - * - * @retval #0 truncate success. - * @retval #-1 truncate failed. - * - * @par Dependency: - *
  • fs.h: the header file that contains the API declaration.
- * @see - * - */ - -int fscheck(const char *path); - -#ifdef LOSCFG_FS_FAT_VIRTUAL_PARTITION -/** - * @ingroup fs - * @get the virtual partitions' or free space information in virtual parition feature. - * - * @par Description: - * The virstatfs() function returns the information about the a virtual partition or the free space - * outside the virtual partition. - * - * @attention - *
    - *
  • This function only support for FAT32.
  • - *
  • This function only support for the virtual partition feature.
  • - *
  • The parameter 'buf' need to be allocate enough memeory space outside the function first.
  • - *
- * - * @param path [IN] Type #const char * The path which virtual partition or free space to be checked. - * @param buf [OUT] Type #struct statfs * The statfs buffer saving the information. - * - * @retval #0 virstatfs success. - * @retval #-1 virstatfs failed. - * - * @par Dependency: - *
  • fs.h: the header file that contains the API declaration.
- * @see - * - */ - -extern int virstatfs(const char *path, struct statfs *buf); - -#endif - /** * @ingroup fs * diff --git a/fs/include/fs/mount.h b/fs/include/fs/mount.h index cd524cda..11f13a2b 100644 --- a/fs/include/fs/mount.h +++ b/fs/include/fs/mount.h @@ -31,11 +31,12 @@ #ifndef _MOUNT_H_ #define _MOUNT_H_ -#include "los_mux.h" -#include "fs/vfs_util.h" -#include "fs/vnode.h" #include -#include +#include +#include "vnode.h" + +#define MS_RDONLY 1 +#define MS_NOSYNC 2 struct MountOps; @@ -60,6 +61,11 @@ struct MountOps { int (*Statfs)(struct Mount *mount, struct statfs *sbp); }; +typedef int (*foreach_mountpoint_t)(const char *mountpoint, + struct statfs *statbuf, + void *arg); + struct Mount* MountAlloc(struct Vnode* vnode, struct MountOps* mop); LIST_HEAD* GetMountList(void); +int foreach_mountpoint(foreach_mountpoint_t handler, void *arg); #endif diff --git a/fs/include/fs/vfs_util.h b/fs/include/fs/vfs_util.h deleted file mode 100644 index fad55ab4..00000000 --- a/fs/include/fs/vfs_util.h +++ /dev/null @@ -1,64 +0,0 @@ -/* - * 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. - */ - -#ifndef _VFS_UTIL_H_ -#define _VFS_UTIL_H_ - -#include "los_list.h" - -typedef LOS_DL_LIST LIST_HEAD; -typedef LOS_DL_LIST LIST_ENTRY; - -#define FNV1_32_INIT ((uint32_t) 33554467UL) -#define FNV1_64_INIT ((uint64_t) 0xcbf29ce484222325ULL) - -#define FNV_32_PRIME ((uint32_t) 0x01000193UL) -#define FNV_64_PRIME ((uint64_t) 0x100000001b3ULL) - -#define V_CREATE 0x0001 -#define V_CACHE 0x0002 -#define V_DUMMY 0x0004 - - -static __inline uint32_t fnv_32_buf(const void *buf, size_t len, uint32_t hval) -{ - const uint8_t *s = (const uint8_t *)buf; - - while (len-- != 0) { - hval *= FNV_32_PRIME; - hval ^= *s++; - } - return hval; -} - -int vfs_normalize_path(const char *directory, const char *filename, char **pathname); -int vfs_normalize_pathat(int fd, const char *filename, char **pathname); - -#endif /* !_VFS_UTIL_H_ */ diff --git a/fs/include/fs/vnode.h b/fs/include/fs/vnode.h index 813a536b..63287166 100644 --- a/fs/include/fs/vnode.h +++ b/fs/include/fs/vnode.h @@ -28,102 +28,7 @@ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef _VNODE_H_ -#define _VNODE_H_ - -#include -#include "fs/fs_operation.h" -#include "fs/file.h" -#include "fs/vfs_util.h" -#include "fs/path_cache.h" - -#define VNODE_FLAG_MOUNT_NEW 1 -#define VNODE_FLAG_MOUNT_ORIGIN 2 -#define DEV_PATH_LEN 5 - - /* - * Vnode types. VNODE_TYPE_UNKNOWN means no type. - */ -enum VnodeType { - VNODE_TYPE_UNKNOWN, /* unknown type */ - VNODE_TYPE_REG, /* regular fle */ - VNODE_TYPE_DIR, /* directory */ - VNODE_TYPE_BLK, /* block device */ - VNODE_TYPE_CHR, /* char device */ - VNODE_TYPE_BCHR, /* block char mix device */ - VNODE_TYPE_FIFO, /* pipe */ - VNODE_TYPE_LNK, /* link */ -}; - -struct fs_dirent_s; -struct VnodeOps; -struct IATTR; - -struct Vnode { - enum VnodeType type; /* vnode type */ - int useCount; /* ref count of users */ - uint32_t hash; /* vnode hash */ - uint uid; /* uid for dac */ - uint gid; /* gid for dac */ - mode_t mode; /* mode for dac */ - LIST_HEAD parentPathCaches; /* pathCaches point to parents */ - LIST_HEAD childPathCaches; /* pathCaches point to children */ - struct Vnode *parent; /* parent vnode */ - struct VnodeOps *vop; /* vnode operations */ - struct file_operations_vfs *fop; /* file operations */ - void *data; /* private data */ - uint32_t flag; /* vnode flag */ - LIST_ENTRY hashEntry; /* list entry for bucket in hash table */ - LIST_ENTRY actFreeEntry; /* vnode active/free list entry */ - struct Mount *originMount; /* fs info about this vnode */ - struct Mount *newMount; /* fs info about who mount on this vnode */ -}; - -struct VnodeOps { - int (*Create)(struct Vnode *parent, const char *name, int mode, struct Vnode **vnode); - int (*Lookup)(struct Vnode *parent, const char *name, int len, struct Vnode **vnode); - int (*Open)(struct Vnode *vnode, int fd, int mode, int flags); - int (*Close)(struct Vnode *vnode); - int (*Reclaim)(struct Vnode *vnode); - int (*Unlink)(struct Vnode *parent, struct Vnode *vnode, const char *fileName); - int (*Rmdir)(struct Vnode *parent, struct Vnode *vnode, const char *dirName); - int (*Mkdir)(struct Vnode *parent, const char *dirName, mode_t mode, struct Vnode **vnode); - int (*Readdir)(struct Vnode *vnode, struct fs_dirent_s *dir); - int (*Opendir)(struct Vnode *vnode, struct fs_dirent_s *dir); - int (*Rewinddir)(struct Vnode *vnode, struct fs_dirent_s *dir); - int (*Closedir)(struct Vnode *vnode, struct fs_dirent_s *dir); - int (*Getattr)(struct Vnode *vnode, struct stat *st); - int (*Setattr)(struct Vnode *vnode, struct stat *st); - int (*Chattr)(struct Vnode *vnode, struct IATTR *attr); - int (*Rename)(struct Vnode *src, struct Vnode *dstParent, const char *srcName, const char *dstName); - int (*Truncate)(struct Vnode *vnode, off_t len); - int (*Truncate64)(struct Vnode *vnode, off64_t len); - int (*Fscheck)(struct Vnode *vnode, struct fs_dirent_s *dir); - int (*Link)(struct Vnode *src, struct Vnode *dstParent, struct Vnode **dst, const char *dstName); - int (*Symlink)(struct Vnode *parentVnode, struct Vnode **newVnode, const char *path, const char *target); - ssize_t (*Readlink)(struct Vnode *vnode, char *buffer, size_t bufLen); -}; - -typedef int VfsHashCmp(struct Vnode *vnode, void *arg); - -int VnodesInit(void); -int VnodeDevInit(void); -int VnodeAlloc(struct VnodeOps *vop, struct Vnode **vnode); -int VnodeFree(struct Vnode *vnode); -int VnodeLookup(const char *path, struct Vnode **vnode, uint32_t flags); -int VnodeHold(void); -int VnodeDrop(void); -void VnodeRefDec(struct Vnode *vnode); -int VnodeFreeAll(const struct Mount *mnt); -int VnodeHashInit(void); -uint32_t VfsHashIndex(struct Vnode *vnode); -int VfsHashGet(const struct Mount *mount, uint32_t hash, struct Vnode **vnode, VfsHashCmp *fun, void *arg); -void VfsHashRemove(struct Vnode *vnode); -int VfsHashInsert(struct Vnode *vnode, uint32_t hash); -void ChangeRoot(struct Vnode *newRoot); -BOOL VnodeInUseIter(const struct Mount *mount); -struct Vnode *VnodeGetRoot(void); -void VnodeMemoryDump(void); -int VnodeDestory(struct Vnode *vnode); - +#ifndef _FS_VNODE_H_ +#define _FS_VNODE_H_ +#include "../../vfs/include/vnode.h" /* for hdf compatibility, should remove later */ #endif /* !_VNODE_H_ */ diff --git a/fs/include/inode/inode.h b/fs/include/inode/inode.h deleted file mode 120000 index af319e46..00000000 --- a/fs/include/inode/inode.h +++ /dev/null @@ -1 +0,0 @@ -../../../../../third_party/NuttX/fs/inode/inode.h \ No newline at end of file diff --git a/fs/include/net/net.h b/fs/include/net/net.h deleted file mode 120000 index 86ac9bd4..00000000 --- a/fs/include/net/net.h +++ /dev/null @@ -1 +0,0 @@ -../../../../../third_party/NuttX/include/nuttx/net/net.h \ No newline at end of file diff --git a/fs/include/syslog.h b/fs/include/syslog.h deleted file mode 120000 index 68623eeb..00000000 --- a/fs/include/syslog.h +++ /dev/null @@ -1 +0,0 @@ -../../../../third_party/NuttX/include/syslog.h \ No newline at end of file diff --git a/fs/include/vfs_config.h b/fs/include/vfs_config.h index 835e94d1..12b8b1fc 100644 --- a/fs/include/vfs_config.h +++ b/fs/include/vfs_config.h @@ -41,6 +41,7 @@ extern "C" { #endif /* __cplusplus */ #endif /* __cplusplus */ +#define PATH_MAX 256 #define CONFIG_DISABLE_MQUEUE // disable posix mqueue inode configure /* file system configur */ @@ -88,6 +89,7 @@ extern "C" { #define CONFIG_NFILE_STREAMS 1 // enable file stream #define CONFIG_STDIO_BUFFER_SIZE 0 #define CONFIG_NUNGET_CHARS 0 +#define MIN_START_FD 3 // 0,1,2 are used for stdin,stdout,stderr respectively #define FD_SET_TOTAL_SIZE (FD_SETSIZE + CONFIG_NEXPANED_DESCRIPTORS) #define FD_SETSIZE (CONFIG_NFILE_DESCRIPTORS + CONFIG_NSOCKET_DESCRIPTORS) @@ -127,6 +129,12 @@ extern "C" { #define VFS_USING_WORKDIR // enable current working directory +/* permission configure */ +#define DEFAULT_DIR_MODE 0777 +#define DEFAULT_FILE_MODE 0666 + +#define MAX_DIRENT_NUM 14 // 14 means 4096 length buffer can store 14 dirent, see struct DIR + #ifdef __cplusplus #if __cplusplus } diff --git a/fs/jffs2/Makefile b/fs/jffs2/Makefile index 77a48a95..a778ca55 100644 --- a/fs/jffs2/Makefile +++ b/fs/jffs2/Makefile @@ -35,6 +35,7 @@ LOCAL_SRCS := $(wildcard src/*.c) \ $(wildcard $(LITEOSTHIRDPARTY)/Linux_Kernel/fs/jffs2/*.c) LOCAL_INCLUDE := \ -I $(LITEOSTOPDIR)/fs/jffs2/include \ + -I $(LITEOSTOPDIR)/drivers/mtd/multi_partition/include \ -I $(LITEOSTHIRDPARTY)/Linux_Kernel/fs/jffs2 \ -I $(LITEOSTHIRDPARTY)/Linux_Kernel/fs LOCAL_FLAGS := $(LOCAL_INCLUDE) $(LITEOS_GCOV_OPTS) diff --git a/fs/jffs2/src/vfs_jffs2.c b/fs/jffs2/src/vfs_jffs2.c index 1f85cf75..a0d3736c 100644 --- a/fs/jffs2/src/vfs_jffs2.c +++ b/fs/jffs2/src/vfs_jffs2.c @@ -46,7 +46,8 @@ #include "fs/dirent_fs.h" #include "fs/fs.h" -#include "fs/vnode.h" +#include "fs/driver.h" +#include "vnode.h" #include "mtd_list.h" #include "mtd_partition.h" #include "jffs2_hash.h" diff --git a/fs/nfs/Makefile b/fs/nfs/Makefile index 5b999391..21c1369d 100644 --- a/fs/nfs/Makefile +++ b/fs/nfs/Makefile @@ -32,6 +32,7 @@ include $(LITEOSTOPDIR)/config.mk MODULE_NAME := $(notdir $(shell pwd)) LOCAL_SRCS := $(wildcard $(LITEOSTHIRDPARTY)/NuttX/fs/nfs/*.c) +LOCAL_INCLUDE := -I $(wildcard $(LITEOSTHIRDPARTY)/NuttX/include) LOCAL_FLAGS := $(LOCAL_INCLUDE) $(LITEOS_GCOV_OPTS) diff --git a/fs/proc/include/proc_fs.h b/fs/proc/include/proc_fs.h index 3cc4ea9d..c519db91 100644 --- a/fs/proc/include/proc_fs.h +++ b/fs/proc/include/proc_fs.h @@ -40,6 +40,7 @@ #ifdef LOSCFG_FS_PROC #include "linux/spinlock.h" #include "asm/atomic.h" +#include "vnode.h" #include "fs/file.h" #include "los_seq_buf.h" diff --git a/fs/proc/os_adapt/mounts_proc.c b/fs/proc/os_adapt/mounts_proc.c index 644a0cc1..54f128c5 100644 --- a/fs/proc/os_adapt/mounts_proc.c +++ b/fs/proc/os_adapt/mounts_proc.c @@ -35,7 +35,7 @@ #include #include -#include "fs/file.h" +#include "fs/mount.h" #include "internal.h" static int ShowType(const char *mountPoint, struct statfs *statBuf, void *arg) diff --git a/fs/proc/os_adapt/proc_init.c b/fs/proc/os_adapt/proc_init.c index 5af830bc..a8616ca8 100644 --- a/fs/proc/os_adapt/proc_init.c +++ b/fs/proc/os_adapt/proc_init.c @@ -38,6 +38,9 @@ #ifdef LOSCFG_FS_PROC +#define PROCFS_MOUNT_POINT "/proc" +#define PROCFS_MOUNT_POINT_SIZE (sizeof(PROCFS_MOUNT_POINT) - 1) + void ProcFsInit(void) { int ret; diff --git a/fs/proc/os_adapt/proc_vfs.c b/fs/proc/os_adapt/proc_vfs.c index 92e2df7e..00cfb7ac 100644 --- a/fs/proc/os_adapt/proc_vfs.c +++ b/fs/proc/os_adapt/proc_vfs.c @@ -36,6 +36,8 @@ #include #include "fs/dirent_fs.h" +#include "fs/mount.h" +#include "fs/fs.h" #include "los_tables.h" #include "internal.h" diff --git a/fs/proc/src/proc_shellcmd.c b/fs/proc/src/proc_shellcmd.c index 2ec4809e..188ffc58 100644 --- a/fs/proc/src/proc_shellcmd.c +++ b/fs/proc/src/proc_shellcmd.c @@ -45,7 +45,6 @@ #include "shcmd.h" #include "proc_file.h" #include "dirent.h" -#include "fs/fs.h" #include "proc_fs.h" #define WRITEPROC_ARGC 3 diff --git a/fs/ramfs/Makefile b/fs/ramfs/Makefile index 4f8e3b9f..2c2ccbc4 100644 --- a/fs/ramfs/Makefile +++ b/fs/ramfs/Makefile @@ -32,6 +32,7 @@ include $(LITEOSTOPDIR)/config.mk MODULE_NAME := $(notdir $(shell pwd)) LOCAL_SRCS := $(wildcard $(LITEOSTHIRDPARTY)/NuttX/fs/tmpfs/*.c) +LOCAL_INCLUDE := -I $(wildcard $(LITEOSTHIRDPARTY)/NuttX/include) LOCAL_FLAGS := $(LOCAL_INCLUDE) $(LITEOS_GCOV_OPTS) diff --git a/fs/vfs/Makefile b/fs/vfs/Makefile index d779909e..744fbed5 100644 --- a/fs/vfs/Makefile +++ b/fs/vfs/Makefile @@ -30,7 +30,6 @@ include $(LITEOSTOPDIR)/config.mk MODULE_NAME := $(notdir $(shell pwd)) - LOCAL_SRCS := \ $(LITEOSTOPDIR)/fs/vfs/mount.c \ $(LITEOSTOPDIR)/fs/vfs/vnode.c \ @@ -71,7 +70,6 @@ $(LITEOSTHIRDPARTY)/NuttX/fs/vfs/fs_write.c \ $(wildcard operation/*.c) \ \ $(LITEOSTHIRDPARTY)/NuttX/fs/inode/fs_files.c \ -$(LITEOSTHIRDPARTY)/NuttX/fs/inode/fs_inode.c \ \ $(LITEOSTHIRDPARTY)/NuttX/fs/dirent/fs_closedir.c \ $(LITEOSTHIRDPARTY)/NuttX/fs/dirent/fs_opendir.c \ @@ -84,7 +82,6 @@ $(LITEOSTHIRDPARTY)/NuttX/fs/mount/fs_mount.c \ $(LITEOSTHIRDPARTY)/NuttX/fs/mount/fs_umount.c \ \ $(LITEOSTHIRDPARTY)/NuttX/fs/driver/fs_blockproxy.c \ -$(LITEOSTHIRDPARTY)/NuttX/fs/driver/fs_devsyslog.c \ $(LITEOSTHIRDPARTY)/NuttX/fs/mount/fs_foreachmountpoint.c \ $(LITEOSTHIRDPARTY)/NuttX/fs/driver/fs_findblockdriver.c \ $(LITEOSTHIRDPARTY)/NuttX/fs/driver/fs_openblockdriver.c \ @@ -99,11 +96,10 @@ $(wildcard vfs_cmd/*.c) LOCAL_INCLUDE := \ -I $(LITEOSTOPDIR)/fs/vfs/include \ -I $(LITEOSTOPDIR)/fs/vfs/include/bcache\ - -I $(LITEOSTOPDIR)/fs/vfs/include/disk\ - -I $(LITEOSTOPDIR)/fs/vfs/include/driver\ - -I $(LITEOSTOPDIR)/fs/vfs/include/multi_partition\ + -I $(LITEOSTOPDIR)/drivers/block/disk/include\ + -I $(LITEOSTOPDIR)/drivers/char/bch/include\ + -I $(LITEOSTOPDIR)/drivers/mtd/multi_partition/include\ -I $(LITEOSTOPDIR)/fs/vfs/include/operation\ - -I $(LITEOSTOPDIR)/fs/include/inode\ -I $(LITEOSTOPDIR)/syscall\ ifeq ($(LOSCFG_FS_FAT), y) diff --git a/fs/vfs/bcache/src/bcache.c b/fs/vfs/bcache/src/bcache.c index b04b0057..c531065a 100644 --- a/fs/vfs/bcache/src/bcache.c +++ b/fs/vfs/bcache/src/bcache.c @@ -34,7 +34,6 @@ #include "stdlib.h" #include "linux/delay.h" #include "disk_pri.h" -#include "fs_other.h" #include "user_copy.h" #undef HALARC_ALIGNMENT diff --git a/fs/vfs/include/bcache/bcache.h b/fs/vfs/include/bcache/bcache.h index 24bf96c0..d4479bd5 100644 --- a/fs/vfs/include/bcache/bcache.h +++ b/fs/vfs/include/bcache/bcache.h @@ -35,7 +35,7 @@ #include "pthread.h" #include "linux/rbtree.h" #include "los_list.h" -#include "fs/vnode.h" +#include "vnode.h" #ifdef __cplusplus #if __cplusplus diff --git a/fs/vfs/include/operation/fs_poll_pri.h b/fs/vfs/include/fs_poll_pri.h similarity index 75% rename from fs/vfs/include/operation/fs_poll_pri.h rename to fs/vfs/include/fs_poll_pri.h index 4321216d..ae9f96cf 100644 --- a/fs/vfs/include/operation/fs_poll_pri.h +++ b/fs/vfs/include/fs_poll_pri.h @@ -1,6 +1,5 @@ /* - * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. - * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. + * 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: @@ -29,21 +28,7 @@ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef _FS_POLL_PRI_H -#define _FS_POLL_PRI_H - -#ifdef __cplusplus -#if __cplusplus -extern "C" { -#endif /* __cplusplus */ -#endif /* __cplusplus */ - -extern void poll_wait(struct file *filp, wait_queue_head_t *wait_address, poll_table *p); - -#ifdef __cplusplus -#if __cplusplus -} -#endif /* __cplusplus */ -#endif /* __cplusplus */ - -#endif /* _FS_POLL_PRI_H */ +#ifndef _FS_POLL_PRI_H_ +#define _FS_POLL_PRI_H_ +/* empty file for hdf compatibility should remove later */ +#endif diff --git a/fs/vfs/include/operation/fs_file.h b/fs/vfs/include/operation/fs_file.h deleted file mode 100644 index 3bfe1df0..00000000 --- a/fs/vfs/include/operation/fs_file.h +++ /dev/null @@ -1,61 +0,0 @@ -/* - * 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. - */ - -#ifndef FS_FILE_H -#define FS_FILE_H - -#define MIN_START_FD 3 // 0,1,2 are used for stdin,stdout,stderr respectively - -int AllocProcessFd(void); - -int AllocLowestProcessFd(int minFd); - -int AllocSpecifiedProcessFd(int procFd); - -int AllocAndAssocProcessFd(int sysFd, int minFd); - -int AllocAndAssocSystemFd(int procFd, int minFd); - -void AssociateSystemFd(int procFd, int sysFd); - -int DisassociateProcessFd(int procFd); - -int GetAssociatedSystemFd(int procFd); - -int CheckProcessFd(int procFd); - -void FreeProcessFd(int procFd); - -int CopyFdToProc(int fd, unsigned int targetPid); - -int CloseProcFd(int fd, unsigned int targetPid); - -#endif diff --git a/fs/vfs/include/operation/fs_other.h b/fs/vfs/include/operation/fs_other.h deleted file mode 100644 index c67ddf6c..00000000 --- a/fs/vfs/include/operation/fs_other.h +++ /dev/null @@ -1,70 +0,0 @@ -/* - * 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. - */ - -#ifndef _FS_OTHER_H -#define _FS_OTHER_H - -#include "sys/types.h" -#include "fs/vnode.h" - -#ifdef __cplusplus -#if __cplusplus -extern "C" { -#endif /* __cplusplus */ -#endif /* __cplusplus */ - -extern void lsfd(void); - -extern void set_sd_sync_fn(int (*sync_fn)(int)); - -extern struct Vnode *files_get_openfile(int fd); - -#define READ_OP 4 -#define WRITE_OP 2 -#define EXEC_OP 1 -#define UGO_NUMS 3 -#define MODE_IXUGO 0111 -#define USER_MODE_SHIFT 6 -#define GROUP_MODE_SHIFT 3 -#define UMASK_FULL 0777 - -mode_t GetUmask(void); - -int VfsPermissionCheck(uint fuid, uint fgid, mode_t fileMode, int accMode); -int VfsVnodePermissionCheck(const struct Vnode *node, int accMode); - -#ifdef __cplusplus -#if __cplusplus -} -#endif /* __cplusplus */ -#endif /* __cplusplus */ - -#endif /* _FS_OTHER_H */ diff --git a/fs/include/fs/path_cache.h b/fs/vfs/include/path_cache.h similarity index 93% rename from fs/include/fs/path_cache.h rename to fs/vfs/include/path_cache.h index d4087904..1b8e861d 100644 --- a/fs/include/fs/path_cache.h +++ b/fs/vfs/include/path_cache.h @@ -33,7 +33,7 @@ #include "los_list.h" #include "fs/mount.h" -#include "fs/vnode.h" +#include "vnode.h" struct PathCache { struct Vnode *parentVnode; /* vnode points to the cache */ @@ -48,7 +48,6 @@ struct PathCache { int PathCacheInit(void); int PathCacheFree(struct PathCache *cache); struct PathCache *PathCacheAlloc(struct Vnode *parent, struct Vnode *vnode, const char *name, uint8_t len); -int PathCacheAllocDummy(struct Vnode *parent, struct Vnode **vnode, const char *name, uint8_t len); int PathCacheLookup(struct Vnode *parent, const char *name, int len, struct Vnode **vnode); void VnodePathCacheFree(struct Vnode *vnode); void PathCacheMemoryDump(void); diff --git a/fs/vfs/include/vnode.h b/fs/vfs/include/vnode.h new file mode 100644 index 00000000..b138416f --- /dev/null +++ b/fs/vfs/include/vnode.h @@ -0,0 +1,180 @@ +/* + * 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. + */ + +#ifndef _VNODE_H_ +#define _VNODE_H_ + +#include +#include "fs/fs_operation.h" +#include "fs/file.h" +#include "los_list.h" + +typedef LOS_DL_LIST LIST_HEAD; +typedef LOS_DL_LIST LIST_ENTRY; + +#define VNODE_FLAG_MOUNT_NEW (1 << 0) /* new mount vnode*/ +#define VNODE_FLAG_MOUNT_ORIGIN (1 << 1) /* origin vnode */ + +#define V_CREATE (1 << 0) +#define V_DUMMY (1 << 2) + +#ifndef VFS_ERROR +#define VFS_ERROR -1 +#endif + +#ifndef OK +#define OK 0 +#endif + +#define AT_REMOVEDIR 0x200 + +#define DEV_PATH_LEN 5 + +/* Permission flags */ +#define READ_OP 4 +#define WRITE_OP 2 +#define EXEC_OP 1 +#define UGO_NUMS 3 +#define MODE_IXUGO 0111 +#define USER_MODE_SHIFT 6 +#define GROUP_MODE_SHIFT 3 +#define UMASK_FULL 0777 + +/* Attribute flags. */ +#define CHG_MODE 1 +#define CHG_UID 2 +#define CHG_GID 4 +#define CHG_SIZE 8 +#define CHG_ATIME 16 +#define CHG_MTIME 32 +#define CHG_CTIME 64 + +struct IATTR +{ + /* This structure is used for record vnode attr. */ + unsigned int attr_chg_valid; + unsigned int attr_chg_flags; + unsigned attr_chg_mode; + unsigned attr_chg_uid; + unsigned attr_chg_gid; + unsigned attr_chg_size; + unsigned attr_chg_atime; + unsigned attr_chg_mtime; + unsigned attr_chg_ctime; +}; + + /* + * Vnode types. VNODE_TYPE_UNKNOWN means no type. + */ +enum VnodeType { + VNODE_TYPE_UNKNOWN, /* unknown type */ + VNODE_TYPE_REG, /* regular fle */ + VNODE_TYPE_DIR, /* directory */ + VNODE_TYPE_BLK, /* block device */ + VNODE_TYPE_CHR, /* char device */ + VNODE_TYPE_BCHR, /* block char mix device */ + VNODE_TYPE_FIFO, /* pipe */ + VNODE_TYPE_LNK, /* link */ +}; + +struct fs_dirent_s; +struct VnodeOps; +struct IATTR; + +struct Vnode { + enum VnodeType type; /* vnode type */ + int useCount; /* ref count of users */ + uint32_t hash; /* vnode hash */ + uint uid; /* uid for dac */ + uint gid; /* gid for dac */ + mode_t mode; /* mode for dac */ + LIST_HEAD parentPathCaches; /* pathCaches point to parents */ + LIST_HEAD childPathCaches; /* pathCaches point to children */ + struct Vnode *parent; /* parent vnode */ + struct VnodeOps *vop; /* vnode operations */ + struct file_operations_vfs *fop; /* file operations */ + void *data; /* private data */ + uint32_t flag; /* vnode flag */ + LIST_ENTRY hashEntry; /* list entry for bucket in hash table */ + LIST_ENTRY actFreeEntry; /* vnode active/free list entry */ + struct Mount *originMount; /* fs info about this vnode */ + struct Mount *newMount; /* fs info about who mount on this vnode */ +}; + +struct VnodeOps { + int (*Create)(struct Vnode *parent, const char *name, int mode, struct Vnode **vnode); + int (*Lookup)(struct Vnode *parent, const char *name, int len, struct Vnode **vnode); + int (*Open)(struct Vnode *vnode, int fd, int mode, int flags); + int (*Close)(struct Vnode *vnode); + int (*Reclaim)(struct Vnode *vnode); + int (*Unlink)(struct Vnode *parent, struct Vnode *vnode, const char *fileName); + int (*Rmdir)(struct Vnode *parent, struct Vnode *vnode, const char *dirName); + int (*Mkdir)(struct Vnode *parent, const char *dirName, mode_t mode, struct Vnode **vnode); + int (*Readdir)(struct Vnode *vnode, struct fs_dirent_s *dir); + int (*Opendir)(struct Vnode *vnode, struct fs_dirent_s *dir); + int (*Rewinddir)(struct Vnode *vnode, struct fs_dirent_s *dir); + int (*Closedir)(struct Vnode *vnode, struct fs_dirent_s *dir); + int (*Getattr)(struct Vnode *vnode, struct stat *st); + int (*Setattr)(struct Vnode *vnode, struct stat *st); + int (*Chattr)(struct Vnode *vnode, struct IATTR *attr); + int (*Rename)(struct Vnode *src, struct Vnode *dstParent, const char *srcName, const char *dstName); + int (*Truncate)(struct Vnode *vnode, off_t len); + int (*Truncate64)(struct Vnode *vnode, off64_t len); + int (*Fscheck)(struct Vnode *vnode, struct fs_dirent_s *dir); + int (*Link)(struct Vnode *src, struct Vnode *dstParent, struct Vnode **dst, const char *dstName); + int (*Symlink)(struct Vnode *parentVnode, struct Vnode **newVnode, const char *path, const char *target); + ssize_t (*Readlink)(struct Vnode *vnode, char *buffer, size_t bufLen); +}; + +typedef int VfsHashCmp(struct Vnode *vnode, void *arg); + +int VnodesInit(void); +int VnodeDevInit(void); +int VnodeAlloc(struct VnodeOps *vop, struct Vnode **vnode); +int VnodeFree(struct Vnode *vnode); +int VnodeLookup(const char *path, struct Vnode **vnode, uint32_t flags); +int VnodeHold(void); +int VnodeDrop(void); +void VnodeRefDec(struct Vnode *vnode); +int VnodeFreeAll(const struct Mount *mnt); +int VnodeHashInit(void); +uint32_t VfsHashIndex(struct Vnode *vnode); +int VfsHashGet(const struct Mount *mount, uint32_t hash, struct Vnode **vnode, VfsHashCmp *fun, void *arg); +void VfsHashRemove(struct Vnode *vnode); +int VfsHashInsert(struct Vnode *vnode, uint32_t hash); +void ChangeRoot(struct Vnode *newRoot); +BOOL VnodeInUseIter(const struct Mount *mount); +struct Vnode *VnodeGetRoot(void); +void VnodeMemoryDump(void); +mode_t GetUmask(void); +int VfsPermissionCheck(uint fuid, uint fgid, mode_t fileMode, int accMode); +int VfsVnodePermissionCheck(const struct Vnode *node, int accMode); + +#endif /* !_VNODE_H_ */ diff --git a/fs/vfs/mount.c b/fs/vfs/mount.c index 1f2ae47c..6e98b9e7 100644 --- a/fs/vfs/mount.c +++ b/fs/vfs/mount.c @@ -29,9 +29,8 @@ */ #include "fs/mount.h" -#include "fs/vfs_util.h" -#include "fs/path_cache.h" -#include "fs/vnode.h" +#include "path_cache.h" +#include "vnode.h" #ifdef LOSCFG_DRIVERS_RANDOM #include "hisoc/random.h" #else diff --git a/fs/vfs/operation/fs_chattr.c b/fs/vfs/operation/fs_chattr.c index 60c6536e..d01aee31 100644 --- a/fs/vfs/operation/fs_chattr.c +++ b/fs/vfs/operation/fs_chattr.c @@ -36,10 +36,11 @@ #include "capability_api.h" #include "errno.h" #include "fs/fs_operation.h" -#include "fs/fs.h" +#include "fs/file.h" #include "string.h" #include "stdlib.h" #include "sys/stat.h" +#include "vnode.h" /**************************************************************************** * Static Functions diff --git a/fs/vfs/operation/fs_check.c b/fs/vfs/operation/fs_check.c index 17c6e48d..ae86d83a 100644 --- a/fs/vfs/operation/fs_check.c +++ b/fs/vfs/operation/fs_check.c @@ -42,7 +42,7 @@ #include "sys/stat.h" #include "sys/prctl.h" #include "fs/dirent_fs.h" -#include "fs/vnode.h" +#include "vnode.h" /**************************************************************************** * Name: fscheck diff --git a/fs/vfs/operation/fs_fallocate.c b/fs/vfs/operation/fs_fallocate.c index 34b017c5..d68eeac5 100644 --- a/fs/vfs/operation/fs_fallocate.c +++ b/fs/vfs/operation/fs_fallocate.c @@ -36,7 +36,7 @@ #include "assert.h" #include "errno.h" #include "fcntl.h" -#include "fs/fs.h" +#include "fs/file.h" #include "sys/types.h" #include "sched.h" #include "unistd.h" diff --git a/fs/vfs/operation/fs_fallocate64.c b/fs/vfs/operation/fs_fallocate64.c index 57cf6fbc..0560feef 100644 --- a/fs/vfs/operation/fs_fallocate64.c +++ b/fs/vfs/operation/fs_fallocate64.c @@ -36,7 +36,7 @@ #include "assert.h" #include "errno.h" #include "fcntl.h" -#include "fs/fs.h" +#include "fs/file.h" #include "sched.h" #include "sys/types.h" #include "unistd.h" diff --git a/fs/vfs/operation/fs_file.c b/fs/vfs/operation/fs_file.c index 96e66779..245d8f5d 100644 --- a/fs/vfs/operation/fs_file.c +++ b/fs/vfs/operation/fs_file.c @@ -29,11 +29,9 @@ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include "fs_file.h" +#include "fs/file.h" #include "los_process_pri.h" #include "fs/fd_table.h" -#include "fs/file.h" -#include "fs/fs.h" #include "mqueue.h" #ifdef LOSCFG_NET_LWIP_SACK #include "lwip/sockets.h" @@ -477,4 +475,4 @@ int CloseProcFd(int procFd, unsigned int targetPid) return 0; #endif -} \ No newline at end of file +} diff --git a/fs/vfs/operation/fs_file_mapping.c b/fs/vfs/operation/fs_file_mapping.c index 496b22ae..8ea8e7c7 100644 --- a/fs/vfs/operation/fs_file_mapping.c +++ b/fs/vfs/operation/fs_file_mapping.c @@ -30,7 +30,7 @@ */ #include "fs/file.h" -#include "fs/fs.h" +#include "fs/file.h" #include "fs/fs_operation.h" #include "unistd.h" #include "los_mux.h" diff --git a/fs/vfs/operation/fs_init.c b/fs/vfs/operation/fs_init.c index a8cf60b7..dcaf2fd8 100644 --- a/fs/vfs/operation/fs_init.c +++ b/fs/vfs/operation/fs_init.c @@ -31,17 +31,16 @@ #include "disk_pri.h" #include "fcntl.h" -#include "fs/fs.h" +#include "fs/file.h" #include "fs/fs_operation.h" #include "linux/spinlock.h" #include "los_init.h" #include "los_printf.h" #include "fs/mount.h" -#include "fs/path_cache.h" +#include "path_cache.h" #include "sys/statfs.h" #include "unistd.h" -#include "fs/vfs_util.h" -#include "fs/vnode.h" +#include "vnode.h" void los_vfs_init(void) { diff --git a/fs/vfs/operation/fs_other.c b/fs/vfs/operation/fs_other.c index 0d831968..791accb9 100644 --- a/fs/vfs/operation/fs_other.c +++ b/fs/vfs/operation/fs_other.c @@ -29,7 +29,6 @@ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include "fs_other.h" #include "errno.h" #include "stdlib.h" #include "string.h" @@ -39,12 +38,12 @@ #include "sys/stat.h" #include "sys/prctl.h" #include "fs/fd_table.h" -#include "fs/fs.h" +#include "fs/file.h" #include "linux/spinlock.h" #include "los_process_pri.h" #include "los_task_pri.h" #include "capability_api.h" -#include "fs/vnode.h" +#include "vnode.h" #define MAX_DIR_ENT 1024 int fstat(int fd, struct stat *buf) diff --git a/fs/vfs/operation/fs_readv.c b/fs/vfs/operation/fs_readv.c index e8311fe5..a9861a52 100644 --- a/fs/vfs/operation/fs_readv.c +++ b/fs/vfs/operation/fs_readv.c @@ -34,7 +34,7 @@ #include "unistd.h" #include "string.h" #include "stdlib.h" -#include "fs/fs.h" +#include "fs/file.h" #include "user_copy.h" #include "stdio.h" #include "limits.h" diff --git a/fs/vfs/operation/fs_utime.c b/fs/vfs/operation/fs_utime.c index fce8c694..8bab3155 100644 --- a/fs/vfs/operation/fs_utime.c +++ b/fs/vfs/operation/fs_utime.c @@ -36,11 +36,10 @@ #include "errno.h" #include "vfs_config.h" #include "sys/stat.h" -#include "fs/vnode.h" +#include "vnode.h" #include "string.h" #include "stdlib.h" #include "utime.h" -#include "fs_other.h" /**************************************************************************** * Global Functions diff --git a/fs/vfs/operation/fs_virstatfs.c b/fs/vfs/operation/fs_virstatfs.c deleted file mode 100644 index 2028faaa..00000000 --- a/fs/vfs/operation/fs_virstatfs.c +++ /dev/null @@ -1,59 +0,0 @@ -/* - * 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. - */ - - -/**************************************************************************** -* Included Files -****************************************************************************/ - -#include "vfs_config.h" - -#include "sys/statfs.h" -#include "string.h" -#include "sched.h" - -#include "errno.h" -#include "stdlib.h" -/**************************************************************************** -* Private Functions -****************************************************************************/ - -/**************************************************************************** -* Name: statpseudo -****************************************************************************/ - -#ifdef LOSCFG_FS_FAT_VIRTUAL_PARTITION -int virstatfs(const char *path, struct statfs *buf) -{ - //currently not implemented - return LOS_OK; -} -#endif diff --git a/fs/vfs/operation/fs_writev.c b/fs/vfs/operation/fs_writev.c index 0c9f0d13..cbea0771 100644 --- a/fs/vfs/operation/fs_writev.c +++ b/fs/vfs/operation/fs_writev.c @@ -34,7 +34,7 @@ #include "unistd.h" #include "string.h" #include "stdlib.h" -#include "fs/fs.h" +#include "fs/file.h" #include "user_copy.h" #include "limits.h" diff --git a/fs/vfs/path_cache.c b/fs/vfs/path_cache.c index c6d71644..01543c50 100644 --- a/fs/vfs/path_cache.c +++ b/fs/vfs/path_cache.c @@ -28,12 +28,12 @@ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include "fs/path_cache.h" +#include "path_cache.h" #include "los_config.h" +#include "los_hash.h" #include "stdlib.h" #include "limits.h" -#include "fs/vfs_util.h" -#include "fs/vnode.h" +#include "vnode.h" #define PATH_CACHE_HASH_MASK (LOSCFG_MAX_PATH_CACHE_SIZE - 1) LIST_HEAD g_pathCacheHashEntrys[LOSCFG_MAX_PATH_CACHE_SIZE]; @@ -81,8 +81,8 @@ void PathCacheMemoryDump(void) static uint32_t NameHash(const char *name, int len, struct Vnode *dvp) { uint32_t hash; - hash = fnv_32_buf(name, len, FNV1_32_INIT); - hash = fnv_32_buf(&dvp, sizeof(struct Vnode *), hash); + hash = LOS_HashFNV32aBuf(name, len, FNV1_32A_INIT); + hash = LOS_HashFNV32aBuf(&dvp, sizeof(struct Vnode *), hash); return hash; } @@ -141,29 +141,6 @@ int PathCacheFree(struct PathCache *nc) return LOS_OK; } -/* alloc an empty node and awlays add it to path_cache.cache */ -int PathCacheAllocDummy(struct Vnode *parent, struct Vnode **vnode, const char *name, uint8_t len) -{ - int ret; - struct PathCache *dt = NULL; - - ret = VnodeAlloc(NULL, vnode); - if (ret != LOS_OK) { - PRINT_ERR("pathCache alloc vnode %s failed\n", name); - return -ENOENT; - } - - dt = PathCacheAlloc(parent, *vnode, name, len); - if (dt == NULL) { - PRINT_ERR("pathCache alloc pathCache %s failed\n", name); - VnodeFree(*vnode); - *vnode = NULL; - return -ENOENT; - } - - return LOS_OK; -} - int PathCacheLookup(struct Vnode *parent, const char *name, int len, struct Vnode **vnode) { struct PathCache *nc = NULL; diff --git a/fs/vfs/vfs_cmd/vfs_shellcmd.c b/fs/vfs/vfs_cmd/vfs_shellcmd.c index 49f59ed6..58016998 100644 --- a/fs/vfs/vfs_cmd/vfs_shellcmd.c +++ b/fs/vfs/vfs_cmd/vfs_shellcmd.c @@ -36,11 +36,9 @@ #include "los_typedef.h" #include "shell.h" -#include "fs/fs.h" #include "sys/stat.h" #include "stdlib.h" #include "unistd.h" -#include "fs_other.h" #include "fcntl.h" #include "sys/statfs.h" #include "stdio.h" diff --git a/fs/vfs/vnode.c b/fs/vfs/vnode.c index 5bc90dcb..c66bdec5 100644 --- a/fs/vfs/vnode.c +++ b/fs/vfs/vnode.c @@ -29,10 +29,9 @@ */ #include "los_mux.h" -#include "fs/vfs_util.h" -#include "fs/vnode.h" +#include "vnode.h" #include "fs/dirent_fs.h" -#include "fs_other.h" +#include "path_cache.h" LIST_HEAD g_vnodeFreeList; /* free vnodes list */ LIST_HEAD g_vnodeVirtualList; /* dev vnodes list */ @@ -183,10 +182,17 @@ int VnodeFree(struct Vnode *vnode) vnode->vop->Reclaim(vnode); } - memset_s(vnode, sizeof(struct Vnode), 0, sizeof(struct Vnode)); - LOS_ListAdd(&g_vnodeFreeList, &vnode->actFreeEntry); - - g_freeVnodeSize++; + if (vnode->vop == &g_devfsOps) { + /* for dev vnode, just free it */ + free(vnode->data); + free(vnode); + g_totalVnodeSize--; + } else { + /* for normal vnode, reclaim it to g_VnodeFreeList */ + memset_s(vnode, sizeof(struct Vnode), 0, sizeof(struct Vnode)); + LOS_ListAdd(&g_vnodeFreeList, &vnode->actFreeEntry); + g_freeVnodeSize++; + } VnodeDrop(); return LOS_OK; @@ -526,7 +532,7 @@ int VnodeDevInit() struct Vnode *devNode = NULL; struct Mount *devMount = NULL; - int retval = VnodeLookup("/dev", &devNode, V_CREATE | V_CACHE | V_DUMMY); + int retval = VnodeLookup("/dev", &devNode, V_CREATE | V_DUMMY); if (retval != LOS_OK) { PRINT_ERR("VnodeDevInit failed error %d\n", retval); return retval; @@ -619,28 +625,3 @@ void VnodeMemoryDump(void) PRINTK("Vnode number = %d\n", vnodeCount); PRINTK("Vnode memory size = %d(B)\n", vnodeCount * sizeof(struct Vnode)); } - -int VnodeDestory(struct Vnode *vnode) -{ - if (vnode == NULL || vnode->vop != &g_devfsOps) { - /* destory only support dev vnode */ - return -EINVAL; - } - - VnodeHold(); - if (vnode->useCount > 0) { - VnodeDrop(); - return -EBUSY; - } - - VnodePathCacheFree(vnode); - LOS_ListDelete(&(vnode->hashEntry)); - LOS_ListDelete(&vnode->actFreeEntry); - - free(vnode->data); - free(vnode); - g_totalVnodeSize--; - VnodeDrop(); - - return LOS_OK; -} diff --git a/fs/vfs/vnode_hash.c b/fs/vfs/vnode_hash.c index 9a97bfad..e3d2ce70 100644 --- a/fs/vfs/vnode_hash.c +++ b/fs/vfs/vnode_hash.c @@ -29,7 +29,8 @@ */ #include "los_mux.h" -#include "fs/vnode.h" +#include "vnode.h" +#include "fs/mount.h" #define VNODE_HASH_BUCKETS 128 @@ -134,4 +135,4 @@ int VfsHashInsert(struct Vnode *vnode, uint32_t hash) LOS_ListHeadInsert(VfsHashBucket(vnode->originMount, hash), &vnode->hashEntry); (void)LOS_MuxUnlock(&g_vnodeHashMux); return LOS_OK; -} \ No newline at end of file +} diff --git a/fs/zpfs/vfs_zpfs.h b/fs/zpfs/vfs_zpfs.h index 7b2b23eb..13aafbca 100644 --- a/fs/zpfs/vfs_zpfs.h +++ b/fs/zpfs/vfs_zpfs.h @@ -32,8 +32,6 @@ #ifndef ZPFS_VFS_ZPFS_H #define ZPFS_VFS_ZPFS_H -#include - #include "compiler.h" #include "los_base.h" #include "los_typedef.h" diff --git a/kernel/base/misc/task_shellcmd.c b/kernel/base/misc/task_shellcmd.c index 49671f7d..085788ad 100644 --- a/kernel/base/misc/task_shellcmd.c +++ b/kernel/base/misc/task_shellcmd.c @@ -49,7 +49,7 @@ #include "los_process_pri.h" #include "los_vm_dump.h" #ifdef LOSCFG_FS_VFS -#include "fs/fs.h" +#include "fs/file.h" #endif #include "los_sched_pri.h" diff --git a/kernel/base/misc/vm_shellcmd.c b/kernel/base/misc/vm_shellcmd.c index 250c28c0..445014b3 100644 --- a/kernel/base/misc/vm_shellcmd.c +++ b/kernel/base/misc/vm_shellcmd.c @@ -43,7 +43,7 @@ #include "los_vm_dump.h" #include "los_process_pri.h" #ifdef LOSCFG_FS_VFS -#include "fs/path_cache.h" +#include "path_cache.h" #endif #ifdef LOSCFG_KERNEL_VM diff --git a/kernel/base/vm/los_vm_dump.c b/kernel/base/vm/los_vm_dump.c index 124ff65f..a0da5669 100644 --- a/kernel/base/vm/los_vm_dump.c +++ b/kernel/base/vm/los_vm_dump.c @@ -37,7 +37,7 @@ #include "los_vm_dump.h" #include "los_mmu_descriptor_v6.h" #ifdef LOSCFG_FS_VFS -#include "fs/fs.h" +#include "fs/file.h" #endif #include "los_printf.h" #include "los_vm_page.h" diff --git a/kernel/base/vm/los_vm_filemap.c b/kernel/base/vm/los_vm_filemap.c index fbdf836c..e63ee4c5 100644 --- a/kernel/base/vm/los_vm_filemap.c +++ b/kernel/base/vm/los_vm_filemap.c @@ -41,6 +41,7 @@ #include "los_vm_fault.h" #include "los_process_pri.h" #include "los_vm_lock.h" +#include "vnode.h" #ifndef UNUSED #define UNUSED(x) (VOID)x diff --git a/kernel/base/vm/los_vm_map.c b/kernel/base/vm/los_vm_map.c index d1b4b567..28f853a7 100644 --- a/kernel/base/vm/los_vm_map.c +++ b/kernel/base/vm/los_vm_map.c @@ -41,7 +41,7 @@ #include "los_arch_mmu.h" #include "los_process_pri.h" #ifdef LOSCFG_FS_VFS -#include "fs/fs.h" +#include "fs/file.h" #endif #include "los_task.h" #include "los_memory_pri.h" diff --git a/kernel/common/Makefile b/kernel/common/Makefile index d3e1199b..958e4024 100644 --- a/kernel/common/Makefile +++ b/kernel/common/Makefile @@ -34,7 +34,7 @@ MODULE_NAME := rootfs LOCAL_SRCS := $(wildcard los_rootfs.c) LOCAL_INCLUDE := \ - -I $(LITEOSTOPDIR)/kernel/common \ + -I $(LITEOSTOPDIR)/kernel/common \ ifeq ($(LOSCFG_PLATFORM_QEMU_ARM_VIRT_CA7), y) LOCAL_INCLUDE += -I $(LITEOSTOPDIR)/../../device/qemu/arm_virt/config/cfiflash diff --git a/kernel/common/console.c b/kernel/common/console.c index 8c916a1a..c70466c3 100644 --- a/kernel/common/console.c +++ b/kernel/common/console.c @@ -47,10 +47,8 @@ #include "los_exc_pri.h" #include "los_process_pri.h" #include "los_sched_pri.h" -#include "fs/path_cache.h" -#include "fs/vfs_util.h" #include "user_copy.h" -#include "fs/vnode.h" +#include "fs/driver.h" #define EACH_CHAR 1 #define UART_IOC_MAGIC 'u' diff --git a/kernel/common/los_excinfo.c b/kernel/common/los_excinfo.c index 92ec6404..b18ee23b 100644 --- a/kernel/common/los_excinfo.c +++ b/kernel/common/los_excinfo.c @@ -31,9 +31,6 @@ #include "los_base.h" #include "los_hwi.h" -#ifdef LOSCFG_FS_VFS -#include "fs/fs.h" -#endif #ifdef LOSCFG_SHELL #include "shcmd.h" #endif diff --git a/kernel/common/los_hilog.c b/kernel/common/los_hilog.c index 7ff2f215..f4bc5f9d 100644 --- a/kernel/common/los_hilog.c +++ b/kernel/common/los_hilog.c @@ -35,7 +35,8 @@ #include "los_mux.h" #include "los_process_pri.h" #include "los_task_pri.h" -#include "fs/fs.h" +#include "fs/file.h" +#include "fs/driver.h" #include "los_vm_map.h" #include "los_vm_lock.h" #include "user_copy.h" diff --git a/kernel/common/los_rootfs.c b/kernel/common/los_rootfs.c index dd4ef1b9..f11e2912 100644 --- a/kernel/common/los_rootfs.c +++ b/kernel/common/los_rootfs.c @@ -42,7 +42,7 @@ #include "los_rootfs.h" #endif #include "mtd_list.h" -#include "fs/path_cache.h" +#include "fs/driver.h" #ifdef LOSCFG_PLATFORM_QEMU_ARM_VIRT_CA7 #include "mtd_partition.h" diff --git a/kernel/common/patchfs/los_patchfs.c b/kernel/common/patchfs/los_patchfs.c index d2ece3b9..82b621a4 100644 --- a/kernel/common/patchfs/los_patchfs.c +++ b/kernel/common/patchfs/los_patchfs.c @@ -32,7 +32,7 @@ #include "los_partition_utils.h" #include "sys/mount.h" -#include "fs/vnode.h" +#include "vnode.h" #ifdef LOSCFG_PLATFORM_PATCHFS diff --git a/kernel/common/virtual_serial.c b/kernel/common/virtual_serial.c index 21a298af..da28508d 100644 --- a/kernel/common/virtual_serial.c +++ b/kernel/common/virtual_serial.c @@ -36,11 +36,9 @@ #endif #ifdef LOSCFG_FS_VFS #include "console.h" +#include "fs/driver.h" #endif -#include "fs/path_cache.h" - - STATIC volatile UINT32 g_serialType = 0; STATIC struct file g_serialFilep; diff --git a/kernel/common/virtual_serial.h b/kernel/common/virtual_serial.h index ceefe83d..b0ae6e46 100644 --- a/kernel/common/virtual_serial.h +++ b/kernel/common/virtual_serial.h @@ -33,9 +33,7 @@ #define _VIRTUAL_SERIAL_H #include "los_config.h" -#ifdef LOSCFG_FS_VFS -#include "fs/fs.h" -#endif +#include "fs/file.h" #if defined(LOSCFG_DRIVERS_USB_SERIAL_GADGET) || defined(LOSCFG_DRIVERS_USB_ETH_SER_GADGET) #include "implementation/usb_api_pri.h" #endif diff --git a/kernel/extended/dynload/include/los_load_elf.h b/kernel/extended/dynload/include/los_load_elf.h index 9912954f..ce95055e 100644 --- a/kernel/extended/dynload/include/los_load_elf.h +++ b/kernel/extended/dynload/include/los_load_elf.h @@ -45,7 +45,7 @@ #ifdef LOSCFG_DRIVERS_TZDRIVER #include "fs/file.h" #endif -#include "fs/fs.h" +#include "fs/file.h" #include "unistd.h" #ifdef __cplusplus diff --git a/kernel/extended/dynload/src/los_load_elf.c b/kernel/extended/dynload/src/los_load_elf.c index 1d0fa835..ef7411eb 100644 --- a/kernel/extended/dynload/src/los_load_elf.c +++ b/kernel/extended/dynload/src/los_load_elf.c @@ -32,7 +32,7 @@ #include "los_load_elf.h" #include "fcntl.h" #include "fs/fd_table.h" -#include "fs_file.h" +#include "fs/file.h" #include "los_config.h" #include "los_vm_map.h" #include "los_vm_syscall.h" diff --git a/kernel/extended/liteipc/hm_liteipc.c b/kernel/extended/liteipc/hm_liteipc.c index 1a8dc3b3..8f07ef6a 100644 --- a/kernel/extended/liteipc/hm_liteipc.c +++ b/kernel/extended/liteipc/hm_liteipc.c @@ -31,8 +31,8 @@ #include "hm_liteipc.h" #include "linux/kernel.h" -#include "fs/fs.h" -#include "fs_file.h" +#include "fs/file.h" +#include "fs/driver.h" #include "los_init.h" #include "los_mp.h" #include "los_mux.h" diff --git a/kernel/include/los_toolchain.h b/kernel/include/los_toolchain.h index a54f00a2..9a310437 100644 --- a/kernel/include/los_toolchain.h +++ b/kernel/include/los_toolchain.h @@ -47,6 +47,13 @@ extern "C" { #endif /* __cplusplus */ #endif /* __cplusplus */ +#ifndef UNUSED +#define UNUSED(var) \ + do { \ + (void)var; \ + } while (0) +#endif + /* for ARM Compiler */ #if defined ( __CC_ARM ) #ifndef ASM diff --git a/net/telnet/include/telnet_dev.h b/net/telnet/include/telnet_dev.h index 23d56fc8..7a6da243 100644 --- a/net/telnet/include/telnet_dev.h +++ b/net/telnet/include/telnet_dev.h @@ -34,8 +34,6 @@ #include "los_config.h" #include "linux/wait.h" -#include "fs/fs.h" -#include "fs_poll_pri.h" #ifdef __cplusplus #if __cplusplus diff --git a/net/telnet/src/telnet_dev.c b/net/telnet/src/telnet_dev.c index 85004063..06ab5685 100644 --- a/net/telnet/src/telnet_dev.c +++ b/net/telnet/src/telnet_dev.c @@ -47,7 +47,7 @@ #include "lwip/sockets.h" #include "telnet_pri.h" -#include "fs/vnode.h" +#include "fs/driver.h" /* event: there are more commands left in the FIFO to run */ #define TELNET_EVENT_MORE_CMD 0x01 diff --git a/syscall/fs_syscall.c b/syscall/fs_syscall.c index dbd5a6ee..9bb01f3a 100644 --- a/syscall/fs_syscall.c +++ b/syscall/fs_syscall.c @@ -34,7 +34,6 @@ #include "unistd.h" #include "fs/fd_table.h" #include "fs/file.h" -#include "fs/fs.h" #include "fs/fs_operation.h" #include "sys/mount.h" #include "los_task_pri.h" @@ -51,10 +50,10 @@ #include "los_vm_map.h" #include "los_memory.h" #include "los_strncpy_from_user.h" -#include "fs_other.h" -#include "fs_file.h" +#include "fs/file.h" #include "capability_type.h" #include "capability_api.h" +#include "sys/statfs.h" #define HIGH_SHIFT_BIT 32 diff --git a/syscall/ipc_syscall.c b/syscall/ipc_syscall.c index 551f4984..2ebf7457 100644 --- a/syscall/ipc_syscall.c +++ b/syscall/ipc_syscall.c @@ -37,7 +37,7 @@ #include "user_copy.h" #include "los_signal.h" #include "los_strncpy_from_user.h" -#include "fs_file.h" +#include "fs/file.h" #define MQUEUE_FD_U2K(id) \ do { \ diff --git a/syscall/los_syscall.c b/syscall/los_syscall.c index fe8d46d8..b590c97a 100644 --- a/syscall/los_syscall.c +++ b/syscall/los_syscall.c @@ -31,7 +31,7 @@ #define _GNU_SOURCE #ifdef LOSCFG_FS_VFS -#include "fs/fs.h" +#include "fs/file.h" #include "fs/file.h" #endif #include "los_init.h" diff --git a/syscall/los_syscall.h b/syscall/los_syscall.h index ca453e3e..14995d43 100644 --- a/syscall/los_syscall.h +++ b/syscall/los_syscall.h @@ -32,13 +32,11 @@ #ifndef _LOS_SYSCALL_H #define _LOS_SYSCALL_H +#include #include "los_typedef.h" #include "los_task.h" #include "los_mux.h" #include "los_signal.h" -#ifdef LOSCFG_FS_VFS -#include "fs/fs.h" -#endif #include "syscall.h" #include "sysinfo.h" #include "time_posix.h" @@ -60,10 +58,11 @@ #ifdef LOSCFG_FS_VFS #include "sys/socket.h" #include "dirent.h" -#include "fs/fs.h" +#include "fs/file.h" #endif #include #include "sys/resource.h" +#include "vnode.h" /* process */ extern unsigned int SysGetGroupId(void); diff --git a/syscall/net_syscall.c b/syscall/net_syscall.c index 6abc6d09..b8b6aed2 100644 --- a/syscall/net_syscall.c +++ b/syscall/net_syscall.c @@ -31,8 +31,7 @@ #include "syscall_pub.h" #include "stdlib.h" -#include "fs_file.h" -#include "fs/fs.h" +#include "fs/file.h" #include "los_process_pri.h" #include "los_signal.h" #include "los_syscall.h" diff --git a/syscall/vm_syscall.c b/syscall/vm_syscall.c index 3e7194e6..3c02e6cd 100644 --- a/syscall/vm_syscall.c +++ b/syscall/vm_syscall.c @@ -34,7 +34,7 @@ #include "errno.h" #include "unistd.h" #include "los_vm_syscall.h" -#include "fs_file.h" +#include "fs/file.h" void *SysMmap(void *addr, size_t size, int prot, int flags, int fd, size_t offset) diff --git a/tools/build/mk/los_config.mk b/tools/build/mk/los_config.mk index 5dc50170..1d805b1a 100644 --- a/tools/build/mk/los_config.mk +++ b/tools/build/mk/los_config.mk @@ -284,14 +284,13 @@ ifeq ($(LOSCFG_FS_VFS), y) LITEOS_BASELIB += -lvfs -lmulti_partition ifeq ($(LOSCFG_FS_VFS_BLOCK_DEVICE), y) LITEOS_BASELIB += -lbch - LIB_SUBDIRS += fs/vfs fs/vfs/bch + LIB_SUBDIRS += $(LITEOSTOPDIR)/drivers/char/bch endif - LIB_SUBDIRS += fs/vfs fs/vfs/multi_partition + LIB_SUBDIRS += fs/vfs drivers/mtd/multi_partition LITEOS_VFS_INCLUDE += -I $(LITEOSTOPDIR)/fs/include - LITEOS_VFS_INCLUDE += -I $(LITEOSTOPDIR)/fs/vfs/include/driver LITEOS_VFS_INCLUDE += -I $(LITEOSTOPDIR)/fs/vfs/include/operation - LITEOS_VFS_MTD_INCLUDE := -I $(LITEOSTOPDIR)/fs/vfs/include/multi_partition - LITEOS_VFS_DISK_INCLUDE := -I $(LITEOSTOPDIR)/fs/vfs/include/disk + LITEOS_VFS_MTD_INCLUDE := -I $(LITEOSTOPDIR)/drivers/mtd/multi_partition/include + LITEOS_VFS_DISK_INCLUDE := -I $(LITEOSTOPDIR)/drivers/block/disk/include endif ifeq ($(LOSCFG_FS_FAT), y) @@ -308,13 +307,14 @@ endif ifeq ($(LOSCFG_FS_FAT_DISK), y) LITEOS_BASELIB += -ldisk - LIB_SUBDIRS += fs/vfs/disk + LIB_SUBDIRS += $(LITEOSTOPDIR)/drivers/block/disk endif ifeq ($(LOSCFG_FS_FAT_CACHE), y) LITEOS_BASELIB += -lbcache LIB_SUBDIRS += fs/vfs/bcache - LITEOS_FAT_CACHE_INCLUDE += -I $(LITEOSTOPDIR)/fs/vfs/include/bcache + LITEOS_FAT_CACHE_INCLUDE += -I $(LITEOSTOPDIR)/fs/vfs/include/bcache \ + -I $(LITEOSTOPDIR)/fs/vfs/include endif