AquilaOS documentation
How it works, and its code
Loading...
Searching...
No Matches
zero.c
Go to the documentation of this file.
1
5
6#include <core/system.h>
7#include <dev/dev.h>
8#include <fs/posix.h>
9#include <aquila/errno.h>
10
11#include <memdev.h>
12
13struct dev zerodev;
14
16static ssize_t zerodev_read(struct devid *dd __unused, off_t offset __unused, struct iobuf *io)
17{
18 return iobuf_zero(io, io->resid);
19}
20
22static ssize_t zerodev_write(struct devid *dd __unused, off_t offset __unused, struct iobuf *io)
23{
24 return iobuf_skip(io, io->resid);
25}
26
27struct dev zerodev = {
28 .read = zerodev_read,
29 .write = zerodev_write,
30
31 .fops = {
32 .open = posix_file_open,
33 .read = posix_file_read,
34 .write = posix_file_write,
35 .close = posix_file_close,
36
37 .can_read = __vfs_can_always,
38 .can_write = __vfs_can_always,
39 .eof = __vfs_eof_never,
40 },
41};
ssize_t iobuf_zero(struct iobuf *io, size_t n)
Fills bytes of the iobuf's buffer with zeros, and moves past them.
Definition iobuf.c:167
size_t iobuf_skip(struct iobuf *io, size_t n)
Moves an iobuf past bytes, without copying them.
Definition iobuf.c:81
struct dev zerodev
Definition zero.c:27
int posix_file_open(struct file *file)
Finishes opening a file: with O_TRUNC, a regular file is truncated to 0 bytes.
Definition open.c:17
int posix_file_close(struct file *file)
Closes an open file by dropping its reference to its vnode.
Definition close.c:15
ssize_t posix_file_read(struct file *file, struct iobuf *io)
Reads from an open file at its offset, and moves the offset past what was read.
Definition read.c:29
ssize_t posix_file_write(struct file *file, struct iobuf *io)
Writes to an open file at its offset, and moves the offset past what was written.
Definition write.c:25
A device driver: its operations, any of which may be NULL.
Definition dev.h:28
Which device: its kind (S_IFCHR or S_IFBLK) and numbers.
Definition dev.h:21
An iobuf.
Definition iobuf.h:35
size_t resid
Definition iobuf.h:38
long int ssize_t
Definition types.h:12
long int off_t
Definition types.h:10
static ssize_t zerodev_write(struct devid *dd, off_t offset, struct iobuf *io)
Takes all that is written, and throws it away.
Definition zero.c:22
static ssize_t zerodev_read(struct devid *dd, off_t offset, struct iobuf *io)
Fills the reader's buffer with zeros.
Definition zero.c:16