413 lines
14 KiB
C
413 lines
14 KiB
C
/****************************************************************************
|
|
* include/fs/file.h
|
|
*
|
|
* Copyright (C) 2007-2009, 2011-2013 Gregory Nutt. All rights reserved.
|
|
* Copyright (c) <2014-2015>, <Huawei Technologies Co., Ltd>
|
|
* All rights reserved.
|
|
*
|
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
|
*
|
|
* Redistribution and use in source and binary forms, with or without
|
|
* modification, are permitted provided that the following conditions
|
|
* are met:
|
|
*
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
* notice, this list of conditions and the following disclaimer.
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
* notice, this list of conditions and the following disclaimer in
|
|
* the documentation and/or other materials provided with the
|
|
* distribution.
|
|
* 3. Neither the name NuttX nor the names of its contributors may be
|
|
* used to endorse or promote products derived from this software
|
|
* without specific prior written permission.
|
|
*
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
|
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
|
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
|
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
|
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
*
|
|
****************************************************************************/
|
|
/****************************************************************************
|
|
* Notice of Export Control Law
|
|
* ===============================================
|
|
* Huawei LiteOS may be subject to applicable export control laws and regulations,
|
|
* which might include those applicable to Huawei LiteOS of U.S. and the country in
|
|
* which you are located.
|
|
* Import, export and usage of Huawei LiteOS in any manner by you shall be in
|
|
* compliance with such applicable export control laws and regulations.
|
|
****************************************************************************/
|
|
|
|
/**@defgroup fs Filesystem
|
|
*
|
|
*/
|
|
|
|
|
|
#ifndef __INCLUDE_FS_FILE_H
|
|
#define __INCLUDE_FS_FILE_H
|
|
|
|
/****************************************************************************
|
|
* Included Files
|
|
****************************************************************************/
|
|
|
|
#include "vfs_config.h"
|
|
#include "compiler.h"
|
|
|
|
#include "sys/types.h"
|
|
#include "stdarg.h"
|
|
#include "stdint.h"
|
|
|
|
#include "semaphore.h"
|
|
|
|
#ifdef __cplusplus
|
|
#if __cplusplus
|
|
extern "C" {
|
|
#endif /* __cplusplus */
|
|
#endif /* __cplusplus */
|
|
|
|
|
|
/****************************************************************************
|
|
* Global Function Prototypes
|
|
****************************************************************************/
|
|
|
|
struct filelist *sched_getfiles(void);
|
|
|
|
/* fs_inode.c ***************************************************************/
|
|
/****************************************************************************
|
|
* Name: fs_initialize
|
|
*
|
|
* Description:
|
|
* This is called from the OS initialization logic to configure the file
|
|
* system.
|
|
*
|
|
****************************************************************************/
|
|
|
|
void fs_initialize(void);
|
|
|
|
/* fs_files.c ***************************************************************/
|
|
/****************************************************************************
|
|
* Name: files_initlist
|
|
*
|
|
* Description:
|
|
* Initializes the list of files for a new task
|
|
*
|
|
****************************************************************************/
|
|
|
|
#if CONFIG_NFILE_DESCRIPTORS > 0
|
|
void files_initlist(FAR struct filelist *list);
|
|
#endif
|
|
|
|
/****************************************************************************
|
|
* Name: files_releaselist
|
|
*
|
|
* Description:
|
|
* Release a reference to the file list
|
|
*
|
|
****************************************************************************/
|
|
|
|
#if CONFIG_NFILE_DESCRIPTORS > 0
|
|
void files_releaselist(FAR struct filelist *list);
|
|
#endif
|
|
|
|
/****************************************************************************
|
|
* Name: file_dup2
|
|
*
|
|
* Description:
|
|
* Assign an inode to a specific files structure. This is the heart of
|
|
* dup2.
|
|
*
|
|
****************************************************************************/
|
|
|
|
#if CONFIG_NFILE_DESCRIPTORS > 0
|
|
int file_dup2(FAR struct file *filep1, FAR struct file *filep2);
|
|
#endif
|
|
|
|
/* fs_filedup.c *************************************************************/
|
|
/****************************************************************************
|
|
* Name: fs_dupfd OR dup
|
|
*
|
|
* Description:
|
|
* Clone a file descriptor 'fd' to an arbitray descriptor number (any value
|
|
* greater than or equal to 'minfd'). If socket descriptors are
|
|
* implemented, then this is called by dup() for the case of file
|
|
* descriptors. If socket descriptors are not implemented, then this
|
|
* function IS dup().
|
|
*
|
|
* This alternative naming is used when dup could operate on both file and
|
|
* socket descritors to avoid drawing unused socket support into the link.
|
|
*
|
|
****************************************************************************/
|
|
|
|
#if CONFIG_NFILE_DESCRIPTORS > 0
|
|
int fs_dupfd(int fd, int minfd);
|
|
#endif
|
|
|
|
/****************************************************************************
|
|
* Name: file_dup
|
|
*
|
|
* Description:
|
|
* Equivalent to the non-standard fs_dupfd() function except that it
|
|
* accepts a struct file instance instead of a file descriptor. Currently
|
|
* used only by file_vfcntl();
|
|
*
|
|
****************************************************************************/
|
|
|
|
int file_dup(FAR struct file *filep, int minfd);
|
|
|
|
/* fs_filedup2.c ************************************************************/
|
|
/****************************************************************************
|
|
* Name: fs_dupfd2 OR dup2
|
|
*
|
|
* Description:
|
|
* Clone a file descriptor to a specific descriptor number. If socket
|
|
* descriptors are implemented, then this is called by dup2() for the
|
|
* case of file descriptors. If socket descriptors are not implemented,
|
|
* then this function IS dup2().
|
|
*
|
|
* This alternative naming is used when dup2 could operate on both file and
|
|
* socket descritors to avoid drawing unused socket support into the link.
|
|
*
|
|
****************************************************************************/
|
|
|
|
#if CONFIG_NFILE_DESCRIPTORS > 0
|
|
int fs_dupfd2(int fd1, int fd2);
|
|
#endif
|
|
|
|
/* fs/vfs/fs_ioctl.c ********************************************************/
|
|
/****************************************************************************
|
|
* Name: fs_ioctl
|
|
*
|
|
* Description:
|
|
* Perform device specific operations.
|
|
*
|
|
* Parameters:
|
|
* fd File/socket descriptor of device
|
|
* req The ioctl command
|
|
* arg The argument of the ioctl cmd
|
|
*
|
|
* Return:
|
|
* >=0 on success (positive non-zero values are cmd-specific)
|
|
* -1 on failure with errno set properly:
|
|
*
|
|
* EBADF
|
|
* 'fd' is not a valid descriptor.
|
|
* EFAULT
|
|
* 'arg' references an inaccessible memory area.
|
|
* EINVAL
|
|
* 'cmd' or 'arg' is not valid.
|
|
* ENOTTY
|
|
* 'fd' is not associated with a character special device.
|
|
* ENOTTY
|
|
* The specified request does not apply to the kind of object that the
|
|
* descriptor 'fd' references.
|
|
*
|
|
****************************************************************************/
|
|
|
|
#ifdef CONFIG_LIBC_IOCTL_VARIADIC
|
|
int fs_ioctl(int fd, int req, unsigned long arg);
|
|
#endif
|
|
|
|
/* fs_fdopen.c **************************************************************/
|
|
/****************************************************************************
|
|
* Name: fs_fdopen
|
|
*
|
|
* Description:
|
|
* This function does the core operations for fopen and fdopen. It is
|
|
* used by the OS to clone stdin, stdout, stderr
|
|
*
|
|
****************************************************************************/
|
|
|
|
#if CONFIG_NFILE_STREAMS > 0
|
|
struct tcb_s; /* Forward reference */
|
|
FAR struct file_struct *fs_fdopen(int fd, int oflags);
|
|
#endif
|
|
|
|
/* libc/stdio/lib_fflush.c *************************************************/
|
|
/****************************************************************************
|
|
* Name: lib_flushall
|
|
*
|
|
* Description:
|
|
* Called either (1) by the OS when a task exits, or (2) from fflush()
|
|
* when a NULL stream argument is provided.
|
|
*
|
|
****************************************************************************/
|
|
|
|
#if CONFIG_NFILE_STREAMS > 0
|
|
int lib_flushall(FAR struct streamlist *list);
|
|
#endif
|
|
|
|
/* libc/misc/lib_sendfile.c *************************************************/
|
|
/****************************************************************************
|
|
* Name: lib_sendfile
|
|
*
|
|
* Description:
|
|
* Transfer a file
|
|
*
|
|
****************************************************************************/
|
|
|
|
#ifdef CONFIG_NET_SENDFILE
|
|
ssize_t lib_sendfile(int outfd, int infd, off_t *offset, size_t count);
|
|
#endif
|
|
|
|
/* fs/fs_getfilep.c *********************************************************/
|
|
/****************************************************************************
|
|
* Name: fs_getfilep
|
|
*
|
|
* Description:
|
|
* Given a file descriptor, return the corresponding instance of struct
|
|
* file. NOTE that this function will currently fail if it is provided
|
|
* with a socket descriptor.
|
|
*
|
|
* Parameters:
|
|
* fd - The file descriptor
|
|
*
|
|
* Return:
|
|
* A point to the corresponding struct file instance is returned on
|
|
* success. On failure, NULL is returned and the errno value is
|
|
* set appropriately (EBADF).
|
|
*
|
|
****************************************************************************/
|
|
|
|
#if CONFIG_NFILE_DESCRIPTORS > 0
|
|
FAR struct file *fs_getfilep(int fd);
|
|
#endif
|
|
|
|
/* fs/fs_read.c *************************************************************/
|
|
/****************************************************************************
|
|
* Name: file_read
|
|
*
|
|
* Description:
|
|
* Equivalent to the standard read() function except that is accepts a
|
|
* struct file instance instead of a file descriptor. Currently used
|
|
* only by net_sendfile() and aio_read();
|
|
*
|
|
****************************************************************************/
|
|
|
|
#if CONFIG_NFILE_DESCRIPTORS > 0
|
|
ssize_t file_read(FAR struct file *filep, FAR void *buf, size_t nbytes);
|
|
#endif
|
|
|
|
/* fs/fs_write.c ************************************************************/
|
|
/****************************************************************************
|
|
* Name: file_write
|
|
*
|
|
* Description:
|
|
* Equivalent to the standard write() function except that is accepts a
|
|
* struct file instance instead of a file descriptor. Currently used
|
|
* only by aio_write();
|
|
*
|
|
****************************************************************************/
|
|
|
|
#if CONFIG_NFILE_DESCRIPTORS > 0
|
|
ssize_t file_write(FAR struct file *filep, FAR const void *buf, size_t nbytes);
|
|
#endif
|
|
|
|
/* fs/fs_pread.c ************************************************************/
|
|
/****************************************************************************
|
|
* Name: file_pread
|
|
*
|
|
* Description:
|
|
* Equivalent to the standard pread function except that is accepts a
|
|
* struct file instance instead of a file descriptor. Currently used
|
|
* only by aio_read();
|
|
*
|
|
****************************************************************************/
|
|
|
|
#if CONFIG_NFILE_DESCRIPTORS > 0
|
|
ssize_t file_pread(FAR struct file *filep, FAR void *buf, size_t nbytes,
|
|
off_t offset);
|
|
#endif
|
|
|
|
/* fs/fs_pwrite.c ***********************************************************/
|
|
/****************************************************************************
|
|
* Name: file_pwrite
|
|
*
|
|
* Description:
|
|
* Equivalent to the standard pwrite function except that is accepts a
|
|
* struct file instance instead of a file descriptor. Currently used
|
|
* only by aio_write();
|
|
*
|
|
****************************************************************************/
|
|
|
|
#if CONFIG_NFILE_DESCRIPTORS > 0
|
|
ssize_t file_pwrite(FAR struct file *filep, FAR const void *buf,
|
|
size_t nbytes, off_t offset);
|
|
#endif
|
|
|
|
/* fs/fs_lseek.c ************************************************************/
|
|
/****************************************************************************
|
|
* Name: file_seek
|
|
*
|
|
* Description:
|
|
* Equivalent to the standard lseek() function except that is accepts a
|
|
* struct file instance instead of a file descriptor. Currently used
|
|
* only by net_sendfile()
|
|
*
|
|
****************************************************************************/
|
|
|
|
#if CONFIG_NFILE_DESCRIPTORS > 0
|
|
off_t file_seek(FAR struct file *filep, off_t offset, int whence);
|
|
#endif
|
|
|
|
/* fs/fs_lseek64.c ************************************************************/
|
|
/****************************************************************************
|
|
* Name: file_seek64
|
|
*
|
|
* Description:
|
|
* Equivalent to the standard lseek64() function except that is accepts a
|
|
* struct file instance instead of a file descriptor. Currently used
|
|
* only by net_sendfile()
|
|
*
|
|
****************************************************************************/
|
|
#if CONFIG_NFILE_DESCRIPTORS > 0
|
|
off64_t file_seek64(FAR struct file *filep, off64_t offset, int whence);
|
|
#endif
|
|
|
|
/* fs/fs_fsync.c ************************************************************/
|
|
/****************************************************************************
|
|
* Name: file_fsync
|
|
*
|
|
* Description:
|
|
* Equivalent to the standard fsync() function except that is accepts a
|
|
* struct file instance instead of a file descriptor. Currently used
|
|
* only by aio_fsync();
|
|
*
|
|
****************************************************************************/
|
|
|
|
#if CONFIG_NFILE_DESCRIPTORS > 0
|
|
int file_fsync(FAR struct file *filep);
|
|
#endif
|
|
|
|
/* fs/fs_fcntl.c ************************************************************/
|
|
/****************************************************************************
|
|
* Name: file_vfcntl
|
|
*
|
|
* Description:
|
|
* Similar to the standard vfcntl function except that is accepts a struct
|
|
* struct file instance instead of a file descriptor. Currently used
|
|
* only by aio_fcntl();
|
|
*
|
|
****************************************************************************/
|
|
|
|
#if CONFIG_NFILE_DESCRIPTORS > 0
|
|
int file_vfcntl(FAR struct file *filep, int cmd, va_list ap);
|
|
#endif
|
|
|
|
|
|
void clear_fd(int fd);
|
|
|
|
|
|
#ifdef __cplusplus
|
|
#if __cplusplus
|
|
}
|
|
#endif /* __cplusplus */
|
|
#endif /* __cplusplus */
|
|
#endif /* __INCLUDE_FS_FILE_H */
|