diff --git a/sys/include/vfs.h b/sys/include/vfs.h index 27ad332485..033a107813 100644 --- a/sys/include/vfs.h +++ b/sys/include/vfs.h @@ -68,6 +68,7 @@ #include "sched.h" #include "clist.h" +#include "iolist.h" #include "mtd.h" #include "xfa.h" @@ -809,6 +810,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 Write bytes from an iolist to an open file + * + * @param[in] fd fd number obtained from vfs_open + * @param[in] iolist iolist to read from + * + * @return number of bytes written on success + * @return <0 on error + */ +ssize_t vfs_write_iol(int fd, const iolist_t *iolist); + /** * @brief Synchronize a file on storage * Any pending writes are written out to storage. diff --git a/sys/vfs/vfs.c b/sys/vfs/vfs.c index 817f248c0b..8d6d75d681 100644 --- a/sys/vfs/vfs.c +++ b/sys/vfs/vfs.c @@ -355,6 +355,22 @@ ssize_t vfs_write(int fd, const void *src, size_t count) return filp->f_op->write(filp, src, count); } +ssize_t vfs_write_iol(int fd, const iolist_t *snips) +{ + int res, sum = 0; + + while (snips) { + res = vfs_write(fd, snips->iol_base, snips->iol_len); + if (res < 0) { + return res; + } + sum += res; + snips = snips->iol_next; + } + + return sum; +} + int vfs_fsync(int fd) { DEBUG_NOT_STDOUT(fd, "vfs_fsync: %d\n", fd);