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


##########
fs/inode/fs_files.c:
##########
@@ -858,6 +1026,342 @@ int fs_putfilep(FAR struct file *filep)
 }
 #endif
 
+/****************************************************************************
+ * Name: fs_setcloseonexec
+ *
+ * Description:
+ *   Given a file descriptor, set the close on exec flag.
+ *
+ * Input Parameters:
+ *   fd   - The file descriptor
+ *   flag - The close on exec flag
+ *
+ * Returned Value:
+ *   Zero (OK) is returned on success; a negated errno value is returned on
+ *   any failure.
+ *
+ ****************************************************************************/
+
+int fs_setcloseonexec(int fd, int flag)
+{
+  int i = fd / CONFIG_NFILE_DESCRIPTORS_PER_BLOCK;
+  int j = fd % CONFIG_NFILE_DESCRIPTORS_PER_BLOCK;
+  FAR struct fdlist *list;
+  irqstate_t flags;
+  int ret = OK;
+
+  list = nxsched_get_fdlist();
+
+  /* Perform some sanity checks */
+
+  if (fd < 0 || fd >= fdlist_count(list))
+    {
+      return -EBADF;
+    }
+
+  flags = spin_lock_irqsave_notrace(&list->fl_lock);
+
+  if (list->fl_fds[i][j].f_file == NULL)
+    {
+      ret = -EBADF;
+    }
+  else if (flag == FD_CLOEXEC)
+    {
+      list->fl_fds[i][j].f_cloexec = true;
+    }
+  else
+    {
+      list->fl_fds[i][j].f_cloexec = false;
+    }
+
+  spin_unlock_irqrestore_notrace(&list->fl_lock, flags);
+  return ret;
+}
+
+/****************************************************************************
+ * Name: fs_getcloseonexec
+ *
+ * Description:
+ *   Given a file descriptor, get the close on exec flag.
+ *
+ * Input Parameters:
+ *   fd   - The file descriptor
+ *
+ * Returned Value:
+ *   A non-negative value on success; A negated errno value is returned on
+ *   any failure to indicate the nature of the failure.
+ *
+ ****************************************************************************/
+
+int fs_getcloseonexec(int fd)
+{
+  int i = fd / CONFIG_NFILE_DESCRIPTORS_PER_BLOCK;
+  int j = fd % CONFIG_NFILE_DESCRIPTORS_PER_BLOCK;
+  FAR struct fdlist *list;
+  irqstate_t flags;
+  int ret;
+
+  list = nxsched_get_fdlist();
+
+  /* Perform some sanity checks */
+
+  if (fd < 0 || fd >= fdlist_count(list))
+    {
+      return -EBADF;
+    }
+
+  flags = spin_lock_irqsave_notrace(&list->fl_lock);
+
+  if (list->fl_fds[i][j].f_file == NULL)
+    {
+      ret = -EBADF;
+    }
+  else
+    {
+      ret = list->fl_fds[i][j].f_cloexec ? FD_CLOEXEC : 0;
+    }
+
+  spin_unlock_irqrestore_notrace(&list->fl_lock, flags);
+  return ret;
+}
+
+/****************************************************************************
+ * Name: nx_ioctl
+ *
+ * Description:
+ *   nx_ioctl() will perform the operation specified by 'cmd' on an open
+ *   file.
+ *
+ * Input Parameters:
+ *   fd  - File descriptor of the open file
+ *   cmd - Identifies the operation to be performed.  Command specific
+ *         arguments may follow.
+ *   arg - The argument.
+ *
+ * Returned Value:
+ *   A non-negative value is returned on success; a negated errno value is
+ *   returned on any failure.
+ *
+ ****************************************************************************/
+
+int nx_ioctl(int fd, int cmd, unsigned long arg)

Review Comment:
   why move nx_ioctl here, not fs_ioctl.c? it's better to expose one api which 
convert `fd` to `struct fd`



-- 
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-unsubscr...@nuttx.apache.org

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

Reply via email to