From c1280bedb0e06d39fbeedb1980ace693b2982b54 Mon Sep 17 00:00:00 2001 From: Jonas 'Sortie' Termansen Date: Wed, 24 Oct 2012 19:52:28 +0200 Subject: [PATCH] Add fchown(2). --- libc/Makefile | 1 + libc/fchown.cpp | 35 ++++++++++++++++++++++++++++++ libc/include/unistd.h | 2 +- sortix/include/sortix/syscallnum.h | 3 ++- sortix/io.cpp | 10 ++++++++- 5 files changed, 48 insertions(+), 3 deletions(-) create mode 100644 libc/fchown.cpp diff --git a/libc/Makefile b/libc/Makefile index 57399489..48dcf069 100644 --- a/libc/Makefile +++ b/libc/Makefile @@ -142,6 +142,7 @@ faccessat.o \ fchdir.o \ fchmod.o \ fchownat.o \ +fchown.o \ fcloseall.o \ fcntl.o \ fddir-sortix.o \ diff --git a/libc/fchown.cpp b/libc/fchown.cpp new file mode 100644 index 00000000..b4344c82 --- /dev/null +++ b/libc/fchown.cpp @@ -0,0 +1,35 @@ +/******************************************************************************* + + Copyright(C) Jonas 'Sortie' Termansen 2012. + + 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 . + + fchown.cpp + Changes the owner and group of a file. + +*******************************************************************************/ + +#include +#include + +#include + +DEFN_SYSCALL3(int, sys_fchown, SYSCALL_FCHOWN, int, uid_t, gid_t); + +extern "C" int fchown(int fd, uid_t owner, gid_t group) +{ + return sys_fchown(fd, owner, group); +} diff --git a/libc/include/unistd.h b/libc/include/unistd.h index 866399c4..d20b506e 100644 --- a/libc/include/unistd.h +++ b/libc/include/unistd.h @@ -92,7 +92,6 @@ size_t confstr(int, char*, size_t); char* crypt(const char*, const char*); char* ctermid(char*); void encrypt(char [64], int); -int fchown(int, uid_t, gid_t); int fdatasync(int); int fexecve(int, char* const [], char* const []); long fpathconf(int, int); @@ -160,6 +159,7 @@ int execvp(const char*, char* const []); pid_t fork(void); int faccessat(int, const char*, int, int); int fchdir(int); +int fchown(int, uid_t, gid_t); int fchownat(int, const char*, uid_t, gid_t, int); int ftruncate(int, off_t); char* getcwd(char*, size_t); diff --git a/sortix/include/sortix/syscallnum.h b/sortix/include/sortix/syscallnum.h index 26c07234..60cce093 100644 --- a/sortix/include/sortix/syscallnum.h +++ b/sortix/include/sortix/syscallnum.h @@ -88,6 +88,7 @@ #define SYSCALL_FCHDIR 64 #define SYSCALL_TRUNCATEAT 65 #define SYSCALL_FCHOWNAT 66 -#define SYSCALL_MAX_NUM 67 /* index of highest constant + 1 */ +#define SYSCALL_FCHOWN 67 +#define SYSCALL_MAX_NUM 68 /* index of highest constant + 1 */ #endif diff --git a/sortix/io.cpp b/sortix/io.cpp index 0f1ed73d..146128a8 100644 --- a/sortix/io.cpp +++ b/sortix/io.cpp @@ -351,7 +351,14 @@ static int sys_chdir(const char* path) return 0; } -// TODO: fchown(2) +static int sys_fchown(int fd, uid_t owner, gid_t group) +{ + Ref desc = CurrentProcess()->GetDescriptor(fd); + if ( !desc ) + return -1; + ioctx_t ctx; SetupUserIOCtx(&ctx); + return desc->chown(&ctx, owner, group); +} static int sys_fchownat(int dirfd, const char* path, uid_t owner, gid_t group, int flags) { @@ -472,6 +479,7 @@ void Init() Syscall::Register(SYSCALL_FACCESSAT, (void*) sys_faccessat); Syscall::Register(SYSCALL_FCHDIR, (void*) sys_fchdir); Syscall::Register(SYSCALL_FCHOWNAT, (void*) sys_fchownat); + Syscall::Register(SYSCALL_FCHOWN, (void*) sys_fchown); Syscall::Register(SYSCALL_FCNTL, (void*) sys_fcntl); Syscall::Register(SYSCALL_FSTATAT, (void*) sys_fstatat); Syscall::Register(SYSCALL_FSTAT, (void*) sys_fstat);