]> git.proxmox.com Git - mirror_qemu.git/blame - iov.h
change qemu_iovec_to_buf() to match other to,from_buf functions
[mirror_qemu.git] / iov.h
CommitLineData
e4d5639d 1/*
2278a69e 2 * Helpers for using (partial) iovecs.
e4d5639d
AS
3 *
4 * Copyright (C) 2010 Red Hat, Inc.
5 *
6 * Author(s):
7 * Amit Shah <amit.shah@redhat.com>
2278a69e 8 * Michael Tokarev <mjt@tls.msk.ru>
e4d5639d
AS
9 *
10 * This work is licensed under the terms of the GNU GPL, version 2. See
11 * the COPYING file in the top-level directory.
12 */
13
14#include "qemu-common.h"
15
dcf6f5e1
MT
16/**
17 * count and return data size, in bytes, of an iovec
18 * starting at `iov' of `iov_cnt' number of elements.
19 */
20size_t iov_size(const struct iovec *iov, const unsigned int iov_cnt);
21
22/**
23 * Copy from single continuous buffer to scatter-gather vector of buffers
24 * (iovec) and back like memcpy() between two continuous memory regions.
25 * Data in single continuous buffer starting at address `buf' and
26 * `bytes' bytes long will be copied to/from an iovec `iov' with
27 * `iov_cnt' number of elements, starting at byte position `offset'
28 * within the iovec. If the iovec does not contain enough space,
29 * only part of data will be copied, up to the end of the iovec.
30 * Number of bytes actually copied will be returned, which is
31 * min(bytes, iov_size(iov)-offset)
2278a69e
MT
32 * `Offset' must point to the inside of iovec.
33 * It is okay to use very large value for `bytes' since we're
34 * limited by the size of the iovec anyway, provided that the
35 * buffer pointed to by buf has enough space. One possible
36 * such "large" value is -1 (sinice size_t is unsigned),
37 * so specifying `-1' as `bytes' means 'up to the end of iovec'.
dcf6f5e1 38 */
348e7b8d 39size_t iov_from_buf(struct iovec *iov, unsigned int iov_cnt,
dcf6f5e1 40 size_t offset, const void *buf, size_t bytes);
348e7b8d 41size_t iov_to_buf(const struct iovec *iov, const unsigned int iov_cnt,
dcf6f5e1
MT
42 size_t offset, void *buf, size_t bytes);
43
44/**
45 * Set data bytes pointed out by iovec `iov' of size `iov_cnt' elements,
46 * starting at byte offset `start', to value `fillc', repeating it
2278a69e 47 * `bytes' number of times. `Offset' must point to the inside of iovec.
dcf6f5e1
MT
48 * If `bytes' is large enough, only last bytes portion of iovec,
49 * up to the end of it, will be filled with the specified value.
50 * Function return actual number of bytes processed, which is
51 * min(size, iov_size(iov) - offset).
2278a69e 52 * Again, it is okay to use large value for `bytes' to mean "up to the end".
dcf6f5e1
MT
53 */
54size_t iov_memset(const struct iovec *iov, const unsigned int iov_cnt,
55 size_t offset, int fillc, size_t bytes);
56
57/**
58 * Produce a text hexdump of iovec `iov' with `iov_cnt' number of elements
59 * in file `fp', prefixing each line with `prefix' and processing not more
60 * than `limit' data bytes.
61 */
3a1dca94
GH
62void iov_hexdump(const struct iovec *iov, const unsigned int iov_cnt,
63 FILE *fp, const char *prefix, size_t limit);