mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2026-11-17 07:05:31 +08:00
[fix][dfs] 增加文件系统操作的类型检查,防止类型不匹配导致数据结构不一致引发的异常
This commit is contained in:
1 parent
395dff4e2e
commit
2f7a2299f6
5 files changed
+26
No files matched your search
@@ -588,6 +588,11 @@ int dfs_elm_flush(struct dfs_file *file)
|
||||
FIL *fd;
|
||||
FRESULT result;
|
||||
|
||||
if (file->vnode->type == FT_DIRECTORY)
|
||||
{
|
||||
return -EISDIR;
|
||||
}
|
||||
|
||||
fd = (FIL *)(file->data);
|
||||
RT_ASSERT(fd != RT_NULL);
|
||||
|
||||
|
||||
@@ -460,6 +460,11 @@ int fsync(int fildes)
|
||||
}
|
||||
|
||||
ret = dfs_file_flush(d);
|
||||
if (ret < 0)
|
||||
{
|
||||
rt_set_errno(ret);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -623,6 +623,11 @@ int dfs_elm_flush(struct dfs_file *file)
|
||||
FIL *fd;
|
||||
FRESULT result;
|
||||
|
||||
if (file->vnode->type == FT_DIRECTORY)
|
||||
{
|
||||
return -EISDIR;
|
||||
}
|
||||
|
||||
fd = (FIL *)(file->vnode->data);
|
||||
RT_ASSERT(fd != RT_NULL);
|
||||
|
||||
|
||||
@@ -2202,6 +2202,7 @@ int dfs_file_rename(const char *old_file, const char *new_file)
|
||||
* @return int Operation result:
|
||||
* - 0 on success
|
||||
* -EBADF if invalid file descriptor
|
||||
* -EISDIR if the file is a directory (directories cannot be truncated)
|
||||
* -ENOSYS if truncate operation not supported
|
||||
* -EINVAL if invalid parameters or not mounted
|
||||
*
|
||||
@@ -2214,6 +2215,11 @@ int dfs_file_ftruncate(struct dfs_file *file, off_t length)
|
||||
|
||||
if (file)
|
||||
{
|
||||
if (file->vnode->type == FT_DIRECTORY)
|
||||
{
|
||||
return -EISDIR;
|
||||
}
|
||||
|
||||
if (file->fops->truncate)
|
||||
{
|
||||
if (dfs_is_mounted(file->vnode->mnt) == 0)
|
||||
|
||||
@@ -605,6 +605,11 @@ int fsync(int fildes)
|
||||
}
|
||||
|
||||
ret = dfs_file_fsync(file);
|
||||
if (ret < 0)
|
||||
{
|
||||
rt_set_errno(ret);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user