From 2fe3595febc2b52d4a7626d1161d5f6397d411c0 Mon Sep 17 00:00:00 2001 From: Jonas 'Sortie' Termansen Date: Sun, 19 Jan 2014 22:45:49 +0100 Subject: [PATCH] Add getumask(2). --- kernel/include/sortix/syscallnum.h | 5 +++-- kernel/process.cpp | 10 ++++++++- libc/Makefile | 1 + libc/include/sys/stat.h | 3 ++- libc/sys/stat/getumask.cpp | 33 ++++++++++++++++++++++++++++++ 5 files changed, 48 insertions(+), 4 deletions(-) create mode 100644 libc/sys/stat/getumask.cpp diff --git a/kernel/include/sortix/syscallnum.h b/kernel/include/sortix/syscallnum.h index eac5b40c..046891e7 100644 --- a/kernel/include/sortix/syscallnum.h +++ b/kernel/include/sortix/syscallnum.h @@ -1,6 +1,6 @@ /******************************************************************************* - Copyright(C) Jonas 'Sortie' Termansen 2011, 2012, 2013. + Copyright(C) Jonas 'Sortie' Termansen 2011, 2012, 2013, 2014. This file is part of Sortix. @@ -147,6 +147,7 @@ #define SYSCALL_SYMLINKAT 123 #define SYSCALL_TCGETWINCURPOS 124 #define SYSCALL_PIPE2 125 -#define SYSCALL_MAX_NUM 126 /* index of highest constant + 1 */ +#define SYSCALL_GETUMASK 126 +#define SYSCALL_MAX_NUM 127 /* index of highest constant + 1 */ #endif diff --git a/kernel/process.cpp b/kernel/process.cpp index d4ddcd71..bde831e7 100644 --- a/kernel/process.cpp +++ b/kernel/process.cpp @@ -1,6 +1,6 @@ /******************************************************************************* - Copyright(C) Jonas 'Sortie' Termansen 2011, 2012, 2013. + Copyright(C) Jonas 'Sortie' Termansen 2011, 2012, 2013, 2014. This file is part of Sortix. @@ -1208,6 +1208,13 @@ static mode_t sys_umask(mode_t newmask) return oldmask; } +static mode_t sys_getumask(void) +{ + Process* process = CurrentProcess(); + ScopedLock lock(&process->idlock); + return process->umask; +} + void Process::Init() { Syscall::Register(SYSCALL_EXEC, (void*) sys_execve); @@ -1216,6 +1223,7 @@ void Process::Init() Syscall::Register(SYSCALL_GETPGID, (void*) sys_getpgid); Syscall::Register(SYSCALL_GETPID, (void*) sys_getpid); Syscall::Register(SYSCALL_GETPPID, (void*) sys_getppid); + Syscall::Register(SYSCALL_GETUMASK, (void*) sys_getumask); Syscall::Register(SYSCALL_SBRK, (void*) sys_sbrk); Syscall::Register(SYSCALL_SETPGID, (void*) sys_setpgid); Syscall::Register(SYSCALL_TFORK, (void*) sys_tfork); diff --git a/libc/Makefile b/libc/Makefile index 3290cb22..d8066586 100644 --- a/libc/Makefile +++ b/libc/Makefile @@ -429,6 +429,7 @@ sys/stat/fchmod.o \ sys/stat/fstatat.o \ sys/stat/fstat.o \ sys/stat/futimens.o \ +sys/stat/getumask.o \ sys/stat/lstat.o \ sys/stat/mkdirat.o \ sys/stat/mkdir.o \ diff --git a/libc/include/sys/stat.h b/libc/include/sys/stat.h index 4ac9b762..4531979f 100644 --- a/libc/include/sys/stat.h +++ b/libc/include/sys/stat.h @@ -1,6 +1,6 @@ /******************************************************************************* - Copyright(C) Jonas 'Sortie' Termansen 2011, 2012, 2013. + Copyright(C) Jonas 'Sortie' Termansen 2011, 2012, 2013, 2014. This file is part of the Sortix C Library. @@ -105,6 +105,7 @@ int fstat(int fd, struct stat* st); int fstatat(int dirfd, const char* path, struct stat* buf, int flags); int futimens(int fd, const struct timespec times[2]); int lstat(const char* __restrict path, struct stat* __restrict st); +mode_t getumask(void); int mkdir(const char* path, mode_t mode); int mkdirat(int dirfd, const char* path, mode_t mode); /* TODO: mkfifo */ diff --git a/libc/sys/stat/getumask.cpp b/libc/sys/stat/getumask.cpp new file mode 100644 index 00000000..269a8115 --- /dev/null +++ b/libc/sys/stat/getumask.cpp @@ -0,0 +1,33 @@ +/******************************************************************************* + + Copyright(C) Jonas 'Sortie' Termansen 2014. + + 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/stat/getumask.cpp + Get file mode creation mask. + +*******************************************************************************/ + +#include +#include + +DEFN_SYSCALL0(mode_t, sys_getumask, SYSCALL_GETUMASK); + +extern "C" mode_t getumask(void) +{ + return sys_getumask(); +}