kernel: Add an ioctl() system call

This commit is contained in:
apio 2023-04-09 11:22:57 +02:00
parent e5a3bbcbbc
commit 76eb8cd129
Signed by: apio
GPG Key ID: B8A7D06E42258954
5 changed files with 29 additions and 1 deletions

View File

@ -27,6 +27,11 @@ namespace VFS
class Inode
{
public:
virtual Result<u64> ioctl(int, void*)
{
return err(ENOTTY);
}
// Directory-specific methods
virtual Result<SharedPtr<Inode>> find(const char* name) const = 0;

View File

@ -8,6 +8,11 @@ class Device
virtual Result<usize> write(const u8* buf, usize offset, usize length) = 0;
virtual Result<u64> ioctl(int, void*)
{
return err(ENOTTY);
}
virtual bool blocking() const = 0;
virtual ~Device() = default;

View File

@ -153,6 +153,11 @@ namespace TmpFS
return err(EINVAL);
}
Result<u64> ioctl(int request, void* arg) override
{
return m_device->ioctl(request, arg);
}
bool blocking() const override
{
return m_device->blocking();

View File

@ -135,3 +135,15 @@ Result<u64> sys_fcntl(Registers*, SyscallArgs args)
default: return err(EINVAL);
}
}
Result<u64> sys_ioctl(Registers*, SyscallArgs args)
{
int fd = (int)args[0];
int request = (int)args[1];
void* arg = (void*)args[2];
Thread* current = Scheduler::current();
auto& descriptor = *TRY(current->resolve_fd(fd));
return descriptor.inode->ioctl(request, arg);
}

View File

@ -3,7 +3,8 @@
#define enumerate_syscalls(_e) \
_e(exit) _e(clock_gettime) _e(mmap) _e(munmap) _e(usleep) _e(open) _e(close) _e(read) _e(getpid) _e(write) \
_e(lseek) _e(mkdir) _e(execve) _e(mknod) _e(fork) _e(waitpid) _e(getppid) _e(fcntl) _e(getdents) _e(getuid) \
_e(geteuid) _e(getgid) _e(getegid) _e(setuid) _e(setgid) _e(seteuid) _e(setegid) _e(chmod) _e(chown)
_e(geteuid) _e(getgid) _e(getegid) _e(setuid) _e(setgid) _e(seteuid) _e(setegid) _e(chmod) _e(chown) \
_e(ioctl)
enum Syscalls
{