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
8int 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}
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_ioctl(int fd, uint32_t req, void *arg)
Definition ioctl.c:8
#define LOG2_ERROR(mod, fmt,...)
Definition serial.h:38
Definition fd.h:20
unsigned int uint32_t
Definition type.h:19