]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - include/os/freebsd/spl/sys/uio.h
Vendor import of openzfs master @ 184df27eef0abdc7ab2105b21257f753834b936b
[FreeBSD/FreeBSD.git] / include / os / freebsd / spl / sys / uio.h
1 /*
2  * Copyright (c) 2010 Pawel Jakub Dawidek <pjd@FreeBSD.org>
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
15  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24  * SUCH DAMAGE.
25  *
26  * $FreeBSD$
27  */
28
29 #ifndef _OPENSOLARIS_SYS_UIO_H_
30 #define _OPENSOLARIS_SYS_UIO_H_
31
32 #include_next <sys/uio.h>
33 #include <sys/_uio.h>
34 #include <sys/debug.h>
35
36
37
38 #define uio_loffset     uio_offset
39
40 typedef struct uio      uio_t;
41 typedef struct iovec    iovec_t;
42 typedef enum uio_seg    uio_seg_t;
43
44 typedef enum xuio_type {
45         UIOTYPE_ASYNCIO,
46         UIOTYPE_ZEROCOPY
47 } xuio_type_t;
48
49 typedef struct xuio {
50         uio_t   xu_uio;
51
52         /* Extended uio fields */
53         enum xuio_type xu_type; /* What kind of uio structure? */
54         union {
55                 struct {
56                         int xu_zc_rw;
57                         void *xu_zc_priv;
58                 } xu_zc;
59         } xu_ext;
60 } xuio_t;
61
62 #define XUIO_XUZC_PRIV(xuio)    xuio->xu_ext.xu_zc.xu_zc_priv
63 #define XUIO_XUZC_RW(xuio)      xuio->xu_ext.xu_zc.xu_zc_rw
64
65 static __inline int
66 zfs_uiomove(void *cp, size_t n, enum uio_rw dir, uio_t *uio)
67 {
68
69         ASSERT(uio->uio_rw == dir);
70         return (uiomove(cp, (int)n, uio));
71 }
72 #define uiomove(cp, n, dir, uio)        zfs_uiomove((cp), (n), (dir), (uio))
73
74 int uiocopy(void *p, size_t n, enum uio_rw rw, struct uio *uio, size_t *cbytes);
75 void uioskip(uio_t *uiop, size_t n);
76
77 #define uio_segflg(uio)                 (uio)->uio_segflg
78 #define uio_offset(uio)                 (uio)->uio_loffset
79 #define uio_resid(uio)                  (uio)->uio_resid
80 #define uio_iovcnt(uio)                 (uio)->uio_iovcnt
81 #define uio_iovlen(uio, idx)            (uio)->uio_iov[(idx)].iov_len
82 #define uio_iovbase(uio, idx)           (uio)->uio_iov[(idx)].iov_base
83
84 static inline void
85 uio_iov_at_index(uio_t *uio, uint_t idx, void **base, uint64_t *len)
86 {
87         *base = uio_iovbase(uio, idx);
88         *len = uio_iovlen(uio, idx);
89 }
90
91 static inline void
92 uio_advance(uio_t *uio, size_t size)
93 {
94         uio->uio_resid -= size;
95         uio->uio_loffset += size;
96 }
97
98 static inline offset_t
99 uio_index_at_offset(uio_t *uio, offset_t off, uint_t *vec_idx)
100 {
101         *vec_idx = 0;
102         while (*vec_idx < uio_iovcnt(uio) && off >= uio_iovlen(uio, *vec_idx)) {
103                 off -= uio_iovlen(uio, *vec_idx);
104                 (*vec_idx)++;
105         }
106
107         return (off);
108 }
109
110 #endif  /* !_OPENSOLARIS_SYS_UIO_H_ */