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
The following commit(s) were added to refs/heads/master by this push:
new e3513e01eff fs/tmpfs: Give each file and directory a serial number.
e3513e01eff is described below
commit e3513e01effad01e905ec7c2ce84c515fef36967
Author: Marco Casaroli <[email protected]>
AuthorDate: Sat Oct 24 02:40:19 2026 +0200
fs/tmpfs: Give each file and directory a serial number.
tmpfs gave st_ino = 0 to every file and directory, and d_ino = 0 in
readdir(). POSIX says that st_dev and st_ino identify a file. du
counted only one file of a tmpfs, and tar and cp took all the files for
hard links of one file.
Give each new tmpfs object a serial number from a counter that all tmpfs
mounts share, and return it in st_ino and d_ino.
Assisted-by: Claude Code:claude-opus-5-5
Signed-off-by: Marco Casaroli <[email protected]>
---
fs/tmpfs/fs_tmpfs.c | 29 ++++++++++++++++++++++++++++-
fs/tmpfs/fs_tmpfs.h | 3 +++
2 files changed, 31 insertions(+), 1 deletion(-)
diff --git a/fs/tmpfs/fs_tmpfs.c b/fs/tmpfs/fs_tmpfs.c
index e9fcbcdad50..13285109575 100644
--- a/fs/tmpfs/fs_tmpfs.c
+++ b/fs/tmpfs/fs_tmpfs.c
@@ -35,6 +35,7 @@
#include <assert.h>
#include <nuttx/debug.h>
+#include <nuttx/atomic.h>
#include <nuttx/sched.h>
#include <nuttx/kmalloc.h>
#include <nuttx/fs/fs.h>
@@ -187,6 +188,14 @@ static int tmpfs_permission(FAR struct inode *mountpt,
FAR const char *relpath, int amode);
#endif
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+/* The last file serial number given, shared by all tmpfs mounts */
+
+static atomic_t g_tmpfs_ino;
+
/****************************************************************************
* Public Data
****************************************************************************/
@@ -814,6 +823,20 @@ static int tmpfs_chstat_object(FAR struct tmpfs_object_s
*to,
#endif /* CONFIG_FS_PERMISSION */
+/****************************************************************************
+ * Name: tmpfs_new_ino
+ *
+ * Description:
+ * Return a new file serial number. The numbers are unique in all tmpfs
+ * mounts.
+ *
+ ****************************************************************************/
+
+static ino_t tmpfs_new_ino(void)
+{
+ return (ino_t)atomic_add(&g_tmpfs_ino, 1) + 1;
+}
+
/****************************************************************************
* Name: tmpfs_alloc_file
****************************************************************************/
@@ -839,6 +862,7 @@ tmpfs_alloc_file(FAR struct tmpfs_directory_s *parent,
mode_t mode)
tfo->tfo_type = TMPFS_REGULAR;
tfo->tfo_refs = 1;
tfo->tfo_parent = parent;
+ tfo->tfo_ino = tmpfs_new_ino();
tfo->tfo_flags = 0;
tfo->tfo_size = 0;
tfo->tfo_data = NULL;
@@ -995,6 +1019,7 @@ tmpfs_alloc_directory(FAR struct tmpfs_directory_s
*parent, mode_t mode)
tdo->tdo_type = TMPFS_DIRECTORY;
tdo->tdo_refs = 0;
tdo->tdo_parent = parent;
+ tdo->tdo_ino = tmpfs_new_ino();
tdo->tdo_nentries = 0;
tdo->tdo_entry = NULL;
@@ -2490,8 +2515,9 @@ static int tmpfs_readdir(FAR struct inode *mountpt,
entry->d_type = DTYPE_FILE;
}
- /* Copy the entry name */
+ /* Copy the serial number and the entry name */
+ entry->d_ino = to->to_ino;
strlcpy(entry->d_name, tde->tde_name, sizeof(entry->d_name));
/* Save the index for next time */
@@ -3112,6 +3138,7 @@ static void tmpfs_stat_common(FAR struct tmpfs_object_s
*to,
/* Is the tmpfs object a regular file? */
memset(buf, 0, sizeof(struct stat));
+ buf->st_ino = to->to_ino;
if (to->to_type == TMPFS_REGULAR)
{
diff --git a/fs/tmpfs/fs_tmpfs.h b/fs/tmpfs/fs_tmpfs.h
index dce67da1cb6..4b6bc67a78f 100644
--- a/fs/tmpfs/fs_tmpfs.h
+++ b/fs/tmpfs/fs_tmpfs.h
@@ -84,6 +84,7 @@ struct tmpfs_object_s
uint8_t to_type; /* See enum tmpfs_objtype_e */
uint8_t to_refs; /* Reference count */
FAR struct tmpfs_directory_s *to_parent;
+ ino_t to_ino; /* File serial number (st_ino, d_ino) */
#ifdef CONFIG_FS_PERMISSION
mode_t to_mode; /* File mode (permission bits) */
uid_t to_uid; /* Owner user ID */
@@ -103,6 +104,7 @@ struct tmpfs_directory_s
uint8_t tdo_type; /* See enum tmpfs_objtype_e */
uint8_t tdo_refs; /* Reference count */
FAR struct tmpfs_directory_s *tdo_parent;
+ ino_t tdo_ino; /* File serial number (st_ino, d_ino) */
#ifdef CONFIG_FS_PERMISSION
mode_t tdo_mode; /* Directory mode (permission bits) */
uid_t tdo_uid; /* Owner user ID */
@@ -135,6 +137,7 @@ struct tmpfs_file_s
uint8_t tfo_type; /* See enum tmpfs_objtype_e */
uint8_t tfo_refs; /* Reference count */
FAR struct tmpfs_directory_s *tfo_parent;
+ ino_t tfo_ino; /* File serial number (st_ino, d_ino) */
#ifdef CONFIG_FS_PERMISSION
mode_t tfo_mode; /* File mode (permission bits) */
uid_t tfo_uid; /* Owner user ID */