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
9
int
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
}
count
int count
Definition
cache.h:2
get_current_core_data
each_core_data * get_current_core_data(void)
Definition
core.c:54
ops
void * ops
Definition
dev.h:2
err_no.h
ENOTTY
#define ENOTTY
Definition
err_no.h:26
EBADF
#define EBADF
Definition
err_no.h:12
event.h
fd.h
fdt
struct fdtable * fdt
Definition
fd.h:1
core.h
syscall_read
int syscall_read(int fd, void *buf, long count)
Definition
read.c:9
serial.h
LOG2_ERROR
#define LOG2_ERROR(mod, fmt,...)
Definition
serial.h:38
fdtable
Definition
fd.h:20
vops_file_t
Definition
vnode.h:28
syscall.h
vnode.h
kernel
sys
syscall
read.c
Generated on Sat May 30 2026 11:09:57 for Voxia OS by
1.13.2