This is an automated email from the ASF dual-hosted git repository. xiaoxiang781216 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit 19e76b7935f5da0066190755d551c984ed046efb Author: zhengyu16 <[email protected]> AuthorDate: Wed Nov 11 15:31:17 2026 +0800 fs/romfs: hold the mount while a directory is open romfs_opendir() does not count the open directory in rm_refs, so romfs_unbind() lets the volume be unmounted while a directory handle is still open. With CONFIG_FS_ROMFS_CACHE_NODE the handle keeps pointing into the cached node tree, which unbind frees. Take a reference in romfs_opendir() and drop it in romfs_closedir(). Signed-off-by: zhengyu16 <[email protected]> Signed-off-by: jingfei <[email protected]> --- fs/romfs/fs_romfs.c | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/fs/romfs/fs_romfs.c b/fs/romfs/fs_romfs.c index 07eeee39137..fa162a77770 100644 --- a/fs/romfs/fs_romfs.c +++ b/fs/romfs/fs_romfs.c @@ -874,6 +874,10 @@ static int romfs_opendir(FAR struct inode *mountpt, FAR const char *relpath, rdir->curroffset = nodeinfo.rn_offset; #endif + /* An open directory keeps the mount busy (see romfs_unbind()) */ + + rm->rm_refs++; + *dir = &rdir->base; nxrmutex_unlock(&rm->rm_lock); return 0; @@ -897,9 +901,30 @@ errout_with_rdir: static int romfs_closedir(FAR struct inode *mountpt, FAR struct fs_dirent_s *dir) { - DEBUGASSERT(dir); + FAR struct romfs_mountpt_s *rm; + int ret; + + DEBUGASSERT(mountpt != NULL && dir != NULL); + + /* Recover our private data from the inode instance */ + + rm = mountpt->i_private; + DEBUGASSERT(rm != NULL); + + ret = nxrmutex_lock(&rm->rm_lock); + if (ret < 0) + { + goto errout_with_dir; + } + + /* Give back the reference taken by romfs_opendir() */ + + rm->rm_refs--; + nxrmutex_unlock(&rm->rm_lock); + +errout_with_dir: fs_heap_free(dir); - return 0; + return ret; } /****************************************************************************
