AquilaOS documentation
How it works, and its code
Toggle main menu visibility
Loading...
Searching...
No Matches
write.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
#include <
mm/vm.h
>
10
22
ssize_t
vfs_write_io
(
struct
vnode
*
vnode
,
off_t
off,
struct
iobuf
*io)
23
{
24
vfs_log(
LOG_DEBUG
,
"vfs_write_io(vnode=%p, off=%d, size=%d)\n"
,
vnode
, off, io->
resid
);
25
26
/* invalid request */
27
if
(!
vnode
)
28
return
-EINVAL;
29
30
/* a device node: the driver writes it */
31
if
(
ISDEV
(
vnode
))
32
return
kdev_write
(&
VNODE_DEV
(
vnode
), off, io);
33
34
/* invalid request */
35
if
(!
vnode
->
fs
)
36
return
-EINVAL;
37
38
/* the filesystem doesn't support it */
39
if
(!
vnode
->
fs
->
vops
.
write
)
40
return
-ENOSYS;
41
42
ssize_t
ret =
vnode
->
fs
->
vops
.
write
(
vnode
, off, io);
43
44
/* refresh the file's pages in the page cache, if it's mapped */
45
if
(ret > 0)
46
vnode_pages_update
(
vnode
, off, off + ret);
47
48
return
ret;
49
}
50
60
ssize_t
vfs_write
(
struct
vnode
*
vnode
,
off_t
off,
size_t
size,
void
*buf)
61
{
62
struct
iobuf
io;
63
iobuf_init
(&io, buf, size, 0);
64
return
vfs_write_io
(
vnode
, off, &io);
65
}
dev.h
VNODE_DEV
#define VNODE_DEV(vnode)
Definition
dev.h:79
vnode_pages_update
void vnode_pages_update(struct vnode *vnode, off_t start, off_t end)
Reads a file's cached pages again after a write or a truncation changed a range of it.
Definition
vm_object.c:128
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_write
ssize_t kdev_write(struct devid *dd, off_t offset, struct iobuf *io)
Writes to a device: a character device through its driver, a block device in blocks.
Definition
kdev.c:319
LOG_DEBUG
#define LOG_DEBUG
Definition
printk.h:19
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::write
ssize_t(*) write(struct vnode *vnode, off_t offset, struct iobuf *io)
Definition
vfs.h:73
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
vm.h
vfs_write_io
ssize_t vfs_write_io(struct vnode *vnode, off_t off, struct iobuf *io)
Writes to a vnode from an iobuf (user or kernel memory).
Definition
write.c:22
vfs_write
ssize_t vfs_write(struct vnode *vnode, off_t off, size_t size, void *buf)
Writes to a vnode from a kernel buffer.
Definition
write.c:60
kernel
fs
write.c
Generated by
1.18.0