Skip to content
Merged
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
4 changes: 2 additions & 2 deletions components/dfs/dfs_v2/filesystems/elmfat/dfs_elm.c
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ int dfs_elm_open(struct dfs_file *file)
}

file->vnode->data = dir;
rt_mutex_init(&file->vnode->lock, file->dentry->pathname, RT_IPC_FLAG_PRIO);
dfs_vnode_lock_init(file->vnode, file->dentry);
return RT_EOK;
}
else
Expand Down Expand Up @@ -488,7 +488,7 @@ int dfs_elm_open(struct dfs_file *file)
file->vnode->size = f_size(fd);
file->vnode->type = FT_REGULAR;
file->vnode->data = fd;
rt_mutex_init(&file->vnode->lock, file->dentry->pathname, RT_IPC_FLAG_PRIO);
dfs_vnode_lock_init(file->vnode, file->dentry);

if (file->flags & O_APPEND)
{
Expand Down
4 changes: 3 additions & 1 deletion components/dfs/dfs_v2/filesystems/tmpfs/dfs_tmpfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ struct tmpfs_file *dfs_tmpfs_lookup(struct tmpfs_sb *superblock,
{
if (rt_strcmp(file->name, filename) == 0)
{
/* cppcheck-suppress uninitvar */
*size = file->size;

rt_spin_unlock(&superblock->lock);
Expand Down Expand Up @@ -455,7 +456,7 @@ static int dfs_tmpfs_open(struct dfs_file *file)
RT_ASSERT(file->vnode->ref_count > 0);
if(file->vnode->ref_count == 1)
{
rt_mutex_init(&file->vnode->lock, file->dentry->pathname, RT_IPC_FLAG_PRIO);
dfs_vnode_lock_init(file->vnode, file->dentry);
}

return 0;
Expand Down Expand Up @@ -525,6 +526,7 @@ static int dfs_tmpfs_getdents(struct dfs_file *file,
if (index >= (rt_size_t)file->fpos)
{
d = dirp + count;
/* cppcheck-suppress uninitvar */
if (n_file->type == TMPFS_TYPE_FILE)
{
d->d_type = DT_REG;
Expand Down
1 change: 1 addition & 0 deletions components/dfs/dfs_v2/include/dfs_file.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ struct dfs_file
int dfs_vnode_init(struct dfs_vnode *vnode, int type, const struct dfs_file_ops *fops);
struct dfs_vnode *dfs_vnode_create(void);
int dfs_vnode_destroy(struct dfs_vnode* vnode);
rt_err_t dfs_vnode_lock_init(struct dfs_vnode *vnode, struct dfs_dentry *dentry);

struct dfs_vnode *dfs_vnode_ref(struct dfs_vnode *vnode);
void dfs_vnode_unref(struct dfs_vnode *vnode);
Expand Down
26 changes: 26 additions & 0 deletions components/dfs/dfs_v2/src/dfs_vnode.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
*/

#include <dfs_file.h>
#include <dfs_dentry.h>
#include <dfs_mnt.h>
#ifdef RT_USING_PAGECACHE
#include "dfs_pcache.h"
Expand Down Expand Up @@ -63,6 +64,31 @@ struct dfs_vnode *dfs_vnode_create(void)
return vnode;
}

/**
* @brief Initialize the lock of a virtual node (vnode)
*
* @param[in,out] vnode Pointer to the vnode containing the lock
* @param[in] dentry Pointer to the dentry used to identify the vnode
*
* @return RT_EOK on success, or -RT_EINVAL if a parameter is invalid
*/
rt_err_t dfs_vnode_lock_init(struct dfs_vnode *vnode, struct dfs_dentry *dentry)
{
char lock_name[RT_NAME_MAX];
uint32_t path_hash;

if (vnode == RT_NULL || dentry == RT_NULL)
{
return -RT_EINVAL;
}

path_hash = dfs_dentry_full_path_crc32(dentry);
rt_snprintf(lock_name, sizeof(lock_name), "vn-%04x",
(unsigned int)(path_hash & 0xffffU));

Comment on lines +85 to +88
return rt_mutex_init(&vnode->lock, lock_name, RT_IPC_FLAG_PRIO);
}

/**
* @brief Destroy a virtual node (vnode) and free its resources
*
Expand Down
Loading