fs/vfs/fs_fcntl.c, net/socket/net_dupsd.c, and net/socket/net_vfcntl.c: Add file_fcntl, psock_fcntl, and psock_dupsd for use within the kernel.
This commit is contained in:
parent
aa52c457cc
commit
3f50451046
@ -214,6 +214,46 @@ int file_vfcntl(FAR struct file *filep, int cmd, va_list ap)
|
||||
}
|
||||
#endif /* CONFIG_NFILE_DESCRIPTORS > 0 */
|
||||
|
||||
/****************************************************************************
|
||||
* 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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#if CONFIG_NFILE_DESCRIPTORS > 0
|
||||
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;
|
||||
}
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: fcntl
|
||||
*
|
||||
|
@ -1085,6 +1085,29 @@ int file_ioctl(FAR struct file *filep, int req, unsigned long arg);
|
||||
int file_vfcntl(FAR struct file *filep, int cmd, va_list ap);
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* 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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#if CONFIG_NFILE_DESCRIPTORS > 0
|
||||
int file_fcntl(FAR struct file *filep, int cmd, ...);
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: file_poll
|
||||
*
|
||||
|
@ -1224,6 +1224,23 @@ struct pollfd; /* Forward reference -- see poll.h */
|
||||
int net_poll(int sockfd, struct pollfd *fds, bool setup);
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: psock_dupsd
|
||||
*
|
||||
* Description:
|
||||
* Clone a socket descriptor to an arbitray descriptor number. If file
|
||||
* descriptors are implemented, then this is called by dup() for the case
|
||||
* of socket file descriptors. If file descriptors are not implemented,
|
||||
* then this function IS dup().
|
||||
*
|
||||
* Returned Value:
|
||||
* On success, returns the number of characters sent. On any error,
|
||||
* a negated errno value is returned:.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int psock_dupsd(FAR struct socket *psock, int minsd);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: net_dupsd
|
||||
*
|
||||
@ -1355,6 +1372,46 @@ struct file;
|
||||
ssize_t net_sendfile(int outfd, struct file *infile, off_t *offset, size_t count);
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: psock_vfcntl
|
||||
*
|
||||
* Description:
|
||||
* Performs fcntl operations on socket
|
||||
*
|
||||
* Input Parameters:
|
||||
* psock - An instance of the internal socket structure.
|
||||
* cmd - The fcntl command.
|
||||
* ap - Command-specific arguments
|
||||
*
|
||||
* 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 psock_vfcntl(FAR struct socket *psock, int cmd, va_list ap);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: psock_fcntl
|
||||
*
|
||||
* Description:
|
||||
* Similar to the standard fcntl function except that is accepts a struct
|
||||
* struct socket instance instead of a file descriptor.
|
||||
*
|
||||
* Input Parameters:
|
||||
* psock - An instance of the internal socket structure.
|
||||
* 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 psock_fcntl(FAR struct socket *psock, int cmd, ...);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: net_vfcntl
|
||||
*
|
||||
|
@ -53,7 +53,7 @@
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: net_dupsd
|
||||
* Name: psock_dupsd
|
||||
*
|
||||
* Description:
|
||||
* Clone a socket descriptor to an arbitrary descriptor number. If file
|
||||
@ -67,9 +67,8 @@
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int net_dupsd(int sockfd, int minsd)
|
||||
int psock_dupsd(FAR struct socket *psock, int minsd)
|
||||
{
|
||||
FAR struct socket *psock1;
|
||||
FAR struct socket *psock2;
|
||||
int sockfd2;
|
||||
int ret;
|
||||
@ -94,13 +93,9 @@ int net_dupsd(int sockfd, int minsd)
|
||||
|
||||
sched_lock();
|
||||
|
||||
/* Get the socket structure underlying sockfd */
|
||||
|
||||
psock1 = sockfd_socket(sockfd);
|
||||
|
||||
/* Verify that the sockfd corresponds to valid, allocated socket */
|
||||
|
||||
if (!psock1 || psock1->s_crefs <= 0)
|
||||
if (!psock || psock->s_crefs <= 0)
|
||||
{
|
||||
ret = -EBADF;
|
||||
goto errout;
|
||||
@ -126,7 +121,7 @@ int net_dupsd(int sockfd, int minsd)
|
||||
|
||||
/* Duplicate the socket state */
|
||||
|
||||
ret = net_clone(psock1, psock2);
|
||||
ret = net_clone(psock, psock2);
|
||||
if (ret < 0)
|
||||
{
|
||||
goto errout_with_sockfd;
|
||||
@ -143,4 +138,24 @@ errout:
|
||||
return ret;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: net_dupsd
|
||||
*
|
||||
* Description:
|
||||
* Clone a socket descriptor to an arbitrary descriptor number. If file
|
||||
* descriptors are implemented, then this is called by dup() for the case
|
||||
* of socket file descriptors. If file descriptors are not implemented,
|
||||
* then this function IS dup().
|
||||
*
|
||||
* Returned Value:
|
||||
* On success, returns the number of characters sent. On any error,
|
||||
* a negated errno value is returned:.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int net_dupsd(int sockfd, int minsd)
|
||||
{
|
||||
return psock_dupsd(sockfd_socket(sockfd), minsd);
|
||||
}
|
||||
|
||||
#endif /* defined(CONFIG_NET) && CONFIG_NSOCKET_DESCRIPTORS > 0 */
|
||||
|
@ -59,15 +59,15 @@
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: net_vfcntl
|
||||
* Name: psock_vfcntl
|
||||
*
|
||||
* Description:
|
||||
* Performs fcntl operations on socket
|
||||
*
|
||||
* Input Parameters:
|
||||
* sockfd - Socket descriptor of the socket to operate on
|
||||
* cmd - The fcntl command.
|
||||
* ap - Command-specific arguments
|
||||
* psock - An instance of the internal socket structure.
|
||||
* cmd - The fcntl command.
|
||||
* ap - Command-specific arguments
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero (OK) is returned on success; a negated errno value is returned on
|
||||
@ -75,12 +75,11 @@
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int net_vfcntl(int sockfd, int cmd, va_list ap)
|
||||
int psock_vfcntl(FAR struct socket *psock, int cmd, va_list ap)
|
||||
{
|
||||
FAR struct socket *psock = sockfd_socket(sockfd);
|
||||
int ret = -EINVAL;
|
||||
|
||||
ninfo("sockfd=%d cmd=%d\n", sockfd, cmd);
|
||||
ninfo("sockfd=%p cmd=%d\n", psock, cmd);
|
||||
|
||||
/* Verify that the sockfd corresponds to valid, allocated socket */
|
||||
|
||||
@ -108,7 +107,7 @@ int net_vfcntl(int sockfd, int cmd, va_list ap)
|
||||
{
|
||||
/* Does not set the errno value on failure */
|
||||
|
||||
ret = net_dupsd(sockfd, va_arg(ap, int));
|
||||
ret = psock_dupsd(psock, va_arg(ap, int));
|
||||
}
|
||||
break;
|
||||
|
||||
@ -259,4 +258,64 @@ int net_vfcntl(int sockfd, int cmd, va_list ap)
|
||||
return ret;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: psock_fcntl
|
||||
*
|
||||
* Description:
|
||||
* Similar to the standard fcntl function except that is accepts a struct
|
||||
* struct socket instance instead of a file descriptor.
|
||||
*
|
||||
* Input Parameters:
|
||||
* psock - An instance of the internal socket structure.
|
||||
* 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 psock_fcntl(FAR struct socket *psock, int cmd, ...)
|
||||
{
|
||||
va_list ap;
|
||||
int ret;
|
||||
|
||||
/* Setup to access the variable argument list */
|
||||
|
||||
va_start(ap, cmd);
|
||||
|
||||
/* Let psock_vfcntl() do the real work. The errno is not set on
|
||||
* failures.
|
||||
*/
|
||||
|
||||
ret = psock_vfcntl(psock, cmd, ap);
|
||||
|
||||
va_end(ap);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: net_vfcntl
|
||||
*
|
||||
* Description:
|
||||
* Performs fcntl operations on socket
|
||||
*
|
||||
* Input Parameters:
|
||||
* sockfd - Socket descriptor of the socket to operate on
|
||||
* cmd - The fcntl command.
|
||||
* ap - Command-specific arguments
|
||||
*
|
||||
* 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 net_vfcntl(int sockfd, int cmd, va_list ap)
|
||||
{
|
||||
return psock_vfcntl(sockfd_socket(sockfd), cmd, ap);
|
||||
}
|
||||
|
||||
#endif /* CONFIG_NET && CONFIG_NSOCKET_DESCRIPTORS > 0 */
|
||||
|
Loading…
Reference in New Issue
Block a user