Voxia OS
v0.0.1
Hobby Project Operating System Targeting x86-64
Loading...
Searching...
No Matches
ioctl.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
8
int
syscall_ioctl
(
int
fd,
uint32_t
req,
void
* arg) {
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
(
"Ioctl"
,
"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
(
"Ioctl"
,
"fd %d ops is missing"
, fd);
22
return
-
EBADF
;
23
}
24
25
if
(!curr_fd->vnode) {
26
LOG2_ERROR
(
"Ioctl"
,
"fd %d vnode is missing"
, fd);
27
return
-
EBADF
;
28
}
29
30
if
(!
ops
->ioctl) {
31
LOG2_ERROR
(
"Ioctl"
,
"fd %d `ioctl` ops is missing"
, fd);
32
return
-
ENOTTY
;
33
}
34
35
return
ops
->ioctl(curr_fd->vnode, req, arg);
36
}
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
fd.h
fdt
struct fdtable * fdt
Definition
fd.h:1
syscall_ioctl
int syscall_ioctl(int fd, uint32_t req, void *arg)
Definition
ioctl.c:8
core.h
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
uint32_t
unsigned int uint32_t
Definition
type.h:19
vnode.h
kernel
sys
syscall
ioctl.c
Generated on Sat May 30 2026 11:09:57 for Voxia OS by
1.13.2