AquilaOS documentation
How it works, and its code
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
20ssize_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
52ssize_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}
#define VNODE_DEV(vnode)
Definition dev.h:79
void iobuf_init(struct iobuf *io, void *buf, size_t len, int user)
Sets up an iobuf for one buffer.
Definition iobuf.c:19
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
#define LOG_DEBUG
Definition printk.h:19
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
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
struct vops vops
Definition vfs.h:104
An iobuf.
Definition iobuf.h:35
size_t resid
Definition iobuf.h:38
A file in memory (a vnode): what its inode says, and the kernel's own state.
Definition vfs.h:113
struct fs * fs
Definition vfs.h:127
ssize_t(*) read(struct vnode *vnode, off_t offset, struct iobuf *io)
Definition vfs.h:72
long int ssize_t
Definition types.h:12
long int off_t
Definition types.h:10
#define ISDEV(vnode)
Definition vfs.h:209