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 #include <sys/sysmacros.h>
38
39 /*
40 * uio_extflg: extended flags
41 */
42 #define UIO_DIRECT 0x0001 /* Direct I/O requset */
43
44 typedef struct iovec iovec_t;
45 typedef enum uio_seg zfs_uio_seg_t;
46 typedef enum uio_rw zfs_uio_rw_t;
47
48 /*
49 * This structure is used when doing Direct I/O.
50 */
51 typedef struct {
52 vm_page_t *pages;
53 int npages;
54 } zfs_uio_dio_t;
55
56 typedef struct zfs_uio {
57 struct uio *uio;
58 offset_t uio_soffset;
59 uint16_t uio_extflg;
60 zfs_uio_dio_t uio_dio;
61 } zfs_uio_t;
62
63 #define GET_UIO_STRUCT(u) (u)->uio
64 #define zfs_uio_segflg(u) GET_UIO_STRUCT(u)->uio_segflg
65 #define zfs_uio_offset(u) GET_UIO_STRUCT(u)->uio_offset
66 #define zfs_uio_resid(u) GET_UIO_STRUCT(u)->uio_resid
67 #define zfs_uio_iovcnt(u) GET_UIO_STRUCT(u)->uio_iovcnt
68 #define zfs_uio_iovlen(u, idx) GET_UIO_STRUCT(u)->uio_iov[(idx)].iov_len
69 #define zfs_uio_iovbase(u, idx) GET_UIO_STRUCT(u)->uio_iov[(idx)].iov_base
70 #define zfs_uio_td(u) GET_UIO_STRUCT(u)->uio_td
71 #define zfs_uio_rw(u) GET_UIO_STRUCT(u)->uio_rw
72 #define zfs_uio_soffset(u) (u)->uio_soffset
73 #define zfs_uio_fault_disable(u, set)
74 #define zfs_uio_prefaultpages(size, u) (0)
75
76 static inline void
zfs_uio_setoffset(zfs_uio_t * uio,offset_t off)77 zfs_uio_setoffset(zfs_uio_t *uio, offset_t off)
78 {
79 zfs_uio_offset(uio) = off;
80 }
81
82 static inline void
zfs_uio_setsoffset(zfs_uio_t * uio,offset_t off)83 zfs_uio_setsoffset(zfs_uio_t *uio, offset_t off)
84 {
85 ASSERT3U(zfs_uio_offset(uio), ==, off);
86 zfs_uio_soffset(uio) = off;
87 }
88
89 static inline void
zfs_uio_advance(zfs_uio_t * uio,ssize_t size)90 zfs_uio_advance(zfs_uio_t *uio, ssize_t size)
91 {
92 zfs_uio_resid(uio) -= size;
93 zfs_uio_offset(uio) += size;
94 }
95
96 static __inline void
zfs_uio_init(zfs_uio_t * uio,struct uio * uio_s)97 zfs_uio_init(zfs_uio_t *uio, struct uio *uio_s)
98 {
99 memset(uio, 0, sizeof (zfs_uio_t));
100 if (uio_s != NULL) {
101 GET_UIO_STRUCT(uio) = uio_s;
102 zfs_uio_soffset(uio) = uio_s->uio_offset;
103 }
104 }
105
106 int zfs_uio_fault_move(void *p, size_t n, zfs_uio_rw_t dir, zfs_uio_t *uio);
107
108 #endif /* !_STANDALONE */
109
110 #endif /* !_OPENSOLARIS_SYS_UIO_H_ */
111