1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

sys/vfs: provide vfs_fsync()

This commit is contained in:
Benjamin Valentin 2022-02-07 16:07:20 +01:00
parent 4e007d3f3e
commit aac538ba7f
2 changed files with 41 additions and 0 deletions

View File

@ -440,6 +440,17 @@ struct vfs_file_ops {
* @return <0 on error
*/
ssize_t (*write) (vfs_file_t *filp, const void *src, size_t nbytes);
/**
* @brief Synchronize a file on storage
* Any pending writes are written out to storage.
*
* @param[in] filp pointer to open file
*
* @return 0 on success
* @return <0 on error
*/
int (*fsync) (vfs_file_t *filp);
};
/**
@ -739,6 +750,17 @@ ssize_t vfs_read(int fd, void *dest, size_t count);
*/
ssize_t vfs_write(int fd, const void *src, size_t count);
/**
* @brief Synchronize a file on storage
* Any pending writes are written out to storage.
*
* @param[in] fd fd number obtained from vfs_open
*
* @return 0 on success
* @return <0 on error
*/
int vfs_fsync(int fd);
/**
* @brief Open a directory for reading with readdir
*

View File

@ -333,6 +333,25 @@ ssize_t vfs_write(int fd, const void *src, size_t count)
return filp->f_op->write(filp, src, count);
}
int vfs_fsync(int fd)
{
DEBUG_NOT_STDOUT(fd, "vfs_fsync: %d\n", fd);
int res = _fd_is_valid(fd);
if (res < 0) {
return res;
}
vfs_file_t *filp = &_vfs_open_files[fd];
if (((filp->flags & O_ACCMODE) != O_WRONLY) & ((filp->flags & O_ACCMODE) != O_RDWR)) {
/* File not open for writing */
return -EBADF;
}
if (filp->f_op->fsync == NULL) {
/* driver does not implement fsync() */
return -EINVAL;
}
return filp->f_op->fsync(filp);
}
int vfs_opendir(vfs_DIR *dirp, const char *dirname)
{
DEBUG("vfs_opendir: %p, \"%s\"\n", (void *)dirp, dirname);