diff --git a/drivers/pipes/pipe.c b/drivers/pipes/pipe.c index ed22db3fc5..a6fbba0ce4 100644 --- a/drivers/pipes/pipe.c +++ b/drivers/pipes/pipe.c @@ -44,13 +44,15 @@ #include #include -#include + #include #include #include #include #include +#include + #include "pipe_common.h" #if CONFIG_DEV_PIPE_SIZE > 0 diff --git a/include/nuttx/fs/fs.h b/include/nuttx/fs/fs.h index ef99ff6f51..bf8d1b60ec 100644 --- a/include/nuttx/fs/fs.h +++ b/include/nuttx/fs/fs.h @@ -60,6 +60,7 @@ /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ + /* Stream flags for the fs_flags field of in struct file_struct */ #define __FS_FLAG_EOF (1 << 0) /* EOF detected by a read operation */ @@ -1160,6 +1161,71 @@ ssize_t bchlib_read(FAR void *handle, FAR char *buffer, size_t offset, ssize_t bchlib_write(FAR void *handle, FAR const char *buffer, size_t offset, size_t len); +/**************************************************************************** + * Name: pipe2 + * + * Description: + * pipe() creates a pair of file descriptors, pointing to a pipe inode, + * and places them in the array pointed to by 'fd'. fd[0] is for reading, + * fd[1] is for writing. + * + * NOTE: mkfifo2 is a special, non-standard, NuttX-only interface. Since + * the NuttX FIFOs are based in in-memory, circular buffers, the ability + * to control the size of those buffers is critical for system tuning. + * + * Inputs: + * fd[2] - The user provided array in which to catch the pipe file + * descriptors + * bufsize - The size of the in-memory, circular buffer in bytes. + * + * Return: + * 0 is returned on success; otherwise, -1 is returned with errno set + * appropriately. + * + ****************************************************************************/ + +#if defined(CONFIG_PIPES) && CONFIG_DEV_PIPE_SIZE > 0 +int pipe2(int fd[2], size_t bufsize); +#endif + +/**************************************************************************** + * Name: mkfifo2 + * + * Description: + * mkfifo() makes a FIFO device driver file with name 'pathname.' Unlike + * Linux, a NuttX FIFO is not a special file type but simply a device + * driver instance. 'mode' specifies the FIFO's permissions. + * + * Once the FIFO has been created by mkfifo(), any thread can open it for + * reading or writing, in the same way as an ordinary file. However, it + * must have been opened from both reading and writing before input or + * output can be performed. This FIFO implementation will block all + * attempts to open a FIFO read-only until at least one thread has opened + * the FIFO for writing. + * + * If all threads that write to the FIFO have closed, subsequent calls to + * read() on the FIFO will return 0 (end-of-file). + * + * NOTE: mkfifo2 is a special, non-standard, NuttX-only interface. Since + * the NuttX FIFOs are based in in-memory, circular buffers, the ability + * to control the size of those buffers is critical for system tuning. + * + * Inputs: + * pathname - The full path to the FIFO instance to attach to or to create + * (if not already created). + * mode - Ignored for now + * bufsize - The size of the in-memory, circular buffer in bytes. + * + * Return: + * 0 is returned on success; otherwise, -1 is returned with errno set + * appropriately. + * + ****************************************************************************/ + +#if defined(CONFIG_PIPES) && CONFIG_DEV_FIFO_SIZE > 0 +int mkfifo2(FAR const char *pathname, mode_t mode, size_t bufsize); +#endif + #undef EXTERN #if defined(__cplusplus) } diff --git a/include/sys/stat.h b/include/sys/stat.h index ae450257d0..3f2658b5f1 100644 --- a/include/sys/stat.h +++ b/include/sys/stat.h @@ -130,7 +130,6 @@ extern "C" #endif int mkdir(FAR const char *pathname, mode_t mode); -int mkfifo2(FAR const char *pathname, mode_t mode, size_t bufsize); /* NuttX only */ int mkfifo(FAR const char *pathname, mode_t mode); int stat(const char *path, FAR struct stat *buf); #if 0 /* Not yet supported */ diff --git a/include/unistd.h b/include/unistd.h index cb9eabfd5d..909df0b338 100644 --- a/include/unistd.h +++ b/include/unistd.h @@ -174,7 +174,6 @@ FAR void *sbrk(intptr_t incr); /* Special devices */ -int pipe2(int fd[2], size_t bufsize); /* NuttX only */ int pipe(int fd[2]); /* Working directory operations */ diff --git a/libc/misc/lib_mkfifo.c b/libc/misc/lib_mkfifo.c index 727ac0f361..8357b6428f 100644 --- a/libc/misc/lib_mkfifo.c +++ b/libc/misc/lib_mkfifo.c @@ -42,7 +42,9 @@ #include #include -#if CONFIG_DEV_FIFO_SIZE > 0 +#include + +#if defined(CONFIG_PIPES) && CONFIG_DEV_FIFO_SIZE > 0 /**************************************************************************** * Public Functions @@ -82,5 +84,5 @@ int mkfifo(FAR const char *pathname, mode_t mode) return mkfifo2(pathname, mode, CONFIG_DEV_FIFO_SIZE); } -#endif /* CONFIG_DEV_FIFO_SIZE > 0 */ +#endif /* CONFIG_PIPES && CONFIG_DEV_FIFO_SIZE > 0 */ diff --git a/libc/unistd/lib_pipe.c b/libc/unistd/lib_pipe.c index e36a31ad41..fbee980319 100644 --- a/libc/unistd/lib_pipe.c +++ b/libc/unistd/lib_pipe.c @@ -41,7 +41,9 @@ #include -#if CONFIG_DEV_PIPE_SIZE > 0 +#include + +#if defined(CONFIG_PIPES) && CONFIG_DEV_PIPE_SIZE > 0 /**************************************************************************** * Public Functions @@ -70,5 +72,5 @@ int pipe(int fd[2]) return pipe2(fd, CONFIG_DEV_PIPE_SIZE); } -#endif /* CONFIG_DEV_PIPE_SIZE > 0 */ +#endif /* CONFIG_PIPES && CONFIG_DEV_PIPE_SIZE > 0 */ diff --git a/syscall/syscall.csv b/syscall/syscall.csv index d021313925..42a9ba5f60 100644 --- a/syscall/syscall.csv +++ b/syscall/syscall.csv @@ -34,7 +34,7 @@ "listen","sys/socket.h","CONFIG_NSOCKET_DESCRIPTORS > 0 && defined(CONFIG_NET)","int","int","int" "lseek","unistd.h","CONFIG_NFILE_DESCRIPTORS > 0","off_t","int","off_t","int" "mkdir","sys/stat.h","CONFIG_NFILE_DESCRIPTORS > 0 && !defined(CONFIG_DISABLE_MOUNTPOINT)","int","FAR const char*","mode_t" -"mkfifo2","sys/stat.h","CONFIG_NFILE_DESCRIPTORS > 0","int","FAR const char*","mode_t","size_t" +"mkfifo2","nuttx/fs/fs.h","defined(CONFIG_PIPES) && CONFIG_DEV_FIFO_SIZE > 0","int","FAR const char*","mode_t","size_t" "mmap","sys/mman.h","CONFIG_NFILE_DESCRIPTORS > 0","FAR void*","FAR void*","size_t","int","int","int","off_t" "mount","sys/mount.h","CONFIG_NFILE_DESCRIPTORS > 0 && !defined(CONFIG_DISABLE_MOUNTPOINT) && defined(CONFIG_FS_READABLE)","int","const char*","const char*","const char*","unsigned long","const void*" "mq_close","mqueue.h","!defined(CONFIG_DISABLE_MQUEUE)","int","mqd_t" @@ -52,7 +52,7 @@ "open","fcntl.h","CONFIG_NFILE_DESCRIPTORS > 0","int","const char*","int","..." "opendir","dirent.h","CONFIG_NFILE_DESCRIPTORS > 0","FAR DIR*","FAR const char*" "pgalloc", "nuttx/arch.h", "defined(CONFIG_BUILD_KERNEL)", "uintptr_t", "uintptr_t", "unsigned int" -"pipe2","unistd.h","CONFIG_NFILE_DESCRIPTORS > 0","int","int [2]|int*","size_t" +"pipe2","nuttx/fs/fs.h","defined(CONFIG_PIPES) && CONFIG_DEV_PIPE_SIZE > 0","int","int [2]|int*","size_t" "poll","poll.h","!defined(CONFIG_DISABLE_POLL) && (CONFIG_NSOCKET_DESCRIPTORS > 0 || CONFIG_NFILE_DESCRIPTORS > 0)","int","FAR struct pollfd*","nfds_t","int" "prctl","sys/prctl.h", "CONFIG_TASK_NAME_SIZE > 0","int","int","..." "pread","unistd.h","CONFIG_NSOCKET_DESCRIPTORS > 0 || CONFIG_NFILE_DESCRIPTORS > 0","ssize_t","int","FAR void*","size_t","off_t"