sync: add sync api
Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
This commit is contained in:
parent
21d9163aae
commit
63e6f80fb0
@ -35,6 +35,7 @@
|
||||
#include <nuttx/kmalloc.h>
|
||||
#include <nuttx/cancelpt.h>
|
||||
#include <nuttx/mutex.h>
|
||||
#include <nuttx/sched.h>
|
||||
|
||||
#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 */
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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"
|
||||
|
Can't render this file because it has a wrong number of fields in line 2.
|
Loading…
Reference in New Issue
Block a user