Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions components/dfs/dfs_v1/filesystems/elmfat/dfs_elm.c
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,12 @@ int dfs_elm_ioctl(struct dfs_file *file, int cmd, void *args)
FIL *fd;
FSIZE_t fptr, length;
FRESULT result = FR_OK;

if (file->vnode->type == FT_DIRECTORY)
{
return -EISDIR;
}

fd = (FIL *)(file->data);
RT_ASSERT(fd != RT_NULL);

Expand Down Expand Up @@ -584,6 +590,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);

Expand Down Expand Up @@ -638,6 +649,11 @@ int dfs_elm_getdents(struct dfs_file *file, struct dirent *dirp, uint32_t count)
rt_uint32_t index;
struct dirent *d;

if (file->vnode->type != FT_DIRECTORY)
{
return -ENOTDIR;
}

dir = (DIR *)(file->data);
RT_ASSERT(dir != RT_NULL);

Expand Down
10 changes: 10 additions & 0 deletions components/dfs/dfs_v1/filesystems/tmpfs/dfs_tmpfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,11 @@ ssize_t dfs_tmpfs_read(struct dfs_file *file, void *buf, size_t count)
rt_size_t length;
struct tmpfs_file *d_file;

if (file->vnode->type == FT_DIRECTORY)
{
return -EISDIR;
}

d_file = (struct tmpfs_file *)file->vnode->data;
RT_ASSERT(d_file != NULL);

Expand All @@ -359,6 +364,11 @@ ssize_t dfs_tmpfs_write(struct dfs_file *fd, const void *buf, size_t count)
struct tmpfs_file *d_file;
struct tmpfs_sb *superblock;

if (fd->vnode->type == FT_DIRECTORY)
{
return -EISDIR;
}

d_file = (struct tmpfs_file *)fd->vnode->data;
RT_ASSERT(d_file != NULL);

Expand Down
14 changes: 12 additions & 2 deletions components/dfs/dfs_v1/src/dfs_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,11 @@ ssize_t dfs_file_read(struct dfs_file *fd, void *buf, size_t len)
return -EINVAL;
}

if (fd->vnode->type == FT_DIRECTORY)
{
return -EISDIR;
}

if (fd->vnode->fops->read == NULL)
{
return -ENOSYS;
Expand Down Expand Up @@ -544,6 +549,11 @@ ssize_t dfs_file_write(struct dfs_file *fd, const void *buf, size_t len)
return -EINVAL;
}

if (fd->vnode->type == FT_DIRECTORY)
{
return -EISDIR;
}

if (fd->vnode->fops->write == NULL)
{
return -ENOSYS;
Expand Down Expand Up @@ -738,8 +748,8 @@ int dfs_file_ftruncate(struct dfs_file *fd, off_t length)
{
int result;

/* fd is null or not a regular file system fd, or length is invalid */
if (fd == NULL || fd->vnode->type != FT_REGULAR || length < 0)
/* fd is null or a directory , or length is invalid */
if (fd == NULL || fd->vnode->type == FT_DIRECTORY || length < 0)
return -EINVAL;

if (fd->vnode->fops->ioctl == NULL)
Expand Down
16 changes: 16 additions & 0 deletions components/dfs/dfs_v2/filesystems/elmfat/dfs_elm.c
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,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);

Expand Down Expand Up @@ -689,6 +694,12 @@ static int dfs_elm_truncate(struct dfs_file *file, off_t offset)
FIL *fd;
FSIZE_t fptr;
FRESULT result = FR_OK;

if (file->vnode->type == FT_DIRECTORY)
{
return -EISDIR;
}

fd = (FIL *)(file->vnode->data);
RT_ASSERT(fd != RT_NULL);

Expand Down Expand Up @@ -716,6 +727,11 @@ int dfs_elm_getdents(struct dfs_file *file, struct dirent *dirp, uint32_t count)
rt_uint32_t index;
struct dirent *d;

if (file->vnode->type != FT_DIRECTORY)
{
return -ENOTDIR;
}

dir = (DIR *)(file->vnode->data);
RT_ASSERT(dir != RT_NULL);

Expand Down
21 changes: 21 additions & 0 deletions components/dfs/dfs_v2/filesystems/tmpfs/dfs_tmpfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,12 @@ static ssize_t dfs_tmpfs_read(struct dfs_file *file, void *buf, size_t count, of
{
ssize_t length;
struct tmpfs_file *d_file;

if (file->vnode->type == FT_DIRECTORY)
{
return -EISDIR;
}

d_file = (struct tmpfs_file *)file->vnode->data;
RT_ASSERT(d_file != NULL);

Expand Down Expand Up @@ -352,6 +358,11 @@ static ssize_t dfs_tmpfs_write(struct dfs_file *file, const void *buf, size_t co
{
struct tmpfs_file *d_file;

if (file->vnode->type == FT_DIRECTORY)
{
return -EISDIR;
}

d_file = (struct tmpfs_file *)file->vnode->data;
RT_ASSERT(d_file != NULL);

Expand Down Expand Up @@ -500,6 +511,11 @@ static int dfs_tmpfs_getdents(struct dfs_file *file,
struct tmpfs_file *d_file, *n_file, *tmp;
struct tmpfs_sb *superblock;

if (file->vnode->type != FT_DIRECTORY)
{
return -ENOTDIR;
}

d_file = (struct tmpfs_file *)file->vnode->data;

rt_mutex_take(&file->vnode->lock, RT_WAITING_FOREVER);
Expand Down Expand Up @@ -828,6 +844,11 @@ static int dfs_tmpfs_truncate(struct dfs_file *file, off_t offset)
struct tmpfs_sb *superblock = RT_NULL;
rt_uint8_t *ptr = RT_NULL;

if (file->vnode->type == FT_DIRECTORY)
{
return -EISDIR;
}

d_file = (struct tmpfs_file *)file->vnode->data;
RT_ASSERT(d_file != RT_NULL);

Expand Down
5 changes: 5 additions & 0 deletions components/dfs/dfs_v2/src/dfs_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -2214,6 +2214,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)
Expand Down
Loading