diff options
| author | Laurent Vivier <lvivier@redhat.com> | 2026-05-13 13:52:09 +0200 |
|---|---|---|
| committer | Stefano Brivio <sbrivio@redhat.com> | 2026-05-20 01:21:03 +0200 |
| commit | a804574bc42c73915944b38ef638f667067bbf8c (patch) | |
| tree | 9b6a8611059110c2d91ba75b608c1cceb21f51ad | |
| parent | bcc3d37a6e010b9340d085482f98caab21833776 (diff) | |
| download | passt-a804574bc42c73915944b38ef638f667067bbf8c.tar passt-a804574bc42c73915944b38ef638f667067bbf8c.tar.gz passt-a804574bc42c73915944b38ef638f667067bbf8c.tar.bz2 passt-a804574bc42c73915944b38ef638f667067bbf8c.tar.lz passt-a804574bc42c73915944b38ef638f667067bbf8c.tar.xz passt-a804574bc42c73915944b38ef638f667067bbf8c.tar.zst passt-a804574bc42c73915944b38ef638f667067bbf8c.zip | |
iov: Introduce iov_memset()
Add a helper to set a range of bytes across an IO vector to a given
value, similar to memset() but operating over scatter-gather buffers.
It skips to the given offset and fills across iovec entries up to the
requested length.
Signed-off-by: Laurent Vivier <lvivier@redhat.com>
Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
Reviewed-by: Jon Maloy <jmaloy@redhat.com>
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
| -rw-r--r-- | iov.c | 27 | ||||
| -rw-r--r-- | iov.h | 2 |
2 files changed, 29 insertions, 0 deletions
@@ -171,6 +171,33 @@ size_t iov_truncate(struct iovec *iov, size_t iov_cnt, size_t size) } /** + * iov_memset() - Set bytes of an IO vector to a given value + * @iov: IO vector + * @iov_cnt: Number of elements in @iov + * @offset: Byte offset in the iovec at which to start + * @c: Byte value to fill with + * @length: Number of bytes to set + * Will write less than @length bytes if it runs out of space in + * the iov + */ +/* cppcheck-suppress unusedFunction */ +void iov_memset(const struct iovec *iov, size_t iov_cnt, size_t offset, int c, + size_t length) +{ + size_t i; + + i = iov_skip_bytes(iov, iov_cnt, offset, &offset); + + for ( ; i < iov_cnt && length; i++) { + size_t n = MIN(iov[i].iov_len - offset, length); + + memset((char *)iov[i].iov_base + offset, c, n); + offset = 0; + length -= n; + } +} + +/** * iov_tail_prune() - Remove any unneeded buffers from an IOV tail * @tail: IO vector tail (modified) * @@ -30,6 +30,8 @@ size_t iov_to_buf(const struct iovec *iov, size_t iov_cnt, size_t offset, void *buf, size_t bytes); size_t iov_size(const struct iovec *iov, size_t iov_cnt); size_t iov_truncate(struct iovec *iov, size_t iov_cnt, size_t size); +void iov_memset(const struct iovec *iov, size_t iov_cnt, size_t offset, int c, + size_t length); /* * DOC: Theory of Operation, struct iov_tail |
