miniOS
x86_64 hobby kernel with SMP, VFS, and POSIX process model
Loading...
Searching...
No Matches
pipe.h File Reference
#include <miniOS/types.h>
Include dependency graph for pipe.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  pipe_t

Macros

#define PIPE_SIZE   4096

Functions

pipe_tpipe_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

Macro Definition Documentation

◆ PIPE_SIZE

#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).

Function Documentation

◆ pipe_create()

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.

Returns
: Pointer to the new pipe_t on success, NULL if kmalloc returns NULL.

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.

Returns
: Pointer to the allocated pipe_t, or NULL on OOM.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ pipe_free()

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.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ pipe_read()

int pipe_read ( uint32_t ino,
uint64_t off,
void * buf,
uint32_t len )

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.

Returns
: Number of bytes read, or 0 if the buffer is empty.
Here is the call graph for this function:

◆ pipe_read_buf()

int pipe_read_buf ( pipe_t * p,
void * buf,
uint32_t len )

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.

Returns
: Bytes read, or 0 when the buffer is empty (regardless of write_closed).
Here is the caller graph for this function:

◆ pipe_write()

int pipe_write ( uint32_t ino,
uint64_t off,
const void * buf,
uint32_t len )

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).

Returns
: Number of bytes written (may be less than len if buffer fills).
Here is the call graph for this function:

◆ pipe_write_buf()

int pipe_write_buf ( pipe_t * p,
const void * buf,
uint32_t len )

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.

Returns
: Bytes written (may be less than len if buffer is partially or fully full).
Here is the caller graph for this function:

Variable Documentation

◆ pipe_ops

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