|
miniOS
x86_64 hobby kernel with SMP, VFS, and POSIX process model
|
#include <miniOS/types.h>

Go to the source code of this file.
Classes | |
| struct | pipe_t |
Macros | |
| #define | PIPE_SIZE 4096 |
Functions | |
| pipe_t * | pipe_create (void) |
| int | pipe_read (uint32_t ino, uint64_t off, void *buf, uint32_t len) |
| int | pipe_write (uint32_t ino, uint64_t off, const void *buf, uint32_t len) |
| void | pipe_free (pipe_t *p) |
| int | pipe_write_buf (pipe_t *p, const void *buf, uint32_t len) |
| int | pipe_read_buf (pipe_t *p, void *buf, uint32_t len) |
Variables | |
| struct vfs_ops | pipe_ops |
| #define PIPE_SIZE 4096 |
PIPE_SIZE - Capacity of the ring-buffer backing each anonymous pipe. Must be a power of 2 so that monotonic uint32_t cursors can index with a simple modulo (write_pos % PIPE_SIZE).
| pipe_t * pipe_create | ( | void | ) |
pipe_create() - Allocate and initialise a new pipe object.
Uses kmalloc to allocate the pipe_t; zero-fills all fields so that write_pos==read_pos==ref_count==write_closed==0.
pipe_create() - Allocate and zero-initialise a new pipe object.
All fields are zeroed so that write_pos == read_pos == 0 (empty buffer), ref_count == 0 (caller sets it after both fds are established), and write_closed == 0.


| void pipe_free | ( | pipe_t * | p | ) |
pipe_free() - Decrement reference count and free when it reaches zero. : Pipe to release. If NULL, this is a safe no-op.
Decrements p->ref_count. Calls kfree(p) only when ref_count reaches 0.
pipe_free() - Release a reference to a pipe; free when ref_count reaches 0. : Pipe to release. NULL is a safe no-op.
Decrements p->ref_count. If it reaches 0, calls kfree(p) to release the kernel heap allocation.


pipe_read() - Read bytes from a pipe ring buffer. @ino: pipe_t pointer cast to uint32_t via uintptr_t (vfs_ops_t constraint). @off: Ignored (pipes have no seek position). @buf: Destination buffer for read bytes. @len: Maximum number of bytes to read.
Reads up to min(len, available) bytes. Advances read_pos. If available == 0, returns 0 regardless of write_closed state.

pipe_read() - Read bytes from the ring buffer. @ino: pipe_t * cast to uint32_t via uintptr_t (vfs_ops_t ABI constraint). The syscall layer passes (uint32_t)(uintptr_t)vf->pipe as ino. @off: Ignored; pipes have no file offset. @buf: Destination buffer. @len: Maximum bytes to read.
Uses monotonic cursor arithmetic: available = write_pos - read_pos. Reads byte-by-byte using read_pos % PIPE_SIZE as the buffer index.

pipe_write() - Write bytes into a pipe ring buffer. @ino: pipe_t pointer cast to uint32_t via uintptr_t (vfs_ops_t constraint). @off: Ignored (pipes have no seek position). @buf: Source buffer for bytes to write. @len: Number of bytes to write.
Writes up to min(len, free_space) bytes. Advances write_pos. If the buffer is full, returns 0 (partial write of 0 bytes).

pipe_write_buf() / pipe_read_buf() — direct pointer variants.
These bypass the vfs_ops_t ino-as-uint32_t ABI, which cannot represent kernel-heap pointers above 4 GB. Use these in the kernel fast-paths (e.g. syscall_dispatch) where the pipe_t * is already available.
pipe_write() - Write bytes into the ring buffer. @ino: pipe_t * cast to uint32_t via uintptr_t (vfs_ops_t ABI constraint). @off: Ignored. @buf: Source buffer. @len: Number of bytes to write.
Uses monotonic cursor arithmetic: free_space = PIPE_SIZE - (write_pos - read_pos). Writes byte-by-byte using write_pos % PIPE_SIZE as the buffer index. Returns 0 (partial write of 0) when the buffer is completely full.

|
extern |
pipe_ops - VFS ops dispatch table for pipe file descriptors. Declared as struct vfs_ops (not vfs_ops_t typedef) to avoid circular dependency with vfs.h. Callers that include vfs.h can use the typedef.
pipe_ops - VFS ops dispatch table for pipe file descriptors.
Only .read and .write are populated; all other ops (lookup, readdir, flush, create, unlink, mkdir, set_root) are NULL because pipes have no filesystem representation and are not seekable or stat-able.