Voxia OS v0.0.1
Hobby Project Operating System Targeting x86-64
Loading...
Searching...
No Matches
write.c
Go to the documentation of this file.
1#include "hal/cpu/core.h"
2#include "libk/serial.h"
3#include "sys/err_no.h"
4#include "vfs/vnode.h"
5#include <sys/fd.h>
6#include <sys/syscall.h>
7
8int syscall_write(int fd, void* buf, long count) {
9 auto curr_procc = get_current_core_data()->active_thread->process;
10 auto fdt = (struct fdtable*)curr_procc->fdtable;
11 auto curr_fd = fdt->fds[fd];
12
13 if (fd < 0 || fd > (int)fdt->max_fds) {
14 LOG2_ERROR("writev", "fd %d is invalid, max fd %d", fd,
15 fdt->max_fds);
16 return -EBADF;
17 }
18
19 auto ops = (vops_file_t*)curr_fd->ops;
20 if (!ops) {
21 LOG2_ERROR("writev", "fd %d ops is missing", fd);
22 return -EBADF;
23 }
24
25 if (!curr_fd->vnode) {
26 LOG2_ERROR("writev", "fd %d vnode is missing", fd);
27 return -EBADF;
28 }
29
30 if (!ops->write) {
31 LOG2_ERROR("writev", "fd %d `write` ops is missing", fd);
32 return -ENOTTY;
33 }
34
35 auto s = ops->write(curr_fd->vnode, buf, (size_t)count, 0);
36 return (int)s;
37}
int count
Definition cache.h:2
each_core_data * get_current_core_data(void)
Definition core.c:54
void * ops
Definition dev.h:2
#define ENOTTY
Definition err_no.h:26
#define EBADF
Definition err_no.h:12
struct fdtable * fdt
Definition fd.h:1
#define LOG2_ERROR(mod, fmt,...)
Definition serial.h:38
Definition fd.h:20
int syscall_write(int fd, void *buf, long count)
Definition write.c:8