From dbc6c8c6637eb7e3c83c6f4cd2446000b46e28bf Mon Sep 17 00:00:00 2001 From: Jonas 'Sortie' Termansen Date: Thu, 21 Mar 2013 21:35:51 +0100 Subject: [PATCH] Add ioctl(2). --- libc/Makefile | 1 + libc/include/sys/ioctl.h | 36 +++++++++++++++++++++++++++ libc/ioctl.cpp | 39 ++++++++++++++++++++++++++++++ sortix/include/sortix/syscallnum.h | 5 ++-- sortix/io.cpp | 16 ++++++++++++ 5 files changed, 95 insertions(+), 2 deletions(-) create mode 100644 libc/include/sys/ioctl.h create mode 100644 libc/ioctl.cpp diff --git a/libc/Makefile b/libc/Makefile index 92941640..def7844d 100644 --- a/libc/Makefile +++ b/libc/Makefile @@ -198,6 +198,7 @@ gettermmode.o \ gettimeofday.o \ getuid.o \ init.o \ +ioctl.o \ ioleast.o \ isatty.o \ kernelinfo.o \ diff --git a/libc/include/sys/ioctl.h b/libc/include/sys/ioctl.h new file mode 100644 index 00000000..bf6a9049 --- /dev/null +++ b/libc/include/sys/ioctl.h @@ -0,0 +1,36 @@ +/******************************************************************************* + + Copyright(C) Jonas 'Sortie' Termansen 2013. + + This file is part of the Sortix C Library. + + The Sortix C Library is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 3 of the License, or (at your + option) any later version. + + The Sortix C Library is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with the Sortix C Library. If not, see . + + sys/ioctl.h + Miscellaneous device control interface. + +*******************************************************************************/ + +#ifndef INCLUDE_SYS_IOCTL_H +#define INCLUDE_SYS_IOCTL_H + +#include + +__BEGIN_DECLS + +int ioctl(int fd, int request, ...); + +__END_DECLS + +#endif diff --git a/libc/ioctl.cpp b/libc/ioctl.cpp new file mode 100644 index 00000000..2f554cfe --- /dev/null +++ b/libc/ioctl.cpp @@ -0,0 +1,39 @@ +/******************************************************************************* + + Copyright(C) Jonas 'Sortie' Termansen 2013. + + This file is part of the Sortix C Library. + + The Sortix C Library is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 3 of the License, or (at your + option) any later version. + + The Sortix C Library is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with the Sortix C Library. If not, see . + + ioctl.cpp + Miscellaneous device control interface. + +*******************************************************************************/ + +#include +#include + +#include + +DEFN_SYSCALL3(int, sys_ioctl, SYSCALL_IOCTL, int, int, void*); + +extern "C" int ioctl(int fd, int request, ...) +{ + va_list ap; + va_start(ap, request); + void* ptr = va_arg(ap, void*); + va_end(ap); + return sys_ioctl(fd, request, ptr); +} diff --git a/sortix/include/sortix/syscallnum.h b/sortix/include/sortix/syscallnum.h index 5871a162..494003d8 100644 --- a/sortix/include/sortix/syscallnum.h +++ b/sortix/include/sortix/syscallnum.h @@ -1,6 +1,6 @@ /******************************************************************************* - Copyright(C) Jonas 'Sortie' Termansen 2011, 2012. + Copyright(C) Jonas 'Sortie' Termansen 2011, 2012, 2013. This file is part of Sortix. @@ -105,6 +105,7 @@ #define SYSCALL_GETEGID 81 #define SYSCALL_SETEUID 82 #define SYSCALL_SETEGID 83 -#define SYSCALL_MAX_NUM 84 /* index of highest constant + 1 */ +#define SYSCALL_IOCTL 84 +#define SYSCALL_MAX_NUM 85 /* index of highest constant + 1 */ #endif diff --git a/sortix/io.cpp b/sortix/io.cpp index 84aef4fc..cd1e50ba 100644 --- a/sortix/io.cpp +++ b/sortix/io.cpp @@ -325,6 +325,21 @@ static int sys_fcntl(int fd, int cmd, unsigned long arg) return ret; } +static int sys_ioctl(int fd, int cmd, void* /*ptr*/) +{ + Ref desc = CurrentProcess()->GetDescriptor(fd); + if ( !desc ) + return -1; + int ret = -1; + switch ( cmd ) + { + default: + errno = EINVAL; + break; + } + return ret; +} + static ssize_t sys_readdirents(int fd, kernel_dirent* dirent, size_t size/*, size_t maxcount*/) { @@ -594,6 +609,7 @@ void Init() Syscall::Register(SYSCALL_FSYNC, (void*) sys_fsync); Syscall::Register(SYSCALL_FTRUNCATE, (void*) sys_ftruncate); Syscall::Register(SYSCALL_GETTERMMODE, (void*) sys_gettermmode); + Syscall::Register(SYSCALL_IOCTL, (void*) sys_ioctl); Syscall::Register(SYSCALL_ISATTY, (void*) sys_isatty); Syscall::Register(SYSCALL_LINKAT, (void*) sys_linkat); Syscall::Register(SYSCALL_LINK, (void*) sys_link);