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


##########
fs/tmpfs/fs_tmpfs.c:
##########
@@ -555,12 +561,174 @@ 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;
+  size_t end;
+  int ret;
+
+  begin = 0;
+  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)
+        {
+          break;
+        }
+
+      end++;
+    }
+
+  return OK;
+}
+
+/****************************************************************************
+ * Name: tmpfs_check_parentperm
+ ****************************************************************************/
+
+static int tmpfs_check_parentperm(FAR struct tmpfs_s *fs,
+                                  FAR const char *relpath, int amode)
+{
+  FAR const char *slash;
+  size_t parentlen;
+
+  slash = strrchr(relpath, '/');
+  if (slash == NULL || slash == relpath)
+    {
+      return tmpfs_check_pathperm(fs, relpath, 0, amode);

Review Comment:
   why pass zero as relpathlen here? 



##########
fs/tmpfs/fs_tmpfs.c:
##########
@@ -2853,6 +3119,49 @@ 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)
+{
+  FAR struct tmpfs_s *fs;
+  FAR struct tmpfs_object_s *to;
+  int ret;
+
+  DEBUGASSERT(mountpt != NULL && relpath != NULL && buf != NULL);
+
+#ifndef CONFIG_FS_PERMISSION
+  UNUSED(flags);
+  return -ENOSYS;
+#else
+  fs = mountpt->i_private;
+  DEBUGASSERT(fs != NULL);
+
+  ret = tmpfs_lock(fs);
+  if (ret < 0)
+    {
+      return ret;
+    }
+
+  for (; *relpath == '/'; relpath++);

Review Comment:
   move into tmpfs_find_object



##########
fs/tmpfs/fs_tmpfs.c:
##########
@@ -555,12 +561,174 @@ 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;
+  size_t end;
+  int ret;
+
+  begin = 0;

Review Comment:
   merge to line 599



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