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


##########
fs/mqueue/mq_open.c:
##########
@@ -235,15 +233,18 @@ static int file_mq_vopen(FAR struct file *mq, FAR const 
char *mq_name,
    * have incremented the reference count on the inode.
    */
 
-  SETUP_SEARCH(&desc, fullpath, false);
+  ret = inode_search_setup(&desc, fullpath, false);
+  if (ret < 0)
+    {
+      leave_critical_section(flags);

Review Comment:
   goto errout_with_lock



##########
fs/mount/fs_mount.c:
##########


Review Comment:
   ditto



##########
fs/mount/fs_mount.c:
##########
@@ -380,16 +380,20 @@ int nx_mount(FAR const char *source, FAR const char 
*target,
 #ifndef CONFIG_DISABLE_PSEUDOFS_OPERATIONS
   /* Check if the inode already exists */
 
-  SETUP_SEARCH(&desc, target, false);
+  ret = inode_search_setup(&desc, target, false);
+  if (ret < 0)
+    {
+      inode_unlock();

Review Comment:
   `goto errout_with_lock`



##########
fs/mqueue/mq_open.c:
##########
@@ -356,7 +357,7 @@ static int file_mq_vopen(FAR struct file *mq, FAR const 
char *mq_name,
   inode_release(inode);
 
 errout_with_lock:

Review Comment:
   ```
   errout_with_search:
     inode_search_release(&desc);
   errout_with_lock:
     leave_critical_section(flags);
   ```



##########
fs/mqueue/mq_open.c:
##########


Review Comment:
   errout_with_search



##########
fs/vfs/fs_rename.c:
##########
@@ -118,7 +120,7 @@ static int pseudorename(FAR const char *oldpath, FAR struct 
inode *oldinode,
       if (oldinode == newinode)
         {
           ret = OK;
-          goto errout_with_lock;
+          goto errout_with_newsearch;

Review Comment:
   should we release newinode



##########
fs/mount/fs_mount.c:
##########


Review Comment:
   ditto



##########
fs/mqueue/mq_open.c:
##########


Review Comment:
   return -EINVAL



##########
fs/mount/fs_mount.c:
##########


Review Comment:
   errout_with_search



##########
fs/mount/fs_mount.c:
##########


Review Comment:
   return -ENOTBLK and remove errout



##########
fs/mount/fs_mount.c:
##########


Review Comment:
   ditto



##########
fs/mount/fs_mount.c:
##########
@@ -539,7 +543,7 @@ int nx_mount(FAR const char *source, FAR const char *target,
 errout_with_lock:

Review Comment:
   ```
   errout_with_search:
   #ifndef CONFIG_DISABLE_PSEUDOFS_OPERATIONS
     inode_search_release(&desc);
   #endif
   errout_with_lock:
     inode_unlock();
   ```



##########
fs/mqueue/mq_open.c:
##########


Review Comment:
   ditto



##########
fs/mqueue/mq_open.c:
##########
@@ -356,7 +357,7 @@ static int file_mq_vopen(FAR struct file *mq, FAR const 
char *mq_name,
   inode_release(inode);
 
 errout_with_lock:
-  RELEASE_SEARCH(&desc);
+  inode_search_release(&desc);
   leave_critical_section(flags);
 
 errout:

Review Comment:
   remove errout label



##########
fs/vfs/fs_chroot.c:
##########
@@ -0,0 +1,132 @@
+/****************************************************************************
+ * fs/vfs/fs_chroot.c
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * 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 <sys/stat.h>
+#include <assert.h>
+#include <errno.h>
+#include <string.h>
+
+#include <nuttx/fs/fs.h>
+#include <nuttx/kmalloc.h>
+#include <nuttx/sched.h>
+
+#include "inode/inode.h"
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: chroot
+ *
+ * Description:
+ *   Cause the named directory to become the root directory, that is, the
+ *   starting point for path names beginning with '/'.
+ *
+ * Input Parameters:
+ *   path - Directory to use as the new root
+ *
+ * Returned Value:
+ *   0(OK) on success; -1(ERROR) on failure with errno set appropriately.
+ *
+ ****************************************************************************/
+
+int chroot(FAR const char *path)
+{
+  FAR struct tcb_s *rtcb;
+  FAR struct task_group_s *group;
+  FAR char *newroot;
+  struct inode_search_s desc;
+  struct stat buf;
+  int ret;
+
+  if (path == NULL || path[0] == '\0')
+    {
+      set_errno(ENOENT);
+      return ERROR;
+    }
+
+  rtcb = nxsched_self();
+  DEBUGASSERT(rtcb != NULL && rtcb->group != NULL);
+  group = rtcb->group;
+
+#ifdef CONFIG_SCHED_USER_IDENTITY
+  if (group->tg_euid != 0)
+    {
+      set_errno(EPERM);
+      return ERROR;
+    }
+#endif
+
+  ret = nx_stat(path, &buf, 1);

Review Comment:
   stat and remove line 89



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