From b385c48a30e8c43922928840bae375610eb4e756 Mon Sep 17 00:00:00 2001 From: Jiuzhu Dong Date: Thu, 7 Jul 2022 22:28:04 +0800 Subject: [PATCH] fs/fs_fsync: add file sync operation by ioctl Signed-off-by: Jiuzhu Dong --- fs/vfs/fs_fsync.c | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/fs/vfs/fs_fsync.c b/fs/vfs/fs_fsync.c index 2eb4cc05ad..c36667a808 100644 --- a/fs/vfs/fs_fsync.c +++ b/fs/vfs/fs_fsync.c @@ -32,6 +32,7 @@ #include #include #include +#include #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; } /****************************************************************************