You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2022/10/19 13:20:41 UTC

[incubator-nuttx] branch master updated (c48feac0e9 -> f100a4bb92)

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

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


    from c48feac0e9 arch: cxd56xx: gnss: Fix compile error
     new aa67e0a0f4 inode_stat: handle INODE_IS_PSEUDODIR case
     new 4eee9af668 file_vopen: Retry as a directory in case of EISDIR
     new f100a4bb92 Implement fdopendir

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/vfs/fs_open.c                                   |  5 +++
 fs/vfs/fs_stat.c                                   |  4 +-
 include/dirent.h                                   |  1 +
 libs/libc/dirent/Make.defs                         |  3 +-
 .../libc/dirent/{lib_readdir.c => lib_fdopendir.c} | 48 ++++++++++++++--------
 5 files changed, 40 insertions(+), 21 deletions(-)
 copy libs/libc/dirent/{lib_readdir.c => lib_fdopendir.c} (70%)


[incubator-nuttx] 02/03: file_vopen: Retry as a directory in case of EISDIR

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

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

commit 4eee9af668aedf1e647ec57de0670f88fe89f6de
Author: YAMAMOTO Takashi <ya...@midokura.com>
AuthorDate: Wed Oct 19 19:14:12 2022 +0900

    file_vopen: Retry as a directory in case of EISDIR
    
    This allows you to open() a directory without O_DIRECTORY.
---
 fs/vfs/fs_open.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/fs/vfs/fs_open.c b/fs/vfs/fs_open.c
index 7b3a7544cc..b62aaf0cff 100644
--- a/fs/vfs/fs_open.c
+++ b/fs/vfs/fs_open.c
@@ -186,6 +186,11 @@ static int file_vopen(FAR struct file *filep, FAR const char *path,
       ret = -ENXIO;
     }
 
+  if (ret == -EISDIR)
+    {
+      ret = dir_allocate(filep, desc.relpath);
+    }
+
   if (ret < 0)
     {
       goto errout_with_inode;


[incubator-nuttx] 01/03: inode_stat: handle INODE_IS_PSEUDODIR case

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

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

commit aa67e0a0f4d8c89a6b46f991a3fffa19ebfe4417
Author: YAMAMOTO Takashi <ya...@midokura.com>
AuthorDate: Wed Oct 19 19:11:56 2022 +0900

    inode_stat: handle INODE_IS_PSEUDODIR case
    
    If you open() a directory and fstat() it, you come here.
    This commit fixes the file type in that case.
---
 fs/vfs/fs_stat.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/fs/vfs/fs_stat.c b/fs/vfs/fs_stat.c
index 06b9afff06..f4fb410c6d 100644
--- a/fs/vfs/fs_stat.c
+++ b/fs/vfs/fs_stat.c
@@ -381,9 +381,9 @@ int inode_stat(FAR struct inode *inode, FAR struct stat *buf, int resolve)
 
       /* Determine the type of the inode */
 
-      /* Check for a mountpoint */
+      /* Check for a mountpoint and a pseudo dir */
 
-      if (INODE_IS_MOUNTPT(inode))
+      if (INODE_IS_MOUNTPT(inode) || INODE_IS_PSEUDODIR(inode))
         {
           buf->st_mode |= S_IFDIR;
         }


[incubator-nuttx] 03/03: Implement fdopendir

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

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

commit f100a4bb921c609998507aa6e9354b899758b84f
Author: YAMAMOTO Takashi <ya...@midokura.com>
AuthorDate: Wed Oct 19 19:16:08 2022 +0900

    Implement fdopendir
---
 include/dirent.h                 |  1 +
 libs/libc/dirent/Make.defs       |  3 +-
 libs/libc/dirent/lib_fdopendir.c | 87 ++++++++++++++++++++++++++++++++++++++++
 3 files changed, 90 insertions(+), 1 deletion(-)

diff --git a/include/dirent.h b/include/dirent.h
index 54ea3aeb7c..1ac8cf2b58 100644
--- a/include/dirent.h
+++ b/include/dirent.h
@@ -141,6 +141,7 @@ extern "C"
 
 int        closedir(FAR DIR *dirp);
 FAR DIR   *opendir(FAR const char *path);
+FAR DIR   *fdopendir(int fd);
 FAR struct dirent *readdir(FAR DIR *dirp);
 int        readdir_r(FAR DIR *dirp, FAR struct dirent *entry,
                      FAR struct dirent **result);
diff --git a/libs/libc/dirent/Make.defs b/libs/libc/dirent/Make.defs
index 440a3d0477..5814ab8071 100644
--- a/libs/libc/dirent/Make.defs
+++ b/libs/libc/dirent/Make.defs
@@ -21,7 +21,8 @@
 # Add the dirent C files to the build
 
 CSRCS += lib_readdirr.c lib_telldir.c lib_alphasort.c lib_scandir.c
-CSRCS += lib_ftw.c lib_nftw.c lib_opendir.c lib_closedir.c lib_readdir.c
+CSRCS += lib_ftw.c lib_nftw.c
+CSRCS += lib_opendir.c lib_fdopendir.c lib_closedir.c lib_readdir.c
 CSRCS += lib_rewinddir.c lib_seekdir.c lib_dirfd.c
 
 # Add the dirent directory to the build
diff --git a/libs/libc/dirent/lib_fdopendir.c b/libs/libc/dirent/lib_fdopendir.c
new file mode 100644
index 0000000000..80107ddefd
--- /dev/null
+++ b/libs/libc/dirent/lib_fdopendir.c
@@ -0,0 +1,87 @@
+/****************************************************************************
+ * libs/libc/dirent/lib_fdopendir.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 <sys/stat.h>
+
+#include <dirent.h>
+#include <errno.h>
+
+#include "libc.h"
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: fdopendir
+ *
+ * Description:
+ *   An equivalent of opendir() except that this takes an open descriptor
+ *   instead of a pathname.
+ *
+ * Input Parameters:
+ *   fd -- the directory to open
+ *
+ * Returned Value:
+ *   The fdopendir() function returns a pointer to the directory stream.
+ *   On error, NULL is returned, and errno is set appropriately.
+ *
+ *   ENOTDIR - 'fd' is not a directory.
+ *
+ *   See opendir() for other errors.
+ *
+ ****************************************************************************/
+
+FAR DIR *fdopendir(int fd)
+{
+  struct stat st;
+  FAR DIR *dir;
+  int ret;
+
+  ret = fstat(fd, &st);
+  if (ret == -1)
+    {
+      return NULL;
+    }
+
+  if (!S_ISDIR(st.st_mode))
+    {
+      set_errno(ENOTDIR);
+      return NULL;
+    }
+
+  dir = lib_malloc(sizeof(*dir));
+  if (dir == NULL)
+    {
+      set_errno(ENOMEM);
+      return NULL;
+    }
+
+  dir->fd = fd;
+  return dir;
+}