mirror of
https://gitlab.com/sortix/sortix.git
synced 2023-02-13 20:55:38 -05:00
Add fchown(2).
This commit is contained in:
parent
cb4569c615
commit
c1280bedb0
5 changed files with 48 additions and 3 deletions
|
@ -142,6 +142,7 @@ faccessat.o \
|
|||
fchdir.o \
|
||||
fchmod.o \
|
||||
fchownat.o \
|
||||
fchown.o \
|
||||
fcloseall.o \
|
||||
fcntl.o \
|
||||
fddir-sortix.o \
|
||||
|
|
35
libc/fchown.cpp
Normal file
35
libc/fchown.cpp
Normal file
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
fchown.cpp
|
||||
Changes the owner and group of a file.
|
||||
|
||||
*******************************************************************************/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/syscall.h>
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
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);
|
||||
}
|
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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<Descriptor> 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);
|
||||
|
|
Loading…
Add table
Reference in a new issue