xiaoxiang781216 commented on code in PR #19166:
URL: https://github.com/apache/nuttx/pull/19166#discussion_r3432551361


##########
fs/littlefs/lfs_vfs.c:
##########
@@ -28,12 +28,15 @@
 
 #include <errno.h>
 #include <fcntl.h>
-#include <stdio.h>
 #include <string.h>
+#include <sys/stat.h>
+#include <unistd.h>
 
 #include <nuttx/crc16.h>
 #include <nuttx/fs/fs.h>
 #include <nuttx/fs/ioctl.h>
+
+#include "inode/inode.h"

Review Comment:
   remove, dup with line 47



##########
fs/littlefs/lfs_vfs.c:
##########
@@ -337,6 +341,192 @@ static FAR const char *littlefs_convert_path(FAR const 
char *path)
   return path;
 }
 
+#if defined(CONFIG_FS_PERMISSION) && defined(CONFIG_FS_LITTLEFS_ATTR_UPDATE)
+
+/****************************************************************************
+ * Name: littlefs_statbuf_locked
+ ****************************************************************************/
+
+static int littlefs_statbuf_locked(FAR struct littlefs_mountpt_s *fs,
+                                   FAR const char *relpath,
+                                   FAR struct stat *buf)
+{
+  struct lfs_info info;
+  struct littlefs_attr_s attr;
+  int ret;
+
+  memset(buf, 0, sizeof(*buf));
+
+  ret = lfs_stat(&fs->lfs, relpath, &info);
+  if (ret < 0)
+    {
+      return littlefs_convert_result(ret);
+    }
+
+  ret = littlefs_convert_result(lfs_getattr(&fs->lfs, relpath, 0,
+                                            &attr, sizeof(attr)));
+  if (ret < 0)
+    {
+      if (ret != -ENODATA)
+        {
+          return ret;
+        }
+
+      memset(&attr, 0, sizeof(attr));
+      attr.at_mode = S_IRWXG | S_IRWXU | S_IRWXO;
+    }
+
+  buf->st_mode         = attr.at_mode;
+  buf->st_uid          = attr.at_uid;
+  buf->st_gid          = attr.at_gid;
+  buf->st_atim.tv_sec  = attr.at_atim / 1000000000ull;
+  buf->st_atim.tv_nsec = attr.at_atim % 1000000000ull;
+  buf->st_mtim.tv_sec  = attr.at_mtim / 1000000000ull;
+  buf->st_mtim.tv_nsec = attr.at_mtim % 1000000000ull;
+  buf->st_ctim.tv_sec  = attr.at_ctim / 1000000000ull;
+  buf->st_ctim.tv_nsec = attr.at_ctim % 1000000000ull;
+  buf->st_blksize      = fs->cfg.block_size;
+
+  if (info.type == LFS_TYPE_REG)
+    {
+      buf->st_mode |= S_IFREG;
+      buf->st_size = info.size;
+    }
+  else
+    {
+      buf->st_mode |= S_IFDIR;
+      buf->st_size = 0;
+    }
+
+  buf->st_blocks = (buf->st_size + buf->st_blksize - 1) / buf->st_blksize;
+  return OK;
+}
+
+/****************************************************************************
+ * Name: littlefs_check_pathperm_locked
+ ****************************************************************************/
+
+static int littlefs_check_pathperm_locked(FAR struct littlefs_mountpt_s *fs,
+                                          FAR const char *relpath,
+                                          int final_amode)
+{
+  struct stat st;
+  char subpath[NAME_MAX + 1];
+  size_t len;
+  size_t begin = 0;
+  size_t end;
+  int ret;
+
+  len = strlen(relpath);
+  while (begin < len && relpath[begin] == '/')
+    {
+      begin++;
+    }
+
+  if (begin >= len)
+    {
+      return OK;
+    }
+
+  end = begin;
+  while (end <= len)
+    {
+      if (end < len && relpath[end] != '/')
+        {
+          end++;
+          continue;
+        }
+
+      if ((end - begin) > NAME_MAX)
+        {
+          return -ENAMETOOLONG;
+        }
+
+      memcpy(subpath, relpath + begin, end - begin);
+      subpath[end - begin] = '\0';
+
+      ret = littlefs_statbuf_locked(fs, subpath, &st);
+      if (ret < 0)
+        {
+          return ret;
+        }
+
+      ret = fs_checkmode(st.st_uid, st.st_gid, st.st_mode,
+                         (relpath[end] == '\0') ? final_amode : X_OK);
+      if (ret < 0)
+        {
+          return ret;
+        }
+
+      if (relpath[end] == '\0')
+        {
+          break;
+        }
+
+      end++;
+    }
+
+  return OK;
+}
+
+/****************************************************************************
+ * Name: littlefs_check_openperm_locked
+ ****************************************************************************/
+
+static int littlefs_check_openperm_locked(FAR struct littlefs_mountpt_s *fs,
+                                          FAR const char *relpath,
+                                          int oflags)
+{
+  return littlefs_check_pathperm_locked(fs, relpath,
+                                        fs_open_amode(oflags));
+}
+
+/****************************************************************************
+ * Name: littlefs_check_parentperm_locked
+ ****************************************************************************/
+
+static int littlefs_check_parentperm_locked(
+                FAR struct littlefs_mountpt_s *fs,
+                FAR const char *relpath, int amode)
+{
+  FAR const char *slash;
+  char parent[NAME_MAX + 1];

Review Comment:
   ```suggestion
     char parent[PATH_MAX + 1];
   ```



##########
fs/littlefs/lfs_vfs.c:
##########
@@ -376,8 +572,30 @@ static int littlefs_open(FAR struct file *filep, FAR const 
char *relpath,
 
   /* Try to open the file */
 
-  relpath = littlefs_convert_path(relpath);
-  oflags = littlefs_convert_oflags(oflags);
+  nuttx_oflags = oflags;

Review Comment:
   why need save nuttx_oflags



##########
fs/inode/inode.h:
##########
@@ -455,6 +455,12 @@ int inode_checkperm(FAR struct inode *inode, int oflags);
 
 int inode_checkdirperm(FAR struct inode *dir, int amode);
 
+#if defined(CONFIG_FS_PERMISSION)

Review Comment:
   ```suggestion
   #ifdef CONFIG_FS_PERMISSION
   ```



##########
fs/littlefs/lfs_vfs.c:
##########
@@ -337,6 +341,192 @@ static FAR const char *littlefs_convert_path(FAR const 
char *path)
   return path;
 }
 
+#if defined(CONFIG_FS_PERMISSION) && defined(CONFIG_FS_LITTLEFS_ATTR_UPDATE)
+
+/****************************************************************************
+ * Name: littlefs_statbuf_locked
+ ****************************************************************************/
+
+static int littlefs_statbuf_locked(FAR struct littlefs_mountpt_s *fs,
+                                   FAR const char *relpath,
+                                   FAR struct stat *buf)
+{
+  struct lfs_info info;
+  struct littlefs_attr_s attr;
+  int ret;
+
+  memset(buf, 0, sizeof(*buf));
+
+  ret = lfs_stat(&fs->lfs, relpath, &info);
+  if (ret < 0)
+    {
+      return littlefs_convert_result(ret);
+    }
+
+  ret = littlefs_convert_result(lfs_getattr(&fs->lfs, relpath, 0,
+                                            &attr, sizeof(attr)));
+  if (ret < 0)
+    {
+      if (ret != -ENODATA)
+        {
+          return ret;
+        }
+
+      memset(&attr, 0, sizeof(attr));
+      attr.at_mode = S_IRWXG | S_IRWXU | S_IRWXO;
+    }
+
+  buf->st_mode         = attr.at_mode;
+  buf->st_uid          = attr.at_uid;
+  buf->st_gid          = attr.at_gid;
+  buf->st_atim.tv_sec  = attr.at_atim / 1000000000ull;
+  buf->st_atim.tv_nsec = attr.at_atim % 1000000000ull;
+  buf->st_mtim.tv_sec  = attr.at_mtim / 1000000000ull;
+  buf->st_mtim.tv_nsec = attr.at_mtim % 1000000000ull;
+  buf->st_ctim.tv_sec  = attr.at_ctim / 1000000000ull;
+  buf->st_ctim.tv_nsec = attr.at_ctim % 1000000000ull;
+  buf->st_blksize      = fs->cfg.block_size;
+
+  if (info.type == LFS_TYPE_REG)
+    {
+      buf->st_mode |= S_IFREG;
+      buf->st_size = info.size;
+    }
+  else
+    {
+      buf->st_mode |= S_IFDIR;
+      buf->st_size = 0;
+    }
+
+  buf->st_blocks = (buf->st_size + buf->st_blksize - 1) / buf->st_blksize;
+  return OK;
+}
+
+/****************************************************************************
+ * Name: littlefs_check_pathperm_locked
+ ****************************************************************************/
+
+static int littlefs_check_pathperm_locked(FAR struct littlefs_mountpt_s *fs,
+                                          FAR const char *relpath,
+                                          int final_amode)
+{
+  struct stat st;
+  char subpath[NAME_MAX + 1];
+  size_t len;
+  size_t begin = 0;
+  size_t end;
+  int ret;
+
+  len = strlen(relpath);

Review Comment:
   remove, check '\0' instead



##########
fs/littlefs/lfs_vfs.c:
##########
@@ -337,6 +341,192 @@ static FAR const char *littlefs_convert_path(FAR const 
char *path)
   return path;
 }
 
+#if defined(CONFIG_FS_PERMISSION) && defined(CONFIG_FS_LITTLEFS_ATTR_UPDATE)
+
+/****************************************************************************
+ * Name: littlefs_statbuf_locked
+ ****************************************************************************/
+
+static int littlefs_statbuf_locked(FAR struct littlefs_mountpt_s *fs,
+                                   FAR const char *relpath,
+                                   FAR struct stat *buf)
+{
+  struct lfs_info info;
+  struct littlefs_attr_s attr;
+  int ret;
+
+  memset(buf, 0, sizeof(*buf));
+
+  ret = lfs_stat(&fs->lfs, relpath, &info);
+  if (ret < 0)
+    {
+      return littlefs_convert_result(ret);
+    }
+
+  ret = littlefs_convert_result(lfs_getattr(&fs->lfs, relpath, 0,
+                                            &attr, sizeof(attr)));
+  if (ret < 0)
+    {
+      if (ret != -ENODATA)
+        {
+          return ret;
+        }
+
+      memset(&attr, 0, sizeof(attr));
+      attr.at_mode = S_IRWXG | S_IRWXU | S_IRWXO;
+    }
+
+  buf->st_mode         = attr.at_mode;
+  buf->st_uid          = attr.at_uid;
+  buf->st_gid          = attr.at_gid;
+  buf->st_atim.tv_sec  = attr.at_atim / 1000000000ull;
+  buf->st_atim.tv_nsec = attr.at_atim % 1000000000ull;
+  buf->st_mtim.tv_sec  = attr.at_mtim / 1000000000ull;
+  buf->st_mtim.tv_nsec = attr.at_mtim % 1000000000ull;
+  buf->st_ctim.tv_sec  = attr.at_ctim / 1000000000ull;
+  buf->st_ctim.tv_nsec = attr.at_ctim % 1000000000ull;
+  buf->st_blksize      = fs->cfg.block_size;
+
+  if (info.type == LFS_TYPE_REG)
+    {
+      buf->st_mode |= S_IFREG;
+      buf->st_size = info.size;
+    }
+  else
+    {
+      buf->st_mode |= S_IFDIR;
+      buf->st_size = 0;
+    }
+
+  buf->st_blocks = (buf->st_size + buf->st_blksize - 1) / buf->st_blksize;
+  return OK;
+}
+
+/****************************************************************************
+ * Name: littlefs_check_pathperm_locked
+ ****************************************************************************/
+
+static int littlefs_check_pathperm_locked(FAR struct littlefs_mountpt_s *fs,
+                                          FAR const char *relpath,
+                                          int final_amode)
+{
+  struct stat st;
+  char subpath[NAME_MAX + 1];

Review Comment:
   ```suggestion
     char subpath[PATH_MAX];
   ```



##########
fs/littlefs/lfs_vfs.c:
##########
@@ -376,8 +572,30 @@ static int littlefs_open(FAR struct file *filep, FAR const 
char *relpath,
 
   /* Try to open the file */
 
-  relpath = littlefs_convert_path(relpath);
-  oflags = littlefs_convert_oflags(oflags);
+  nuttx_oflags = oflags;
+  path = littlefs_convert_path(relpath);
+
+#if defined(CONFIG_FS_PERMISSION) && defined(CONFIG_FS_LITTLEFS_ATTR_UPDATE)
+  sret = lfs_stat(&fs->lfs, path, &info);

Review Comment:
   why not reuse ret



##########
fs/littlefs/lfs_vfs.c:
##########
@@ -376,8 +572,30 @@ static int littlefs_open(FAR struct file *filep, FAR const 
char *relpath,
 
   /* Try to open the file */
 
-  relpath = littlefs_convert_path(relpath);
-  oflags = littlefs_convert_oflags(oflags);
+  nuttx_oflags = oflags;
+  path = littlefs_convert_path(relpath);

Review Comment:
   ```suggestion
     relpath = littlefs_convert_path(relpath);
   ```
   and remove path
   



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to