You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by GitBox <gi...@apache.org> on 2021/07/09 16:24:33 UTC

[GitHub] [incubator-nuttx] xiaoxiang781216 opened a new pull request #4109: libc: Implement ttyname and ttyname_r

xiaoxiang781216 opened a new pull request #4109:
URL: https://github.com/apache/incubator-nuttx/pull/4109


   ## Summary
   Note: this patch can get file path from root pseudo file handle,
   but a general infrastructure is setup for other file system too.
   
   ## Impact
   New API
   
   ## Testing
   
   


-- 
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: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-nuttx] gustavonihei commented on a change in pull request #4109: libc: Implement ttyname and ttyname_r

Posted by GitBox <gi...@apache.org>.
gustavonihei commented on a change in pull request #4109:
URL: https://github.com/apache/incubator-nuttx/pull/4109#discussion_r667170160



##########
File path: include/nuttx/fs/ioctl.h
##########
@@ -180,6 +180,9 @@
 #define FIONCLEX        _FIOC(0x000e)     /* IN:  None
                                            * OUT: None
                                            */
+#define FIOC_FILEPATH   _FIOC(0x0004)     /* IN:  FAR char *(length >= PATH_MAX)

Review comment:
       ```suggestion
   #define FIOC_FILEPATH   _FIOC(0x000f)     /* IN:  FAR char *(length >= PATH_MAX)
   ```
   This value will conflict `FIOC_FILENAME`.




-- 
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: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-nuttx] xiaoxiang781216 commented on a change in pull request #4109: libc: Implement ttyname and ttyname_r

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on a change in pull request #4109:
URL: https://github.com/apache/incubator-nuttx/pull/4109#discussion_r667136501



##########
File path: fs/vfs/fs_ioctl.c
##########
@@ -103,6 +103,13 @@ int file_vioctl(FAR struct file *filep, int req, va_list ap)
         ret = file_fcntl(filep, F_SETFD,
                          file_fcntl(filep, F_GETFD) & ~FD_CLOEXEC);
         break;
+
+      case FIOC_FILEPATH:
+        if (!INODE_IS_MOUNTPT(inode))
+          {
+            ret = inode_getpath(inode, (FAR char *)arg);

Review comment:
       Done.




-- 
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: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-nuttx] xiaoxiang781216 commented on a change in pull request #4109: libc: Implement ttyname and ttyname_r

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on a change in pull request #4109:
URL: https://github.com/apache/incubator-nuttx/pull/4109#discussion_r667137363



##########
File path: include/fcntl.h
##########
@@ -95,6 +95,7 @@
 #define F_SETLKW    12 /* Like F_SETLK, but wait for lock to become available */
 #define F_SETOWN    13 /* Set pid that will receive SIGIO and SIGURG signals for fd */
 #define F_SETSIG    14 /* Set the signal to be sent */
+#define F_GETPATH   15 /* Get the path of the file descriptor(macos) */

Review comment:
       Update to (BSD/macOS)




-- 
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: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-nuttx] gustavonihei commented on a change in pull request #4109: libc: Implement ttyname and ttyname_r

Posted by GitBox <gi...@apache.org>.
gustavonihei commented on a change in pull request #4109:
URL: https://github.com/apache/incubator-nuttx/pull/4109#discussion_r667093737



##########
File path: fs/vfs/fs_ioctl.c
##########
@@ -103,6 +103,13 @@ int file_vioctl(FAR struct file *filep, int req, va_list ap)
         ret = file_fcntl(filep, F_SETFD,
                          file_fcntl(filep, F_GETFD) & ~FD_CLOEXEC);
         break;
+
+      case FIOC_FILEPATH:
+        if (!INODE_IS_MOUNTPT(inode))
+          {
+            ret = inode_getpath(inode, (FAR char *)arg);

Review comment:
       ```suggestion
               FAR char *path = (FAR char *)(uintptr_t)arg;
               ret = inode_getpath(inode, path);
   ```
   CI is failing on a warning:
   >Error: vfs/fs_ioctl.c:110:40: error: cast to pointer from integer of different size [-Werror=int-to-pointer-cast]




-- 
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: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-nuttx] gustavonihei commented on a change in pull request #4109: libc: Implement ttyname and ttyname_r

Posted by GitBox <gi...@apache.org>.
gustavonihei commented on a change in pull request #4109:
URL: https://github.com/apache/incubator-nuttx/pull/4109#discussion_r667171365



##########
File path: libs/libc/termios/lib_ttynamer.c
##########
@@ -0,0 +1,87 @@
+/****************************************************************************
+ * libs/libc/termios/lib_ttynamer.c
+ *
+ * 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 <errno.h>
+#include <fcntl.h>
+#include <string.h>
+#include <unistd.h>
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: ttyname_r
+ *
+ * Description:
+ *   The ttyname_r() function shall store the null-terminated pathname of
+ *   the terminal associated with the file descriptor fildes in the
+ *   character array referenced by name. The array is namesize characters
+ *   long and should have space for the name and the terminating null
+ *   character. The maximum length of the terminal name shall be
+ *   {TTY_NAME_MAX}.
+ *
+ * Input Parameters:
+ *   fd - The 'fd' argument is an open file descriptor associated with
+ *        a terminal.
+ *   buf - Caller provided buffer to hold tty name.
+ *   buflen - The size of the caller-provided buffer.
+ *
+ * Returned Value:
+ *   If successful, the ttyname_r() function shall return zero.
+ *   Otherwise, an error number shall be returned to indicate the error.
+ *
+ ****************************************************************************/
+
+int ttyname_r(int fd, FAR char *buf, size_t buflen)

Review comment:
       For POSIX standard compliance, instead of setting `errno`, `ttyname_r` should return the error code.




-- 
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: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-nuttx] xiaoxiang781216 commented on a change in pull request #4109: libc: Implement ttyname and ttyname_r

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on a change in pull request #4109:
URL: https://github.com/apache/incubator-nuttx/pull/4109#discussion_r667192272



##########
File path: libs/libc/termios/lib_ttynamer.c
##########
@@ -0,0 +1,87 @@
+/****************************************************************************
+ * libs/libc/termios/lib_ttynamer.c
+ *
+ * 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 <errno.h>
+#include <fcntl.h>
+#include <string.h>
+#include <unistd.h>
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: ttyname_r
+ *
+ * Description:
+ *   The ttyname_r() function shall store the null-terminated pathname of
+ *   the terminal associated with the file descriptor fildes in the
+ *   character array referenced by name. The array is namesize characters
+ *   long and should have space for the name and the terminating null
+ *   character. The maximum length of the terminal name shall be
+ *   {TTY_NAME_MAX}.
+ *
+ * Input Parameters:
+ *   fd - The 'fd' argument is an open file descriptor associated with
+ *        a terminal.
+ *   buf - Caller provided buffer to hold tty name.
+ *   buflen - The size of the caller-provided buffer.
+ *
+ * Returned Value:
+ *   If successful, the ttyname_r() function shall return zero.
+ *   Otherwise, an error number shall be returned to indicate the error.
+ *
+ ****************************************************************************/
+
+int ttyname_r(int fd, FAR char *buf, size_t buflen)

Review comment:
       Done.

##########
File path: include/nuttx/fs/ioctl.h
##########
@@ -180,6 +180,9 @@
 #define FIONCLEX        _FIOC(0x000e)     /* IN:  None
                                            * OUT: None
                                            */
+#define FIOC_FILEPATH   _FIOC(0x0004)     /* IN:  FAR char *(length >= PATH_MAX)

Review comment:
       Done.




-- 
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: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-nuttx] gustavonihei commented on a change in pull request #4109: libc: Implement ttyname and ttyname_r

Posted by GitBox <gi...@apache.org>.
gustavonihei commented on a change in pull request #4109:
URL: https://github.com/apache/incubator-nuttx/pull/4109#discussion_r667171596



##########
File path: libs/libc/termios/lib_ttyname.c
##########
@@ -0,0 +1,65 @@
+/****************************************************************************
+ * libs/libc/termios/lib_ttyname.c
+ *
+ * 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 <limits.h>
+#include <unistd.h>
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: ttyname
+ *
+ * Description:
+ *   The ttyname() function shall return a pointer to a string containing
+ *   a null-terminated pathname of the terminal associated with file
+ *   descriptor fildes. The application shall not modify the string returned.
+ *   The returned pointer might be invalidated or the string content might
+ *   be overwritten by a subsequent call to ttyname(). The returned pointer
+ *   and the string content might also be invalidated if the calling thread
+ *   is terminated.
+ *
+ * Input Parameters:
+ *   fd - The 'fd' argument is an open file descriptor associated with
+ *        a terminal.
+ *
+ * Returned Value:
+ *   Upon successful completion, ttyname() shall return a pointer to
+ *   a string. Otherwise, a null pointer shall be returned and errno
+ *   set to indicate the error.
+ *
+ ****************************************************************************/
+
+FAR char *ttyname(int fd)

Review comment:
       For POSIX standard compliance, `ttyname` should set `errno` with the error code returned from `ttyname_r`.




-- 
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: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-nuttx] gustavonihei commented on a change in pull request #4109: libc: Implement ttyname and ttyname_r

Posted by GitBox <gi...@apache.org>.
gustavonihei commented on a change in pull request #4109:
URL: https://github.com/apache/incubator-nuttx/pull/4109#discussion_r667171596



##########
File path: libs/libc/termios/lib_ttyname.c
##########
@@ -0,0 +1,65 @@
+/****************************************************************************
+ * libs/libc/termios/lib_ttyname.c
+ *
+ * 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 <limits.h>
+#include <unistd.h>
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: ttyname
+ *
+ * Description:
+ *   The ttyname() function shall return a pointer to a string containing
+ *   a null-terminated pathname of the terminal associated with file
+ *   descriptor fildes. The application shall not modify the string returned.
+ *   The returned pointer might be invalidated or the string content might
+ *   be overwritten by a subsequent call to ttyname(). The returned pointer
+ *   and the string content might also be invalidated if the calling thread
+ *   is terminated.
+ *
+ * Input Parameters:
+ *   fd - The 'fd' argument is an open file descriptor associated with
+ *        a terminal.
+ *
+ * Returned Value:
+ *   Upon successful completion, ttyname() shall return a pointer to
+ *   a string. Otherwise, a null pointer shall be returned and errno
+ *   set to indicate the error.
+ *
+ ****************************************************************************/
+
+FAR char *ttyname(int fd)

Review comment:
       `ttyname` should set `errno` with the error code returned from `ttyname_r`.




-- 
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: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-nuttx] xiaoxiang781216 commented on a change in pull request #4109: libc: Implement ttyname and ttyname_r

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on a change in pull request #4109:
URL: https://github.com/apache/incubator-nuttx/pull/4109#discussion_r667132654



##########
File path: include/fcntl.h
##########
@@ -95,6 +95,7 @@
 #define F_SETLKW    12 /* Like F_SETLK, but wait for lock to become available */
 #define F_SETOWN    13 /* Set pid that will receive SIGIO and SIGURG signals for fd */
 #define F_SETSIG    14 /* Set the signal to be sent */
+#define F_GETPATH   15 /* Get the path of the file descriptor(macos) */

Review comment:
       F_GETPATH is BSD/macOS specific:
   https://lwn.net/Articles/277736/




-- 
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: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-nuttx] gustavonihei commented on a change in pull request #4109: libc: Implement ttyname and ttyname_r

Posted by GitBox <gi...@apache.org>.
gustavonihei commented on a change in pull request #4109:
URL: https://github.com/apache/incubator-nuttx/pull/4109#discussion_r667085150



##########
File path: fs/inode/fs_inodegetpath.c
##########
@@ -0,0 +1,72 @@
+/****************************************************************************
+ * fs/inode/fs_inodegetpath.c
+ *
+ * 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 <errno.h>
+#include <string.h>
+#include <nuttx/fs/fs.h>
+
+#include "inode/inode.h"
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: inode_getpath
+ *
+ * Description:
+ *   Given the full path from inode.
+ *
+ ****************************************************************************/
+
+int inode_getpath(FAR struct inode *node, FAR char *path)
+{
+  if (path == NULL)
+    {
+      return -EINVAL;
+    }
+  else if (node == NULL)
+    {
+      path[0] = '\0';
+      return OK;
+    }
+  else if (node->i_parent)

Review comment:
       ```suggestion
     else if (node->i_parent != NULL)
   ```




-- 
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: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-nuttx] xiaoxiang781216 commented on a change in pull request #4109: libc: Implement ttyname and ttyname_r

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on a change in pull request #4109:
URL: https://github.com/apache/incubator-nuttx/pull/4109#discussion_r667135609



##########
File path: fs/inode/fs_inodegetpath.c
##########
@@ -0,0 +1,72 @@
+/****************************************************************************
+ * fs/inode/fs_inodegetpath.c
+ *
+ * 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 <errno.h>
+#include <string.h>
+#include <nuttx/fs/fs.h>
+
+#include "inode/inode.h"
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: inode_getpath
+ *
+ * Description:
+ *   Given the full path from inode.
+ *
+ ****************************************************************************/
+
+int inode_getpath(FAR struct inode *node, FAR char *path)
+{
+  if (path == NULL)
+    {
+      return -EINVAL;
+    }
+  else if (node == NULL)
+    {
+      path[0] = '\0';
+      return OK;
+    }
+  else if (node->i_parent)
+    {
+      int ret = inode_getpath(node->i_parent, path);
+      if (ret < 0)
+        {
+          return ret;
+        }
+    }
+
+  strcat(path, node->i_name);
+  if (node->i_child)
+    {
+      strcat(path, "/");
+    }
+
+  return OK;
+}

Review comment:
       Yes, I consider this initially, but finally select the current form because:
   
   1. One function is more simpler than two function
   2. The recurse only happen for pseudo root file system which usually has the limited deepth(<=3).




-- 
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: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-nuttx] gustavonihei commented on a change in pull request #4109: libc: Implement ttyname and ttyname_r

Posted by GitBox <gi...@apache.org>.
gustavonihei commented on a change in pull request #4109:
URL: https://github.com/apache/incubator-nuttx/pull/4109#discussion_r667083787



##########
File path: include/fcntl.h
##########
@@ -95,6 +95,7 @@
 #define F_SETLKW    12 /* Like F_SETLK, but wait for lock to become available */
 #define F_SETOWN    13 /* Set pid that will receive SIGIO and SIGURG signals for fd */
 #define F_SETSIG    14 /* Set the signal to be sent */
+#define F_GETPATH   15 /* Get the path of the file descriptor(macos) */

Review comment:
       A curious question: why is `macos` stated in the description?




-- 
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: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-nuttx] gustavonihei commented on a change in pull request #4109: libc: Implement ttyname and ttyname_r

Posted by GitBox <gi...@apache.org>.
gustavonihei commented on a change in pull request #4109:
URL: https://github.com/apache/incubator-nuttx/pull/4109#discussion_r667091116



##########
File path: fs/inode/fs_inodegetpath.c
##########
@@ -0,0 +1,72 @@
+/****************************************************************************
+ * fs/inode/fs_inodegetpath.c
+ *
+ * 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 <errno.h>
+#include <string.h>
+#include <nuttx/fs/fs.h>
+
+#include "inode/inode.h"
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: inode_getpath
+ *
+ * Description:
+ *   Given the full path from inode.
+ *
+ ****************************************************************************/
+
+int inode_getpath(FAR struct inode *node, FAR char *path)
+{
+  if (path == NULL)
+    {
+      return -EINVAL;
+    }
+  else if (node == NULL)
+    {
+      path[0] = '\0';
+      return OK;
+    }
+  else if (node->i_parent)
+    {
+      int ret = inode_getpath(node->i_parent, path);
+      if (ret < 0)
+        {
+          return ret;
+        }
+    }
+
+  strcat(path, node->i_name);
+  if (node->i_child)
+    {
+      strcat(path, "/");
+    }
+
+  return OK;
+}

Review comment:
       This might be a small optimization, since there is no need for NULL-checking `path` more than once.
   
   ```c
   static int inode_getpathrecurse(FAR struct inode *node, FAR char *path)
   {
     if (node == NULL)
       {
         path[0] = '\0';
         return OK;
       }
     else if (node->i_parent)
       {
         int ret = inode_getpathrecurse(node->i_parent, path);
         if (ret < 0)
           {
             return ret;
           }
       }
   
     strcat(path, node->i_name);
     if (node->i_child)
       {
         strcat(path, "/");
       }
   
     return OK;
   }
   
   int inode_getpath(FAR struct inode *node, FAR char *path)
   {
     if (path == NULL)
       {
         return -EINVAL;
       }
   
     return inode_getpath_recurse(node, 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: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-nuttx] xiaoxiang781216 commented on a change in pull request #4109: libc: Implement ttyname and ttyname_r

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on a change in pull request #4109:
URL: https://github.com/apache/incubator-nuttx/pull/4109#discussion_r667136724



##########
File path: fs/inode/fs_inodegetpath.c
##########
@@ -0,0 +1,72 @@
+/****************************************************************************
+ * fs/inode/fs_inodegetpath.c
+ *
+ * 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 <errno.h>
+#include <string.h>
+#include <nuttx/fs/fs.h>
+
+#include "inode/inode.h"
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: inode_getpath
+ *
+ * Description:
+ *   Given the full path from inode.
+ *
+ ****************************************************************************/
+
+int inode_getpath(FAR struct inode *node, FAR char *path)
+{
+  if (path == NULL)
+    {
+      return -EINVAL;
+    }
+  else if (node == NULL)
+    {
+      path[0] = '\0';
+      return OK;
+    }
+  else if (node->i_parent)

Review comment:
       Done.




-- 
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: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-nuttx] xiaoxiang781216 commented on a change in pull request #4109: libc: Implement ttyname and ttyname_r

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on a change in pull request #4109:
URL: https://github.com/apache/incubator-nuttx/pull/4109#discussion_r667192171



##########
File path: libs/libc/termios/lib_ttyname.c
##########
@@ -0,0 +1,65 @@
+/****************************************************************************
+ * libs/libc/termios/lib_ttyname.c
+ *
+ * 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 <limits.h>
+#include <unistd.h>
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: ttyname
+ *
+ * Description:
+ *   The ttyname() function shall return a pointer to a string containing
+ *   a null-terminated pathname of the terminal associated with file
+ *   descriptor fildes. The application shall not modify the string returned.
+ *   The returned pointer might be invalidated or the string content might
+ *   be overwritten by a subsequent call to ttyname(). The returned pointer
+ *   and the string content might also be invalidated if the calling thread
+ *   is terminated.
+ *
+ * Input Parameters:
+ *   fd - The 'fd' argument is an open file descriptor associated with
+ *        a terminal.
+ *
+ * Returned Value:
+ *   Upon successful completion, ttyname() shall return a pointer to
+ *   a string. Otherwise, a null pointer shall be returned and errno
+ *   set to indicate the error.
+ *
+ ****************************************************************************/
+
+FAR char *ttyname(int fd)

Review comment:
       Done.




-- 
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: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-nuttx] gustavonihei merged pull request #4109: libc: Implement ttyname and ttyname_r

Posted by GitBox <gi...@apache.org>.
gustavonihei merged pull request #4109:
URL: https://github.com/apache/incubator-nuttx/pull/4109


   


-- 
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: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-nuttx] gustavonihei commented on a change in pull request #4109: libc: Implement ttyname and ttyname_r

Posted by GitBox <gi...@apache.org>.
gustavonihei commented on a change in pull request #4109:
URL: https://github.com/apache/incubator-nuttx/pull/4109#discussion_r667171365



##########
File path: libs/libc/termios/lib_ttynamer.c
##########
@@ -0,0 +1,87 @@
+/****************************************************************************
+ * libs/libc/termios/lib_ttynamer.c
+ *
+ * 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 <errno.h>
+#include <fcntl.h>
+#include <string.h>
+#include <unistd.h>
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: ttyname_r
+ *
+ * Description:
+ *   The ttyname_r() function shall store the null-terminated pathname of
+ *   the terminal associated with the file descriptor fildes in the
+ *   character array referenced by name. The array is namesize characters
+ *   long and should have space for the name and the terminating null
+ *   character. The maximum length of the terminal name shall be
+ *   {TTY_NAME_MAX}.
+ *
+ * Input Parameters:
+ *   fd - The 'fd' argument is an open file descriptor associated with
+ *        a terminal.
+ *   buf - Caller provided buffer to hold tty name.
+ *   buflen - The size of the caller-provided buffer.
+ *
+ * Returned Value:
+ *   If successful, the ttyname_r() function shall return zero.
+ *   Otherwise, an error number shall be returned to indicate the error.
+ *
+ ****************************************************************************/
+
+int ttyname_r(int fd, FAR char *buf, size_t buflen)

Review comment:
       Instead of setting `errno`, `ttyname_r` should return the error code.




-- 
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: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org