mirror of
https://gitlab.com/sortix/sortix.git
synced 2023-02-13 20:55:38 -05:00
Add fchownat(2).
This commit is contained in:
parent
f843e15666
commit
cb4569c615
5 changed files with 53 additions and 4 deletions
|
@ -141,6 +141,7 @@ exit.o \
|
|||
faccessat.o \
|
||||
fchdir.o \
|
||||
fchmod.o \
|
||||
fchownat.o \
|
||||
fcloseall.o \
|
||||
fcntl.o \
|
||||
fddir-sortix.o \
|
||||
|
|
36
libc/fchownat.cpp
Normal file
36
libc/fchownat.cpp
Normal file
|
@ -0,0 +1,36 @@
|
|||
/*******************************************************************************
|
||||
|
||||
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/>.
|
||||
|
||||
fchownat.cpp
|
||||
Changes the owner and group of a file.
|
||||
|
||||
*******************************************************************************/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/syscall.h>
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
|
||||
DEFN_SYSCALL5(int, sys_fchownat, SYSCALL_FCHOWNAT, int, const char*, uid_t, gid_t, int);
|
||||
|
||||
extern "C" int fchownat(int dirfd, const char* path, uid_t owner, gid_t group, int flags)
|
||||
{
|
||||
return sys_fchownat(dirfd, path, owner, group, flags);
|
||||
}
|
|
@ -93,7 +93,6 @@ char* crypt(const char*, const char*);
|
|||
char* ctermid(char*);
|
||||
void encrypt(char [64], int);
|
||||
int fchown(int, uid_t, gid_t);
|
||||
int fchownat(int, const char*, uid_t, gid_t, int);
|
||||
int fdatasync(int);
|
||||
int fexecve(int, char* const [], char* const []);
|
||||
long fpathconf(int, int);
|
||||
|
@ -161,6 +160,7 @@ int execvp(const char*, char* const []);
|
|||
pid_t fork(void);
|
||||
int faccessat(int, const char*, int, int);
|
||||
int fchdir(int);
|
||||
int fchownat(int, const char*, uid_t, gid_t, int);
|
||||
int ftruncate(int, off_t);
|
||||
char* getcwd(char*, size_t);
|
||||
char* get_current_dir_name(void);
|
||||
|
|
|
@ -87,6 +87,7 @@
|
|||
#define SYSCALL_MKDIRAT 63
|
||||
#define SYSCALL_FCHDIR 64
|
||||
#define SYSCALL_TRUNCATEAT 65
|
||||
#define SYSCALL_MAX_NUM 66 /* index of highest constant + 1 */
|
||||
#define SYSCALL_FCHOWNAT 66
|
||||
#define SYSCALL_MAX_NUM 67 /* index of highest constant + 1 */
|
||||
|
||||
#endif
|
||||
|
|
|
@ -351,14 +351,19 @@ static int sys_chdir(const char* path)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int sys_chown(const char* path, uid_t owner, gid_t group)
|
||||
// TODO: fchown(2)
|
||||
|
||||
static int sys_fchownat(int dirfd, const char* path, uid_t owner, gid_t group, int flags)
|
||||
{
|
||||
if ( flags )
|
||||
return errno = ENOTSUP, -1;
|
||||
char* pathcopy = GetStringFromUser(path);
|
||||
if ( !pathcopy )
|
||||
return -1;
|
||||
ioctx_t ctx; SetupUserIOCtx(&ctx);
|
||||
const char* relpath = pathcopy;
|
||||
Ref<Descriptor> from = PrepareLookup(&relpath);
|
||||
Ref<Descriptor> from = PrepareLookup(&relpath, dirfd);
|
||||
if ( !from ) { delete[] pathcopy; return -1; }
|
||||
Ref<Descriptor> desc = from->open(&ctx, relpath, O_WRONLY);
|
||||
from.Reset();
|
||||
delete[] pathcopy;
|
||||
|
@ -367,6 +372,11 @@ static int sys_chown(const char* path, uid_t owner, gid_t group)
|
|||
return desc->chown(&ctx, owner, group);
|
||||
}
|
||||
|
||||
static int sys_chown(const char* path, uid_t owner, gid_t group)
|
||||
{
|
||||
return sys_fchownat(AT_FDCWD, path, owner, group, 0);
|
||||
}
|
||||
|
||||
static int sys_chmod(const char* path, mode_t mode)
|
||||
{
|
||||
char* pathcopy = GetStringFromUser(path);
|
||||
|
@ -461,6 +471,7 @@ void Init()
|
|||
Syscall::Register(SYSCALL_DUP2, (void*) sys_dup2);
|
||||
Syscall::Register(SYSCALL_FACCESSAT, (void*) sys_faccessat);
|
||||
Syscall::Register(SYSCALL_FCHDIR, (void*) sys_fchdir);
|
||||
Syscall::Register(SYSCALL_FCHOWNAT, (void*) sys_fchownat);
|
||||
Syscall::Register(SYSCALL_FCNTL, (void*) sys_fcntl);
|
||||
Syscall::Register(SYSCALL_FSTATAT, (void*) sys_fstatat);
|
||||
Syscall::Register(SYSCALL_FSTAT, (void*) sys_fstat);
|
||||
|
|
Loading…
Reference in a new issue