diff --git a/Kconfig b/Kconfig index 77380a27..1ba5c3c1 100755 --- a/Kconfig +++ b/Kconfig @@ -93,12 +93,27 @@ source "../../kernel/liteos_a/fs/ramfs/Kconfig" source "../../kernel/liteos_a/fs/nfs/Kconfig" source "../../kernel/liteos_a/fs/proc/Kconfig" source "../../kernel/liteos_a/fs/jffs2/Kconfig" -source "../../kernel/liteos_a/fs/zpfs/Kconfig" config ENABLE_READ_BUFFER bool "Enable read buffer Option" default n help Answer Y to add enable read buffer Option. + +config MAX_VNODE_SIZE + int "Vnode max number" + range 0 512 + default 512 + depends on FS_VFS + help + vnode number, range from 0 to 512. + +config MAX_PATH_CACHE_SIZE + int "PathCache max number" + range 0 1024 + default 512 + depends on FS_VFS + help + pathCache number, range from 0 to 1024. endmenu ######################## config options of net ############################ diff --git a/apps/shell/src/shcmd.c b/apps/shell/src/shcmd.c index a4930a90..31aca4cc 100755 --- a/apps/shell/src/shcmd.c +++ b/apps/shell/src/shcmd.c @@ -453,6 +453,7 @@ unsigned int OsCmdKeyShift(const char *cmdKey, char *cmdOut, unsigned int size) free(outputBak); return SH_OK; } + int OsTabCompletion(char *cmdKey, unsigned int *len) { int count; diff --git a/fs/fat/Makefile b/fs/fat/Makefile index ce372490..b4e3e624 100755 --- a/fs/fat/Makefile +++ b/fs/fat/Makefile @@ -37,7 +37,9 @@ LOCAL_SRCS += $(wildcard $(LITEOSTHIRDPARTY)/FatFs/source/*.c) LOCAL_INCLUDE := \ -I $(LITEOSTHIRDPARTY)/FatFs/source \ -I $(LITEOSTOPDIR)/fs/fat/os_adapt \ - -I $(LITEOSTOPDIR)/fs/fat/virpart/include + -I $(LITEOSTOPDIR)/fs/fat/virpart/include \ + -I $(LITEOSTOPDIR)/fs/vfs \ + -I $(LITEOSTHIRDPARTY)/NuttX/include LOCAL_FLAGS := $(LOCAL_INCLUDE) $(LITEOS_GCOV_OPTS) diff --git a/fs/fat/os_adapt/dirop_fat.c b/fs/fat/os_adapt/dirop_fat.c deleted file mode 100755 index 0515cf15..00000000 --- a/fs/fat/os_adapt/dirop_fat.c +++ /dev/null @@ -1,274 +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. - */ - -#include "dirop_fat.h" -#include "fatfs.h" -#include "errno.h" -#include "fs/fs.h" -#include "inode/inode.h" -#include "integer.h" -#include "string.h" - -#ifdef LOSCFG_FS_FAT - -#ifdef __cplusplus -#if __cplusplus -extern "C"{ -#endif -#endif /* __cplusplus */ - -extern const struct mountpt_operations fat_operations; -#define SECTOR_SIZE 512 -#define FIRST_MALLOC_SIZE 10 - -static INT vfat_check_path(const char *path) -{ - struct inode *inode_ptr = NULL; - char *fullpath = NULL; - INT ret = vfs_normalize_path((const char *)NULL, path, &fullpath); - struct inode_search_s desc; - - if (ret < ENOERR) { - ret = -ret; - set_errno(ret); - return FAT_ERROR; - } - - SETUP_SEARCH(&desc, fullpath, false); - ret = inode_find(&desc); - if (ret < 0) { - PRINT_ERR("ERROR: Failed to find %s\n", fullpath); - ret = -ret; - set_errno(ret); - return FAT_ERROR; - } - inode_ptr = desc.node; - - free(fullpath); - - if (inode_ptr && (inode_ptr->u.i_mops == &fat_operations)) { - inode_release(inode_ptr); - return ENOERR; - } - - return FAT_ERROR; -} - -static DIR_FAT *initdir_fat(DIR *dp) -{ - DIR_FAT *dir_fat = NULL; - - if (dp != NULL) { - dir_fat = (DIR_FAT *)malloc(sizeof(DIR_FAT) + PATH_MAX); - if (dir_fat != NULL) { - (void)memset_s(dir_fat, sizeof(DIR_FAT) + PATH_MAX, 0, sizeof(DIR_FAT) + PATH_MAX); - - dir_fat->stDirStream.dd_nextloc = 0; - dir_fat->stDirStream.dd_size = 0; - dir_fat->stBuf.d_count = SECTOR_SIZE; - dir_fat->stBuf.d_usecount = 0; - - (void)pthread_mutex_init(&(dir_fat->stDirStream.dd_lock), (const pthread_mutexattr_t *)NULL); - dir_fat->stDirStream.dp = dp; - - return dir_fat; - } - - (void)closedir(dp); - } - - return NULL; -} - -DIR_FAT *opendir_fat(const char *name) -{ - INT ret; - DIR *dp = NULL; - - ret = vfat_check_path(name); - if (ret) { - return NULL; - } - - dp = opendir(name); - - return initdir_fat(dp); -} - -int closedir_fat(DIR_FAT *dir_fat) -{ - INT ret; - - if (dir_fat == NULL) { - return FAT_ERROR; - } - - ret = closedir(dir_fat->stDirStream.dp); - if (ret == ENOERR) { - (void)pthread_mutex_destroy(&(dir_fat->stDirStream.dd_lock)); - free(dir_fat); - } - - return ret; -} - -extern int fatfs_readdir_all(DIR_FAT *dir_fat); - -struct fat_direntall *readdir_fat(DIR_FAT *dir_fat) -{ - INT ret; - struct fat_direntall *de = (struct fat_direntall *)NULL; - - if (dir_fat == NULL) { - return NULL; - } - - if (pthread_mutex_lock(&(dir_fat->stDirStream.dd_lock)) != ENOERR) { - return NULL; - } - - ret = fatfs_readdir_all(dir_fat); - if (!ret) { - de = &(dir_fat->stBuf.direntall); - } - - if (pthread_mutex_unlock(&(dir_fat->stDirStream.dd_lock)) != ENOERR) - PRINT_ERR("readdir_fat mutex unlock error \n"); - return de; -} - -static struct fat_direntall **scandir_fat_remalloc_names(struct fat_direntall **names, - UINT *names_size, UINT pos, bool *failed) -{ - struct fat_direntall **new_direntall = NULL; - INT32 ret; - - if (pos == *names_size) { - - if (*names_size == 0) { - *names_size = FIRST_MALLOC_SIZE; - } else { - *names_size <<= 1; - } - - new_direntall = (struct fat_direntall **)malloc(*names_size * sizeof(struct fat_direntall *)); - if (new_direntall == NULL) { - *failed = 1; - return names; - } - - if (names != NULL) { - ret = memcpy_s(new_direntall, (*names_size) * sizeof(struct fat_direntall *), - names, pos * sizeof(struct fat_direntall *)); - if (ret != EOK){ - *failed = 1; - free(new_direntall); - return names; - } - free(names); - } - return new_direntall; - } - return names; -} - -int scandir_fat(const char *dir, struct fat_direntall ***namelist, - int (*selector) (const struct fat_direntall *), - int (*compar) (const struct fat_direntall **, const struct fat_direntall **)) -{ - DIR_FAT *dp = opendir_fat(dir); - struct fat_direntall *current = NULL; - struct fat_direntall **names = NULL; - struct fat_direntall *vnew = NULL; - UINT names_size = 0; - UINT pos = 0; - UINT dsize; - bool failed = 0; - INT use_it; - - if (dp == NULL) { - return FAT_ERROR; - } - - current = readdir_fat(dp); - while (current != NULL) { - use_it = (selector == NULL); - if (!use_it) { - use_it = (*selector) (current); - } - if (use_it) { - names = scandir_fat_remalloc_names(names, &names_size, pos, &failed); - if (failed == 1) { - break; - } - - dsize = current->d_reclen; - vnew = (struct fat_direntall *)malloc(dsize); - if (vnew == NULL) { - failed = 1; - break; - } - - (void)memcpy_s(vnew, dsize, current, dsize); - names[pos++] = vnew; - } - current = readdir_fat(dp); - } - - if (failed == 1) { - (void)closedir_fat(dp); - while (pos > 0) { - free(names[--pos]); - } - - if (names != NULL) { - free(names); - } - - return FAT_ERROR; - } - - (void)closedir_fat(dp); - - /* Sort the list if we have a comparison function to sort with. */ - if (compar != NULL && names != NULL) { - qsort((void *)names, pos, sizeof (struct fat_direntall *), (int (*)(const void *, const void *))*compar); - } - *namelist = names; - return pos; -} - -#ifdef __cplusplus -#if __cplusplus -} -#endif -#endif /* __cplusplus */ -#endif /* CONFIG_FS_FAT */ diff --git a/fs/fat/os_adapt/dirop_fat.h b/fs/fat/os_adapt/dirop_fat.h deleted file mode 100755 index 2f9b9fa2..00000000 --- a/fs/fat/os_adapt/dirop_fat.h +++ /dev/null @@ -1,195 +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. - */ - -/** - * @defgroup fat Fat - * @ingroup filesystem - */ - -#ifndef _DIROP_FAT_H -#define _DIROP_FAT_H - -#include "pthread.h" -#include "dirent.h" -#ifdef LOSCFG_FS_FAT - -#ifdef __cplusplus -#if __cplusplus -extern "C"{ -#endif -#endif /* __cplusplus */ - -#define TIME_LENGTH 8 - -struct fat_direntall { - unsigned long d_ino; - unsigned long d_off; - unsigned char d_type; - unsigned int d_size; - char d_createtime[TIME_LENGTH]; - unsigned short d_reclen; - char d_name[1]; -}; - -struct fat_direntall_buf { - int d_count; - int d_usecount; - struct fat_direntall direntall; -}; - -struct dirstream_fat { - DIR *dp; - - /* offset of the next dir entry in buffer */ - unsigned int dd_nextloc; - - /* bytes of valid entries in buffer */ - unsigned int dd_size; - - pthread_mutex_t dd_lock; -}; - -typedef struct fat_dir{ - struct dirstream_fat stDirStream; - struct fat_direntall_buf stBuf; -} DIR_FAT; - -/** - * @ingroup fat - * @brief open a directory - * - * @par Description: - * This API is used to open a directory stream corresponding to the directory name, and - * returns a pointer to the directory stream. - * - * @attention - * - * - * @param name [IN] the directory to open. - * - * @retval #NULL Open directory unsuccessfully and set errno. - * @retval #DIR_FAT* A pointer to the directory stream. - * @par Dependency: - * - * @see closedir_fat - */ -DIR_FAT *opendir_fat(const char *name); - -/** - * @ingroup fat - * @brief close a directory - * - * @par Description: - * This API is used to close the directory stream associated with dirp. - * - * @attention - * - * - * @param dir_fat [IN] Directory object structure pointer which opendir_fat returns. - * - * @retval #FAT_ERROR The directory dirp close unsuccessfully and set errno. - * @retval #OK The directory dirp close successfully. - * @par Dependency: - * - * @see opendir_fat - */ -int closedir_fat(DIR_FAT *dir_fat); - -/** - * @ingroup fat - * @brief read a directory - * - * @par Description: - * This API is used to get a pointer to a dirent structure - * representing the next directory entry in the directory stream pointed - * to by dirp. - * - * @attention - * - * - * @param dir_fat [IN] An instance of type DIR created by a previous call to opendir_fat(). - * - * @retval #NULL Reaching the end of the directory stream or if an error occurred and set errno. - * @retval #fat_direntall* A pointer to a dirent structure. - * @par Dependency: - * - * @see opendir_fat - */ -struct fat_direntall *readdir_fat(DIR_FAT *dir_fat); - -/** -* @ingroup fat -* @brief scan a directory for matching entries. -* -* @par Description: -* The scandir_fat() function scans the directory dirp, calling selector() in -* each directory entry. Entries for which selector() returns nonzero are -* stored in strings allocated via malloc, sorted using qsort with -* the comparison function compar(), and collected in array namelist -* which is allocated via malloc. If filter is NULL, all entries are -* selected, compare with scandir(), scandir_fat() can get the create-time of -* file. -* -* @attention -* -* -* @param dir [IN] Type #const char* a pointer to directory information. -* @param namelist [OUT] Type #const struct fat_direntall*** a pointer to collected directory entries. -* @param selector [IN] Type #int(*selector)(const struct fat_direntall*) a filter type function. -* @param compar [IN] Type #int(*compar)(const struct fat_direntall**,const struct dirent**) a compar type function. -* -* @retval #int The number of directory entries selected. -* @retval #<0 An error occurred. -* @par Dependency: -* -* @see readdir_fat -*/ -int scandir_fat(const char *dir, struct fat_direntall ***namelist, - int (*selector) (const struct fat_direntall *), - int (*compar) (const struct fat_direntall **, const struct fat_direntall **)); - -#ifdef __cplusplus -#if __cplusplus -} -#endif -#endif /* __cplusplus */ - -#endif /* LOSCFG_FS_FAT */ - -#endif /* _DIROP_FAT_H */ diff --git a/fs/fat/os_adapt/fat_shellcmd.c b/fs/fat/os_adapt/fat_shellcmd.c old mode 100644 new mode 100755 index 0648d29c..35dcbdd1 --- a/fs/fat/os_adapt/fat_shellcmd.c +++ b/fs/fat/os_adapt/fat_shellcmd.c @@ -45,8 +45,8 @@ int osShellCmdFormat(int argc, char **argv) if (argc < 3) { /* 3, at least 3 params for this shell command. */ perror("format error"); PRINTK("Usage :\n"); - PRINTK(" format