drivers/pipes: add fcntl(F_SETPIPE_SZ/F_GETPIPE_SZ) support
allows user programs to modify pipe size, but not larger than CONFIG_DEV_PIPE_MAXSIZE Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
This commit is contained in:
parent
41537fe90f
commit
420648b0c6
@ -27,6 +27,7 @@
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/param.h>
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
@ -849,6 +850,32 @@ int pipecommon_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
|
||||
}
|
||||
break;
|
||||
|
||||
case PIPEIOC_SETSIZE:
|
||||
{
|
||||
size_t size = (size_t)arg;
|
||||
if (size == 0)
|
||||
{
|
||||
ret = -EINVAL;
|
||||
break;
|
||||
}
|
||||
|
||||
size = MIN(size, CONFIG_DEV_PIPE_MAXSIZE);
|
||||
ret = circbuf_resize(&dev->d_buffer, size);
|
||||
if (ret != 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
dev->d_bufsize = size;
|
||||
}
|
||||
break;
|
||||
|
||||
case PIPEIOC_GETSIZE:
|
||||
{
|
||||
ret = dev->d_bufsize;
|
||||
}
|
||||
break;
|
||||
|
||||
case FIONWRITE: /* Number of bytes waiting in send queue */
|
||||
case FIONREAD: /* Number of bytes available for reading */
|
||||
{
|
||||
|
@ -243,6 +243,26 @@ static int file_vfcntl(FAR struct file *filep, int cmd, va_list ap)
|
||||
ret = file_ioctl(filep, FIOC_FILEPATH, va_arg(ap, FAR char *));
|
||||
}
|
||||
|
||||
break;
|
||||
case F_SETPIPE_SZ:
|
||||
/* Modify the capacity of the pipe to arg bytes, but not larger than
|
||||
* CONFIG_DEV_PIPE_MAXSIZE.
|
||||
*/
|
||||
|
||||
{
|
||||
ret = file_ioctl(filep, PIPEIOC_SETSIZE, va_arg(ap, int));
|
||||
}
|
||||
|
||||
break;
|
||||
case F_GETPIPE_SZ:
|
||||
|
||||
/* Return the capacity of the pipe */
|
||||
|
||||
{
|
||||
ret = file_ioctl(filep, PIPEIOC_GETSIZE);
|
||||
}
|
||||
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -103,6 +103,8 @@
|
||||
#define F_ADD_SEALS 16 /* Add the bit-mask argument arg to the set of seals of the inode */
|
||||
#define F_GET_SEALS 17 /* Get (as the function result) the current set of seals of the inode */
|
||||
#define F_DUPFD_CLOEXEC 18 /* Duplicate file descriptor with close-on-exit set. */
|
||||
#define F_SETPIPE_SZ 19 /* Modify the capacity of the pipe to arg bytes, but not larger than CONFIG_DEV_PIPE_MAXSIZE */
|
||||
#define F_GETPIPE_SZ 20 /* Return the capacity of the pipe */
|
||||
|
||||
/* For posix fcntl() and lockf() */
|
||||
|
||||
|
@ -484,6 +484,14 @@
|
||||
* IN: pipe_peek_s
|
||||
* OUT: Length of data */
|
||||
|
||||
#define PIPEIOC_SETSIZE _PIPEIOC(0x0005) /* Pipe get size interface
|
||||
* IN: size_t
|
||||
* OUT: None */
|
||||
|
||||
#define PIPEIOC_GETSIZE _PIPEIOC(0x0006) /* Pipe get size interface
|
||||
* IN: None
|
||||
* OUT: int */
|
||||
|
||||
/* RTC driver ioctl definitions *********************************************/
|
||||
|
||||
/* (see nuttx/include/rtc.h */
|
||||
|
Loading…
Reference in New Issue
Block a user