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


##########
fs/tmpfs/fs_tmpfs.c:
##########
@@ -555,12 +561,176 @@ static int tmpfs_add_dirent(FAR struct tmpfs_directory_s 
*tdo,
   return OK;
 }
 
+#if defined(CONFIG_FS_PERMISSION)
+
+/****************************************************************************
+ * Name: tmpfs_init_object
+ ****************************************************************************/
+
+static void tmpfs_init_object(FAR struct tmpfs_object_s *to, mode_t mode)
+{
+  FAR struct tcb_s *rtcb;
+
+  to->to_mode = mode & 07777;
+  rtcb = nxsched_self();
+  if ((rtcb->flags & TCB_FLAG_TTYPE_MASK) == TCB_FLAG_TTYPE_KERNEL ||
+      rtcb->group == NULL)
+    {
+      to->to_uid = 0;
+      to->to_gid = 0;
+    }
+  else
+    {
+      to->to_uid = rtcb->group->tg_euid;
+      to->to_gid = rtcb->group->tg_egid;
+    }
+}
+
+/****************************************************************************
+ * Name: tmpfs_check_pathperm
+ ****************************************************************************/
+
+static int tmpfs_check_pathperm(FAR struct tmpfs_s *fs,
+                                FAR const char *relpath, size_t relpathlen,
+                                int final_amode)
+{
+  FAR struct tmpfs_directory_s *tdo;
+  FAR struct tmpfs_object_s *to;
+  size_t begin = 0;
+  size_t end;
+  int ret;
+
+  while (begin < relpathlen && relpath[begin] == '/')
+    {
+      begin++;
+    }
+
+  if (begin >= relpathlen)
+    {
+      to = fs->tfs_root.tde_object;
+      return fs_checkmode(to->to_uid, to->to_gid,
+                          to->to_mode | S_IFDIR, final_amode);
+    }
+
+  end = begin;
+  while (end <= relpathlen)
+    {
+      if (end < relpathlen && relpath[end] != '/')
+        {
+          end++;
+          continue;
+        }
+
+      if (end == begin)
+        {
+          break;
+        }
+
+      ret = tmpfs_find_directory(fs, relpath, end, &tdo, NULL);
+      if (ret < 0)
+        {
+          return ret;
+        }
+
+      to = (FAR struct tmpfs_object_s *)tdo;
+      ret = fs_checkmode(to->to_uid, to->to_gid,
+                         to->to_mode | S_IFDIR,
+                         (end >= relpathlen) ? final_amode : X_OK);

Review Comment:
   ```suggestion
                            end >= relpathlen ? final_amode : X_OK);
   ```



##########
fs/tmpfs/fs_tmpfs.c:
##########
@@ -555,12 +561,176 @@ static int tmpfs_add_dirent(FAR struct tmpfs_directory_s 
*tdo,
   return OK;
 }
 
+#if defined(CONFIG_FS_PERMISSION)
+
+/****************************************************************************
+ * Name: tmpfs_init_object
+ ****************************************************************************/
+
+static void tmpfs_init_object(FAR struct tmpfs_object_s *to, mode_t mode)
+{
+  FAR struct tcb_s *rtcb;
+
+  to->to_mode = mode & 07777;
+  rtcb = nxsched_self();
+  if ((rtcb->flags & TCB_FLAG_TTYPE_MASK) == TCB_FLAG_TTYPE_KERNEL ||
+      rtcb->group == NULL)
+    {
+      to->to_uid = 0;
+      to->to_gid = 0;
+    }
+  else
+    {
+      to->to_uid = rtcb->group->tg_euid;
+      to->to_gid = rtcb->group->tg_egid;
+    }
+}
+
+/****************************************************************************
+ * Name: tmpfs_check_pathperm
+ ****************************************************************************/
+
+static int tmpfs_check_pathperm(FAR struct tmpfs_s *fs,
+                                FAR const char *relpath, size_t relpathlen,
+                                int final_amode)
+{
+  FAR struct tmpfs_directory_s *tdo;
+  FAR struct tmpfs_object_s *to;
+  size_t begin = 0;
+  size_t end;
+  int ret;
+
+  while (begin < relpathlen && relpath[begin] == '/')
+    {
+      begin++;
+    }
+
+  if (begin >= relpathlen)
+    {
+      to = fs->tfs_root.tde_object;
+      return fs_checkmode(to->to_uid, to->to_gid,
+                          to->to_mode | S_IFDIR, final_amode);
+    }
+
+  end = begin;
+  while (end <= relpathlen)

Review Comment:
   ```suggestion
     for (end = begin; end <= relpathlen; end++)
   ```
   remove line 620 and 651



##########
fs/tmpfs/fs_tmpfs.c:
##########
@@ -555,12 +561,176 @@ static int tmpfs_add_dirent(FAR struct tmpfs_directory_s 
*tdo,
   return OK;
 }
 
+#if defined(CONFIG_FS_PERMISSION)

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



##########
fs/tmpfs/fs_tmpfs.c:
##########
@@ -555,12 +561,176 @@ static int tmpfs_add_dirent(FAR struct tmpfs_directory_s 
*tdo,
   return OK;
 }
 
+#if defined(CONFIG_FS_PERMISSION)
+
+/****************************************************************************
+ * Name: tmpfs_init_object
+ ****************************************************************************/
+
+static void tmpfs_init_object(FAR struct tmpfs_object_s *to, mode_t mode)
+{
+  FAR struct tcb_s *rtcb;
+
+  to->to_mode = mode & 07777;
+  rtcb = nxsched_self();
+  if ((rtcb->flags & TCB_FLAG_TTYPE_MASK) == TCB_FLAG_TTYPE_KERNEL ||
+      rtcb->group == NULL)
+    {
+      to->to_uid = 0;
+      to->to_gid = 0;
+    }
+  else
+    {
+      to->to_uid = rtcb->group->tg_euid;
+      to->to_gid = rtcb->group->tg_egid;
+    }
+}
+
+/****************************************************************************
+ * Name: tmpfs_check_pathperm
+ ****************************************************************************/
+
+static int tmpfs_check_pathperm(FAR struct tmpfs_s *fs,
+                                FAR const char *relpath, size_t relpathlen,
+                                int final_amode)
+{
+  FAR struct tmpfs_directory_s *tdo;
+  FAR struct tmpfs_object_s *to;
+  size_t begin = 0;
+  size_t end;
+  int ret;
+
+  while (begin < relpathlen && relpath[begin] == '/')
+    {
+      begin++;
+    }
+
+  if (begin >= relpathlen)
+    {
+      to = fs->tfs_root.tde_object;
+      return fs_checkmode(to->to_uid, to->to_gid,
+                          to->to_mode | S_IFDIR, final_amode);
+    }
+
+  end = begin;
+  while (end <= relpathlen)
+    {
+      if (end < relpathlen && relpath[end] != '/')
+        {
+          end++;
+          continue;
+        }
+
+      if (end == begin)
+        {
+          break;
+        }
+
+      ret = tmpfs_find_directory(fs, relpath, end, &tdo, NULL);
+      if (ret < 0)
+        {
+          return ret;
+        }
+
+      to = (FAR struct tmpfs_object_s *)tdo;
+      ret = fs_checkmode(to->to_uid, to->to_gid,
+                         to->to_mode | S_IFDIR,
+                         (end >= relpathlen) ? final_amode : X_OK);
+      tdo->tdo_refs--;
+      tmpfs_unlock_directory(tdo);
+      if (ret < 0)
+        {
+          return ret;
+        }
+
+      if (end >= relpathlen)

Review Comment:
   remove, dup with line 616



##########
fs/tmpfs/fs_tmpfs.c:
##########
@@ -1936,6 +2139,36 @@ static int tmpfs_fstat(FAR const struct file *filep, FAR 
struct stat *buf)
   return OK;
 }
 
+/****************************************************************************
+ * Name: tmpfs_fchstat
+ ****************************************************************************/
+
+static int tmpfs_fchstat(FAR const struct file *filep,
+                         FAR const struct stat *buf, int flags)
+{
+  DEBUGASSERT(filep->f_priv != NULL && buf != NULL);
+
+#ifndef CONFIG_FS_PERMISSION

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



##########
fs/tmpfs/fs_tmpfs.c:
##########
@@ -555,12 +561,176 @@ static int tmpfs_add_dirent(FAR struct tmpfs_directory_s 
*tdo,
   return OK;
 }
 
+#if defined(CONFIG_FS_PERMISSION)
+
+/****************************************************************************
+ * Name: tmpfs_init_object
+ ****************************************************************************/
+
+static void tmpfs_init_object(FAR struct tmpfs_object_s *to, mode_t mode)
+{
+  FAR struct tcb_s *rtcb;
+
+  to->to_mode = mode & 07777;
+  rtcb = nxsched_self();
+  if ((rtcb->flags & TCB_FLAG_TTYPE_MASK) == TCB_FLAG_TTYPE_KERNEL ||
+      rtcb->group == NULL)
+    {
+      to->to_uid = 0;
+      to->to_gid = 0;
+    }
+  else
+    {
+      to->to_uid = rtcb->group->tg_euid;
+      to->to_gid = rtcb->group->tg_egid;
+    }
+}
+
+/****************************************************************************
+ * Name: tmpfs_check_pathperm
+ ****************************************************************************/
+
+static int tmpfs_check_pathperm(FAR struct tmpfs_s *fs,
+                                FAR const char *relpath, size_t relpathlen,
+                                int final_amode)
+{
+  FAR struct tmpfs_directory_s *tdo;
+  FAR struct tmpfs_object_s *to;
+  size_t begin = 0;
+  size_t end;
+  int ret;
+
+  while (begin < relpathlen && relpath[begin] == '/')
+    {
+      begin++;
+    }
+
+  if (begin >= relpathlen)
+    {
+      to = fs->tfs_root.tde_object;
+      return fs_checkmode(to->to_uid, to->to_gid,
+                          to->to_mode | S_IFDIR, final_amode);
+    }
+
+  end = begin;
+  while (end <= relpathlen)
+    {
+      if (end < relpathlen && relpath[end] != '/')
+        {
+          end++;
+          continue;
+        }
+
+      if (end == begin)

Review Comment:
   remove impossible since the check at line 608



##########
fs/tmpfs/fs_tmpfs.c:
##########
@@ -2853,6 +3105,47 @@ static int tmpfs_stat(FAR struct inode *mountpt, FAR 
const char *relpath,
   return ret;
 }
 
+/****************************************************************************
+ * Name: tmpfs_chstat
+ ****************************************************************************/
+
+static int tmpfs_chstat(FAR struct inode *mountpt, FAR const char *relpath,
+                        FAR const struct stat *buf, int flags)
+{
+  DEBUGASSERT(mountpt != NULL && relpath != NULL && buf != NULL);
+
+#ifndef CONFIG_FS_PERMISSION

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



-- 
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