1
0
Fork 0
mirror of https://gitlab.com/sortix/sortix.git synced 2023-02-13 20:55:38 -05:00

Add fchmodat(2).

This commit is contained in:
Jonas 'Sortie' Termansen 2012-10-25 00:29:48 +02:00
parent f21462bf18
commit 2ef2269168
5 changed files with 49 additions and 3 deletions

View file

@ -140,6 +140,7 @@ _Exit.o \
exit.o \ exit.o \
faccessat.o \ faccessat.o \
fchdir.o \ fchdir.o \
fchmodat.o \
fchmod.o \ fchmod.o \
fchownat.o \ fchownat.o \
fchown.o \ fchown.o \

34
libc/fchmodat.cpp Normal file
View file

@ -0,0 +1,34 @@
/*******************************************************************************
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/>.
fchmodat.cpp
Changes the mode bits of a file.
*******************************************************************************/
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/syscall.h>
DEFN_SYSCALL4(int, sys_fchmodat, SYSCALL_FCHMODAT, int, const char*, mode_t, int);
extern "C" int fchmodat(int dirfd, const char* path, mode_t mode, int flags)
{
return sys_fchmodat(dirfd, path, mode, flags);
}

View file

@ -48,6 +48,7 @@ __BEGIN_DECLS
int chmod(const char* path, mode_t mode); int chmod(const char* path, mode_t mode);
int fchmod(int fd, mode_t mode); int fchmod(int fd, mode_t mode);
int fchmodat(int dirfd, const char* path, mode_t mode, int flags);
int fstat(int fd, struct stat* st); int fstat(int fd, struct stat* st);
int fstatat(int dirfd, const char* path, struct stat* buf, int flags); int fstatat(int dirfd, const char* path, struct stat* buf, int flags);
int lstat(const char* restrict path, struct stat* restrict st); int lstat(const char* restrict path, struct stat* restrict st);

View file

@ -90,6 +90,7 @@
#define SYSCALL_FCHOWNAT 66 #define SYSCALL_FCHOWNAT 66
#define SYSCALL_FCHOWN 67 #define SYSCALL_FCHOWN 67
#define SYSCALL_FCHMOD 68 #define SYSCALL_FCHMOD 68
#define SYSCALL_MAX_NUM 69 /* index of highest constant + 1 */ #define SYSCALL_FCHMODAT 69
#define SYSCALL_MAX_NUM 70 /* index of highest constant + 1 */
#endif #endif

View file

@ -393,14 +393,17 @@ static int sys_fchmod(int fd, mode_t mode)
return desc->chmod(&ctx, mode); return desc->chmod(&ctx, mode);
} }
static int sys_chmod(const char* path, mode_t mode) static int sys_fchmodat(int dirfd, const char* path, mode_t mode, int flags)
{ {
if ( flags )
return errno = ENOTSUP, -1;
char* pathcopy = GetStringFromUser(path); char* pathcopy = GetStringFromUser(path);
if ( !pathcopy ) if ( !pathcopy )
return -1; return -1;
ioctx_t ctx; SetupUserIOCtx(&ctx); ioctx_t ctx; SetupUserIOCtx(&ctx);
const char* relpath = pathcopy; 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); Ref<Descriptor> desc = from->open(&ctx, relpath, O_WRONLY);
from.Reset(); from.Reset();
delete[] pathcopy; delete[] pathcopy;
@ -409,6 +412,11 @@ static int sys_chmod(const char* path, mode_t mode)
return desc->chmod(&ctx, mode); return desc->chmod(&ctx, mode);
} }
static int sys_chmod(const char* path, mode_t mode)
{
return sys_fchmodat(AT_FDCWD, path, mode, 0);
}
static int sys_link(const char* oldpath, const char* newpath) static int sys_link(const char* oldpath, const char* newpath)
{ {
ioctx_t ctx; SetupUserIOCtx(&ctx); ioctx_t ctx; SetupUserIOCtx(&ctx);
@ -487,6 +495,7 @@ void Init()
Syscall::Register(SYSCALL_DUP2, (void*) sys_dup2); Syscall::Register(SYSCALL_DUP2, (void*) sys_dup2);
Syscall::Register(SYSCALL_FACCESSAT, (void*) sys_faccessat); Syscall::Register(SYSCALL_FACCESSAT, (void*) sys_faccessat);
Syscall::Register(SYSCALL_FCHDIR, (void*) sys_fchdir); Syscall::Register(SYSCALL_FCHDIR, (void*) sys_fchdir);
Syscall::Register(SYSCALL_FCHMODAT, (void*) sys_fchmodat);
Syscall::Register(SYSCALL_FCHMOD, (void*) sys_fchmod); Syscall::Register(SYSCALL_FCHMOD, (void*) sys_fchmod);
Syscall::Register(SYSCALL_FCHOWNAT, (void*) sys_fchownat); Syscall::Register(SYSCALL_FCHOWNAT, (void*) sys_fchownat);
Syscall::Register(SYSCALL_FCHOWN, (void*) sys_fchown); Syscall::Register(SYSCALL_FCHOWN, (void*) sys_fchown);