Voxia OS v0.0.1
Hobby Project Operating System Targeting x86-64
Loading...
Searching...
No Matches
read.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/syscall.h>
6#include <dev/event.h>
7#include <sys/fd.h>
8
9int syscall_read(int fd, void* buf, long count) {
10 auto curr_procc = get_current_core_data()->active_thread->process;
11 auto fdt = (struct fdtable*)curr_procc->fdtable;
12 auto curr_fd = fdt->fds[fd];
13
14 if (fd < 0 || fd > (int)fdt->max_fds) {
15 LOG2_ERROR("writev", "fd %d is invalid, max fd %d", fd,
16 fdt->max_fds);
17 return -EBADF;
18 }
19
20 auto ops = (vops_file_t*)curr_fd->ops;
21 if (!ops) {
22 LOG2_ERROR("writev", "fd %d ops is missing", fd);
23 return -EBADF;
24 }
25
26 if (!curr_fd->vnode) {
27 LOG2_ERROR("writev", "fd %d vnode is missing", fd);
28 return -EBADF;
29 }
30
31 if (!ops->read) {
32 LOG2_ERROR("writev", "fd %d `write` ops is missing", fd);
33 return -ENOTTY;
34 }
35
36 return ops->read(curr_fd->vnode, buf, (size_t)count, 0);
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
int syscall_read(int fd, void *buf, long count)
Definition read.c:9
#define LOG2_ERROR(mod, fmt,...)
Definition serial.h:38
Definition fd.h:20