From b9527543a5121afb535feae2de2d514be590a363 Mon Sep 17 00:00:00 2001 From: bernard Date: Fri, 31 Jul 2026 08:42:50 +0800 Subject: [PATCH 1/2] components/dfs: unify vnode lock names Using full paths as mutex object names triggers RT_NAME_MAX warnings for long file names. Add dfs_vnode_lock_init to generate short vn-xxxx names from the full-path CRC32, and migrate tmpfs and elmfat to the common helper. Impact: DFS v2 vnode mutex object names only.\nVerified by the qemu-virt64-aarch64 cross-build and QEMU /bin/ls test. --- .../dfs/dfs_v2/filesystems/elmfat/dfs_elm.c | 4 +-- .../dfs/dfs_v2/filesystems/tmpfs/dfs_tmpfs.c | 2 +- components/dfs/dfs_v2/include/dfs_file.h | 1 + components/dfs/dfs_v2/src/dfs_vnode.c | 26 +++++++++++++++++++ 4 files changed, 30 insertions(+), 3 deletions(-) diff --git a/components/dfs/dfs_v2/filesystems/elmfat/dfs_elm.c b/components/dfs/dfs_v2/filesystems/elmfat/dfs_elm.c index 52d3cafdac1..eab787cde41 100644 --- a/components/dfs/dfs_v2/filesystems/elmfat/dfs_elm.c +++ b/components/dfs/dfs_v2/filesystems/elmfat/dfs_elm.c @@ -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) { diff --git a/components/dfs/dfs_v2/filesystems/tmpfs/dfs_tmpfs.c b/components/dfs/dfs_v2/filesystems/tmpfs/dfs_tmpfs.c index 996c01df782..422e15e534e 100644 --- a/components/dfs/dfs_v2/filesystems/tmpfs/dfs_tmpfs.c +++ b/components/dfs/dfs_v2/filesystems/tmpfs/dfs_tmpfs.c @@ -455,7 +455,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; diff --git a/components/dfs/dfs_v2/include/dfs_file.h b/components/dfs/dfs_v2/include/dfs_file.h index 5010ed45346..0e609e9eef4 100644 --- a/components/dfs/dfs_v2/include/dfs_file.h +++ b/components/dfs/dfs_v2/include/dfs_file.h @@ -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); diff --git a/components/dfs/dfs_v2/src/dfs_vnode.c b/components/dfs/dfs_v2/src/dfs_vnode.c index d46885e0b31..75bca31e7ee 100644 --- a/components/dfs/dfs_v2/src/dfs_vnode.c +++ b/components/dfs/dfs_v2/src/dfs_vnode.c @@ -9,6 +9,7 @@ */ #include +#include #include #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 * From d9d45fdd495d5554a22686a37dcc61b71574064a Mon Sep 17 00:00:00 2001 From: bernard Date: Fri, 31 Jul 2026 09:45:02 +0800 Subject: [PATCH 2/2] components/dfs: fix static analysis checks Align the vnode lock name formatting with the repository style. Suppress two cppcheck uninitvar false positives caused by the tmpfs intrusive-list iterator. The affected fields are initialized when each tmpfs node is created. Validation: - clang-format 22.1.8 on all PR changed lines - cppcheck 2.21.0 on all changed C files - git diff --check --- components/dfs/dfs_v2/filesystems/tmpfs/dfs_tmpfs.c | 2 ++ components/dfs/dfs_v2/src/dfs_vnode.c | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/components/dfs/dfs_v2/filesystems/tmpfs/dfs_tmpfs.c b/components/dfs/dfs_v2/filesystems/tmpfs/dfs_tmpfs.c index 422e15e534e..011e6e14c24 100644 --- a/components/dfs/dfs_v2/filesystems/tmpfs/dfs_tmpfs.c +++ b/components/dfs/dfs_v2/filesystems/tmpfs/dfs_tmpfs.c @@ -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); @@ -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; diff --git a/components/dfs/dfs_v2/src/dfs_vnode.c b/components/dfs/dfs_v2/src/dfs_vnode.c index 75bca31e7ee..462f94e05e6 100644 --- a/components/dfs/dfs_v2/src/dfs_vnode.c +++ b/components/dfs/dfs_v2/src/dfs_vnode.c @@ -84,7 +84,7 @@ rt_err_t dfs_vnode_lock_init(struct dfs_vnode *vnode, struct dfs_dentry *dentry) path_hash = dfs_dentry_full_path_crc32(dentry); rt_snprintf(lock_name, sizeof(lock_name), "vn-%04x", - (unsigned int)(path_hash & 0xffffU)); + (unsigned int)(path_hash & 0xffffU)); return rt_mutex_init(&vnode->lock, lock_name, RT_IPC_FLAG_PRIO); }