This is an automated email from the ASF dual-hosted git repository.

michallenc pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit 4456f7753eb6a4bcd490288e69bf098f3a217db8
Author: Marco Casaroli <[email protected]>
AuthorDate: Fri Nov 27 14:47:26 2026 +0100

    fs/tmpfs: Count the references of an object in 32 bits.
    
    The reference count of a tmpfs object was 8 bits.  Each open file, each
    dup() and each open directory takes one reference, so 256 of them on one
    file made the count zero again.  unlink() then removed the file at once,
    while the open files still used it.  In the same way, rmdir() removed a
    directory that was open 256 times, where it must fail with EBUSY.  Two
    processes that each open a file 128 times are enough.
    
    Use 32 bits for the count, as for the other counts of open files.
    tmpfs_mmap() refused a mapping at 255 references to keep the 8-bit
    tfo_maps in range; test tfo_maps itself now.
    
    Assisted-by: Claude Code:claude-opus-5-5
    Signed-off-by: Marco Casaroli <[email protected]>
---
 fs/tmpfs/fs_tmpfs.c | 4 ++--
 fs/tmpfs/fs_tmpfs.h | 6 +++---
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/fs/tmpfs/fs_tmpfs.c b/fs/tmpfs/fs_tmpfs.c
index a38f5916590..2051eba2f1b 100644
--- a/fs/tmpfs/fs_tmpfs.c
+++ b/fs/tmpfs/fs_tmpfs.c
@@ -2377,9 +2377,9 @@ static int tmpfs_mmap(FAR struct file *filep, FAR struct 
mm_map_entry_s *map)
       goto errout_with_lock;
     }
 
-  /* Each mapping also holds a reference, so tfo_maps <= tfo_refs */
+  /* Keep the 8-bit tfo_maps in range */
 
-  if (tfo->tfo_refs == UINT8_MAX)
+  if (tfo->tfo_maps == UINT8_MAX)
     {
       ret = -ENOMEM;
       goto errout_with_lock;
diff --git a/fs/tmpfs/fs_tmpfs.h b/fs/tmpfs/fs_tmpfs.h
index 610dbdba402..69b8f960ea3 100644
--- a/fs/tmpfs/fs_tmpfs.h
+++ b/fs/tmpfs/fs_tmpfs.h
@@ -82,7 +82,7 @@ struct tmpfs_object_s
 
   size_t   to_alloc;     /* Allocated size of the memory object */
   uint8_t  to_type;      /* See enum tmpfs_objtype_e */
-  uint8_t  to_refs;      /* Reference count */
+  uint32_t to_refs;      /* Reference count */
   FAR struct tmpfs_directory_s *to_parent;
   ino_t    to_ino;       /* File serial number (st_ino, d_ino) */
 
@@ -108,7 +108,7 @@ struct tmpfs_directory_s
 
   size_t   tdo_alloc;    /* Allocated size of the directory object */
   uint8_t  tdo_type;     /* See enum tmpfs_objtype_e */
-  uint8_t  tdo_refs;     /* Reference count */
+  uint32_t tdo_refs;     /* Reference count */
   FAR struct tmpfs_directory_s *tdo_parent;
   ino_t    tdo_ino;      /* File serial number (st_ino, d_ino) */
 
@@ -147,7 +147,7 @@ struct tmpfs_file_s
 
   size_t   tfo_alloc;    /* Allocated size of the file object */
   uint8_t  tfo_type;     /* See enum tmpfs_objtype_e */
-  uint8_t  tfo_refs;     /* Reference count */
+  uint32_t tfo_refs;     /* Reference count */
   FAR struct tmpfs_directory_s *tfo_parent;
   ino_t    tfo_ino;      /* File serial number (st_ino, d_ino) */
 

Reply via email to