!92 fix bad code in fs codes

Merge pull request !92 from 野生毛霉君/master
This commit is contained in:
openharmony_ci 2021-03-30 09:49:11 +08:00 committed by Gitee
commit e3ca50e8ad
8 changed files with 25 additions and 10 deletions

View File

@ -1371,7 +1371,7 @@ int fatfs_readdir(struct Vnode *vp, struct fs_dirent_s *idir)
} }
DEF_NAMBUF; DEF_NAMBUF;
INIT_NAMBUF(fs); 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); result = dir_read(dp, 0);
if (result == FR_NO_FILE) { if (result == FR_NO_FILE) {
break; break;

View File

@ -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 * @ingroup fs

View File

@ -470,7 +470,7 @@ int VfsJffs2Readdir(struct Vnode *pVnode, struct fs_dirent_s *dir)
LOS_MuxLock(&g_jffs2FsLock, (uint32_t)JFFS2_WAITING_FOREVER); LOS_MuxLock(&g_jffs2FsLock, (uint32_t)JFFS2_WAITING_FOREVER);
/* set jffs2_d */ /* 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, ret = jffs2_readdir((struct jffs2_inode *)pVnode->data, &dir->fd_position,
&dir->fd_int_offset, &dir->fd_dir[i]); &dir->fd_int_offset, &dir->fd_dir[i]);
if (ret) { if (ret) {

View File

@ -182,7 +182,7 @@ int VfsProcfsReaddir(struct Vnode *node, struct fs_dirent_s *dir)
} }
pde = VnodeToEntry(node); pde = VnodeToEntry(node);
while ((i < MAX_DIRENT_NUM) || (i < dir->read_cnt)) { while (i < dir->read_cnt) {
buffer = (char *)zalloc(sizeof(char) * NAME_MAX); buffer = (char *)zalloc(sizeof(char) * NAME_MAX);
if (buffer == NULL) { if (buffer == NULL) {
PRINT_ERR("malloc failed\n"); PRINT_ERR("malloc failed\n");

View File

@ -696,9 +696,13 @@ static INT32 DiskPartitionRecognition(struct Vnode *blkDrv, struct disk_divide_i
CHAR *mbrBuf = NULL; CHAR *mbrBuf = NULL;
CHAR *ebrBuf = NULL; CHAR *ebrBuf = NULL;
if (blkDrv == NULL) {
return -EINVAL;
}
struct block_operations *bops = (struct block_operations *)((struct drv_data *)blkDrv->data)->ops; 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; return -EINVAL;
} }
@ -832,8 +836,11 @@ INT32 los_disk_read(INT32 drvID, VOID *buf, UINT64 sector, UINT32 count)
} }
} else { } else {
#endif #endif
if (disk->dev == NULL) {
goto ERROR_HANDLE;
}
struct block_operations *bops = (struct block_operations *)((struct drv_data *)disk->dev->data)->ops; 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); result = bops->read(disk->dev, (UINT8 *)buf, sector, count);
if (result == (INT32)count) { if (result == (INT32)count) {
result = ENOERR; result = ENOERR;

View File

@ -245,7 +245,7 @@ out:
(VOID)LOS_MuxUnlock(&g_file_mapping.lock); (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; unsigned int i = 3;
struct filelist *f_list = NULL; 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); (VOID)LOS_MuxLock(&g_file_mapping.lock, LOS_WAIT_FOREVER);
while (i < CONFIG_NFILE_DESCRIPTORS) { while (i < CONFIG_NFILE_DESCRIPTORS) {
i++; i++;
if (!get_bit(i)) { if (!get_bit(i - 1)) {
continue; 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)) { if (filp->f_path == NULL || strcmp(filp->f_path, old_path)) {
continue; continue;
} }

View File

@ -93,6 +93,7 @@ struct PathCache *PathCacheAlloc(struct Vnode *parent, struct Vnode *vnode, cons
{ {
struct PathCache *nc = NULL; struct PathCache *nc = NULL;
size_t pathCacheSize; size_t pathCacheSize;
int ret;
if (name == NULL || len > NAME_MAX || parent == NULL || vnode == NULL) { if (name == NULL || len > NAME_MAX || parent == NULL || vnode == NULL) {
return NULL; return NULL;
@ -105,7 +106,10 @@ struct PathCache *PathCacheAlloc(struct Vnode *parent, struct Vnode *vnode, cons
return NULL; 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->parentVnode = parent;
nc->nameLen = len; nc->nameLen = len;

View File

@ -573,6 +573,10 @@ int VnodeDevInit()
devNode->type = VNODE_TYPE_DIR; devNode->type = VNODE_TYPE_DIR;
devMount = MountAlloc(devNode, NULL); devMount = MountAlloc(devNode, NULL);
if (devMount == NULL) {
PRINT_ERR("VnodeDevInit failed mount point alloc failed.\n");
return -ENOMEM;
}
devMount->vnodeCovered = devNode; devMount->vnodeCovered = devNode;
devMount->vnodeBeCovered->flag |= VNODE_FLAG_MOUNT_NEW; devMount->vnodeBeCovered->flag |= VNODE_FLAG_MOUNT_NEW;
return LOS_OK; return LOS_OK;