Add fsync(2).

This commit is contained in:
Jonas 'Sortie' Termansen 2013-03-20 13:16:12 +01:00
parent 04a4564924
commit f29abd73ec
5 changed files with 48 additions and 2 deletions

View File

@ -176,6 +176,7 @@ fsm_recv.o \
fsm_send.o \
fstatat.o \
fstat.o \
fsync.o \
ftruncate.o \
getc.o \
getcwd.o \

34
libc/fsync.cpp Normal file
View File

@ -0,0 +1,34 @@
/*******************************************************************************
Copyright(C) Jonas 'Sortie' Termansen 2013.
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/>.
fsync.cpp
Open a file relative to directory.
*******************************************************************************/
#include <sys/syscall.h>
#include <unistd.h>
DEFN_SYSCALL1(int, sys_fsync, SYSCALL_FSYNC, int);
extern "C" int fsync(int fd)
{
return sys_fsync(fd);
}

View File

@ -93,7 +93,6 @@ void encrypt(char [64], int);
int fdatasync(int);
int fexecve(int, char* const [], char* const []);
long fpathconf(int, int);
int fsync(int);
gid_t getegid(void);
uid_t geteuid(void);
gid_t getgid(void);
@ -155,6 +154,7 @@ 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 fsync(int);
int ftruncate(int, off_t);
char* getcwd(char*, size_t);
char* get_current_dir_name(void);

View File

@ -96,6 +96,7 @@
#define SYSCALL_PPOLL 72
#define SYSCALL_RENAMEAT 73
#define SYSCALL_READLINKAT 74
#define SYSCALL_MAX_NUM 75 /* index of highest constant + 1 */
#define SYSCALL_FSYNC 75
#define SYSCALL_MAX_NUM 76 /* index of highest constant + 1 */
#endif

View File

@ -559,6 +559,15 @@ static ssize_t sys_readlinkat(int dirfd, const char* path, char* buf, size_t siz
return (int) desc->readlink(&ctx, buf, size);
}
static int sys_fsync(int fd)
{
Ref<Descriptor> desc = CurrentProcess()->GetDescriptor(fd);
if ( !desc )
return -1;
ioctx_t ctx; SetupUserIOCtx(&ctx);
return desc->sync(&ctx);
}
void Init()
{
Syscall::Register(SYSCALL_ACCESS, (void*) sys_access);
@ -577,6 +586,7 @@ void Init()
Syscall::Register(SYSCALL_FCNTL, (void*) sys_fcntl);
Syscall::Register(SYSCALL_FSTATAT, (void*) sys_fstatat);
Syscall::Register(SYSCALL_FSTAT, (void*) sys_fstat);
Syscall::Register(SYSCALL_FSYNC, (void*) sys_fsync);
Syscall::Register(SYSCALL_FTRUNCATE, (void*) sys_ftruncate);
Syscall::Register(SYSCALL_GETTERMMODE, (void*) sys_gettermmode);
Syscall::Register(SYSCALL_ISATTY, (void*) sys_isatty);