diff --git a/libc/Makefile b/libc/Makefile index f243c1ec..b7a538be 100644 --- a/libc/Makefile +++ b/libc/Makefile @@ -176,6 +176,7 @@ fsm_recv.o \ fsm_send.o \ fstatat.o \ fstat.o \ +fsync.o \ ftruncate.o \ getc.o \ getcwd.o \ diff --git a/libc/fsync.cpp b/libc/fsync.cpp new file mode 100644 index 00000000..6f3972d4 --- /dev/null +++ b/libc/fsync.cpp @@ -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 . + + fsync.cpp + Open a file relative to directory. + +*******************************************************************************/ + +#include + +#include + +DEFN_SYSCALL1(int, sys_fsync, SYSCALL_FSYNC, int); + +extern "C" int fsync(int fd) +{ + return sys_fsync(fd); +} diff --git a/libc/include/unistd.h b/libc/include/unistd.h index 8a9d2715..ff7b84f8 100644 --- a/libc/include/unistd.h +++ b/libc/include/unistd.h @@ -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); diff --git a/sortix/include/sortix/syscallnum.h b/sortix/include/sortix/syscallnum.h index 3f18848c..42e4a9c7 100644 --- a/sortix/include/sortix/syscallnum.h +++ b/sortix/include/sortix/syscallnum.h @@ -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 diff --git a/sortix/io.cpp b/sortix/io.cpp index 58f6270d..96ee9067 100644 --- a/sortix/io.cpp +++ b/sortix/io.cpp @@ -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 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);