AquilaOS documentation
How it works, and its code
Loading...
Searching...
No Matches
iobuf.c File Reference

iobufs: moving bytes into and out of the buffer of a read or a write, which may be in user memory (see fs/iobuf.h). More...

#include <core/system.h>
#include <core/string.h>
#include <fs/iobuf.h>
#include <sys/uaccess.h>

Go to the source code of this file.

Functions

void iobuf_init (struct iobuf *io, void *buf, size_t len, int user)
 Sets up an iobuf for one buffer.
static ssize_t iobuf_copy (struct iobuf *io, char *kbuf, size_t n, int out)
 Copies up to n bytes between the iobuf's buffer, from where it is, and kbuf: into the buffer if out is set, out of it otherwise, one segment at a time.
size_t iobuf_skip (struct iobuf *io, size_t n)
 Moves an iobuf past bytes, without copying them.
ssize_t iobuf_out (struct iobuf *io, const void *src, size_t n)
 Copies bytes from the kernel into the iobuf's buffer, and moves past them.
ssize_t iobuf_in (struct iobuf *io, void *dst, size_t n)
 Copies bytes from the iobuf's buffer into the kernel, and moves past them.
ssize_t iobuf_peek (struct iobuf *io, void *dst, size_t n)
 Copies bytes from the iobuf's buffer into the kernel, without moving past them.
ssize_t iobuf_zero (struct iobuf *io, size_t n)
 Fills bytes of the iobuf's buffer with zeros, and moves past them.

Detailed Description

iobufs: moving bytes into and out of the buffer of a read or a write, which may be in user memory (see fs/iobuf.h).

Definition in file iobuf.c.

Function Documentation

◆ iobuf_copy()

ssize_t iobuf_copy ( struct iobuf * io,
char * kbuf,
size_t n,
int out )
static

Copies up to n bytes between the iobuf's buffer, from where it is, and kbuf: into the buffer if out is set, out of it otherwise, one segment at a time.

It doesn't move the iobuf past them. Returns how many bytes were copied (fewer if a fault stopped it), or -EFAULT if a fault came first.

Definition at line 36 of file iobuf.c.

References iobuf_seg::base, iobuf::fault, iobuf_copy(), iobuf_seg::len, memcpy(), MIN, iobuf::nseg, iobuf::resid, iobuf::seg, and iobuf::user.

Referenced by iobuf_copy(), iobuf_in(), iobuf_out(), and iobuf_peek().

◆ iobuf_in()

ssize_t iobuf_in ( struct iobuf * io,
void * dst,
size_t n )

Copies bytes from the iobuf's buffer into the kernel, and moves past them.

Parameters
iothe iobuf
dstwhere they go
nhow many
Returns
how many were copied (fewer if a fault stopped it), or -EFAULT if a fault came first

Definition at line 135 of file iobuf.c.

References iobuf_copy(), iobuf_in(), and iobuf_skip().

Referenced by ext2_write(), fbdev_vesa_write(), iobuf_in(), kdev_blk_io(), kmsgdev_write(), minix_write(), ps2mouse_write(), randomdev_write(), ringbuf_write_iobuf(), and tmpfs_write().

◆ iobuf_init()

void iobuf_init ( struct iobuf * io,
void * buf,
size_t len,
int user )

Sets up an iobuf for one buffer.

Parameters
iothe iobuf
bufthe buffer
lenits length, in bytes
userwhether the buffer is in user memory (copies are checked)

Definition at line 19 of file iobuf.c.

References iobuf_seg::base, iobuf::fault, iobuf_init(), iobuf_seg::len, iobuf::nseg, iobuf::one, iobuf::resid, iobuf::seg, and iobuf::user.

Referenced by iobuf_init(), sys_read(), sys_recv(), sys_send(), sys_write(), vfs_read(), and vfs_write().

◆ iobuf_out()

ssize_t iobuf_out ( struct iobuf * io,
const void * src,
size_t n )

Copies bytes from the kernel into the iobuf's buffer, and moves past them.

Parameters
iothe iobuf
srcthe bytes
nhow many
Returns
how many were copied (fewer if a fault stopped it), or -EFAULT if a fault came first

Definition at line 115 of file iobuf.c.

References iobuf_copy(), iobuf_out(), and iobuf_skip().

Referenced by ext2_read(), iobuf_out(), iobuf_zero(), kdev_blk_io(), kmsgdev_read(), minix_read(), procfs_read(), randomdev_read(), ring_to_iobuf(), ringbuf_read_iobuf(), socket_inet_recv(), socket_tcp_recv(), tmpfs_read(), and vcs_read().

◆ iobuf_peek()

ssize_t iobuf_peek ( struct iobuf * io,
void * dst,
size_t n )

Copies bytes from the iobuf's buffer into the kernel, without moving past them.

Parameters
iothe iobuf
dstwhere they go
nhow many
Returns
how many were copied, or -EFAULT

Definition at line 154 of file iobuf.c.

References iobuf_copy(), and iobuf_peek().

Referenced by iobuf_peek(), iobuf_to_ring(), and tty_write_iobuf().

◆ iobuf_skip()

size_t iobuf_skip ( struct iobuf * io,
size_t n )

Moves an iobuf past bytes, without copying them.

Parameters
iothe iobuf
nhow many bytes (no more than are left)
Returns
how many it moved past

Definition at line 81 of file iobuf.c.

References iobuf_seg::base, iobuf_skip(), iobuf_seg::len, MIN, iobuf::nseg, iobuf::resid, and iobuf::seg.

Referenced by iobuf_in(), iobuf_out(), iobuf_skip(), iobuf_to_ring(), nulldev_write(), tty_write_iobuf(), and zerodev_write().

◆ iobuf_zero()

ssize_t iobuf_zero ( struct iobuf * io,
size_t n )

Fills bytes of the iobuf's buffer with zeros, and moves past them.

Parameters
iothe iobuf
nhow many
Returns
how many were zeroed (fewer if a fault stopped it), or -EFAULT if a fault came first

Definition at line 167 of file iobuf.c.

References iobuf_out(), iobuf_zero(), MIN, and iobuf::resid.

Referenced by iobuf_zero(), and zerodev_read().