AquilaOS documentation
How it works, and its code
Toggle main menu visibility
Loading...
Searching...
No Matches
read.c
Go to the documentation of this file.
1
4
5
#include <
core/system.h
>
6
#include <
fs/vfs.h
>
7
#include <
fs/iobuf.h
>
8
#include <
dev/dev.h
>
9
20
ssize_t
vfs_read_io
(
struct
vnode
*
vnode
,
off_t
off,
struct
iobuf
*io)
21
{
22
vfs_log(
LOG_DEBUG
,
"vfs_read_io(vnode=%p, off=%d, size=%d)\n"
,
vnode
, off, io->
resid
);
23
24
/* invalid request */
25
if
(!
vnode
)
26
return
-EINVAL;
27
28
/* a device node: the driver reads it */
29
if
(
ISDEV
(
vnode
))
30
return
kdev_read
(&
VNODE_DEV
(
vnode
), off, io);
31
32
/* invalid request */
33
if
(!
vnode
->
fs
)
34
return
-EINVAL;
35
36
/* the filesystem doesn't support it */
37
if
(!
vnode
->
fs
->
vops
.
read
)
38
return
-ENOSYS;
39
40
return
vnode
->
fs
->
vops
.
read
(
vnode
, off, io);
41
}
42
52
ssize_t
vfs_read
(
struct
vnode
*
vnode
,
off_t
off,
size_t
size,
void
*buf)
53
{
54
struct
iobuf
io;
55
iobuf_init
(&io, buf, size, 0);
56
return
vfs_read_io
(
vnode
, off, &io);
57
}
dev.h
VNODE_DEV
#define VNODE_DEV(vnode)
Definition
dev.h:79
system.h
iobuf_init
void iobuf_init(struct iobuf *io, void *buf, size_t len, int user)
Sets up an iobuf for one buffer.
Definition
iobuf.c:19
iobuf.h
kdev_read
ssize_t kdev_read(struct devid *dd, off_t offset, struct iobuf *io)
Reads from a device: a character device through its driver, a block device in blocks.
Definition
kdev.c:297
LOG_DEBUG
#define LOG_DEBUG
Definition
printk.h:19
vfs_read
ssize_t vfs_read(struct vnode *vnode, off_t off, size_t size, void *buf)
Reads from a vnode into a kernel buffer.
Definition
read.c:52
vfs_read_io
ssize_t vfs_read_io(struct vnode *vnode, off_t off, struct iobuf *io)
Reads from a vnode into an iobuf (user or kernel memory).
Definition
read.c:20
fs::vops
struct vops vops
Definition
vfs.h:104
iobuf
An iobuf.
Definition
iobuf.h:35
iobuf::resid
size_t resid
Definition
iobuf.h:38
vnode
A file in memory (a vnode): what its inode says, and the kernel's own state.
Definition
vfs.h:113
vnode::fs
struct fs * fs
Definition
vfs.h:127
vops::read
ssize_t(*) read(struct vnode *vnode, off_t offset, struct iobuf *io)
Definition
vfs.h:72
ssize_t
long int ssize_t
Definition
types.h:12
off_t
long int off_t
Definition
types.h:10
vfs.h
ISDEV
#define ISDEV(vnode)
Definition
vfs.h:209
kernel
fs
read.c
Generated by
1.18.0