From 1884fa0523efe6a47629df545a1990ac17ccd276 Mon Sep 17 00:00:00 2001 From: mucor Date: Wed, 24 Mar 2021 16:38:23 +0800 Subject: [PATCH] fix readdir, rename Change-Id: Ic443742e125915f0e5332a338dedea5c40348928 --- fs/fat/os_adapt/fatfs.c | 2 +- fs/include/fs/fs_operation.h | 2 +- fs/jffs2/src/vfs_jffs2.c | 2 +- fs/proc/os_adapt/proc_vfs.c | 2 +- fs/vfs/disk/disk.c | 11 +++++++++-- fs/vfs/operation/fs_file_mapping.c | 6 +++--- fs/vfs/path_cache.c | 6 +++++- fs/vfs/vnode.c | 4 ++++ 8 files changed, 25 insertions(+), 10 deletions(-) diff --git a/fs/fat/os_adapt/fatfs.c b/fs/fat/os_adapt/fatfs.c index 6a173100..7e061226 100755 --- a/fs/fat/os_adapt/fatfs.c +++ b/fs/fat/os_adapt/fatfs.c @@ -1368,7 +1368,7 @@ int fatfs_readdir(struct Vnode *vp, struct fs_dirent_s *idir) } DEF_NAMBUF; INIT_NAMBUF(fs); - for (i = 0; i < DIR_READ_COUNT && i < idir->read_cnt; i++) { + for (i = 0; i < idir->read_cnt; i++) { result = dir_read(dp, 0); if (result == FR_NO_FILE) { break; diff --git a/fs/include/fs/fs_operation.h b/fs/include/fs/fs_operation.h index 23898d88..ab9287bf 100644 --- a/fs/include/fs/fs_operation.h +++ b/fs/include/fs/fs_operation.h @@ -113,7 +113,7 @@ extern void dec_mapping_nolock(struct page_mapping *mapping); * ****************************************************************************/ -extern int update_file_path(char *old_path, char *new_path); +extern int update_file_path(const char *old_path, const char *new_path); /** * @ingroup fs diff --git a/fs/jffs2/src/vfs_jffs2.c b/fs/jffs2/src/vfs_jffs2.c index f82f9c5f..f3e24e24 100755 --- a/fs/jffs2/src/vfs_jffs2.c +++ b/fs/jffs2/src/vfs_jffs2.c @@ -474,7 +474,7 @@ int VfsJffs2Readdir(struct Vnode *pVnode, struct fs_dirent_s *dir) LOS_MuxLock(&g_jffs2FsLock, (uint32_t)JFFS2_WAITING_FOREVER); /* set jffs2_d */ - while (i < MAX_DIRENT_NUM && i < dir->read_cnt) { + while (i < dir->read_cnt) { ret = jffs2_readdir((struct jffs2_inode *)pVnode->data, &dir->fd_position, &dir->fd_int_offset, &dir->fd_dir[i]); if (ret) { diff --git a/fs/proc/os_adapt/proc_vfs.c b/fs/proc/os_adapt/proc_vfs.c index 3e3374f7..87412b11 100755 --- a/fs/proc/os_adapt/proc_vfs.c +++ b/fs/proc/os_adapt/proc_vfs.c @@ -182,7 +182,7 @@ int VfsProcfsReaddir(struct Vnode *node, struct fs_dirent_s *dir) } pde = VnodeToEntry(node); - while ((i < MAX_DIRENT_NUM) || (i < dir->read_cnt)) { + while (i < dir->read_cnt) { buffer = (char *)zalloc(sizeof(char) * NAME_MAX); if (buffer == NULL) { PRINT_ERR("malloc failed\n"); diff --git a/fs/vfs/disk/disk.c b/fs/vfs/disk/disk.c index c4b7cd9d..c4a4a90d 100755 --- a/fs/vfs/disk/disk.c +++ b/fs/vfs/disk/disk.c @@ -696,9 +696,13 @@ static INT32 DiskPartitionRecognition(struct Vnode *blkDrv, struct disk_divide_i CHAR *mbrBuf = NULL; CHAR *ebrBuf = NULL; + if (blkDrv == NULL) { + return -EINVAL; + } + struct block_operations *bops = (struct block_operations *)((struct drv_data *)blkDrv->data)->ops; - if ((blkDrv == NULL) || (bops == NULL) || (bops->read == NULL)) { + if ((bops == NULL) || (bops->read == NULL)) { return -EINVAL; } @@ -832,8 +836,11 @@ INT32 los_disk_read(INT32 drvID, VOID *buf, UINT64 sector, UINT32 count) } } else { #endif + if (disk->dev == NULL) { + goto ERROR_HANDLE; + } struct block_operations *bops = (struct block_operations *)((struct drv_data *)disk->dev->data)->ops; - if ((disk->dev != NULL) && (bops != NULL) && (bops->read != NULL)) { + if ((bops != NULL) && (bops->read != NULL)) { result = bops->read(disk->dev, (UINT8 *)buf, sector, count); if (result == (INT32)count) { result = ENOERR; diff --git a/fs/vfs/operation/fs_file_mapping.c b/fs/vfs/operation/fs_file_mapping.c index a8f6b1f7..22cbca4f 100644 --- a/fs/vfs/operation/fs_file_mapping.c +++ b/fs/vfs/operation/fs_file_mapping.c @@ -245,7 +245,7 @@ out: (VOID)LOS_MuxUnlock(&g_file_mapping.lock); } -int update_file_path(char *old_path, char *new_path) +int update_file_path(const char *old_path, const char *new_path) { unsigned int i = 3; struct filelist *f_list = NULL; @@ -262,10 +262,10 @@ int update_file_path(char *old_path, char *new_path) (VOID)LOS_MuxLock(&g_file_mapping.lock, LOS_WAIT_FOREVER); while (i < CONFIG_NFILE_DESCRIPTORS) { i++; - if (!get_bit(i)) { + if (!get_bit(i - 1)) { continue; } - filp = &tg_filelist.fl_files[i]; + filp = &tg_filelist.fl_files[i - 1]; if (filp->f_path == NULL || strcmp(filp->f_path, old_path)) { continue; } diff --git a/fs/vfs/path_cache.c b/fs/vfs/path_cache.c index 6242f7dc..ab279104 100755 --- a/fs/vfs/path_cache.c +++ b/fs/vfs/path_cache.c @@ -93,6 +93,7 @@ struct PathCache *PathCacheAlloc(struct Vnode *parent, struct Vnode *vnode, cons { struct PathCache *nc = NULL; size_t pathCacheSize; + int ret; if (name == NULL || len > NAME_MAX || parent == NULL || vnode == NULL) { return NULL; @@ -105,7 +106,10 @@ struct PathCache *PathCacheAlloc(struct Vnode *parent, struct Vnode *vnode, cons return NULL; } - (void)strncpy_s(nc->name, pathCacheSize, name, len); + ret = strncpy_s(nc->name, pathCacheSize, name, len); + if (ret != LOS_OK) { + return NULL; + } nc->parentVnode = parent; nc->nameLen = len; diff --git a/fs/vfs/vnode.c b/fs/vfs/vnode.c index a2cf6575..0293cfd0 100755 --- a/fs/vfs/vnode.c +++ b/fs/vfs/vnode.c @@ -573,6 +573,10 @@ int VnodeDevInit() devNode->type = VNODE_TYPE_DIR; devMount = MountAlloc(devNode, NULL); + if (devMount == NULL) { + PRINT_ERR("VnodeDevInit failed mount point alloc failed.\n"); + return -ENOMEM; + } devMount->vnodeCovered = devNode; devMount->vnodeBeCovered->flag |= VNODE_FLAG_MOUNT_NEW; return LOS_OK;