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)