AquilaOS documentation
How it works, and its code
Toggle main menu visibility
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
13
struct
dev
zerodev
;
14
16
static
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
22
static
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
27
struct
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
};
dev.h
system.h
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.
Definition
iobuf.c:167
iobuf_skip
size_t iobuf_skip(struct iobuf *io, size_t n)
Moves an iobuf past bytes, without copying them.
Definition
iobuf.c:81
memdev.h
zerodev
struct dev zerodev
Definition
zero.c:27
posix_file_open
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
posix_file_close
int posix_file_close(struct file *file)
Closes an open file by dropping its reference to its vnode.
Definition
close.c:15
posix_file_read
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
posix_file_write
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
posix.h
dev
A device driver: its operations, any of which may be NULL.
Definition
dev.h:28
devid
Which device: its kind (S_IFCHR or S_IFBLK) and numbers.
Definition
dev.h:21
iobuf
An iobuf.
Definition
iobuf.h:35
iobuf::resid
size_t resid
Definition
iobuf.h:38
ssize_t
long int ssize_t
Definition
types.h:12
off_t
long int off_t
Definition
types.h:10
zerodev_write
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
zerodev_read
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
kernel
dev
mem
zero.c
Generated by
1.18.0