You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by ag...@apache.org on 2021/01/11 22:48:09 UTC

[incubator-nuttx] 02/02: fs: Remove file_detach since it is unefficient to call open and file_detach

This is an automated email from the ASF dual-hosted git repository.

aguettouche pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git

commit 1604fe0b4b52e823fd1514e44e9086209facb5f5
Author: Xiang Xiao <xi...@xiaomi.com>
AuthorDate: Sun Jan 3 02:35:06 2021 +0800

    fs: Remove file_detach since it is unefficient to call open and file_detach
    
    the kernel user should call file_open directly instead
    
    Signed-off-by: Xiang Xiao <xi...@xiaomi.com>
    Change-Id: I5bf7f661006f5d43739bc8618abfb4b983fde78d
---
 fs/inode/Make.defs       |   1 -
 fs/inode/fs_filedetach.c | 147 -----------------------------------------------
 fs/vfs/fs_close.c        |   5 +-
 include/nuttx/fs/fs.h    |  31 +---------
 4 files changed, 4 insertions(+), 180 deletions(-)

diff --git a/fs/inode/Make.defs b/fs/inode/Make.defs
index d019c5c..67c4549 100644
--- a/fs/inode/Make.defs
+++ b/fs/inode/Make.defs
@@ -36,7 +36,6 @@
 CSRCS += fs_files.c fs_foreachinode.c fs_inode.c fs_inodeaddref.c
 CSRCS += fs_inodebasename.c fs_inodefind.c fs_inodefree.c fs_inoderelease.c
 CSRCS += fs_inoderemove.c fs_inodereserve.c fs_inodesearch.c
-CSRCS += fs_filedetach.c
 
 # Include inode/utils build support
 
diff --git a/fs/inode/fs_filedetach.c b/fs/inode/fs_filedetach.c
deleted file mode 100644
index 227f97b..0000000
--- a/fs/inode/fs_filedetach.c
+++ /dev/null
@@ -1,147 +0,0 @@
-/****************************************************************************
- * fs/inode/fs_filedetach.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 <assert.h>
-#include <errno.h>
-
-#include <nuttx/sched.h>
-#include <nuttx/fs/fs.h>
-#include <nuttx/semaphore.h>
-
-#include "inode/inode.h"
-
-/****************************************************************************
- * Private Functions
- ****************************************************************************/
-
-/****************************************************************************
- * Name: _files_semtake
- ****************************************************************************/
-
-static inline int _files_semtake(FAR struct filelist *list)
-{
-  return nxsem_wait_uninterruptible(&list->fl_sem);
-}
-
-/****************************************************************************
- * Name: _files_semgive
- ****************************************************************************/
-
-#define _files_semgive(list) nxsem_post(&list->fl_sem)
-
-/****************************************************************************
- * Public Functions
- ****************************************************************************/
-
-/****************************************************************************
- * Name: file_detach
- *
- * Description:
- *   This function is used in device drivers to create a task-independent
- *   handle to an entity in the file system.  file_detach() duplicates the
- *   'struct file' that underlies the file descriptor, then closes the file
- *   descriptor.
- *
- *   This function will fail if fd is not a valid file descriptor.  In
- *   particular, it will fail if fd is a socket descriptor.
- *
- * Input Parameters:
- *   fd    - The file descriptor to be detached.  This descriptor will be
- *           closed and invalid if the file was successfully detached.
- *   filep - A pointer to a user provided memory location in which to
- *           received the duplicated, detached file structure.
- *
- * Returned Value:
- *   Zero (OK) is returned on success; A negated errno value is returned on
- *   any failure to indicate the nature of the failure.
- *
- ****************************************************************************/
-
-int file_detach(int fd, FAR struct file *filep)
-{
-  FAR struct filelist *list;
-  FAR struct file *parent;
-  int ret;
-
-  DEBUGASSERT(filep != NULL);
-
-  /* Verify the file descriptor range */
-
-  if (fd < 0 || fd >= CONFIG_NFILE_DESCRIPTORS)
-    {
-      /* Not a file descriptor (might be a socket descriptor) */
-
-      return -EBADF;
-    }
-
-  /* Get the thread-specific file list.  It should never be NULL in this
-   * context.
-   */
-
-  list = nxsched_get_files();
-  DEBUGASSERT(list != NULL);
-
-  /* If the file was properly opened, there should be an inode assigned */
-
-  ret = _files_semtake(list);
-  if (ret < 0)
-    {
-      /* Probably canceled */
-
-      return ret;
-    }
-
-  parent = &list->fl_files[fd];
-  if (parent->f_inode == NULL)
-    {
-      /* File is not open */
-
-      _files_semgive(list);
-      return -EBADF;
-    }
-
-  /* Duplicate the 'struct file' content into the user-provided file
-   * structure.
-   */
-
-  filep->f_oflags  = parent->f_oflags;
-  filep->f_pos     = parent->f_pos;
-  filep->f_inode   = parent->f_inode;
-  filep->f_priv    = parent->f_priv;
-
-  /* Release the file descriptor *without* calling the driver close method
-   * and without decrementing the inode reference count.  That will be done
-   * in file_close().
-   */
-
-  parent->f_oflags = 0;
-  parent->f_pos    = 0;
-  parent->f_inode  = NULL;
-  parent->f_priv   = NULL;
-
-  _files_semgive(list);
-  return OK;
-}
diff --git a/fs/vfs/fs_close.c b/fs/vfs/fs_close.c
index 89c4fd8..4f7eec8 100644
--- a/fs/vfs/fs_close.c
+++ b/fs/vfs/fs_close.c
@@ -60,12 +60,11 @@
  * Name: file_close
  *
  * Description:
- *   Close a file that was previously opend with file_open() (or detached
- *   with file_detach()).
+ *   Close a file that was previously opened with file_open().
  *
  * Input Parameters:
  *   filep - A pointer to a user provided memory location containing the
- *           open file data returned by file_detach().
+ *           open file data returned by file_open().
  *
  * Returned Value:
  *   Zero (OK) is returned on success; A negated errno value is returned on
diff --git a/include/nuttx/fs/fs.h b/include/nuttx/fs/fs.h
index e69c8e2..cc8b3ca 100644
--- a/include/nuttx/fs/fs.h
+++ b/include/nuttx/fs/fs.h
@@ -882,41 +882,14 @@ int nx_open(FAR const char *path, int oflags, ...);
 int fs_getfilep(int fd, FAR struct file **filep);
 
 /****************************************************************************
- * Name: file_detach
- *
- * Description:
- *   This function is used to device drivers to create a task-independent
- *   handle to an entity in the file system.  file_detach() duplicates the
- *   'struct file' that underlies the file descriptor, then closes the file
- *   descriptor.
- *
- *   This function will fail if fd is not a valid file descriptor.  In
- *   particular, it will fail if fd is a socket descriptor.
- *
- * Input Parameters:
- *   fd    - The file descriptor to be detached.  This descriptor will be
- *           closed and invalid if the file was successfully detached.
- *   filep - A pointer to a user provided memory location in which to
- *           received the duplicated, detached file structure.
- *
- * Returned Value:
- *   Zero (OK) is returned on success; A negated errno value is returned on
- *   any failure to indicate the nature of the failure.
- *
- ****************************************************************************/
-
-int file_detach(int fd, FAR struct file *filep);
-
-/****************************************************************************
  * Name: file_close
  *
  * Description:
- *   Close a file that was previously opened with file_open() (or detached
- *   with file_detach()).
+ *   Close a file that was previously opened with file_open().
  *
  * Input Parameters:
  *   filep - A pointer to a user provided memory location containing the
- *           open file data returned by file_detach().
+ *           open file data returned by file_open().
  *
  * Returned Value:
  *   Zero (OK) is returned on success; A negated errno value is returned on