diff --git a/fs/inode/fs_files.c b/fs/inode/fs_files.c index 570f5f5f6a..ad6e2e893b 100644 --- a/fs/inode/fs_files.c +++ b/fs/inode/fs_files.c @@ -35,6 +35,7 @@ #include #include #include +#include #include "inode/inode.h" @@ -97,6 +98,39 @@ static int files_extend(FAR struct filelist *list, size_t row) return 0; } +#ifndef CONFIG_DISABLE_MOUNTPOINT + +static void task_fssync(FAR struct tcb_s *tcb, FAR void *arg) +{ + FAR struct filelist *list; + int i; + int j; + + list = &tcb->group->tg_filelist; + if (nxmutex_lock(&list->fl_lock) < 0) + { + return; + } + + for (i = 0; i < list->fl_rows; i++) + { + for (j = 0; j < CONFIG_NFILE_DESCRIPTORS_PER_BLOCK; j++) + { + FAR struct file *filep; + + filep = &list->fl_files[i][j]; + if (filep != NULL && filep->f_inode != NULL) + { + file_fsync(filep); + } + } + } + + nxmutex_unlock(&list->fl_lock); +} + +#endif /* !CONFIG_DISABLE_MOUNTPOINT */ + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -603,3 +637,21 @@ int close(int fd) leave_cancellation_point(); return ret; } + +#ifndef CONFIG_DISABLE_MOUNTPOINT + +/**************************************************************************** + * Name: sync + * + * Description: + * sync() causes all pending modifications to filesystem metadata and + * cached file data to be written to the underlying filesystems. + * + ****************************************************************************/ + +void sync(void) +{ + nxsched_foreach(task_fssync, NULL); +} + +#endif /* !CONFIG_DISABLE_MOUNTPOINT */ diff --git a/include/sys/syscall_lookup.h b/include/sys/syscall_lookup.h index 4c44ea2919..a159cad3ff 100644 --- a/include/sys/syscall_lookup.h +++ b/include/sys/syscall_lookup.h @@ -271,6 +271,7 @@ SYSCALL_LOOKUP(munmap, 2) #ifndef CONFIG_DISABLE_MOUNTPOINT SYSCALL_LOOKUP(mount, 5) + SYSCALL_LOOKUP(sync, 0) SYSCALL_LOOKUP(fsync, 1) SYSCALL_LOOKUP(ftruncate, 2) SYSCALL_LOOKUP(mkdir, 2) diff --git a/include/unistd.h b/include/unistd.h index 0ee4275de9..4c49eaabd2 100644 --- a/include/unistd.h +++ b/include/unistd.h @@ -438,6 +438,8 @@ int setregid(gid_t rgid, gid_t egid); int getentropy(FAR void *buffer, size_t length); +void sync(void); + #undef EXTERN #if defined(__cplusplus) } diff --git a/syscall/syscall.csv b/syscall/syscall.csv index dd3a221d43..ac2706ac36 100644 --- a/syscall/syscall.csv +++ b/syscall/syscall.csv @@ -166,6 +166,7 @@ "stat","sys/stat.h","","int","FAR const char *","FAR struct stat *" "statfs","sys/statfs.h","","int","FAR const char *","FAR struct statfs *" "symlink","unistd.h","defined(CONFIG_PSEUDOFS_SOFTLINKS)","int","FAR const char *","FAR const char *" +"sync","unistd.h","!defined(CONFIG_DISABLE_MOUNTPOINT)","void" "sysinfo","sys/sysinfo.h","","int","FAR struct sysinfo *" "task_create","sched.h","!defined(CONFIG_BUILD_KERNEL)", "int","FAR const char *","int","int","main_t","FAR char * const []|FAR char * const *" "task_delete","sched.h","!defined(CONFIG_BUILD_KERNEL)","int","pid_t"