1 // SPDX-License-Identifier: BSD-2-Clause
2 /*
3 * Copyright (c) 2010 Pawel Jakub Dawidek <pjd@FreeBSD.org>
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 * SUCH DAMAGE.
26 *
27 * $FreeBSD$
28 */
29
30 #ifndef _OPENSOLARIS_SYS_UIO_H_
31 #define _OPENSOLARIS_SYS_UIO_H_
32
33 #ifndef _STANDALONE
34
35 #include_next <sys/uio.h>
36 #include <sys/_uio.h>
37 #include <sys/debug.h>
38 #include <sys/sysmacros.h>
39
40 /*
41 * uio_extflg: extended flags
42 */
43 #define UIO_DIRECT 0x0001 /* Direct I/O requset */
44
45 typedef struct iovec iovec_t;
46 typedef enum uio_seg zfs_uio_seg_t;
47 typedef enum uio_rw zfs_uio_rw_t;
48
49 /*
50 * This structure is used when doing Direct I/O.
51 */
52 typedef struct {
53 vm_page_t *pages;
54 int npages;
55 } zfs_uio_dio_t;
56
57 typedef struct zfs_uio {
58 struct uio *uio;
59 offset_t uio_soffset;
60 uint16_t uio_extflg;
61 zfs_uio_dio_t uio_dio;
62 } zfs_uio_t;
63
64 #define GET_UIO_STRUCT(u) (u)->uio
65 #define zfs_uio_segflg(u) GET_UIO_STRUCT(u)->uio_segflg
66 #define zfs_uio_offset(u) GET_UIO_STRUCT(u)->uio_offset
67 #define zfs_uio_resid(u) GET_UIO_STRUCT(u)->uio_resid
68 #define zfs_uio_iovcnt(u) GET_UIO_STRUCT(u)->uio_iovcnt
69 #define zfs_uio_iovlen(u, idx) GET_UIO_STRUCT(u)->uio_iov[(idx)].iov_len
70 #define zfs_uio_iovbase(u, idx) GET_UIO_STRUCT(u)->uio_iov[(idx)].iov_base
71 #define zfs_uio_td(u) GET_UIO_STRUCT(u)->uio_td
72 #define zfs_uio_rw(u) GET_UIO_STRUCT(u)->uio_rw
73 #define zfs_uio_soffset(u) (u)->uio_soffset
74 #define zfs_uio_fault_disable(u, set)
75 #define zfs_uio_prefaultpages(size, u) (0)
76
77 static inline void
zfs_uio_setoffset(zfs_uio_t * uio,offset_t off)78 zfs_uio_setoffset(zfs_uio_t *uio, offset_t off)
79 {
80 zfs_uio_offset(uio) = off;
81 }
82
83 static inline void
zfs_uio_setsoffset(zfs_uio_t * uio,offset_t off)84 zfs_uio_setsoffset(zfs_uio_t *uio, offset_t off)
85 {
86 ASSERT3U(zfs_uio_offset(uio), ==, off);
87 zfs_uio_soffset(uio) = off;
88 }
89
90 static inline void
zfs_uio_advance(zfs_uio_t * uio,ssize_t size)91 zfs_uio_advance(zfs_uio_t *uio, ssize_t size)
92 {
93 zfs_uio_resid(uio) -= size;
94 zfs_uio_offset(uio) += size;
95 }
96
97 static __inline void
zfs_uio_init(zfs_uio_t * uio,struct uio * uio_s)98 zfs_uio_init(zfs_uio_t *uio, struct uio *uio_s)
99 {
100 memset(uio, 0, sizeof (zfs_uio_t));
101 if (uio_s != NULL) {
102 GET_UIO_STRUCT(uio) = uio_s;
103 zfs_uio_soffset(uio) = uio_s->uio_offset;
104 }
105 }
106
107 int zfs_uio_fault_move(void *p, size_t n, zfs_uio_rw_t dir, zfs_uio_t *uio);
108
109 #endif /* !_STANDALONE */
110
111 #endif /* !_OPENSOLARIS_SYS_UIO_H_ */
112