From 1be24fc7daa732da3a2f6b4eede71ae7c3c7ef6d Mon Sep 17 00:00:00 2001 From: zhuzhuzhu <945386260@qq.com> Date: Sun, 25 Aug 2024 22:57:38 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E4=BF=AE=E5=A4=8D=E3=80=91=E4=BF=AE?= =?UTF-8?q?=E5=A4=8Dlink=E7=B3=BB=E7=BB=9F=E8=B0=83=E7=94=A8=E8=BF=94?= =?UTF-8?q?=E5=9B=9E=E5=80=BC=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/dfs/dfs_v2/src/dfs_file.c | 1 + components/lwp/lwp_syscall.c | 12 +++++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/components/dfs/dfs_v2/src/dfs_file.c b/components/dfs/dfs_v2/src/dfs_file.c index 1f98d5ceab..57ff2e992f 100644 --- a/components/dfs/dfs_v2/src/dfs_file.c +++ b/components/dfs/dfs_v2/src/dfs_file.c @@ -1379,6 +1379,7 @@ int dfs_file_link(const char *oldname, const char *newname) if (dfs_file_isdir(oldname) == 0) { + rt_set_errno(-EPERM); return ret; } diff --git a/components/lwp/lwp_syscall.c b/components/lwp/lwp_syscall.c index 7dff63dbcd..8b8276ae63 100644 --- a/components/lwp/lwp_syscall.c +++ b/components/lwp/lwp_syscall.c @@ -5013,7 +5013,8 @@ ssize_t sys_readlink(char* path, char *buf, size_t bufsz) err = dfs_file_readlink(copy_path, link_fn, DFS_PATH_MAX); if (err > 0) { - rtn = lwp_put_to_user(buf, link_fn, bufsz > err ? err : bufsz - 1); + buf[bufsz > err ? err : bufsz] = '\0'; + rtn = lwp_put_to_user(buf, link_fn, bufsz > err ? err : bufsz); } else { @@ -5855,7 +5856,7 @@ sysret_t sys_umount2(char *__special_file, int __flags) sysret_t sys_link(const char *existing, const char *new) { int ret = -1; - + int err = 0; #ifdef RT_USING_DFS_V2 #ifdef ARCH_MM_MMU int len = 0; @@ -5902,6 +5903,10 @@ sysret_t sys_link(const char *existing, const char *new) } ret = dfs_file_link(kexisting, knew); + if(ret < 0) + { + err = GET_ERRNO(); + } kmem_put(knew); kmem_put(kexisting); @@ -5910,9 +5915,10 @@ sysret_t sys_link(const char *existing, const char *new) #endif #else SET_ERRNO(EFAULT); + err = GET_ERRNO(); #endif - return (ret < 0 ? GET_ERRNO() : ret); + return (err < 0 ? err : ret); } sysret_t sys_symlink(const char *existing, const char *new)