diff --git a/drivers/pipes/pipe_common.c b/drivers/pipes/pipe_common.c index efb95027ca..0d8fb24b6e 100644 --- a/drivers/pipes/pipe_common.c +++ b/drivers/pipes/pipe_common.c @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #include @@ -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 */ { diff --git a/fs/vfs/fs_fcntl.c b/fs/vfs/fs_fcntl.c index d7e7a152a9..c87417376b 100644 --- a/fs/vfs/fs_fcntl.c +++ b/fs/vfs/fs_fcntl.c @@ -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; } diff --git a/include/fcntl.h b/include/fcntl.h index 132c1ebe9e..9e897dba82 100644 --- a/include/fcntl.h +++ b/include/fcntl.h @@ -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() */ diff --git a/include/nuttx/fs/ioctl.h b/include/nuttx/fs/ioctl.h index ff5df177e6..825de7dbcf 100644 --- a/include/nuttx/fs/ioctl.h +++ b/include/nuttx/fs/ioctl.h @@ -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 */