2008-07-31 02:28:24 +02:00
|
|
|
/****************************************************************************
|
2014-09-28 19:06:21 +02:00
|
|
|
* fs/inode/fs_files.c
|
2007-02-18 00:21:28 +01:00
|
|
|
*
|
2020-03-30 01:36:19 +02:00
|
|
|
* 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
|
2007-02-18 00:21:28 +01:00
|
|
|
*
|
2020-03-30 01:36:19 +02:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2007-02-18 00:21:28 +01:00
|
|
|
*
|
2020-03-30 01:36:19 +02:00
|
|
|
* 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.
|
2007-02-18 00:21:28 +01:00
|
|
|
*
|
2008-07-31 02:28:24 +02:00
|
|
|
****************************************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2008-07-31 02:28:24 +02:00
|
|
|
/****************************************************************************
|
2007-02-18 00:21:28 +01:00
|
|
|
* Included Files
|
2008-07-31 02:28:24 +02:00
|
|
|
****************************************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
2009-12-15 01:18:32 +01:00
|
|
|
|
|
|
|
#include <sys/types.h>
|
2007-02-18 00:21:28 +01:00
|
|
|
#include <string.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <sched.h>
|
|
|
|
#include <errno.h>
|
2011-04-03 22:41:49 +02:00
|
|
|
|
2012-03-21 19:01:07 +01:00
|
|
|
#include <nuttx/fs/fs.h>
|
2007-02-18 00:21:28 +01:00
|
|
|
#include <nuttx/kmalloc.h>
|
2020-02-01 08:17:32 +01:00
|
|
|
#include <nuttx/semaphore.h>
|
2009-12-15 01:18:32 +01:00
|
|
|
|
2014-09-29 15:14:38 +02:00
|
|
|
#include "inode/inode.h"
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2008-07-31 02:28:24 +02:00
|
|
|
/****************************************************************************
|
2007-02-18 00:21:28 +01:00
|
|
|
* Private Functions
|
2008-07-31 02:28:24 +02:00
|
|
|
****************************************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2008-08-01 02:22:09 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: _files_semtake
|
|
|
|
****************************************************************************/
|
2012-02-01 00:39:12 +01:00
|
|
|
|
2020-03-30 01:36:19 +02:00
|
|
|
static int _files_semtake(FAR struct filelist *list)
|
2007-02-18 00:21:28 +01:00
|
|
|
{
|
2020-03-30 01:36:19 +02:00
|
|
|
return nxsem_wait_uninterruptible(&list->fl_sem);
|
2007-02-18 00:21:28 +01:00
|
|
|
}
|
|
|
|
|
2008-08-01 02:22:09 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: _files_semgive
|
|
|
|
****************************************************************************/
|
2012-02-01 00:39:12 +01:00
|
|
|
|
2017-10-03 23:35:24 +02:00
|
|
|
#define _files_semgive(list) nxsem_post(&list->fl_sem)
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2008-08-01 03:59:11 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: _files_close
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Close an inode (if open)
|
|
|
|
*
|
2020-02-23 09:50:23 +01:00
|
|
|
* Assumptions:
|
2020-03-30 01:36:19 +02:00
|
|
|
* Caller holds the list semaphore because the file descriptor will be
|
|
|
|
* freed.
|
2008-08-01 03:59:11 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
2012-02-01 00:39:12 +01:00
|
|
|
|
2008-08-01 03:59:11 +02:00
|
|
|
static int _files_close(FAR struct file *filep)
|
|
|
|
{
|
|
|
|
struct inode *inode = filep->f_inode;
|
|
|
|
int ret = OK;
|
|
|
|
|
|
|
|
/* Check if the struct file is open (i.e., assigned an inode) */
|
|
|
|
|
|
|
|
if (inode)
|
|
|
|
{
|
|
|
|
/* Close the file, driver, or mountpoint. */
|
|
|
|
|
|
|
|
if (inode->u.i_ops && inode->u.i_ops->close)
|
|
|
|
{
|
|
|
|
/* Perform the close operation */
|
|
|
|
|
|
|
|
ret = inode->u.i_ops->close(filep);
|
|
|
|
}
|
|
|
|
|
2012-07-14 23:05:40 +02:00
|
|
|
/* And release the inode */
|
2008-08-01 03:59:11 +02:00
|
|
|
|
2012-07-14 23:05:40 +02:00
|
|
|
inode_release(inode);
|
2008-08-01 03:59:11 +02:00
|
|
|
|
2012-07-14 23:05:40 +02:00
|
|
|
/* Release the file descriptor */
|
2008-08-01 03:59:11 +02:00
|
|
|
|
2012-07-14 23:05:40 +02:00
|
|
|
filep->f_oflags = 0;
|
|
|
|
filep->f_pos = 0;
|
|
|
|
filep->f_inode = NULL;
|
2008-08-01 03:59:11 +02:00
|
|
|
}
|
2012-07-14 23:05:40 +02:00
|
|
|
|
2008-08-01 03:59:11 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2008-07-31 02:28:24 +02:00
|
|
|
/****************************************************************************
|
2008-08-01 02:22:09 +02:00
|
|
|
* Public Functions
|
2008-07-31 02:28:24 +02:00
|
|
|
****************************************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2008-08-01 02:22:09 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: files_initialize
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* This is called from the FS initialization logic to configure the files.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
2012-02-01 00:39:12 +01:00
|
|
|
|
2007-02-18 00:21:28 +01:00
|
|
|
void files_initialize(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2008-08-01 02:22:09 +02:00
|
|
|
/****************************************************************************
|
2013-01-26 21:17:29 +01:00
|
|
|
* Name: files_initlist
|
2008-08-01 02:22:09 +02:00
|
|
|
*
|
2013-01-26 21:17:29 +01:00
|
|
|
* Description: Initializes the list of files for a new task
|
2008-08-01 02:22:09 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
2012-02-01 00:39:12 +01:00
|
|
|
|
2013-01-26 21:17:29 +01:00
|
|
|
void files_initlist(FAR struct filelist *list)
|
2007-02-18 00:21:28 +01:00
|
|
|
{
|
2013-01-26 21:17:29 +01:00
|
|
|
DEBUGASSERT(list);
|
2012-07-14 23:05:40 +02:00
|
|
|
|
2013-01-26 21:17:29 +01:00
|
|
|
/* Initialize the list access mutex */
|
2012-07-14 23:05:40 +02:00
|
|
|
|
2020-01-02 17:49:34 +01:00
|
|
|
nxsem_init(&list->fl_sem, 0, 1);
|
2007-02-18 00:21:28 +01:00
|
|
|
}
|
|
|
|
|
2008-08-01 02:22:09 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: files_releaselist
|
|
|
|
*
|
2012-08-03 21:11:11 +02:00
|
|
|
* Description:
|
|
|
|
* Release a reference to the file list
|
2008-08-01 02:22:09 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
2009-09-16 22:25:16 +02:00
|
|
|
|
2013-01-26 21:17:29 +01:00
|
|
|
void files_releaselist(FAR struct filelist *list)
|
2007-02-18 00:21:28 +01:00
|
|
|
{
|
2013-01-26 21:17:29 +01:00
|
|
|
int i;
|
2012-07-14 23:05:40 +02:00
|
|
|
|
2013-01-26 21:17:29 +01:00
|
|
|
DEBUGASSERT(list);
|
2012-07-14 23:05:40 +02:00
|
|
|
|
2013-01-26 21:17:29 +01:00
|
|
|
/* Close each file descriptor .. Normally, you would need take the list
|
2020-03-30 01:36:19 +02:00
|
|
|
* semaphore, but it is safe to ignore the semaphore in this context
|
|
|
|
* because there should not be any references in this context.
|
2013-01-26 21:17:29 +01:00
|
|
|
*/
|
2012-07-14 23:05:40 +02:00
|
|
|
|
2013-01-26 21:17:29 +01:00
|
|
|
for (i = 0; i < CONFIG_NFILE_DESCRIPTORS; i++)
|
|
|
|
{
|
2020-01-02 17:49:34 +01:00
|
|
|
_files_close(&list->fl_files[i]);
|
2007-02-18 00:21:28 +01:00
|
|
|
}
|
2012-07-14 23:05:40 +02:00
|
|
|
|
2013-01-26 21:17:29 +01:00
|
|
|
/* Destroy the semaphore */
|
|
|
|
|
2020-01-02 17:49:34 +01:00
|
|
|
nxsem_destroy(&list->fl_sem);
|
2007-02-18 00:21:28 +01:00
|
|
|
}
|
|
|
|
|
2008-08-01 02:22:09 +02:00
|
|
|
/****************************************************************************
|
2014-10-06 18:53:25 +02:00
|
|
|
* Name: file_dup2
|
2008-08-01 02:22:09 +02:00
|
|
|
*
|
|
|
|
* Description:
|
2012-08-03 21:11:11 +02:00
|
|
|
* Assign an inode to a specific files structure. This is the heart of
|
|
|
|
* dup2.
|
2008-08-01 02:22:09 +02:00
|
|
|
*
|
2017-09-30 18:41:21 +02:00
|
|
|
* Equivalent to the non-standard fs_dupfd2() function except that it
|
|
|
|
* accepts struct file instances instead of file descriptors and it does
|
|
|
|
* not set the errno variable.
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* Zero (OK) is returned on success; a negated errno value is return on
|
|
|
|
* any failure.
|
|
|
|
*
|
2008-08-01 02:22:09 +02:00
|
|
|
****************************************************************************/
|
2012-02-01 00:39:12 +01:00
|
|
|
|
2014-10-06 18:53:25 +02:00
|
|
|
int file_dup2(FAR struct file *filep1, FAR struct file *filep2)
|
2007-02-18 00:21:28 +01:00
|
|
|
{
|
2007-02-27 22:17:21 +01:00
|
|
|
FAR struct filelist *list;
|
2008-07-31 02:28:24 +02:00
|
|
|
FAR struct inode *inode;
|
|
|
|
int ret;
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2020-03-30 01:36:19 +02:00
|
|
|
if (filep1 == NULL || filep1->f_inode == NULL || filep2 == NULL)
|
2007-02-18 00:21:28 +01:00
|
|
|
{
|
2017-09-30 18:41:21 +02:00
|
|
|
return -EBADF;
|
2007-02-18 00:21:28 +01:00
|
|
|
}
|
|
|
|
|
2020-05-09 16:04:45 +02:00
|
|
|
list = nxsched_get_files();
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2016-04-14 18:14:38 +02:00
|
|
|
/* The file list can be NULL under two cases: (1) One is an obscure
|
|
|
|
* cornercase: When memory management debug output is enabled. Then
|
|
|
|
* there may be attempts to write to stdout from malloc before the group
|
|
|
|
* data has been allocated. The other other is (2) if this is a kernel
|
|
|
|
* thread. Kernel threads have no allocated file descriptors.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (list != NULL)
|
|
|
|
{
|
2020-03-30 01:36:19 +02:00
|
|
|
ret = _files_semtake(list);
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
/* Probably canceled */
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
2016-04-14 18:14:38 +02:00
|
|
|
}
|
2007-02-18 00:21:28 +01:00
|
|
|
|
|
|
|
/* If there is already an inode contained in the new file structure,
|
2008-07-31 02:28:24 +02:00
|
|
|
* close the file and release the inode.
|
2007-02-18 00:21:28 +01:00
|
|
|
*/
|
|
|
|
|
2008-08-01 03:59:11 +02:00
|
|
|
ret = _files_close(filep2);
|
2008-08-01 02:22:09 +02:00
|
|
|
if (ret < 0)
|
2007-02-18 00:21:28 +01:00
|
|
|
{
|
2008-08-01 02:22:09 +02:00
|
|
|
/* An error occurred while closing the driver */
|
2008-07-31 02:28:24 +02:00
|
|
|
|
2017-09-30 18:41:21 +02:00
|
|
|
goto errout_with_sem;
|
2007-02-18 00:21:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Increment the reference count on the contained inode */
|
|
|
|
|
2008-07-31 02:28:24 +02:00
|
|
|
inode = filep1->f_inode;
|
2020-03-30 01:36:19 +02:00
|
|
|
ret = inode_addref(inode);
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
goto errout_with_sem;
|
|
|
|
}
|
2007-02-18 00:21:28 +01:00
|
|
|
|
|
|
|
/* Then clone the file structure */
|
|
|
|
|
|
|
|
filep2->f_oflags = filep1->f_oflags;
|
|
|
|
filep2->f_pos = filep1->f_pos;
|
2008-07-31 02:28:24 +02:00
|
|
|
filep2->f_inode = inode;
|
|
|
|
|
|
|
|
/* Call the open method on the file, driver, mountpoint so that it
|
|
|
|
* can maintain the correct open counts.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (inode->u.i_ops && inode->u.i_ops->open)
|
|
|
|
{
|
|
|
|
#ifndef CONFIG_DISABLE_MOUNTPOINT
|
|
|
|
if (INODE_IS_MOUNTPT(inode))
|
|
|
|
{
|
2019-10-27 18:48:14 +01:00
|
|
|
/* Dup the open file on the in the new file structure */
|
2008-07-31 02:28:24 +02:00
|
|
|
|
2013-01-14 16:42:03 +01:00
|
|
|
ret = inode->u.i_mops->dup(filep1, filep2);
|
2008-07-31 02:28:24 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
{
|
2013-01-14 16:42:03 +01:00
|
|
|
/* (Re-)open the pseudo file or device driver */
|
2008-07-31 02:28:24 +02:00
|
|
|
|
|
|
|
ret = inode->u.i_ops->open(filep2);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Handle open failures */
|
|
|
|
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
goto errout_with_inode;
|
|
|
|
}
|
|
|
|
}
|
2012-08-02 19:09:25 +02:00
|
|
|
|
2016-04-14 18:14:38 +02:00
|
|
|
if (list != NULL)
|
|
|
|
{
|
|
|
|
_files_semgive(list);
|
|
|
|
}
|
|
|
|
|
2007-02-18 00:21:28 +01:00
|
|
|
return OK;
|
2008-07-31 02:28:24 +02:00
|
|
|
|
2019-10-27 18:48:14 +01:00
|
|
|
/* Handle various error conditions */
|
2008-07-31 02:28:24 +02:00
|
|
|
|
|
|
|
errout_with_inode:
|
2019-10-27 18:48:14 +01:00
|
|
|
|
2008-07-31 02:28:24 +02:00
|
|
|
inode_release(filep2->f_inode);
|
|
|
|
filep2->f_oflags = 0;
|
|
|
|
filep2->f_pos = 0;
|
|
|
|
filep2->f_inode = NULL;
|
2012-08-02 19:09:25 +02:00
|
|
|
|
2017-09-30 18:41:21 +02:00
|
|
|
errout_with_sem:
|
2016-04-14 18:14:38 +02:00
|
|
|
if (list != NULL)
|
|
|
|
{
|
|
|
|
_files_semgive(list);
|
|
|
|
}
|
2012-08-02 19:09:25 +02:00
|
|
|
|
2017-09-30 18:41:21 +02:00
|
|
|
return ret;
|
2007-02-18 00:21:28 +01:00
|
|
|
}
|
|
|
|
|
2008-08-01 02:22:09 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: files_allocate
|
|
|
|
*
|
|
|
|
* Description:
|
2020-03-30 01:36:19 +02:00
|
|
|
* Allocate a struct files instance and associate it with an inode
|
|
|
|
* instance. Returns the file descriptor == index into the files array.
|
2008-08-01 02:22:09 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
2009-07-19 02:14:46 +02:00
|
|
|
|
|
|
|
int files_allocate(FAR struct inode *inode, int oflags, off_t pos, int minfd)
|
2007-02-18 00:21:28 +01:00
|
|
|
{
|
2007-02-27 22:17:21 +01:00
|
|
|
FAR struct filelist *list;
|
2020-03-30 01:36:19 +02:00
|
|
|
int ret;
|
2007-02-18 00:21:28 +01:00
|
|
|
int i;
|
|
|
|
|
2016-04-14 18:14:38 +02:00
|
|
|
/* Get the file descriptor list. It should not be NULL in this context. */
|
|
|
|
|
2020-05-09 16:04:45 +02:00
|
|
|
list = nxsched_get_files();
|
2016-04-14 18:14:38 +02:00
|
|
|
DEBUGASSERT(list != NULL);
|
2013-09-28 22:47:49 +02:00
|
|
|
|
2020-03-30 01:36:19 +02:00
|
|
|
ret = _files_semtake(list);
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
/* Probably canceled */
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-09-28 22:47:49 +02:00
|
|
|
for (i = minfd; i < CONFIG_NFILE_DESCRIPTORS; i++)
|
2007-02-18 00:21:28 +01:00
|
|
|
{
|
2013-09-28 22:47:49 +02:00
|
|
|
if (!list->fl_files[i].f_inode)
|
2007-02-27 22:17:21 +01:00
|
|
|
{
|
2019-10-27 18:48:14 +01:00
|
|
|
list->fl_files[i].f_oflags = oflags;
|
|
|
|
list->fl_files[i].f_pos = pos;
|
|
|
|
list->fl_files[i].f_inode = inode;
|
|
|
|
list->fl_files[i].f_priv = NULL;
|
|
|
|
_files_semgive(list);
|
|
|
|
return i;
|
2007-02-27 22:17:21 +01:00
|
|
|
}
|
|
|
|
}
|
2012-08-02 19:09:25 +02:00
|
|
|
|
2013-09-28 22:47:49 +02:00
|
|
|
_files_semgive(list);
|
2007-02-18 00:21:28 +01:00
|
|
|
return ERROR;
|
|
|
|
}
|
|
|
|
|
2008-08-01 03:59:11 +02:00
|
|
|
/****************************************************************************
|
2012-08-04 00:04:14 +02:00
|
|
|
* Name: files_close
|
2008-08-01 03:59:11 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Close an inode (if open)
|
|
|
|
*
|
2020-02-23 09:50:23 +01:00
|
|
|
* Assumptions:
|
2020-03-30 01:36:19 +02:00
|
|
|
* Caller holds the list semaphore because the file descriptor will be
|
|
|
|
* freed.
|
2008-08-01 03:59:11 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
2012-02-01 00:39:12 +01:00
|
|
|
|
2013-09-29 00:50:07 +02:00
|
|
|
int files_close(int fd)
|
2008-08-01 03:59:11 +02:00
|
|
|
{
|
2012-02-01 00:39:12 +01:00
|
|
|
FAR struct filelist *list;
|
|
|
|
int ret;
|
2008-08-01 04:17:32 +02:00
|
|
|
|
2016-04-14 18:14:38 +02:00
|
|
|
/* Get the thread-specific file list. It should never be NULL in this
|
|
|
|
* context.
|
|
|
|
*/
|
2008-08-01 03:59:11 +02:00
|
|
|
|
2020-05-09 16:04:45 +02:00
|
|
|
list = nxsched_get_files();
|
2016-04-14 18:14:38 +02:00
|
|
|
DEBUGASSERT(list != NULL);
|
2008-08-01 04:17:32 +02:00
|
|
|
|
|
|
|
/* If the file was properly opened, there should be an inode assigned */
|
|
|
|
|
2020-03-30 01:36:19 +02:00
|
|
|
if (fd < 0 || fd >= CONFIG_NFILE_DESCRIPTORS ||
|
|
|
|
!list->fl_files[fd].f_inode)
|
2016-05-26 17:41:50 +02:00
|
|
|
{
|
|
|
|
return -EBADF;
|
|
|
|
}
|
2008-08-01 04:17:32 +02:00
|
|
|
|
2012-02-01 00:39:12 +01:00
|
|
|
/* Perform the protected close operation */
|
2008-08-01 04:17:32 +02:00
|
|
|
|
2020-03-30 01:36:19 +02:00
|
|
|
ret = _files_semtake(list);
|
|
|
|
if (ret >= 0)
|
|
|
|
{
|
|
|
|
ret = _files_close(&list->fl_files[fd]);
|
|
|
|
_files_semgive(list);
|
|
|
|
}
|
|
|
|
|
2012-02-01 00:39:12 +01:00
|
|
|
return ret;
|
2008-08-01 03:59:11 +02:00
|
|
|
}
|
|
|
|
|
2008-08-01 02:22:09 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: files_release
|
2008-08-01 03:59:11 +02:00
|
|
|
*
|
2020-02-23 09:50:23 +01:00
|
|
|
* Assumptions:
|
2008-08-01 03:59:11 +02:00
|
|
|
* Similar to files_close(). Called only from open() logic on error
|
|
|
|
* conditions.
|
|
|
|
*
|
2008-08-01 02:22:09 +02:00
|
|
|
****************************************************************************/
|
2012-02-01 00:39:12 +01:00
|
|
|
|
2013-09-29 00:50:07 +02:00
|
|
|
void files_release(int fd)
|
2007-02-18 00:21:28 +01:00
|
|
|
{
|
2007-02-27 22:17:21 +01:00
|
|
|
FAR struct filelist *list;
|
2020-03-30 01:36:19 +02:00
|
|
|
int ret;
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2020-05-09 16:04:45 +02:00
|
|
|
list = nxsched_get_files();
|
2020-03-30 01:36:19 +02:00
|
|
|
DEBUGASSERT(list != NULL);
|
2013-09-28 22:47:49 +02:00
|
|
|
|
2015-10-11 19:39:29 +02:00
|
|
|
if (fd >= 0 && fd < CONFIG_NFILE_DESCRIPTORS)
|
2007-02-18 00:21:28 +01:00
|
|
|
{
|
2020-03-30 01:36:19 +02:00
|
|
|
ret = _files_semtake(list);
|
|
|
|
if (ret >= 0)
|
|
|
|
{
|
|
|
|
list->fl_files[fd].f_oflags = 0;
|
|
|
|
list->fl_files[fd].f_pos = 0;
|
|
|
|
list->fl_files[fd].f_inode = NULL;
|
|
|
|
_files_semgive(list);
|
|
|
|
}
|
2007-02-18 00:21:28 +01:00
|
|
|
}
|
|
|
|
}
|