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