!300 codex问题修复

Merge pull request !300 from LeonChan/master
This commit is contained in:
openharmony_ci 2021-06-08 08:48:30 +08:00 committed by Gitee
commit 7d10057103
8 changed files with 40 additions and 28 deletions

View File

@ -1836,7 +1836,7 @@ ERROR_OUT:
return -fatfs_2_vfs(result); return -fatfs_2_vfs(result);
} }
int fatfs_rmdir(struct Vnode *parent, struct Vnode *vp, char *name) int fatfs_rmdir(struct Vnode *parent, struct Vnode *vp, const char *name)
{ {
FATFS *fs = (FATFS *)vp->originMount->data; FATFS *fs = (FATFS *)vp->originMount->data;
DIR_FILE *dfp = (DIR_FILE *)vp->data; DIR_FILE *dfp = (DIR_FILE *)vp->data;
@ -1898,7 +1898,7 @@ int fatfs_reclaim(struct Vnode *vp)
return 0; return 0;
} }
int fatfs_unlink(struct Vnode *parent, struct Vnode *vp, char *name) int fatfs_unlink(struct Vnode *parent, struct Vnode *vp, const char *name)
{ {
FATFS *fs = (FATFS *)vp->originMount->data; FATFS *fs = (FATFS *)vp->originMount->data;
DIR_FILE *dfp = (DIR_FILE *)vp->data; DIR_FILE *dfp = (DIR_FILE *)vp->data;

View File

@ -131,8 +131,8 @@ int fatfs_closedir(struct Vnode *vnode, struct fs_dirent_s *dir);
int fatfs_rename(struct Vnode *oldvnode, struct Vnode *newparent, const char *oldname, const char *newname); int fatfs_rename(struct Vnode *oldvnode, struct Vnode *newparent, const char *oldname, const char *newname);
int fatfs_mkfs (struct Vnode *device, int sectors, int option); int fatfs_mkfs (struct Vnode *device, int sectors, int option);
int fatfs_mkdir(struct Vnode *parent, const char *name, mode_t mode, struct Vnode **vpp); int fatfs_mkdir(struct Vnode *parent, const char *name, mode_t mode, struct Vnode **vpp);
int fatfs_rmdir(struct Vnode *parent, struct Vnode *vp, char *name); int fatfs_rmdir(struct Vnode *parent, struct Vnode *vp, const char *name);
int fatfs_unlink(struct Vnode *parent, struct Vnode *vp, char *name); int fatfs_unlink(struct Vnode *parent, struct Vnode *vp, const char *name);
int fatfs_ioctl(struct file *filep, int req, unsigned long arg); int fatfs_ioctl(struct file *filep, int req, unsigned long arg);
int fatfs_fscheck(struct Vnode* vnode, struct fs_dirent_s *dir); int fatfs_fscheck(struct Vnode* vnode, struct fs_dirent_s *dir);

View File

@ -85,8 +85,8 @@ struct VnodeOps {
int (*Open)(struct Vnode *vnode, int fd, int mode, int flags); int (*Open)(struct Vnode *vnode, int fd, int mode, int flags);
int (*Close)(struct Vnode *vnode); int (*Close)(struct Vnode *vnode);
int (*Reclaim)(struct Vnode *vnode); int (*Reclaim)(struct Vnode *vnode);
int (*Unlink)(struct Vnode *parent, struct Vnode *vnode, char *fileName); int (*Unlink)(struct Vnode *parent, struct Vnode *vnode, const char *fileName);
int (*Rmdir)(struct Vnode *parent, struct Vnode *vnode, char *dirName); int (*Rmdir)(struct Vnode *parent, struct Vnode *vnode, const char *dirName);
int (*Mkdir)(struct Vnode *parent, const char *dirName, mode_t mode, struct Vnode **vnode); int (*Mkdir)(struct Vnode *parent, const char *dirName, mode_t mode, struct Vnode **vnode);
int (*Readdir)(struct Vnode *vnode, struct fs_dirent_s *dir); int (*Readdir)(struct Vnode *vnode, struct fs_dirent_s *dir);
int (*Opendir)(struct Vnode *vnode, struct fs_dirent_s *dir); int (*Opendir)(struct Vnode *vnode, struct fs_dirent_s *dir);

View File

@ -603,7 +603,7 @@ int VfsJffs2Chattr(struct Vnode *pVnode, struct IATTR *attr)
return ret; return ret;
} }
int VfsJffs2Rmdir(struct Vnode *parentVnode, struct Vnode *targetVnode, char *path) int VfsJffs2Rmdir(struct Vnode *parentVnode, struct Vnode *targetVnode, const char *path)
{ {
int ret; int ret;
@ -620,7 +620,7 @@ int VfsJffs2Rmdir(struct Vnode *parentVnode, struct Vnode *targetVnode, char *pa
return ret; return ret;
} }
int VfsJffs2Unlink(struct Vnode *parentVnode, struct Vnode *targetVnode, char *path) int VfsJffs2Unlink(struct Vnode *parentVnode, struct Vnode *targetVnode, const char *path)
{ {
int ret; int ret;

View File

@ -270,11 +270,27 @@ int update_file_path(const char *old_path, const char *new_path)
continue; continue;
} }
int len = strlen(new_path) + 1; int len = strlen(new_path) + 1;
filp->f_path = zalloc(len); char *tmp_path = LOS_MemAlloc(m_aucSysMem0, len);
strncpy_s(filp->f_path, strlen(new_path) + 1, new_path, len); if (tmp_path == NULL) {
PRINT_ERR("%s-%d: Mem alloc failed, path length(%d)\n", __FUNCTION__, __LINE__, len);
ret = VFS_ERROR;
goto out;
} }
ret = strncpy_s(tmp_path, strlen(new_path) + 1, new_path, len);
if (ret != 0) {
(VOID)LOS_MemFree(m_aucSysMem0, tmp_path);
PRINT_ERR("%s-%d: strcpy failed.\n", __FUNCTION__, __LINE__);
ret = VFS_ERROR;
goto out;
}
free(filp->f_path);
filp->f_path = tmp_path;
}
ret = LOS_OK;
out:
(VOID)LOS_MuxUnlock(&g_file_mapping.lock); (VOID)LOS_MuxUnlock(&g_file_mapping.lock);
(void)sem_post(&f_list->fl_sem); (void)sem_post(&f_list->fl_sem);
return LOS_OK; return ret;
} }
#endif #endif

View File

@ -82,7 +82,7 @@ static uint32_t NameHash(const char *name, int len, struct Vnode *dvp)
{ {
uint32_t hash; uint32_t hash;
hash = fnv_32_buf(name, len, FNV1_32_INIT); hash = fnv_32_buf(name, len, FNV1_32_INIT);
hash = fnv_32_buf(&dvp, sizeof(dvp), hash); hash = fnv_32_buf(&dvp, sizeof(struct Vnode *), hash);
return hash; return hash;
} }

View File

@ -245,9 +245,6 @@ int VnodeDrop()
static char *NextName(char *pos, uint8_t *len) static char *NextName(char *pos, uint8_t *len)
{ {
char *name = NULL; char *name = NULL;
if (*pos == '\0') {
return NULL;
}
while (*pos != 0 && *pos == '/') { while (*pos != 0 && *pos == '/') {
pos++; pos++;
} }
@ -319,6 +316,7 @@ static int Step(char **currentDir, struct Vnode **currentVnode, uint32_t flags)
} }
nextDir = NextName(*currentDir, &len); nextDir = NextName(*currentDir, &len);
if (nextDir == NULL) { if (nextDir == NULL) {
// there is '/' at the end of the *currentDir.
*currentDir = NULL; *currentDir = NULL;
return LOS_OK; return LOS_OK;
} }
@ -361,7 +359,6 @@ int VnodeLookup(const char *path, struct Vnode **result, uint32_t flags)
struct Vnode *startVnode = NULL; struct Vnode *startVnode = NULL;
char *normalizedPath = NULL; char *normalizedPath = NULL;
int ret = PreProcess(path, &startVnode, &normalizedPath); int ret = PreProcess(path, &startVnode, &normalizedPath);
if (ret != LOS_OK) { if (ret != LOS_OK) {
PRINT_ERR("[VFS]lookup failed, invalid path=%s err = %d\n", path, ret); PRINT_ERR("[VFS]lookup failed, invalid path=%s err = %d\n", path, ret);
@ -377,9 +374,9 @@ int VnodeLookup(const char *path, struct Vnode **result, uint32_t flags)
char *currentDir = normalizedPath; char *currentDir = normalizedPath;
struct Vnode *currentVnode = startVnode; struct Vnode *currentVnode = startVnode;
while (currentDir && *currentDir != '\0') { while (*currentDir != '\0') {
ret = Step(&currentDir, &currentVnode, flags); ret = Step(&currentDir, &currentVnode, flags);
if (*currentDir == '\0') { if (currentDir == NULL || *currentDir == '\0') {
// return target or parent vnode as result // return target or parent vnode as result
*result = currentVnode; *result = currentVnode;
} else if (VfsVnodePermissionCheck(currentVnode, EXEC_OP)) { } else if (VfsVnodePermissionCheck(currentVnode, EXEC_OP)) {

View File

@ -270,13 +270,11 @@ int SysOpen(const char *path, int oflags, ...)
mode_t mode = DEFAULT_FILE_MODE; /* 0666: File read-write properties. */ mode_t mode = DEFAULT_FILE_MODE; /* 0666: File read-write properties. */
char *pathRet = NULL; char *pathRet = NULL;
if (path == NULL && *path == 0) { if (path != NULL) {
return -EINVAL;
}
ret = UserPathCopy(path, &pathRet); ret = UserPathCopy(path, &pathRet);
if (ret != 0) { if (ret != 0) {
return ret; goto ERROUT_PATH_FREE;
}
} }
procFd = AllocProcessFd(); procFd = AllocProcessFd();
@ -310,15 +308,16 @@ int SysOpen(const char *path, int oflags, ...)
return procFd; return procFd;
ERROUT: ERROUT:
if (pathRet != NULL) {
LOS_MemFree(OS_SYS_MEM_ADDR, pathRet);
}
if (ret >= 0) { if (ret >= 0) {
AssociateSystemFd(procFd, ret); AssociateSystemFd(procFd, ret);
ret = procFd; ret = procFd;
} else { } else {
FreeProcessFd(procFd); FreeProcessFd(procFd);
} }
ERROUT_PATH_FREE:
if (pathRet != NULL) {
LOS_MemFree(OS_SYS_MEM_ADDR, pathRet);
}
return ret; return ret;
} }