10#include <aquila/fcntl.h>
121 return size <= ringbuf_available(
pipe->
ring);
129 size_t avail = ringbuf_available(
pipe->
ring);
147 if (!
pipe)
return -ENOMEM;
156 if (ref) *ref =
pipe;
185 node->
mode = S_IFIFO | 0600;
223 write->
flags = O_WRONLY;
int vfs_close(struct vnode *vnode)
Drops a reference to a vnode.
#define MALLOC_DEFINE(type, _name, _desc)
void * kmalloc(size_t size, struct malloc_type *type, int flags)
Allocates memory for one of the kernel's structures.
void kfree(void *)
Frees an object that kmalloc() gave.
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,...
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 has_writers(struct pipe *pipe)
Says whether a pipe has an end open for writing.
static int pipefs_can_read(struct file *file, size_t size)
Says whether a read of size bytes would go on without waiting.
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.
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.
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.
int pipefs_pipe(struct file *read, struct file *write)
Makes an anonymous pipe, for pipe(): one open file for each end.
static int pipefs_can_write(struct file *file, size_t size)
Says whether a write of size bytes would go on without waiting.
static void pipefs_pfree(struct pipe *pipe)
Frees a pipe and its ring buffer.
static int has_readers(struct pipe *pipe)
Says whether a pipe has an end open for reading.
static int pipefs_mkpipe(struct pipe **ref)
Makes a new pipe, with no ends.
static int pipefs_close(struct vnode *node)
Closes an end of a pipe, when its last open file is closed.
int posix_file_close(struct file *file)
Closes an open file by dropping its reference to its vnode.
ssize_t posix_file_read(struct file *file, struct iobuf *io)
Reads from an open file at its offset, and moves the offset past what was read.
ssize_t posix_file_write(struct file *file, struct iobuf *io)
Writes to an open file at its offset, and moves the offset past what was written.
An open file (POSIX's "open file description", fs/file.c).
A pipe, or a FIFO's pipe.
struct waitq queue
readers and writers sleep here
struct vnode * r_node
its ends, NULL once closed (rw_node: a FIFO opened read-write)
struct vnode * fifo
the FIFO this is the pipe of, or NULL for pipe()
struct ringbuf * ring
the data written, not read yet
unsigned long r_opens
how many times a FIFO was opened for reading and for writing, so far: an open waiting for the other s...
A file in memory (a vnode): what its inode says, and the kernel's own state.
struct waitq * write_queue
size_t ref
how many references there are to it
struct waitq * read_queue
where its readers and writers sleep
void * p
the filesystem's own data
struct pipe * fifo
the pipe of a FIFO while it is open
void waitq_wakeup(struct waitq *waitq)
Wakes up every thread sleeping on a wait queue, and every thread polling it.
int waitq_sleep(struct waitq *waitq)
Puts the current thread to sleep on a wait queue until it is woken up.