From ab5bb707bbd6651a90c6adf4dcf38b023f0bb8de Mon Sep 17 00:00:00 2001 From: Far Date: Fri, 15 Oct 2021 12:04:25 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E6=96=87=E4=BB=B6=E7=B3=BB?= =?UTF-8?q?=E7=BB=9Fopen=E6=8E=A5=E5=8F=A3=E6=80=A7=E8=83=BD=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 优化包括: 1. 用VnodeLookupFullpath接口替代VnodeLookup; 2. 修改逻辑,减少strcpy和memset的调用 Close #I4E0CT Signed-off-by: Far --- fs/vfs/fs_symlink.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/fs/vfs/fs_symlink.c b/fs/vfs/fs_symlink.c index 1bf94f1..dcc8c7d 100644 --- a/fs/vfs/fs_symlink.c +++ b/fs/vfs/fs_symlink.c @@ -37,14 +37,13 @@ int follow_symlink(int dirfd, const char *path, struct Vnode **vnode, char **ful { int ret; struct Vnode *newvnode = NULL; - char pathname[PATH_MAX] = {0}; + char *pathname = (char *)path; + char buffer[PATH_MAX] = {0}; if (path == NULL) { return -EINVAL; } - (void)strcpy_s(pathname, PATH_MAX, path); - for (int i = 0; i < CONFIG_FS_MAX_LNK_CNT; i++) { if (*fullpath) @@ -59,7 +58,7 @@ int follow_symlink(int dirfd, const char *path, struct Vnode **vnode, char **ful return ret; } - ret = VnodeLookup(*fullpath, &newvnode, 0); + ret = VnodeLookupFullpath(*fullpath, &newvnode, 0); if (ret != OK) { /* The object of fullpath is not exist. Return its parent's vnode. */ @@ -79,7 +78,7 @@ int follow_symlink(int dirfd, const char *path, struct Vnode **vnode, char **ful } /* The object of fullpath is a symbol link. Read its target and find the source file successively. */ - (void)memset_s(pathname, PATH_MAX, 0, PATH_MAX); + pathname = buffer; ret = newvnode->vop->Readlink(newvnode, pathname, PATH_MAX); if (ret < 0) { -- Gitee