fs: Make nx_vxxx and file_vxxx as internal functions

these functions are the implementation detail and then
don't need expose to external

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
Change-Id: Ief832391d5b42d1f1645907eb465631650490234
This commit is contained in:
Xiang Xiao 2021-01-04 11:33:16 +08:00 committed by Alin Jerpelea
parent 32708ab849
commit fe96250c40
5 changed files with 194 additions and 245 deletions

View File

@ -47,8 +47,8 @@
* or sink pipe file structures before each file_read() or file_write()
* operation to assure that the O_NONBLOCK is set correctly when the
* pipe read or write operation is performed. This might be done with
* file_vfcntl() (there is no file_fcntl(), yet) or directly into the
* source/sink file structure oflags mode settings.
* file_fcntl() or directly into the source/sink file structure oflags
* mode settings.
*
* This would require (1) the ability to lock each pipe individually,
* setting the blocking mode for the source or sink pipe to match the
@ -549,7 +549,7 @@ static ssize_t pty_read(FAR struct file *filep, FAR char *buffer, size_t len)
*
* REVISIT: Should not block if the oflags include O_NONBLOCK.
* How would we ripple the O_NONBLOCK characteristic to the
* contained source pipe? file_vfcntl()? Or FIONREAD? See the
* contained source pipe? file_fcntl()? Or FIONREAD? See the
* TODO comment at the top of this file.
*/
@ -602,7 +602,7 @@ static ssize_t pty_read(FAR struct file *filep, FAR char *buffer, size_t len)
*
* REVISIT: Should not block if the oflags include O_NONBLOCK.
* How would we ripple the O_NONBLOCK characteristic to the
* contained source pipe? file_vfcntl()? Or FIONREAD? See the
* contained source pipe? file_fcntl()? Or FIONREAD? See the
* TODO comment at the top of this file.
*/
@ -670,7 +670,7 @@ static ssize_t pty_write(FAR struct file *filep,
*
* REVISIT: Should not block if the oflags include O_NONBLOCK.
* How would we ripple the O_NONBLOCK characteristic to the
* contained sink pipe? file_vfcntl()? Or FIONSPACE? See the
* contained sink pipe? file_fcntl()? Or FIONSPACE? See the
* TODO comment at the top of this file.
*
* NOTE: The newline is not included in total number of bytes
@ -691,7 +691,7 @@ static ssize_t pty_write(FAR struct file *filep,
*
* REVISIT: Should not block if the oflags include O_NONBLOCK.
* How would we ripple the O_NONBLOCK characteristic to the
* contained sink pipe? file_vfcntl()? Or FIONSPACe? See the
* contained sink pipe? file_fcntl()? Or FIONSPACe? See the
* TODO comment at the top of this file.
*/
@ -715,7 +715,7 @@ static ssize_t pty_write(FAR struct file *filep,
*
* REVISIT: Should not block if the oflags include O_NONBLOCK.
* How would we ripple the O_NONBLOCK characteristic to the
* contained sink pipe? file_vfcntl()? Or FIONSPACE? See the
* contained sink pipe? file_fcntl()? Or FIONSPACE? See the
* TODO comment at the top of this file.
*/

View File

@ -53,29 +53,14 @@
#include "inode/inode.h"
/****************************************************************************
* Public Functions
* Private Functions
****************************************************************************/
/****************************************************************************
* Name: file_vfcntl
*
* Description:
* Similar to the standard vfcntl function except that is accepts a struct
* struct file instance instead of a file descriptor.
*
* Input Parameters:
* filep - Instance for struct file for the opened file.
* cmd - Identifies the operation to be performed.
* ap - Variable argument following the command.
*
* Returned Value:
* The nature of the return value depends on the command. Non-negative
* values indicate success. Failures are reported as negated errno
* values.
*
****************************************************************************/
int file_vfcntl(FAR struct file *filep, int cmd, va_list ap)
static int file_vfcntl(FAR struct file *filep, int cmd, va_list ap)
{
int ret = -EINVAL;
@ -245,64 +230,10 @@ int file_vfcntl(FAR struct file *filep, int cmd, va_list ap)
}
/****************************************************************************
* Name: file_fcntl
*
* Description:
* Similar to the standard fcntl function except that is accepts a struct
* struct file instance instead of a file descriptor.
*
* Input Parameters:
* filep - Instance for struct file for the opened file.
* cmd - Identifies the operation to be performed. Command specific
* arguments may follow.
*
* Returned Value:
* The nature of the return value depends on the command. Non-negative
* values indicate success. Failures are reported as negated errno
* values.
*
* Name: nx_vfcntl
****************************************************************************/
int file_fcntl(FAR struct file *filep, int cmd, ...)
{
va_list ap;
int ret;
/* Setup to access the variable argument list */
va_start(ap, cmd);
/* Let file_vfcntl() do the real work. The errno is not set on
* failures.
*/
ret = file_vfcntl(filep, cmd, ap);
va_end(ap);
return ret;
}
/****************************************************************************
* Name: nx_fcntl and nx_vfcntl
*
* Description:
* nx_fcntl() is similar to the standard 'fcntl' interface except that is
* not a cancellation point and it does not modify the errno variable.
*
* nx_vfcntl() is identical except that it accepts a va_list as an argument
* versus taking a variable length list of arguments.
*
* nx_fcntl() and nx_vfcntl are internal NuttX interface and should not be
* called from applications.
*
* Returned Value:
* Returns a non-negative number on success; A negated errno value is
* returned on any failure (see comments fcntl() for a list of appropriate
* errno values).
*
****************************************************************************/
int nx_vfcntl(int fd, int cmd, va_list ap)
static int nx_vfcntl(int fd, int cmd, va_list ap)
{
FAR struct file *filep;
int ret;
@ -350,6 +281,65 @@ int nx_vfcntl(int fd, int cmd, va_list ap)
return ret;
}
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: file_fcntl
*
* Description:
* Similar to the standard fcntl function except that is accepts a struct
* struct file instance instead of a file descriptor.
*
* Input Parameters:
* filep - Instance for struct file for the opened file.
* cmd - Identifies the operation to be performed. Command specific
* arguments may follow.
*
* Returned Value:
* The nature of the return value depends on the command. Non-negative
* values indicate success. Failures are reported as negated errno
* values.
*
****************************************************************************/
int file_fcntl(FAR struct file *filep, int cmd, ...)
{
va_list ap;
int ret;
/* Setup to access the variable argument list */
va_start(ap, cmd);
/* Let file_vfcntl() do the real work. The errno is not set on
* failures.
*/
ret = file_vfcntl(filep, cmd, ap);
va_end(ap);
return ret;
}
/****************************************************************************
* Name: nx_fcntl
*
* Description:
* nx_fcntl() is similar to the standard 'fcntl' interface except that is
* not a cancellation point and it does not modify the errno variable.
*
* nx_fcntl() is an internal NuttX interface and should not be called
* from applications.
*
* Returned Value:
* Returns a non-negative number on success; A negated errno value is
* returned on any failure (see comments fcntl() for a list of appropriate
* errno values).
*
****************************************************************************/
int nx_fcntl(int fd, int cmd, ...)
{
va_list ap;

View File

@ -55,25 +55,11 @@
#include "inode/inode.h"
/****************************************************************************
* Public Functions
* Private Functions
****************************************************************************/
/****************************************************************************
* Name: file_ioctl and file_vioctl
*
* Description:
* Perform device specific operations.
*
* Input Parameters:
* file File structure instance
* req The ioctl command
* ap The argument of the ioctl cmd
*
* Returned Value:
* Returns a non-negative number on success; A negated errno value is
* returned on any failure (see comments ioctl() for a list of appropriate
* errno values).
*
* Name: file_vioctl
****************************************************************************/
int file_vioctl(FAR struct file *filep, int req, va_list ap)
@ -102,38 +88,11 @@ int file_vioctl(FAR struct file *filep, int req, va_list ap)
return inode->u.i_ops->ioctl(filep, req, va_arg(ap, unsigned long));
}
int file_ioctl(FAR struct file *filep, int req, ...)
{
va_list ap;
int ret;
/* Let file_vioctl() do the real work. */
va_start(ap, req);
ret = file_vioctl(filep, req, ap);
va_end(ap);
return ret;
}
/****************************************************************************
* Name: nx_ioctl and nx_vioctl
*
* Description:
* nx_ioctl() is similar to the standard 'ioctl' interface except that is
* not a cancellation point and it does not modify the errno variable.
*
* nx_ioctl() is an internal NuttX interface and should not be called from
* applications.
*
* Returned Value:
* Returns a non-negative number on success; A negated errno value is
* returned on any failure (see comments ioctl() for a list of appropriate
* errno values).
*
* Name: nx_vioctl
****************************************************************************/
int nx_vioctl(int fd, int req, va_list ap)
static int nx_vioctl(int fd, int req, va_list ap)
{
FAR struct file *filep;
FAR int *arg;
@ -206,6 +165,59 @@ int nx_vioctl(int fd, int req, va_list ap)
return ret;
}
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: file_ioctl
*
* Description:
* Perform device specific operations.
*
* Input Parameters:
* file File structure instance
* req The ioctl command
* ap The argument of the ioctl cmd
*
* Returned Value:
* Returns a non-negative number on success; A negated errno value is
* returned on any failure (see comments ioctl() for a list of appropriate
* errno values).
*
****************************************************************************/
int file_ioctl(FAR struct file *filep, int req, ...)
{
va_list ap;
int ret;
/* Let file_vioctl() do the real work. */
va_start(ap, req);
ret = file_vioctl(filep, req, ap);
va_end(ap);
return ret;
}
/****************************************************************************
* Name: nx_ioctl
*
* Description:
* nx_ioctl() is similar to the standard 'ioctl' interface except that is
* not a cancellation point and it does not modify the errno variable.
*
* nx_ioctl() is an internal NuttX interface and should not be called from
* applications.
*
* Returned Value:
* Returns a non-negative number on success; A negated errno value is
* returned on any failure (see comments ioctl() for a list of appropriate
* errno values).
*
****************************************************************************/
int nx_ioctl(int fd, int req, ...)
{
va_list ap;

View File

@ -55,48 +55,15 @@
#include "driver/driver.h"
/****************************************************************************
* Public Functions
* Private Functions
****************************************************************************/
/****************************************************************************
* Name: inode_checkflags
*
* Description:
* Check if the access described by 'oflags' is supported on 'inode'
*
****************************************************************************/
int inode_checkflags(FAR struct inode *inode, int oflags)
{
if (((oflags & O_RDOK) != 0 && !inode->u.i_ops->read) ||
((oflags & O_WROK) != 0 && !inode->u.i_ops->write))
{
return -EACCES;
}
else
{
return OK;
}
}
/****************************************************************************
* Name: file_vopen
*
* Description:
* file_vopen() is identical to 'file_open' except that it accepts va_list
* as an argument versus taking a variable length list of arguments.
*
* file_vopen() is an internal NuttX interface and should not be called
* from applications.
*
* Returned Value:
* Zero (OK) is returned on success. On failure, a negated errno value is
* returned.
*
****************************************************************************/
int file_vopen(FAR struct file *filep,
FAR const char *path, int oflags, va_list ap)
static int file_vopen(FAR struct file *filep,
FAR const char *path, int oflags, va_list ap)
{
struct inode_search_s desc;
FAR struct inode *inode;
@ -236,6 +203,62 @@ errout_with_search:
return ret;
}
/****************************************************************************
* Name: nx_vopen
****************************************************************************/
static int nx_vopen(FAR const char *path, int oflags, va_list ap)
{
struct file filep;
int ret;
int fd;
/* Let file_vopen() do all of the work */
ret = file_vopen(&filep, path, oflags, ap);
if (ret < 0)
{
return ret;
}
/* Allocate a new file descriptor for the inode */
fd = files_allocate(filep.f_inode, filep.f_oflags,
filep.f_pos, filep.f_priv, 0);
if (fd < 0)
{
file_close(&filep);
return fd;
}
return fd;
}
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: inode_checkflags
*
* Description:
* Check if the access described by 'oflags' is supported on 'inode'
*
****************************************************************************/
int inode_checkflags(FAR struct inode *inode, int oflags)
{
if (((oflags & O_RDOK) != 0 && !inode->u.i_ops->read) ||
((oflags & O_WROK) != 0 && !inode->u.i_ops->write))
{
return -EACCES;
}
else
{
return OK;
}
}
/****************************************************************************
* Name: file_open
*
@ -269,49 +292,6 @@ int file_open(FAR struct file *filep, FAR const char *path, int oflags, ...)
return ret;
}
/****************************************************************************
* Name: nx_vopen
*
* Description:
* nx_vopen() is identical to 'nx_open' except that it accepts a va_list
* as an argument versus taking a variable length list of arguments.
*
* nx_vopen() is an internal NuttX interface and should not be called from
* applications.
*
* Returned Value:
* The new file descriptor is returned on success; a negated errno value is
* returned on any failure.
*
****************************************************************************/
int nx_vopen(FAR const char *path, int oflags, va_list ap)
{
struct file filep;
int ret;
int fd;
/* Let file_vopen() do all of the work */
ret = file_vopen(&filep, path, oflags, ap);
if (ret < 0)
{
return ret;
}
/* Allocate a new file descriptor for the inode */
fd = files_allocate(filep.f_inode, filep.f_oflags,
filep.f_pos, filep.f_priv, 0);
if (fd < 0)
{
file_close(&filep);
return fd;
}
return fd;
}
/****************************************************************************
* Name: nx_open
*

View File

@ -835,22 +835,17 @@ int nx_dup2(int fd1, int fd2);
*
****************************************************************************/
int file_vopen(FAR struct file *filep,
FAR const char *path, int oflags, va_list ap);
int file_open(FAR struct file *filep, FAR const char *path, int oflags, ...);
/****************************************************************************
* Name: nx_open and nx_vopen
* Name: nx_open
*
* Description:
* nx_open() is similar to the standard 'open' interface except that is is
* not a cancellation point and it does not modify the errno variable.
*
* nx_vopen() is identical except that it accepts a va_list as an argument
* versus taking a variable length list of arguments.
*
* nx_open() and nx_vopen are internal NuttX interface and should not be
* called from applications.
* nx_open() is an internal NuttX interface and should not be called
* from applications.
*
* Returned Value:
* The new file descriptor is returned on success; a negated errno value is
@ -858,7 +853,6 @@ int file_open(FAR struct file *filep, FAR const char *path, int oflags, ...);
*
****************************************************************************/
int nx_vopen(FAR const char *path, int oflags, va_list ap);
int nx_open(FAR const char *path, int oflags, ...);
/****************************************************************************
@ -1190,7 +1184,7 @@ int file_truncate(FAR struct file *filep, off_t length);
#endif
/****************************************************************************
* Name: file_ioctl and file_vioctl
* Name: file_ioctl
*
* Description:
* Perform device specific operations.
@ -1207,11 +1201,10 @@ int file_truncate(FAR struct file *filep, off_t length);
*
****************************************************************************/
int file_vioctl(FAR struct file *filep, int req, va_list ap);
int file_ioctl(FAR struct file *filep, int req, ...);
/****************************************************************************
* Name: nx_ioctl and nx_vioctl
* Name: nx_ioctl
*
* Description:
* nx_ioctl() is similar to the standard 'ioctl' interface except that is
@ -1227,30 +1220,8 @@ int file_ioctl(FAR struct file *filep, int req, ...);
*
****************************************************************************/
int nx_vioctl(int fd, int req, va_list ap);
int nx_ioctl(int fd, int req, ...);
/****************************************************************************
* Name: file_vfcntl
*
* Description:
* Similar to the standard vfcntl function except that is accepts a struct
* struct file instance instead of a file descriptor.
*
* Input Parameters:
* filep - Instance for struct file for the opened file.
* cmd - Identifies the operation to be performed.
* ap - Variable argument following the command.
*
* Returned Value:
* The nature of the return value depends on the command. Non-negative
* values indicate success. Failures are reported as negated errno
* values.
*
****************************************************************************/
int file_vfcntl(FAR struct file *filep, int cmd, va_list ap);
/****************************************************************************
* Name: file_fcntl
*
@ -1273,17 +1244,14 @@ int file_vfcntl(FAR struct file *filep, int cmd, va_list ap);
int file_fcntl(FAR struct file *filep, int cmd, ...);
/****************************************************************************
* Name: nx_fcntl and nx_vfcntl
* Name: nx_fcntl
*
* Description:
* nx_fcntl() is similar to the standard 'fcntl' interface except that is
* not a cancellation point and it does not modify the errno variable.
*
* nx_vfcntl() is identical except that it accepts a va_list as an argument
* versus taking a variable length list of arguments.
*
* nx_fcntl() and nx_vfcntl are internal NuttX interface and should not be
* called from applications.
* nx_fcntl() is an internal NuttX interface and should not be called
* from applications.
*
* Returned Value:
* Returns a non-negative number on success; A negated errno value is
@ -1292,7 +1260,6 @@ int file_fcntl(FAR struct file *filep, int cmd, ...);
*
****************************************************************************/
int nx_vfcntl(int fd, int cmd, va_list ap);
int nx_fcntl(int fd, int cmd, ...);
/****************************************************************************