diff --git a/kernel/src/fs/VFS.h b/kernel/src/fs/VFS.h index 34361c4d..709b3dcd 100644 --- a/kernel/src/fs/VFS.h +++ b/kernel/src/fs/VFS.h @@ -27,6 +27,11 @@ namespace VFS class Inode { public: + virtual Result ioctl(int, void*) + { + return err(ENOTTY); + } + // Directory-specific methods virtual Result> find(const char* name) const = 0; diff --git a/kernel/src/fs/devices/Device.h b/kernel/src/fs/devices/Device.h index dbf9bd28..a6d7dee0 100644 --- a/kernel/src/fs/devices/Device.h +++ b/kernel/src/fs/devices/Device.h @@ -8,6 +8,11 @@ class Device virtual Result write(const u8* buf, usize offset, usize length) = 0; + virtual Result ioctl(int, void*) + { + return err(ENOTTY); + } + virtual bool blocking() const = 0; virtual ~Device() = default; diff --git a/kernel/src/fs/tmpfs/FileSystem.h b/kernel/src/fs/tmpfs/FileSystem.h index 0c92f929..8061c3d0 100644 --- a/kernel/src/fs/tmpfs/FileSystem.h +++ b/kernel/src/fs/tmpfs/FileSystem.h @@ -153,6 +153,11 @@ namespace TmpFS return err(EINVAL); } + Result ioctl(int request, void* arg) override + { + return m_device->ioctl(request, arg); + } + bool blocking() const override { return m_device->blocking(); diff --git a/kernel/src/sys/file.cpp b/kernel/src/sys/file.cpp index 58df5f97..f0d8f42f 100644 --- a/kernel/src/sys/file.cpp +++ b/kernel/src/sys/file.cpp @@ -135,3 +135,15 @@ Result sys_fcntl(Registers*, SyscallArgs args) default: return err(EINVAL); } } + +Result 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); +} diff --git a/libluna/include/luna/Syscall.h b/libluna/include/luna/Syscall.h index db35e950..beec457b 100644 --- a/libluna/include/luna/Syscall.h +++ b/libluna/include/luna/Syscall.h @@ -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 {