]> xenbits.xensource.com Git - unikraft/unikraft.git/commitdiff
lib/ukfile: Add `uk_iov_remaining` to help tell remaining iov space
authorSergiu Moga <sergiu@unikraft.io>
Wed, 26 Mar 2025 16:09:51 +0000 (18:09 +0200)
committerUnikraft Bot <monkey@unikraft.io>
Wed, 23 Apr 2025 10:01:21 +0000 (10:01 +0000)
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 <sergiu@unikraft.io>
Approved-by: Michalis Pappas <michalis@unikraft.io>
Reviewed-by: Michalis Pappas <michalis@unikraft.io>
Reviewed-by: Andrei Tatar <andrei@unikraft.io>
GitHub-Closes: #1619

lib/ukfile/include/uk/file/iovutil.h

index 3a8b805b58e7a0045072054e870ea1fae2e689f3..331ec9b6f7114a71f65ab4426d114c5e87070ccd 100644 (file)
@@ -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__ */