]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - include/os/freebsd/spl/sys/uio.h
Update OpenZFS to 2.0.0-rc3-gbd565f
[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 #ifndef _STANDALONE
33
34 #include_next <sys/uio.h>
35 #include <sys/_uio.h>
36 #include <sys/debug.h>
37
38
39
40 #define uio_loffset     uio_offset
41
42 typedef struct uio      uio_t;
43 typedef struct iovec    iovec_t;
44 typedef enum uio_seg    uio_seg_t;
45
46 typedef enum xuio_type {
47         UIOTYPE_ASYNCIO,
48         UIOTYPE_ZEROCOPY
49 } xuio_type_t;
50
51 typedef struct xuio {
52         uio_t   xu_uio;
53
54         /* Extended uio fields */
55         enum xuio_type xu_type; /* What kind of uio structure? */
56         union {
57                 struct {
58                         int xu_zc_rw;
59                         void *xu_zc_priv;
60                 } xu_zc;
61         } xu_ext;
62 } xuio_t;
63
64 #define XUIO_XUZC_PRIV(xuio)    xuio->xu_ext.xu_zc.xu_zc_priv
65 #define XUIO_XUZC_RW(xuio)      xuio->xu_ext.xu_zc.xu_zc_rw
66
67 static __inline int
68 zfs_uiomove(void *cp, size_t n, enum uio_rw dir, uio_t *uio)
69 {
70
71         ASSERT(uio->uio_rw == dir);
72         return (uiomove(cp, (int)n, uio));
73 }
74 #define uiomove(cp, n, dir, uio)        zfs_uiomove((cp), (n), (dir), (uio))
75
76 int uiocopy(void *p, size_t n, enum uio_rw rw, struct uio *uio, size_t *cbytes);
77 void uioskip(uio_t *uiop, size_t n);
78
79 #define uio_segflg(uio)                 (uio)->uio_segflg
80 #define uio_offset(uio)                 (uio)->uio_loffset
81 #define uio_resid(uio)                  (uio)->uio_resid
82 #define uio_iovcnt(uio)                 (uio)->uio_iovcnt
83 #define uio_iovlen(uio, idx)            (uio)->uio_iov[(idx)].iov_len
84 #define uio_iovbase(uio, idx)           (uio)->uio_iov[(idx)].iov_base
85
86 static inline void
87 uio_iov_at_index(uio_t *uio, uint_t idx, void **base, uint64_t *len)
88 {
89         *base = uio_iovbase(uio, idx);
90         *len = uio_iovlen(uio, idx);
91 }
92
93 static inline void
94 uio_advance(uio_t *uio, size_t size)
95 {
96         uio->uio_resid -= size;
97         uio->uio_loffset += size;
98 }
99
100 static inline offset_t
101 uio_index_at_offset(uio_t *uio, offset_t off, uint_t *vec_idx)
102 {
103         *vec_idx = 0;
104         while (*vec_idx < uio_iovcnt(uio) && off >= uio_iovlen(uio, *vec_idx)) {
105                 off -= uio_iovlen(uio, *vec_idx);
106                 (*vec_idx)++;
107         }
108
109         return (off);
110 }
111
112 #endif /* !_STANDALONE */
113
114 #endif  /* !_OPENSOLARIS_SYS_UIO_H_ */