From c1c2be2a87495f4caf796751657d53a0fe4ca5b2 Mon Sep 17 00:00:00 2001 From: Far Date: Fri, 15 Oct 2021 11:59:38 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E6=96=87=E4=BB=B6=E7=B3=BB?= =?UTF-8?q?=E7=BB=9FOpen=E6=80=A7=E8=83=BD=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 优化包括: 1. 提供VnodeLookupFullpath接口,如果路径是规范化的路径,则调用此接口可减少一次vfs_normalizepath接口的调用; 2. fatfs open钩子函数FIL和buffer同时malloc,减少一次malloc调用,同时去除不必要的数据写回; 3. 其他小细节的优化。 Close #I4E0CT Signed-off-by: Far --- fs/fat/os_adapt/fatfs.c | 13 +++---------- fs/vfs/include/vnode.h | 1 + fs/vfs/vnode.c | 7 ++++++- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/fs/fat/os_adapt/fatfs.c b/fs/fat/os_adapt/fatfs.c index 504e7755..d8bf81b8 100644 --- a/fs/fat/os_adapt/fatfs.c +++ b/fs/fat/os_adapt/fatfs.c @@ -606,7 +606,7 @@ int fatfs_open(struct file *filep) FIL *fp; int ret; - fp = (FIL *)zalloc(sizeof(FIL)); + fp = (FIL *)zalloc(sizeof(FIL) + SS(fs)); if (fp == NULL) { ret = ENOMEM; goto ERROR_EXIT; @@ -630,19 +630,13 @@ int fatfs_open(struct file *filep) fp->err = 0; fp->sect = 0; fp->fptr = 0; - fp->buf = (BYTE*) ff_memalloc(SS(fs)); - if (fp->buf == NULL) { - ret = ENOMEM; - goto ERROR_UNLOCK; - } + fp->buf = (BYTE *)fp + sizeof(FIL); LOS_ListAdd(&finfo->fp_list, &fp->fp_entry); unlock_fs(fs, FR_OK); filep->f_priv = fp; - return fatfs_sync(vp->originMount->mountFlags, fs); + return 0; -ERROR_UNLOCK: - unlock_fs(fs, FR_OK); ERROR_FREE: free(fp); ERROR_EXIT: @@ -672,7 +666,6 @@ int fatfs_close(struct file *filep) } #endif LOS_ListDelete(&fp->fp_entry); - ff_memfree(fp->buf); free(fp); filep->f_priv = NULL; EXIT: diff --git a/fs/vfs/include/vnode.h b/fs/vfs/include/vnode.h index 169a0915..f04e1a11 100644 --- a/fs/vfs/include/vnode.h +++ b/fs/vfs/include/vnode.h @@ -163,6 +163,7 @@ 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 VnodeLookupFullpath(const char *fullpath, struct Vnode **vnode, uint32_t flags); int VnodeLookupAt(const char *path, struct Vnode **vnode, uint32_t flags, struct Vnode *orgVnode); int VnodeHold(void); int VnodeDrop(void); diff --git a/fs/vfs/vnode.c b/fs/vfs/vnode.c index c5933a33..c85665ac 100644 --- a/fs/vfs/vnode.c +++ b/fs/vfs/vnode.c @@ -388,7 +388,7 @@ int VnodeLookupAt(const char *path, struct Vnode **result, uint32_t flags, struc } } - if (normalizedPath[0] == '/' && normalizedPath[1] == '\0') { + if (normalizedPath[1] == '\0' && normalizedPath[0] == '/') { *result = g_rootVnode; free(normalizedPath); return LOS_OK; @@ -447,6 +447,11 @@ int VnodeLookup(const char *path, struct Vnode **vnode, uint32_t flags) return VnodeLookupAt(path, vnode, flags, NULL); } +int VnodeLookupFullpath(const char *fullpath, struct Vnode **vnode, uint32_t flags) +{ + return VnodeLookupAt(fullpath, vnode, flags, g_rootVnode); +} + static void ChangeRootInternal(struct Vnode *rootOld, char *dirname) { int ret;