|
miniOS
x86_64 hobby kernel with SMP, VFS, and POSIX process model
|
#include <miniOS/fs/pipe.h>#include <miniOS/fs/vfs.h>#include <miniOS/mm/heap.h>#include <string.h>
Functions | |
| pipe_t * | pipe_create (void) |
| int | pipe_read_buf (pipe_t *p, void *buf, uint32_t len) |
| int | pipe_read (uint32_t ino, uint64_t off, void *buf, uint32_t len) |
| int | pipe_write_buf (pipe_t *p, const 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) |
Variables | |
| struct vfs_ops | pipe_ops |
| pipe_t * pipe_create | ( | void | ) |
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() - 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() - 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.

| struct vfs_ops pipe_ops |
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.