fs/fs_fsync: add file sync operation by ioctl

Signed-off-by: Jiuzhu Dong <dongjiuzhu1@xiaomi.com>
This commit is contained in:
Jiuzhu Dong 2022-07-07 22:28:04 +08:00 committed by Petro Karashchenko
parent 8f54f9e1c3
commit b385c48a30
1 changed files with 17 additions and 7 deletions

View File

@ -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;
}
/****************************************************************************