miniOS
x86_64 hobby kernel with SMP, VFS, and POSIX process model
Loading...
Searching...
No Matches
pipe.c File Reference
#include <miniOS/fs/pipe.h>
#include <miniOS/fs/vfs.h>
#include <miniOS/mm/heap.h>
#include <string.h>
Include dependency graph for pipe.c:

Functions

pipe_tpipe_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

Function Documentation

◆ pipe_create()

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.

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() - 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() - 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
Initial value:
= {
.lookup = NULL,
.read = pipe_read,
.readdir = NULL,
.write = pipe_write,
.flush = NULL,
.create = NULL,
.unlink = NULL,
.mkdir = NULL,
.set_root = NULL,
}
int pipe_read(uint32_t ino, uint64_t off, void *buf, uint32_t len)
Definition pipe.c:71
int pipe_write(uint32_t ino, uint64_t off, const void *buf, uint32_t len)
Definition pipe.c:101
#define NULL
Definition types.h:52

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.