🐞 fix(components/dfs/filesystems/tmpfs/dfs_tmpfs.c): cannot open the same file repeatedly in 'w' mode
This commit is contained in:
parent
e010d844af
commit
da8f5c08c2
@ -6,6 +6,7 @@
|
|||||||
* Change Logs:
|
* Change Logs:
|
||||||
* Date Author Notes
|
* Date Author Notes
|
||||||
* 2022-10-24 flybreak the first version
|
* 2022-10-24 flybreak the first version
|
||||||
|
* 2023-02-01 xqyjlj fix cannot open the same file repeatedly in 'w' mode
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <rthw.h>
|
#include <rthw.h>
|
||||||
@ -382,9 +383,7 @@ int dfs_tmpfs_open(struct dfs_fd *file)
|
|||||||
/* Creates a new file. */
|
/* Creates a new file. */
|
||||||
if (file->flags & O_CREAT)
|
if (file->flags & O_CREAT)
|
||||||
{
|
{
|
||||||
if (d_file != NULL)
|
if (d_file == NULL) {
|
||||||
return -EEXIST;
|
|
||||||
|
|
||||||
/* find parent file */
|
/* find parent file */
|
||||||
_path_separate(file->vnode->path, parent_path, file_name);
|
_path_separate(file->vnode->path, parent_path, file_name);
|
||||||
if (file_name[0] == '\0') /* it's root dir */
|
if (file_name[0] == '\0') /* it's root dir */
|
||||||
@ -397,8 +396,7 @@ int dfs_tmpfs_open(struct dfs_fd *file)
|
|||||||
|
|
||||||
/* create a file entry */
|
/* create a file entry */
|
||||||
d_file = (struct tmpfs_file *)rt_calloc(1, sizeof(struct tmpfs_file));
|
d_file = (struct tmpfs_file *)rt_calloc(1, sizeof(struct tmpfs_file));
|
||||||
if (d_file == NULL)
|
if (d_file == NULL) {
|
||||||
{
|
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
}
|
}
|
||||||
superblock->df_size += sizeof(struct tmpfs_file);
|
superblock->df_size += sizeof(struct tmpfs_file);
|
||||||
@ -410,18 +408,17 @@ int dfs_tmpfs_open(struct dfs_fd *file)
|
|||||||
d_file->data = NULL;
|
d_file->data = NULL;
|
||||||
d_file->size = 0;
|
d_file->size = 0;
|
||||||
d_file->sb = superblock;
|
d_file->sb = superblock;
|
||||||
if (file->flags & O_DIRECTORY)
|
if (file->flags & O_DIRECTORY) {
|
||||||
{
|
|
||||||
d_file->type = TMPFS_TYPE_DIR;
|
d_file->type = TMPFS_TYPE_DIR;
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
d_file->type = TMPFS_TYPE_FILE;
|
d_file->type = TMPFS_TYPE_FILE;
|
||||||
}
|
}
|
||||||
rt_hw_spin_lock(&lock);
|
rt_hw_spin_lock(&lock);
|
||||||
rt_list_insert_after(&(p_file->subdirs), &(d_file->sibling));
|
rt_list_insert_after(&(p_file->subdirs), &(d_file->sibling));
|
||||||
rt_hw_spin_unlock(&lock);
|
rt_hw_spin_unlock(&lock);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
/* Creates a new file.
|
/* Creates a new file.
|
||||||
* If the file is existing, it is truncated and overwritten.
|
* If the file is existing, it is truncated and overwritten.
|
||||||
*/
|
*/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user