mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2026-08-18 02:58:57 +08:00
components/dfs: unify vnode lock names
This commit is contained in:
@@ -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
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -266,6 +266,7 @@ find_subpath:
|
||||
{
|
||||
if (rt_strcmp(file->name, filename) == 0)
|
||||
{
|
||||
/* cppcheck-suppress uninitvar */
|
||||
*size = file->size;
|
||||
|
||||
rt_spin_unlock(&superblock->lock);
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
*/
|
||||
|
||||
#include <dfs_file.h>
|
||||
#include <dfs_dentry.h>
|
||||
#include <dfs_mnt.h>
|
||||
#ifdef RT_USING_PAGECACHE
|
||||
#include "dfs_pcache.h"
|
||||
@@ -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));
|
||||
|
||||
return rt_mutex_init(&vnode->lock, lock_name, RT_IPC_FLAG_PRIO);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Destroy a virtual node (vnode) and free its resources
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user