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


##########
fs/inode/fs_inodesearch.c:
##########
@@ -193,6 +199,120 @@ static int _inode_linktarget(FAR struct inode *inode,
 }
 #endif
 
+#ifdef CONFIG_FS_CHROOT
+/****************************************************************************
+ * Name: inode_get_chroot
+ ****************************************************************************/
+
+static FAR struct inode *inode_get_chroot(FAR const char **relpath)
+{
+  FAR struct tcb_s *tcb = nxsched_self();
+
+  if (relpath != NULL)
+    {
+      *relpath = NULL;
+    }
+
+  if (tcb != NULL && tcb->group != NULL && tcb->group->tg_root != NULL)
+    {
+      if (relpath != NULL)
+        {
+          *relpath = tcb->group->tg_rootrel;
+        }
+
+      return tcb->group->tg_root;
+    }
+
+  return g_root_inode;
+}
+
+/****************************************************************************
+ * Name: inode_normalize_abs
+ *
+ * Description:
+ *   Normalize an absolute path: drop empty and "." segments, and clamp
+ *   ".." at the search root.  Needed even before a jail is installed:
+ *   chroot(".") becomes "$PWD/.", and if PWD sits under a mountpoint
+ *   (tmpfs /tmp) the leftover "." is passed to the filesystem as
+ *   relpath and fails with ENOENT.
+ *
+ ****************************************************************************/
+
+static int inode_normalize_abs(FAR const char *in, FAR char *out,
+                               size_t outlen)
+{
+  FAR char *dst;
+  FAR const char *src = in;
+
+  if (outlen < 2)
+    {
+      return -ENAMETOOLONG;
+    }
+
+  out[0] = '/';
+  dst = out + 1;
+
+  while (*src == '/')
+    {
+      src++;
+    }
+
+  while (*src != '\0')
+    {
+      FAR const char *end = src;
+      size_t seglen;
+
+      while (*end != '\0' && *end != '/')

Review Comment:
   why not?



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