You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by ar...@apache.org on 2022/09/20 08:21:11 UTC

[incubator-nuttx] branch master updated (079a6fa6cc -> 9afb6540dc)

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

archer pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git


    from 079a6fa6cc arch/armv7[a|r]: Implement up_affinity_irq
     new 8df223a1ef libc: Add LIBC prefix to MEM_FD_VFS_PATH
     new db518bf0df fs: Allocate unique serial number for the root pseduo file system node
     new 9afb6540dc libc/ftok: Map token to the root pseduo file system directory

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 fs/inode/fs_inodereserve.c |  7 +++++++
 fs/vfs/fs_stat.c           |  1 +
 include/nuttx/fs/fs.h      |  1 +
 libs/libc/misc/Kconfig     |  8 +++++++-
 libs/libc/misc/lib_ftok.c  | 14 ++++++++++++--
 libs/libc/misc/lib_memfd.c |  5 +++--
 6 files changed, 31 insertions(+), 5 deletions(-)


[incubator-nuttx] 02/03: fs: Allocate unique serial number for the root pseduo file system node

Posted by ar...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit db518bf0dfbaeae3d10d3c7656e4be39e6176ef9
Author: Xiang Xiao <xi...@xiaomi.com>
AuthorDate: Fri Sep 16 14:24:55 2022 +0800

    fs: Allocate unique serial number for the root pseduo file system node
    
    Signed-off-by: Xiang Xiao <xi...@xiaomi.com>
---
 fs/inode/fs_inodereserve.c | 7 +++++++
 fs/vfs/fs_stat.c           | 1 +
 include/nuttx/fs/fs.h      | 1 +
 3 files changed, 9 insertions(+)

diff --git a/fs/inode/fs_inodereserve.c b/fs/inode/fs_inodereserve.c
index ffbf509fde..aca557913c 100644
--- a/fs/inode/fs_inodereserve.c
+++ b/fs/inode/fs_inodereserve.c
@@ -32,6 +32,12 @@
 
 #include "inode/inode.h"
 
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static ino_t g_ino;
+
 /****************************************************************************
  * Private Functions
  ****************************************************************************/
@@ -78,6 +84,7 @@ static FAR struct inode *inode_alloc(FAR const char *name, mode_t mode)
   node    = (FAR struct inode *)kmm_zalloc(FSNODE_SIZE(namelen));
   if (node)
     {
+      node->i_ino   = g_ino++;
 #ifdef CONFIG_PSEUDOFS_ATTRIBUTES
       node->i_mode  = mode;
       clock_gettime(CLOCK_REALTIME, &node->i_atime);
diff --git a/fs/vfs/fs_stat.c b/fs/vfs/fs_stat.c
index e4048f8933..06b9afff06 100644
--- a/fs/vfs/fs_stat.c
+++ b/fs/vfs/fs_stat.c
@@ -438,6 +438,7 @@ int inode_stat(FAR struct inode *inode, FAR struct stat *buf, int resolve)
   buf->st_mtim  = inode->i_mtime;
   buf->st_ctim  = inode->i_ctime;
 #endif
+  buf->st_ino   = inode->i_ino;
 
   return OK;
 }
diff --git a/include/nuttx/fs/fs.h b/include/nuttx/fs/fs.h
index 92ffdc432e..05cd0c7fe1 100644
--- a/include/nuttx/fs/fs.h
+++ b/include/nuttx/fs/fs.h
@@ -393,6 +393,7 @@ struct inode
   int16_t           i_crefs;    /* References to inode */
   uint16_t          i_flags;    /* Flags for inode */
   union inode_ops_u u;          /* Inode operations */
+  ino_t             i_ino;      /* Inode serial number */
 #ifdef CONFIG_PSEUDOFS_ATTRIBUTES
   mode_t            i_mode;     /* Access mode flags */
   uid_t             i_owner;    /* Owner */


[incubator-nuttx] 01/03: libc: Add LIBC prefix to MEM_FD_VFS_PATH

Posted by ar...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 8df223a1efe588e282efc825a2fa8e8b0e1bae08
Author: Xiang Xiao <xi...@xiaomi.com>
AuthorDate: Fri Sep 16 14:33:09 2022 +0800

    libc: Add LIBC prefix to MEM_FD_VFS_PATH
    
    Signed-off-by: Xiang Xiao <xi...@xiaomi.com>
---
 libs/libc/misc/Kconfig     | 2 +-
 libs/libc/misc/lib_memfd.c | 5 +++--
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/libs/libc/misc/Kconfig b/libs/libc/misc/Kconfig
index 99b13f75fd..4a7635e533 100644
--- a/libs/libc/misc/Kconfig
+++ b/libs/libc/misc/Kconfig
@@ -62,7 +62,7 @@ config LIBC_ENVPATH
 		Use the contents of the common environment variable to locate executable
 		or library files.  Default: n
 
-config MEM_FD_VFS_PATH
+config LIBC_MEM_FD_VFS_PATH
 	string "Relative path to memfd storage"
 	default "memfd"
 	depends on FS_TMPFS
diff --git a/libs/libc/misc/lib_memfd.c b/libs/libc/misc/lib_memfd.c
index 1f05fe5ea8..8675d33e43 100644
--- a/libs/libc/misc/lib_memfd.c
+++ b/libs/libc/misc/lib_memfd.c
@@ -31,7 +31,8 @@
  * Pre-processor Definitions
  ****************************************************************************/
 
-#define MEM_FD_VFS_PATH CONFIG_LIBC_TMPDIR "/" CONFIG_MEM_FD_VFS_PATH "/%s"
+#define LIBC_MEM_FD_VFS_PATH \
+          CONFIG_LIBC_TMPDIR "/" CONFIG_LIBC_MEM_FD_VFS_PATH "/%s"
 
 /****************************************************************************
  * Public Functions
@@ -42,7 +43,7 @@ int memfd_create(FAR const char *name, unsigned int flags)
 #ifdef CONFIG_FS_TMPFS
   char path[PATH_MAX];
 
-  snprintf(path, sizeof(path), MEM_FD_VFS_PATH, name);
+  snprintf(path, sizeof(path), LIBC_MEM_FD_VFS_PATH, name);
   return open(path, O_RDWR | flags);
 #else
   set_errno(ENOSYS);


[incubator-nuttx] 03/03: libc/ftok: Map token to the root pseduo file system directory

Posted by ar...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 9afb6540dca26cd4c734cff91e72c59a7721cf2a
Author: Xiang Xiao <xi...@xiaomi.com>
AuthorDate: Fri Sep 16 14:53:46 2022 +0800

    libc/ftok: Map token to the root pseduo file system directory
    
    to ensure the generated key is unique from each other since only
    root pseduo file system really support st_ino field after:
    commit d35fbf534d51f7ef72382d9666a1f19e07c6f00f
    Author: Xiang Xiao <xi...@xiaomi.com>
    Date:   Fri Sep 16 14:24:55 2022 +0800
    
        fs: Allocate unique serial number for the root pseduo file system node
    
    Signed-off-by: Xiang Xiao <xi...@xiaomi.com>
---
 libs/libc/misc/Kconfig    |  6 ++++++
 libs/libc/misc/lib_ftok.c | 14 ++++++++++++--
 2 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/libs/libc/misc/Kconfig b/libs/libc/misc/Kconfig
index 4a7635e533..fc7de51b7d 100644
--- a/libs/libc/misc/Kconfig
+++ b/libs/libc/misc/Kconfig
@@ -62,6 +62,12 @@ config LIBC_ENVPATH
 		Use the contents of the common environment variable to locate executable
 		or library files.  Default: n
 
+config LIBC_FTOK_VFS_PATH
+	string "Relative path to ftok storage"
+	default "/var/ftok"
+	---help---
+		The relative path to where ftok will exist in the root namespace.
+
 config LIBC_MEM_FD_VFS_PATH
 	string "Relative path to memfd storage"
 	default "memfd"
diff --git a/libs/libc/misc/lib_ftok.c b/libs/libc/misc/lib_ftok.c
index 6d38ed62b1..faaddc2c34 100644
--- a/libs/libc/misc/lib_ftok.c
+++ b/libs/libc/misc/lib_ftok.c
@@ -27,6 +27,8 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <sys/ipc.h>
+#include <errno.h>
+#include <string.h>
 
 /****************************************************************************
  * Public Functions
@@ -56,11 +58,19 @@
 
 key_t ftok(FAR const char *pathname, int proj_id)
 {
+  char fullpath[PATH_MAX] = CONFIG_LIBC_FTOK_VFS_PATH "/";
   struct stat st;
 
-  if (stat(pathname, &st) < 0)
+  strlcat(fullpath, pathname, sizeof(fullpath));
+  if (stat(fullpath, &st) < 0 && get_errno() == ENOENT)
     {
-      return (key_t)-1;
+      /* Directory not exist, let's create one for caller */
+
+      mkdir(fullpath, S_IRWXU);
+      if (stat(fullpath, &st) < 0)
+        {
+          return (key_t)-1;
+        }
     }
 
   return ((key_t)proj_id << 24 |