You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by GitBox <gi...@apache.org> on 2022/08/07 14:20:22 UTC

[GitHub] [incubator-nuttx] Donny9 opened a new pull request, #6803: fs/directory: Using file api to implement operations on directories

Donny9 opened a new pull request, #6803:
URL: https://github.com/apache/incubator-nuttx/pull/6803

   ## Summary
   1. Using file api to implement operations on directories.
   ```
   opendir -> open with O_DIRECOTRY
   closedir -> close
   rewindir-> lseek
   readdir -> read
   seekdir -> lseek
   telldir -> lseek
   ```
   2. Using user memory to obtain directory entries and avoid using kernel space buffers. Therefore, add the entry member in DIR and avoid using the fd_dir member in `fs_dirent_s`.
   3. Removing the private information of all file systems in `fs_dirent_s` and use opendir to create them. 
   4. In order to better realize the “*at” system calls api, such as openat, https://linux.die.net/man/2/openat etc.
   
   ## Impact
   Change opendir and readdir prototypes:
   ```
   int     (*opendir)(FAR struct inode *mountpt, FAR const char *relpath,FAR struct fs_dirent_s **dir);
   int     (*readdir)(FAR struct inode *mountpt, FAR struct fs_dirent_s *dir, FAR struct dirent *entry);
   ```
   ## Testing
   Local test
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-nuttx] Donny9 commented on a diff in pull request #6803: fs/directory: Using file api to implement operations on directories

Posted by GitBox <gi...@apache.org>.
Donny9 commented on code in PR #6803:
URL: https://github.com/apache/incubator-nuttx/pull/6803#discussion_r940860920


##########
libs/libc/dirent/lib_telldir.c:
##########
@@ -61,15 +56,11 @@
 
 off_t telldir(FAR DIR *dirp)
 {
-  struct fs_dirent_s *idir = (struct fs_dirent_s *)dirp;
-
-  if (!idir || !idir->fd_root)
+  if (dirp)

Review Comment:
   Done!



##########
libs/libc/dirent/lib_seekdir.c:
##########
@@ -0,0 +1,65 @@
+/****************************************************************************
+ * libs/libc/dirent/lib_seekdir.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <dirent.h>
+#include <errno.h>
+#include <unistd.h>
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: seekdir
+ *
+ * Description:
+ *   The seekdir() function sets the location in the directory stream from
+ *   which the next readdir() call will start.  seekdir() should be used with
+ *   an offset returned by telldir().
+ *
+ * Input Parameters:
+ *   dirp -- An instance of type DIR created by a previous
+ *     call to opendir();
+ *   offset -- offset to seek to
+ *
+ * Returned Value:
+ *   None
+ *
+ ****************************************************************************/
+
+void seekdir(FAR DIR *dirp, off_t offset)
+{
+  if (dirp)

Review Comment:
   Done!



##########
libs/libc/dirent/lib_rewinddir.c:
##########
@@ -0,0 +1,63 @@
+/****************************************************************************
+ * libs/libc/dirent/lib_rewinddir.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <dirent.h>
+#include <errno.h>
+#include <unistd.h>
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: rewinddir
+ *
+ * Description:
+ *   The  rewinddir() function resets the position of the
+ *   directory stream dir to the beginning of the directory.
+ *
+ * Input Parameters:
+ *   dirp -- An instance of type DIR created by a previous
+ *     call to opendir();
+ *
+ * Returned Value:
+ *   None
+ *
+ ****************************************************************************/
+
+void rewinddir(FAR DIR *dirp)
+{
+  if (dirp)

Review Comment:
   Done!



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-nuttx] xiaoxiang781216 commented on pull request #6803: fs/directory: Using file api to implement operations on directories

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on PR #6803:
URL: https://github.com/apache/incubator-nuttx/pull/6803#issuecomment-1207422272

   @yamt this is the first patchset to support openat.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-nuttx] Donny9 commented on a diff in pull request #6803: fs/directory: Using file api to implement operations on directories

Posted by GitBox <gi...@apache.org>.
Donny9 commented on code in PR #6803:
URL: https://github.com/apache/incubator-nuttx/pull/6803#discussion_r940861801


##########
fs/fat/fs_fat32.h:
##########
@@ -1054,8 +1067,9 @@ EXTERN int    fat_allocatedirentry(struct fat_mountpt_s *fs,
                                    struct fat_dirinfo_s *dirinfo);
 EXTERN int    fat_freedirentry(struct fat_mountpt_s *fs,
                                struct fat_dirseq_s *seq);

Review Comment:
   keep original?



##########
fs/fat/fs_fat32.h:
##########
@@ -1054,8 +1067,9 @@ EXTERN int    fat_allocatedirentry(struct fat_mountpt_s *fs,
                                    struct fat_dirinfo_s *dirinfo);

Review Comment:
   keep original?



##########
fs/cromfs/fs_cromfs.c:
##########
@@ -1356,9 +1392,12 @@ static int cromfs_readdir(struct inode *mountpt, struct fs_dirent_s *dir)
 
 static int cromfs_rewinddir(struct inode *mountpt, struct fs_dirent_s *dir)

Review Comment:
   Done



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-nuttx] Donny9 commented on a diff in pull request #6803: fs/directory: Using file api to implement operations on directories

Posted by GitBox <gi...@apache.org>.
Donny9 commented on code in PR #6803:
URL: https://github.com/apache/incubator-nuttx/pull/6803#discussion_r940861954


##########
fs/binfs/fs_binfs.c:
##########
@@ -63,9 +72,12 @@ static int     binfs_fstat(FAR const struct file *filep,
                            FAR struct stat *buf);
 
 static int     binfs_opendir(struct inode *mountpt, const char *relpath,
-                             struct fs_dirent_s *dir);
+                             struct fs_dirent_s **dir);

Review Comment:
   Done



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-nuttx] Donny9 commented on a diff in pull request #6803: fs/directory: Using file api to implement operations on directories

Posted by GitBox <gi...@apache.org>.
Donny9 commented on code in PR #6803:
URL: https://github.com/apache/incubator-nuttx/pull/6803#discussion_r941260316


##########
fs/vfs/fs_dir.c:
##########
@@ -0,0 +1,607 @@
+/****************************************************************************
+ * fs/vfs/fs_dir.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <string.h>
+#include <errno.h>
+
+#include <nuttx/kmalloc.h>
+#include <nuttx/fs/fs.h>
+#include <nuttx/fs/ioctl.h>
+
+#include "inode/inode.h"
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+/* For the root pseudo-file system, we need retain only the 'next' inode
+ * need for the next readdir() operation. We hold a reference on this
+ * inode so we know that it will persist until closedir is called.
+ */
+
+struct fs_pseudodir_s
+{
+  struct fs_dirent_s dir;
+  FAR struct inode *next;
+};
+
+/****************************************************************************
+ * Private Functions Prototypes
+ ****************************************************************************/
+
+static int     dir_open(FAR struct file *filep);
+static int     dir_close(FAR struct file *filep);
+static ssize_t dir_read(FAR struct file *filep, FAR char *buffer,
+                        size_t buflen);
+static off_t   dir_seek(FAR struct file *filep, off_t offset, int whence);
+static int     dir_ioctl(FAR struct file *filep, int cmd, unsigned long arg);
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static const struct file_operations g_dir_fileops =
+{
+  dir_open,   /* open */
+  dir_close,  /* close */
+  dir_read,   /* read */
+  NULL,       /* write */
+  dir_seek,   /* seek */
+  dir_ioctl,  /* ioctl */
+  NULL,       /* poll */
+#ifndef CONFIG_DISABLE_PSEUDOFS_OPERATIONS
+  NULL,       /* unlink */
+#endif
+};
+
+static struct inode g_dir_inode =
+{
+  .i_crefs = 1,
+  .u =
+    {
+      .i_ops = &g_dir_fileops,
+    },

Review Comment:
   Done!



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-nuttx] xiaoxiang781216 commented on a diff in pull request #6803: fs/directory: Using file api to implement operations on directories

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on code in PR #6803:
URL: https://github.com/apache/incubator-nuttx/pull/6803#discussion_r939679035


##########
arch/arm/src/cxd56xx/cxd56_powermgr_procfs.c:
##########
@@ -781,7 +783,7 @@ static int cxd56_powermgr_procfs_readdir(struct fs_dirent_s *dir)
  *
  ****************************************************************************/
 
-static int cxd56_powermgr_procfs_rewinddir(struct fs_dirent_s *dir)
+static int cxd56_powermgr_procfs_rewinddir(FAR struct fs_dirent_s *dir)

Review Comment:
   remove FAR



##########
arch/arm/src/cxd56xx/cxd56_powermgr_procfs.c:
##########
@@ -749,7 +750,8 @@ static int cxd56_powermgr_procfs_closedir(struct fs_dirent_s *dir)
  *
  ****************************************************************************/
 
-static int cxd56_powermgr_procfs_readdir(struct fs_dirent_s *dir)
+static int cxd56_powermgr_procfs_readdir(FAR struct fs_dirent_s *dir,
+                                         FAR struct dirent *entry)

Review Comment:
   remove FAR from both



##########
arch/arm/src/cxd56xx/cxd56_powermgr_procfs.c:
##########
@@ -711,7 +710,7 @@ static int cxd56_powermgr_procfs_opendir(const char *relpath,
     }
 
   procfs->index = 0;
-  dir->u.procfs = (void *)procfs;
+  *dir = (FAR struct fs_dirent_s *)procfs;

Review Comment:
   remove FAR



##########
arch/arm/src/cxd56xx/cxd56_powermgr_procfs.c:
##########
@@ -787,9 +777,9 @@ static int cxd56_powermgr_procfs_rewinddir(FAR struct fs_dirent_s *dir)
 {
   struct cxd56_powermgr_procfs_dir_s *procfs;
 
-  DEBUGASSERT(dir && dir->u.procfs);
+  DEBUGASSERT(dir);
 
-  procfs = (struct cxd56_powermgr_procfs_dir_s *)dir->u.procfs;
+  procfs = (FAR struct cxd56_powermgr_procfs_dir_s *)dir;

Review Comment:
   ditto



##########
arch/arm/src/cxd56xx/cxd56_powermgr_procfs.c:
##########
@@ -755,9 +745,9 @@ static int cxd56_powermgr_procfs_readdir(FAR struct fs_dirent_s *dir,
 {
   struct cxd56_powermgr_procfs_dir_s *procfs;
 
-  DEBUGASSERT(dir && dir->u.procfs);
+  DEBUGASSERT(dir);
 
-  procfs = (struct cxd56_powermgr_procfs_dir_s *)dir->u.procfs;
+  procfs = (FAR struct cxd56_powermgr_procfs_dir_s *)dir;

Review Comment:
   remove FAR



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-nuttx] Donny9 commented on a diff in pull request #6803: fs/directory: Using file api to implement operations on directories

Posted by GitBox <gi...@apache.org>.
Donny9 commented on code in PR #6803:
URL: https://github.com/apache/incubator-nuttx/pull/6803#discussion_r940863797


##########
fs/vfs/fs_dir.c:
##########
@@ -0,0 +1,607 @@
+/****************************************************************************
+ * fs/vfs/fs_dir.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <string.h>
+#include <errno.h>
+
+#include <nuttx/kmalloc.h>
+#include <nuttx/fs/fs.h>
+#include <nuttx/fs/ioctl.h>
+
+#include "inode/inode.h"
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+/* For the root pseudo-file system, we need retain only the 'next' inode
+ * need for the next readdir() operation. We hold a reference on this
+ * inode so we know that it will persist until closedir is called.
+ */
+
+struct fs_pseudodir_s
+{
+  struct fs_dirent_s dir;
+  FAR struct inode *next;
+};
+
+/****************************************************************************
+ * Private Functions Prototypes
+ ****************************************************************************/
+
+static int     dir_open(FAR struct file *filep);
+static int     dir_close(FAR struct file *filep);
+static ssize_t dir_read(FAR struct file *filep, FAR char *buffer,
+                        size_t buflen);
+static off_t   dir_seek(FAR struct file *filep, off_t offset, int whence);
+static int     dir_ioctl(FAR struct file *filep, int cmd, unsigned long arg);
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static const struct file_operations g_dir_fileops =
+{
+  dir_open,   /* open */
+  dir_close,  /* close */
+  dir_read,   /* read */
+  NULL,       /* write */
+  dir_seek,   /* seek */
+  dir_ioctl,  /* ioctl */
+  NULL,       /* poll */
+#ifndef CONFIG_DISABLE_PSEUDOFS_OPERATIONS
+  NULL,       /* unlink */
+#endif
+};
+
+static struct inode g_dir_inode =
+{
+  .i_crefs = 1,
+  .u =
+    {
+      .i_ops = &g_dir_fileops,
+    },

Review Comment:
   what should i do?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-nuttx] btashton commented on pull request #6803: fs/directory: Using file api to implement operations on directories

Posted by GitBox <gi...@apache.org>.
btashton commented on PR #6803:
URL: https://github.com/apache/incubator-nuttx/pull/6803#issuecomment-1221231292

   FYI a report from @lupyuen that this change may have broken some out of tree configs
   
   https://twitter.com/MisterTechBlog/status/1560839031990104064
   
   @lupyuen can you give some more context. 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-nuttx] Donny9 commented on pull request #6803: fs/directory: Using file api to implement operations on directories

Posted by GitBox <gi...@apache.org>.
Donny9 commented on PR #6803:
URL: https://github.com/apache/incubator-nuttx/pull/6803#issuecomment-1208882933

   > @Donny9, @xiaoxiang781216 - What was the motivation for this change?
   > 
   > For a change of this size nature all the file system will need to tested and result posted as well. the statistics on the impact on memory ram/flash.
   
   @davids5 
   Tree situation: nodir, dir, dir_with_fchdir_dirfd
   ```
   djz:nuttx$ ls -l vela_cp.bin 
   -rwxrwxr-x 1 djz djz 2066272 8月   9 10:36 vela_cp.bin
   
   djz:nuttx$ ls -l vela_cp_dir.bin 
   -rwxrwxr-x 1 djz djz 2066260 8月   9 10:56 vela_cp_dir.bin
   
   djz:nuttx$ ls -l vela_cp_dir_with_fchdir_dirfd.bin 
   -rwxrwxr-x 1 djz djz 2066428 8月   9 11:10 vela_cp_dir_with_fchdir_dirfd.bin
   
   no_dir:
   cp> free
                      total       used       free    largest  nused  nfree
           Umem:     519096     210392     308704     304384    672      8
   dir:
   cp> free
                      total       used       free    largest  nused  nfree
           Umem:     519032     210392     308640     304864    672     10
   dir_with_fchdir_dirfd:
   cp> free
                      total       used       free    largest  nused  nfree
           Umem:     519096     210392     308704     304928    672      8
           
   filesystem usage:
   no_dir:
   cp> df -h
     Filesystem    Size      Used  Available Mounted on
     rpmsgfs      2298M      121M      2177M /data
     romfs         512B      512B         0B /etc
     littlefs      256K        8K       248K /misc
     procfs          0B        0B         0B /proc
     tmpfs         512B      512B         0B /tmp
     rpmsgfs      1718K     1718K         0B /vendor
   
   dir:
   cp> df -h
     Filesystem    Size      Used  Available Mounted on
     rpmsgfs      2298M      121M      2177M /data
     romfs         512B      512B         0B /etc
     littlefs      256K        8K       248K /misc
     procfs          0B        0B         0B /proc
     tmpfs         512B      512B         0B /tmp
     rpmsgfs      1718K     1718K         0B /vendor
   
   dir_with_fchdir_dirfd:
   cp> df -h
     Filesystem    Size      Used  Available Mounted on
     rpmsgfs      2298M      122M      2176M /data
     romfs         512B      512B         0B /etc
     littlefs      256K        8K       248K /misc
     procfs          0B        0B         0B /proc
     tmpfs         512B      512B         0B /tmp
     rpmsgfs      1718K     1718K         0B /vendor
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-nuttx] xiaoxiang781216 merged pull request #6803: fs/directory: Using file api to implement operations on directories

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 merged PR #6803:
URL: https://github.com/apache/incubator-nuttx/pull/6803


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-nuttx] Donny9 commented on a diff in pull request #6803: fs/directory: Using file api to implement operations on directories

Posted by GitBox <gi...@apache.org>.
Donny9 commented on code in PR #6803:
URL: https://github.com/apache/incubator-nuttx/pull/6803#discussion_r939681688


##########
arch/arm/src/cxd56xx/cxd56_powermgr_procfs.c:
##########
@@ -781,7 +783,7 @@ static int cxd56_powermgr_procfs_readdir(struct fs_dirent_s *dir)
  *
  ****************************************************************************/
 
-static int cxd56_powermgr_procfs_rewinddir(struct fs_dirent_s *dir)
+static int cxd56_powermgr_procfs_rewinddir(FAR struct fs_dirent_s *dir)

Review Comment:
   Done.



##########
arch/arm/src/cxd56xx/cxd56_powermgr_procfs.c:
##########
@@ -749,7 +750,8 @@ static int cxd56_powermgr_procfs_closedir(struct fs_dirent_s *dir)
  *
  ****************************************************************************/
 
-static int cxd56_powermgr_procfs_readdir(struct fs_dirent_s *dir)
+static int cxd56_powermgr_procfs_readdir(FAR struct fs_dirent_s *dir,
+                                         FAR struct dirent *entry)

Review Comment:
   Done.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-nuttx] Donny9 commented on a diff in pull request #6803: fs/directory: Using file api to implement operations on directories

Posted by GitBox <gi...@apache.org>.
Donny9 commented on code in PR #6803:
URL: https://github.com/apache/incubator-nuttx/pull/6803#discussion_r940861881


##########
fs/binfs/fs_binfs.c:
##########
@@ -63,9 +72,12 @@ static int     binfs_fstat(FAR const struct file *filep,
                            FAR struct stat *buf);
 
 static int     binfs_opendir(struct inode *mountpt, const char *relpath,

Review Comment:
   Done



##########
fs/binfs/fs_binfs.c:
##########
@@ -277,8 +289,10 @@ static int binfs_fstat(FAR const struct file *filep, FAR struct stat *buf)
  ****************************************************************************/
 
 static int binfs_opendir(struct inode *mountpt, const char *relpath,

Review Comment:
   Done



##########
fs/binfs/fs_binfs.c:
##########
@@ -277,8 +289,10 @@ static int binfs_fstat(FAR const struct file *filep, FAR struct stat *buf)
  ****************************************************************************/
 
 static int binfs_opendir(struct inode *mountpt, const char *relpath,
-                         struct fs_dirent_s *dir)
+                         struct fs_dirent_s **dir)

Review Comment:
   Done



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-nuttx] lupyuen commented on pull request #6803: fs/directory: Using file api to implement operations on directories

Posted by GitBox <gi...@apache.org>.
lupyuen commented on PR #6803:
URL: https://github.com/apache/incubator-nuttx/pull/6803#issuecomment-1221761496

   Hi @xiaoxiang781216 after I added logging for `dir_open` / `dir_ioctl` / `dir_close`, LoRaWAN worked OK, which is really weird.
   
   You're right, `dir_open` / `dir_ioctl` / `dir_close` are not called, according to the log. So I don't think they are the cause of the problem.
   
   I'll dig deeper inside the GPIO Interrupt Handler and NimBLE Porting Layer to find out why LoRaWAN isn't handling the Packet Received Interrupt from the SX1262 Radio Module. Thanks!


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-nuttx] xiaoxiang781216 commented on pull request #6803: fs/directory: Using file api to implement operations on directories

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on PR #6803:
URL: https://github.com/apache/incubator-nuttx/pull/6803#issuecomment-1208014948

   > @Donny9, @xiaoxiang781216 - What was the motivation for this change?
   > 
   
   1. From the design perspective, directory is also a file(https://en.wikipedia.org/wiki/Everything_is_a_file).
   2. Support dirfd(https://pubs.opengroup.org/onlinepubs/9699919799/functions/dirfd.html)
   
   > For a change of this size nature all the file system will need to tested and result posted as well. the statistics on the impact on memory ram/flash.
   
   @Donny9 please give a summary.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-nuttx] pkarashchenko commented on a diff in pull request #6803: fs/directory: Using file api to implement operations on directories

Posted by GitBox <gi...@apache.org>.
pkarashchenko commented on code in PR #6803:
URL: https://github.com/apache/incubator-nuttx/pull/6803#discussion_r940564389


##########
fs/binfs/fs_binfs.c:
##########
@@ -63,9 +72,12 @@ static int     binfs_fstat(FAR const struct file *filep,
                            FAR struct stat *buf);
 
 static int     binfs_opendir(struct inode *mountpt, const char *relpath,
-                             struct fs_dirent_s *dir);
+                             struct fs_dirent_s **dir);

Review Comment:
   ```suggestion
                                FAR struct fs_dirent_s **dir);
   ```



##########
fs/binfs/fs_binfs.c:
##########
@@ -277,8 +289,10 @@ static int binfs_fstat(FAR const struct file *filep, FAR struct stat *buf)
  ****************************************************************************/
 
 static int binfs_opendir(struct inode *mountpt, const char *relpath,
-                         struct fs_dirent_s *dir)
+                         struct fs_dirent_s **dir)

Review Comment:
   ```suggestion
                            FAR struct fs_dirent_s **dir)
   ```



##########
fs/binfs/fs_binfs.c:
##########
@@ -63,9 +72,12 @@ static int     binfs_fstat(FAR const struct file *filep,
                            FAR struct stat *buf);
 
 static int     binfs_opendir(struct inode *mountpt, const char *relpath,

Review Comment:
   ```suggestion
   static int     binfs_opendir(FAR struct inode *mountpt, FAR const char *relpath,
   ```



##########
fs/cromfs/fs_cromfs.c:
##########
@@ -1356,9 +1392,12 @@ static int cromfs_readdir(struct inode *mountpt, struct fs_dirent_s *dir)
 
 static int cromfs_rewinddir(struct inode *mountpt, struct fs_dirent_s *dir)

Review Comment:
   ```suggestion
   static int cromfs_rewinddir(FAR struct inode *mountpt, FAR struct fs_dirent_s *dir)
   ```



##########
fs/fat/fs_fat32.h:
##########
@@ -1054,8 +1067,9 @@ EXTERN int    fat_allocatedirentry(struct fat_mountpt_s *fs,
                                    struct fat_dirinfo_s *dirinfo);

Review Comment:
   ```suggestion
                                      FAR struct fat_dirinfo_s *dirinfo);
   ```



##########
fs/fat/fs_fat32.h:
##########
@@ -1054,8 +1067,9 @@ EXTERN int    fat_allocatedirentry(struct fat_mountpt_s *fs,
                                    struct fat_dirinfo_s *dirinfo);
 EXTERN int    fat_freedirentry(struct fat_mountpt_s *fs,
                                struct fat_dirseq_s *seq);

Review Comment:
   ```suggestion
   EXTERN int    fat_freedirentry(FAR struct fat_mountpt_s *fs,
                                  FAR struct fat_dirseq_s *seq);
   ```



##########
fs/binfs/fs_binfs.c:
##########
@@ -277,8 +289,10 @@ static int binfs_fstat(FAR const struct file *filep, FAR struct stat *buf)
  ****************************************************************************/
 
 static int binfs_opendir(struct inode *mountpt, const char *relpath,

Review Comment:
   ```suggestion
   static int binfs_opendir(FAR struct inode *mountpt, FAR const char *relpath,
   ```



##########
fs/vfs/fs_dir.c:
##########
@@ -0,0 +1,607 @@
+/****************************************************************************
+ * fs/vfs/fs_dir.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <string.h>
+#include <errno.h>
+
+#include <nuttx/kmalloc.h>
+#include <nuttx/fs/fs.h>
+#include <nuttx/fs/ioctl.h>
+
+#include "inode/inode.h"
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+/* For the root pseudo-file system, we need retain only the 'next' inode
+ * need for the next readdir() operation. We hold a reference on this
+ * inode so we know that it will persist until closedir is called.
+ */
+
+struct fs_pseudodir_s
+{
+  struct fs_dirent_s dir;
+  FAR struct inode *next;
+};
+
+/****************************************************************************
+ * Private Functions Prototypes
+ ****************************************************************************/
+
+static int     dir_open(FAR struct file *filep);
+static int     dir_close(FAR struct file *filep);
+static ssize_t dir_read(FAR struct file *filep, FAR char *buffer,
+                        size_t buflen);
+static off_t   dir_seek(FAR struct file *filep, off_t offset, int whence);
+static int     dir_ioctl(FAR struct file *filep, int cmd, unsigned long arg);
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static const struct file_operations g_dir_fileops =
+{
+  dir_open,   /* open */
+  dir_close,  /* close */
+  dir_read,   /* read */
+  NULL,       /* write */
+  dir_seek,   /* seek */
+  dir_ioctl,  /* ioctl */
+  NULL,       /* poll */
+#ifndef CONFIG_DISABLE_PSEUDOFS_OPERATIONS
+  NULL,       /* unlink */
+#endif
+};
+
+static struct inode g_dir_inode =
+{
+  .i_crefs = 1,
+  .u =
+    {
+      .i_ops = &g_dir_fileops,
+    },

Review Comment:
   can we move to C89 initializer?



##########
libs/libc/dirent/lib_rewinddir.c:
##########
@@ -0,0 +1,63 @@
+/****************************************************************************
+ * libs/libc/dirent/lib_rewinddir.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <dirent.h>
+#include <errno.h>
+#include <unistd.h>
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: rewinddir
+ *
+ * Description:
+ *   The  rewinddir() function resets the position of the
+ *   directory stream dir to the beginning of the directory.
+ *
+ * Input Parameters:
+ *   dirp -- An instance of type DIR created by a previous
+ *     call to opendir();
+ *
+ * Returned Value:
+ *   None
+ *
+ ****************************************************************************/
+
+void rewinddir(FAR DIR *dirp)
+{
+  if (dirp)

Review Comment:
   ```suggestion
     if (dirp != NULL)
   ```



##########
libs/libc/dirent/lib_telldir.c:
##########
@@ -61,15 +56,11 @@
 
 off_t telldir(FAR DIR *dirp)
 {
-  struct fs_dirent_s *idir = (struct fs_dirent_s *)dirp;
-
-  if (!idir || !idir->fd_root)
+  if (dirp)

Review Comment:
   ```suggestion
     if (dirp != NULL)
   ```



##########
libs/libc/dirent/lib_seekdir.c:
##########
@@ -0,0 +1,65 @@
+/****************************************************************************
+ * libs/libc/dirent/lib_seekdir.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <dirent.h>
+#include <errno.h>
+#include <unistd.h>
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: seekdir
+ *
+ * Description:
+ *   The seekdir() function sets the location in the directory stream from
+ *   which the next readdir() call will start.  seekdir() should be used with
+ *   an offset returned by telldir().
+ *
+ * Input Parameters:
+ *   dirp -- An instance of type DIR created by a previous
+ *     call to opendir();
+ *   offset -- offset to seek to
+ *
+ * Returned Value:
+ *   None
+ *
+ ****************************************************************************/
+
+void seekdir(FAR DIR *dirp, off_t offset)
+{
+  if (dirp)

Review Comment:
   ```suggestion
     if (dirp != NULL)
   ```



##########
libs/libc/dirent/lib_dirfd.c:
##########
@@ -0,0 +1,65 @@
+/****************************************************************************
+ * libs/libc/dirent/lib_dirfd.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <dirent.h>
+#include <errno.h>
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: dirfd
+ *
+ * Description:
+ *   The dirfd() function returns the file descriptor associated
+ *   with the directory stream dirp.
+ *
+ * Input Parameters:
+ *   dirp -- An instance of type DIR created by a previous
+ *           call to opendir();
+ *
+ * Returned Value:
+ *   On success, a nonnegative file descriptor is returned.
+ *   On error, -1 is returned, and errno is set to indicate
+ *   the cause of the error.
+ *
+ *   EINVAL - dirp does not refer to a valid directory stream.
+ *
+ ****************************************************************************/
+
+int dirfd(FAR DIR *dirp)
+{
+  if (dirp)

Review Comment:
   ```suggestion
     if (dirp != NULL)
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-nuttx] Donny9 commented on a diff in pull request #6803: fs/directory: Using file api to implement operations on directories

Posted by GitBox <gi...@apache.org>.
Donny9 commented on code in PR #6803:
URL: https://github.com/apache/incubator-nuttx/pull/6803#discussion_r940866098


##########
libs/libc/dirent/lib_telldir.c:
##########
@@ -61,15 +56,11 @@
 
 off_t telldir(FAR DIR *dirp)
 {
-  struct fs_dirent_s *idir = (struct fs_dirent_s *)dirp;
-
-  if (!idir || !idir->fd_root)
+  if (dirp)

Review Comment:
   > What was the motivation for this change?
   > 
   > For a change of this size nature all the file system will need to tested and result posted as well. the statistics on the impact on memory ram/flash.
   
   @davids5 
   Statistics for three situation: nodir, dir, dir_with_fchdir_dirfd
   ```
   djz:nuttx$ ls -l vela_cp.bin 
   -rwxrwxr-x 1 djz djz 2066272 8月   9 10:36 vela_cp.bin
   
   djz:nuttx$ ls -l vela_cp_dir.bin 
   -rwxrwxr-x 1 djz djz 2066260 8月   9 10:56 vela_cp_dir.bin
   
   djz:nuttx$ ls -l vela_cp_dir_with_fchdir_dirfd.bin 
   -rwxrwxr-x 1 djz djz 2066428 8月   9 11:10 vela_cp_dir_with_fchdir_dirfd.bin
   
   no_dir:
   cp> free
                      total       used       free    largest  nused  nfree
           Umem:     519096     210392     308704     304384    672      8
   dir:
   cp> free
                      total       used       free    largest  nused  nfree
           Umem:     519032     210392     308640     304864    672     10
   dir_with_fchdir_dirfd:
   cp> free
                      total       used       free    largest  nused  nfree
           Umem:     519096     210392     308704     304928    672      8
           
   filesystem usage:
   no_dir:
   cp> df -h
     Filesystem    Size      Used  Available Mounted on
     rpmsgfs      2298M      121M      2177M /data
     romfs         512B      512B         0B /etc
     littlefs      256K        8K       248K /misc
     procfs          0B        0B         0B /proc
     tmpfs         512B      512B         0B /tmp
     rpmsgfs      1718K     1718K         0B /vendor
   
   dir:
   cp> df -h
     Filesystem    Size      Used  Available Mounted on
     rpmsgfs      2298M      121M      2177M /data
     romfs         512B      512B         0B /etc
     littlefs      256K        8K       248K /misc
     procfs          0B        0B         0B /proc
     tmpfs         512B      512B         0B /tmp
     rpmsgfs      1718K     1718K         0B /vendor
   
   dir_with_fchdir_dirfd:
   cp> df -h
     Filesystem    Size      Used  Available Mounted on
     rpmsgfs      2298M      122M      2176M /data
     romfs         512B      512B         0B /etc
     littlefs      256K        8K       248K /misc
     procfs          0B        0B         0B /proc
     tmpfs         512B      512B         0B /tmp
     rpmsgfs      1718K     1718K         0B /vendor
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-nuttx] PetervdPerk-NXP commented on pull request #6803: fs/directory: Using file api to implement operations on directories

Posted by GitBox <gi...@apache.org>.
PetervdPerk-NXP commented on PR #6803:
URL: https://github.com/apache/incubator-nuttx/pull/6803#issuecomment-1210311659

   opendir(), readerdir() etc are POSIX.1-2001 functions.
   This PR removes these functions calls hence breaking with the POSIX spec.
   Can't have fallback functions to still stay compatible with POSIX.1-2001?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-nuttx] lupyuen commented on pull request #6803: fs/directory: Using file api to implement operations on directories

Posted by GitBox <gi...@apache.org>.
lupyuen commented on PR #6803:
URL: https://github.com/apache/incubator-nuttx/pull/6803#issuecomment-1221233188

   Thanks @btashton! PineDio Stack BL604 fails my LoRaWAN Network Test because it couldn't receive any LoRaWAN Packets (Join Accept Response). Sending LoRaWAN Packets is OK. I traced it to this commit: https://github.com/apache/incubator-nuttx/commit/4dbf4555ebb743a908e3016d43b5b456d7a2cf16
   
   The LoRaWAN Test calls my [LoRaWAN Library](https://github.com/lupyuen/LoRaMac-node-nuttx), which calls my [Semtech SX1262 Library](https://github.com/lupyuen/lora-sx1262/tree/lorawan), which calls the [NimBLE Porting Layer](https://github.com/lupyuen/nimble-porting-nuttx) (for multithreading functions).
   
   Since the commit https://github.com/apache/incubator-nuttx/commit/4dbf4555ebb743a908e3016d43b5b456d7a2cf16 has to do with File System, maybe something inside NimBLE Porting Layer broke.
   
   I plan to trace the calls to [`dir_open`](https://github.com/apache/incubator-nuttx/blob/master/fs/vfs/fs_dir.c#L397-L402), [`dir_ioctl`](https://github.com/apache/incubator-nuttx/blob/master/fs/vfs/fs_dir.c#L548-L560) and [`dir_allocate`](https://github.com/apache/incubator-nuttx/blob/master/fs/vfs/fs_dir.c#L566-L608) to see what changed.
   
   The weird thing about this bug: LoRaWAN works perfectly fine on PineCone BL602, only PineDio Stack BL604 is affected. (Maybe due to the different drivers and apps loaded in memory?)


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-nuttx] xiaoxiang781216 commented on pull request #6803: fs/directory: Using file api to implement operations on directories

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on PR #6803:
URL: https://github.com/apache/incubator-nuttx/pull/6803#issuecomment-1221560366

   @lupyuen it's strange that dir_open/dir_ioctl can generate this side effect since:
   
   1.  dir_allocate is already used in open(O_DIRECTORY)
   2. dir_open/dir_ioctl is used to implement fchrdir which don't have any caller yet


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-nuttx] Donny9 commented on a diff in pull request #6803: fs/directory: Using file api to implement operations on directories

Posted by GitBox <gi...@apache.org>.
Donny9 commented on code in PR #6803:
URL: https://github.com/apache/incubator-nuttx/pull/6803#discussion_r940866098


##########
libs/libc/dirent/lib_telldir.c:
##########
@@ -61,15 +56,11 @@
 
 off_t telldir(FAR DIR *dirp)
 {
-  struct fs_dirent_s *idir = (struct fs_dirent_s *)dirp;
-
-  if (!idir || !idir->fd_root)
+  if (dirp)

Review Comment:
   > What was the motivation for this change?
   > 
   > For a change of this size nature all the file system will need to tested and result posted as well. the statistics on the impact on memory ram/flash.
   
   @davids5 
   Statistics for three situation: nodir, dir, dir_with_fchdir_dirfd
   ```
   djz:nuttx$ ls -l vela_cp.bin 
   -rwxrwxr-x 1 djz djz 2066272 8月   9 10:36 vela_cp.bin
   
   djz:nuttx$ ls -l vela_cp_dir.bin 
   -rwxrwxr-x 1 djz djz 2066260 8月   9 10:56 vela_cp_dir.bin
   
   djz:nuttx$ ls -l vela_cp_dir_with_fchdir_dirfd.bin 
   -rwxrwxr-x 1 djz djz 2066428 8月   9 11:10 vela_cp_dir_with_fchdir_dirfd.bin
   
   no_dir:
   cp> free
                      total       used       free    largest  nused  nfree
           Umem:     519096     210392     308704     304384    672      8
   dir:
   cp> free
                      total       used       free    largest  nused  nfree
           Umem:     519032     210392     308640     304864    672     10
   dir_with_fchdir_dirfd:
   cp> free
                      total       used       free    largest  nused  nfree
           Umem:     519096     210392     308704     304928    672      8
           
   filesystem usage:
   no_dir:
   cp> df -h
     Filesystem    Size      Used  Available Mounted on
     rpmsgfs      2298M      121M      2177M /data
     romfs         512B      512B         0B /etc
     littlefs      256K        8K       248K /misc
     procfs          0B        0B         0B /proc
     tmpfs         512B      512B         0B /tmp
     rpmsgfs      1718K     1718K         0B /vendor
   
   dir:
   cp> df -h
     Filesystem    Size      Used  Available Mounted on
     rpmsgfs      2298M      121M      2177M /data
     romfs         512B      512B         0B /etc
     littlefs      256K        8K       248K /misc
     procfs          0B        0B         0B /proc
     tmpfs         512B      512B         0B /tmp
     rpmsgfs      1718K     1718K         0B /vendor
   
   dir_with_fchdir_dirfd:
   cp> df -h
     Filesystem    Size      Used  Available Mounted on
     rpmsgfs      2298M      122M      2176M /data
     romfs         512B      512B         0B /etc
     littlefs      256K        8K       248K /misc
     procfs          0B        0B         0B /proc
     tmpfs         512B      512B         0B /tmp
     rpmsgfs      1718K     1718K         0B /vendor
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-nuttx] xiaoxiang781216 commented on pull request #6803: fs/directory: Using file api to implement operations on directories

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on PR #6803:
URL: https://github.com/apache/incubator-nuttx/pull/6803#issuecomment-1209025905

   @davids5 please take a look, the change is minor.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-nuttx] Donny9 commented on a diff in pull request #6803: fs/directory: Using file api to implement operations on directories

Posted by GitBox <gi...@apache.org>.
Donny9 commented on code in PR #6803:
URL: https://github.com/apache/incubator-nuttx/pull/6803#discussion_r939681648


##########
arch/arm/src/cxd56xx/cxd56_powermgr_procfs.c:
##########
@@ -787,9 +777,9 @@ static int cxd56_powermgr_procfs_rewinddir(FAR struct fs_dirent_s *dir)
 {
   struct cxd56_powermgr_procfs_dir_s *procfs;
 
-  DEBUGASSERT(dir && dir->u.procfs);
+  DEBUGASSERT(dir);
 
-  procfs = (struct cxd56_powermgr_procfs_dir_s *)dir->u.procfs;
+  procfs = (FAR struct cxd56_powermgr_procfs_dir_s *)dir;

Review Comment:
   Done!



##########
arch/arm/src/cxd56xx/cxd56_powermgr_procfs.c:
##########
@@ -711,7 +710,7 @@ static int cxd56_powermgr_procfs_opendir(const char *relpath,
     }
 
   procfs->index = 0;
-  dir->u.procfs = (void *)procfs;
+  *dir = (FAR struct fs_dirent_s *)procfs;

Review Comment:
   Done



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-nuttx] Donny9 commented on a diff in pull request #6803: fs/directory: Using file api to implement operations on directories

Posted by GitBox <gi...@apache.org>.
Donny9 commented on code in PR #6803:
URL: https://github.com/apache/incubator-nuttx/pull/6803#discussion_r940860998


##########
libs/libc/dirent/lib_dirfd.c:
##########
@@ -0,0 +1,65 @@
+/****************************************************************************
+ * libs/libc/dirent/lib_dirfd.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <dirent.h>
+#include <errno.h>
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: dirfd
+ *
+ * Description:
+ *   The dirfd() function returns the file descriptor associated
+ *   with the directory stream dirp.
+ *
+ * Input Parameters:
+ *   dirp -- An instance of type DIR created by a previous
+ *           call to opendir();
+ *
+ * Returned Value:
+ *   On success, a nonnegative file descriptor is returned.
+ *   On error, -1 is returned, and errno is set to indicate
+ *   the cause of the error.
+ *
+ *   EINVAL - dirp does not refer to a valid directory stream.
+ *
+ ****************************************************************************/
+
+int dirfd(FAR DIR *dirp)
+{
+  if (dirp)

Review Comment:
   Done!



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-nuttx] xiaoxiang781216 commented on pull request #6803: fs/directory: Using file api to implement operations on directories

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on PR #6803:
URL: https://github.com/apache/incubator-nuttx/pull/6803#issuecomment-1210383129

   Ok,  #6803 title is modified to avoid the confusion.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org