From: Sergiu Moga Date: Wed, 26 Mar 2025 16:09:51 +0000 (+0200) Subject: lib/ukfile: Add `uk_iov_remaining` to help tell remaining iov space X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=831967791b2a0f95a02d1b3ecf528340359c0cfd;p=unikraft%2Funikraft.git lib/ukfile: Add `uk_iov_remaining` to help tell remaining iov space Add a new routine `uk_iov_remaining` that simply checks how many bytes the memory regions described by `iov[iovcnt]`, starting at `cur` offset from the buffer at `iov[iovi]` can fit. Signed-off-by: Sergiu Moga Approved-by: Michalis Pappas Reviewed-by: Michalis Pappas Reviewed-by: Andrei Tatar GitHub-Closes: #1619 --- diff --git a/lib/ukfile/include/uk/file/iovutil.h b/lib/ukfile/include/uk/file/iovutil.h index 3a8b805b5..331ec9b6f 100644 --- a/lib/ukfile/include/uk/file/iovutil.h +++ b/lib/ukfile/include/uk/file/iovutil.h @@ -168,4 +168,32 @@ size_t uk_iov_gather(char *buf, const struct iovec *iov, size_t iovcnt, return ret; } +/** + * Check how many bytes the memory regions described by `iov[iovcnt]`, + * starting at `cur` offset from the buffer at `iov[iovi]` can fit. + * + * @return total bytes the iov can fit + */ +static inline +size_t uk_iov_remaining(const struct iovec *iov, size_t iovcnt, + size_t iovi, size_t cur) +{ + size_t len = 0, i = iovi; + + UK_ASSERT(i < iovcnt); + UK_ASSERT(cur < iov[i].iov_len); + + if (cur) { + len += iov[i].iov_len - cur; + i++; + } + + while (i < iovcnt) { + len += iov[i].iov_len; + i++; + } + + return len; +} + #endif /* __UKFILE_IOVUTIL_H__ */