|
AquilaOS documentation
How it works, and its code
|
Pipes, and FIFOs: a ring buffer in memory, written at one end and read at the other. More...
#include <core/system.h>#include <ds/ringbuf.h>#include <aquila/fcntl.h>#include <fs/pipe.h>#include <fs/posix.h>#include <sys/sched.h>#include <sys/signal.h>Go to the source code of this file.
Enumerations | |
| enum | { END_READ , END_WRITE , END_RDWR } |
Functions | |
| static int | has_readers (struct pipe *pipe) |
| Says whether a pipe has an end open for reading. | |
| static int | has_writers (struct pipe *pipe) |
| Says whether a pipe has an end open for writing. | |
| static void | pipefs_pfree (struct pipe *pipe) |
| Frees a pipe and its ring buffer. | |
| static ssize_t | pipefs_read (struct vnode *node, off_t offset, struct iobuf *io) |
| Reads what the pipe's ring buffer has, up to what is asked for. | |
| static ssize_t | pipefs_write (struct vnode *node, off_t offset, struct iobuf *io) |
| Writes into the pipe's ring buffer, as much as fits. | |
| static int | pipefs_close (struct vnode *node) |
| Closes an end of a pipe, when its last open file is closed. | |
| static int | pipefs_eof (struct file *file) |
| Says whether a read is at the end of the file: no writers are left, and the pipe is empty. | |
| static int | pipefs_can_read (struct file *file, size_t size) |
| Says whether a read of size bytes would go on without waiting. | |
| static int | pipefs_can_write (struct file *file, size_t size) |
| Says whether a write of size bytes would go on without waiting. | |
| static int | pipefs_mkpipe (struct pipe **ref) |
| Makes a new pipe, with no ends. | |
| static struct vnode * | pipefs_end (struct pipe *pipe, int which) |
| Returns a new reference to an end of a pipe (END_*), making the end if it doesn't exist yet, or NULL if there was no memory. | |
| int | pipefs_pipe (struct file *read, struct file *write) |
| Makes an anonymous pipe, for pipe(): one open file for each end. | |
| int | pipefs_fifo_open (struct file *file) |
| Opens a FIFO: the open file's vnode becomes an end of the FIFO's pipe, made by its first open. | |
Variables | |
| struct fs | pipefs |
Pipes, and FIFOs: a ring buffer in memory, written at one end and read at the other.
Readers and writers sleep on one wait queue until there is data or room.
Definition in file pipe.c.
|
static |
Says whether a pipe has an end open for reading.
Definition at line 29 of file pipe.c.
References has_readers(), pipe::r_node, and pipe::rw_node.
Referenced by has_readers(), pipefs_can_write(), pipefs_close(), pipefs_fifo_open(), and pipefs_write().
|
static |
Says whether a pipe has an end open for writing.
Definition at line 35 of file pipe.c.
References has_writers(), pipe::rw_node, and pipe::w_node.
Referenced by has_writers(), pipefs_can_read(), pipefs_close(), pipefs_eof(), and pipefs_fifo_open().
Says whether a read of size bytes would go on without waiting.
Definition at line 113 of file pipe.c.
References has_writers(), vnode::p, pipefs_can_read(), and pipe::ring.
Referenced by pipefs_can_read().
Says whether a write of size bytes would go on without waiting.
Definition at line 125 of file pipe.c.
References has_readers(), vnode::p, pipefs_can_write(), pipe::ring, and ringbuf::size.
Referenced by pipefs_can_write().
|
static |
Closes an end of a pipe, when its last open file is closed.
The pipe goes with its last end; otherwise, the other end is woken up to see the end of the file, or that writing fails.
Definition at line 73 of file pipe.c.
References pipe::fifo, vnode::fifo, has_readers(), has_writers(), kfree(), NULL, vnode::p, pipefs_close(), pipefs_pfree(), pipe::queue, pipe::r_node, pipe::rw_node, vfs_close(), pipe::w_node, and waitq_wakeup().
Referenced by pipefs_close().
Returns a new reference to an end of a pipe (END_*), making the end if it doesn't exist yet, or NULL if there was no memory.
Definition at line 163 of file pipe.c.
References END_READ, END_WRITE, vnode::fs, kmalloc(), M_ZERO, vnode::mode, NULL, vnode::p, pipefs, pipefs_end(), pipe::queue, pipe::r_node, vnode::read_queue, vnode::ref, pipe::rw_node, pipe::w_node, and vnode::write_queue.
Referenced by pipefs_end(), pipefs_fifo_open(), and pipefs_pipe().
|
static |
Says whether a read is at the end of the file: no writers are left, and the pipe is empty.
Definition at line 105 of file pipe.c.
References has_writers(), pipefs_eof(), and pipe::ring.
Referenced by pipefs_eof().
| int pipefs_fifo_open | ( | struct file * | file | ) |
Opens a FIFO: the open file's vnode becomes an end of the FIFO's pipe, made by its first open.
Opening for reading waits for a writer, and opening for writing for a reader, unless the file is non-blocking (then a writer without readers fails with ENXIO) or opened read-write (which is both).
| file | the open file, whose vnode is the FIFO; it's left as it was on failure |
Definition at line 239 of file pipe.c.
References END_RDWR, END_READ, END_WRITE, pipe::fifo, vnode::fifo, file::flags, has_readers(), has_writers(), NULL, pipefs_end(), pipefs_fifo_open(), pipefs_mkpipe(), pipefs_pfree(), pipe::queue, pipe::r_opens, vnode::ref, vfs_close(), pipe::w_opens, waitq_sleep(), and waitq_wakeup().
Referenced by pipefs_fifo_open(), and vfs_file_open().
|
static |
Makes a new pipe, with no ends.
Returns 0 or -ENOMEM.
Definition at line 142 of file pipe.c.
References kmalloc(), M_ZERO, PIPE_BUFLEN, pipefs_mkpipe(), pipefs_pfree(), and pipe::ring.
Referenced by pipefs_fifo_open(), pipefs_mkpipe(), and pipefs_pipe().
|
static |
Frees a pipe and its ring buffer.
Definition at line 41 of file pipe.c.
References kfree(), pipefs_pfree(), and pipe::ring.
Referenced by pipefs_close(), pipefs_fifo_open(), pipefs_mkpipe(), pipefs_pfree(), and pipefs_pipe().
Makes an anonymous pipe, for pipe(): one open file for each end.
| read | the open file for the reading end, its vnode set here |
| write | the open file for the writing end, its vnode and flags set here |
Definition at line 199 of file pipe.c.
References END_READ, END_WRITE, file::flags, kfree(), NULL, pipefs_end(), pipefs_mkpipe(), pipefs_pfree(), and pipefs_pipe().
Referenced by pipefs_pipe(), and sys_pipe().
Reads what the pipe's ring buffer has, up to what is asked for.
Definition at line 51 of file pipe.c.
References vnode::p, pipefs_read(), iobuf::resid, and pipe::ring.
Referenced by pipefs_read().
Writes into the pipe's ring buffer, as much as fits.
Fails with -EPIPE if no end is open for reading.
Definition at line 59 of file pipe.c.
References has_readers(), vnode::p, pipefs_write(), iobuf::resid, and pipe::ring.
Referenced by pipefs_write().
| struct fs pipefs |
Definition at line 308 of file pipe.c.
Referenced by pipefs_end().