fs/fs_fsync: add file sync operation by ioctl
Signed-off-by: Jiuzhu Dong <dongjiuzhu1@xiaomi.com>
This commit is contained in:
parent
8f54f9e1c3
commit
b385c48a30
|
@ -32,6 +32,7 @@
|
|||
#include <nuttx/sched.h>
|
||||
#include <nuttx/cancelpt.h>
|
||||
#include <nuttx/fs/fs.h>
|
||||
#include <nuttx/fs/ioctl.h>
|
||||
|
||||
#include "inode/inode.h"
|
||||
|
||||
|
@ -53,7 +54,8 @@
|
|||
|
||||
int file_fsync(FAR struct file *filep)
|
||||
{
|
||||
struct inode *inode;
|
||||
FAR struct inode *inode;
|
||||
int ret;
|
||||
|
||||
/* Is this inode a registered mountpoint? Does it support the
|
||||
* sync operations may be relevant to device drivers but only
|
||||
|
@ -61,15 +63,23 @@ int file_fsync(FAR struct file *filep)
|
|||
*/
|
||||
|
||||
inode = filep->f_inode;
|
||||
if (!inode || !INODE_IS_MOUNTPT(inode) ||
|
||||
!inode->u.i_mops || !inode->u.i_mops->sync)
|
||||
if (inode != NULL)
|
||||
{
|
||||
return -EINVAL;
|
||||
if (INODE_IS_MOUNTPT(inode) && inode->u.i_mops &&
|
||||
inode->u.i_mops->sync)
|
||||
{
|
||||
/* Yes, then tell the mountpoint to sync this file */
|
||||
|
||||
return inode->u.i_mops->sync(filep);
|
||||
}
|
||||
else if (inode->u.i_ops && inode->u.i_ops->ioctl)
|
||||
{
|
||||
ret = inode->u.i_ops->ioctl(filep, BIOC_FLUSH, 0);
|
||||
return ret >= 0 ? 0 : ret;
|
||||
}
|
||||
}
|
||||
|
||||
/* Yes, then tell the mountpoint to sync this file */
|
||||
|
||||
return inode->u.i_mops->sync(filep);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
|
|
Loading…
Reference in New Issue