docs/how-to-build.md: use proper markup for directory names
[unleashed/tickless.git] / include / sys / uio.h
blob8ca35d4e0d779e95e2448a0c721395bfaaa8db9d
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
19 * CDDL HEADER END
22 * Copyright 2014 Garrett D'Amore <garrett@damore.org>
24 * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
25 * Use is subject to license terms.
27 * Copyright 2013 Nexenta Systems, Inc. All rights reserved.
28 * Copyright (c) 2015, Joyent, Inc. All rights reserved.
31 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
32 /* All Rights Reserved */
35 * University Copyright- Copyright (c) 1982, 1986, 1988
36 * The Regents of the University of California
37 * All Rights Reserved
39 * University Acknowledgment- Portions of this document are derived from
40 * software developed by the University of California, Berkeley, and its
41 * contributors.
44 #ifndef _SYS_UIO_H
45 #define _SYS_UIO_H
47 #include <sys/feature_tests.h>
49 #ifdef __cplusplus
50 extern "C" {
51 #endif
53 #include <sys/types.h>
56 * I/O parameter information. A uio structure describes the I/O which
57 * is to be performed by an operation. Typically the data movement will
58 * be performed by a routine such as uiomove(), which updates the uio
59 * structure to reflect what was done.
62 #if defined(_XPG4_2)
63 typedef struct iovec {
64 void *iov_base;
65 size_t iov_len;
66 } iovec_t;
67 #else
68 typedef struct iovec {
69 caddr_t iov_base;
70 #if defined(_LP64)
71 size_t iov_len;
72 #else
73 long iov_len;
74 #endif
75 } iovec_t;
76 #endif /* defined(_XPG4_2) */
78 #if defined(_SYSCALL32)
80 /* Kernel's view of user ILP32 iovec struct */
82 typedef struct iovec32 {
83 caddr32_t iov_base;
84 int32_t iov_len;
85 } iovec32_t;
87 #endif /* _SYSCALL32 */
89 #if !defined(_XPG4_2) || defined(__EXTENSIONS__)
91 * Segment flag values.
93 typedef enum uio_seg { UIO_USERSPACE, UIO_SYSSPACE, UIO_USERISPACE } uio_seg_t;
95 typedef struct uio {
96 iovec_t *uio_iov; /* pointer to array of iovecs */
97 int uio_iovcnt; /* number of iovecs */
98 lloff_t _uio_offset; /* file offset */
99 uio_seg_t uio_segflg; /* address space (kernel or user) */
100 uint16_t uio_fmode; /* file mode flags */
101 uint16_t uio_extflg; /* extended flags */
102 lloff_t _uio_limit; /* u-limit (maximum byte offset) */
103 ssize_t uio_resid; /* residual count */
104 } uio_t;
107 * Extended uio_t uioa_t used for asynchronous uio.
109 * Note: UIOA_IOV_MAX is defined and used as it is in "fs/vncalls.c"
110 * as there isn't a formal definition of IOV_MAX for the kernel.
112 #define UIOA_IOV_MAX 16
114 typedef struct uioa_page_s { /* locked uio_iov state */
115 int uioa_pfncnt; /* count of pfn_t(s) in *uioa_ppp */
116 void **uioa_ppp; /* page_t or pfn_t arrary */
117 caddr_t uioa_base; /* address base */
118 size_t uioa_len; /* span length */
119 } uioa_page_t;
121 typedef struct uioa_s {
122 iovec_t *uio_iov; /* pointer to array of iovecs */
123 int uio_iovcnt; /* number of iovecs */
124 lloff_t _uio_offset; /* file offset */
125 uio_seg_t uio_segflg; /* address space (kernel or user) */
126 uint16_t uio_fmode; /* file mode flags */
127 uint16_t uio_extflg; /* extended flags */
128 lloff_t _uio_limit; /* u-limit (maximum byte offset) */
129 ssize_t uio_resid; /* residual count */
131 * uioa extended members.
133 uint32_t uioa_state; /* state of asynch i/o */
134 ssize_t uioa_mbytes; /* bytes that have been uioamove()ed */
135 uioa_page_t *uioa_lcur; /* pointer into uioa_locked[] */
136 void **uioa_lppp; /* pointer into lcur->uioa_ppp[] */
137 void *uioa_hwst[4]; /* opaque hardware state */
138 uioa_page_t uioa_locked[UIOA_IOV_MAX]; /* Per iov locked pages */
139 } uioa_t;
142 * uio extensions
144 * PSARC 2009/478: Copy Reduction Interfaces
146 typedef enum xuio_type {
147 UIOTYPE_ASYNCIO,
148 UIOTYPE_ZEROCOPY
149 } xuio_type_t;
151 typedef struct xuio {
152 uio_t xu_uio; /* Embedded UIO structure */
154 /* Extended uio fields */
155 enum xuio_type xu_type; /* What kind of uio structure? */
156 union {
157 /* Async I/O Support, intend to replace uioa_t. */
158 struct {
159 uint32_t xu_a_state; /* state of async i/o */
160 /* bytes that have been uioamove()ed */
161 ssize_t xu_a_mbytes;
162 uioa_page_t *xu_a_lcur; /* pointer into uioa_locked[] */
163 /* pointer into lcur->uioa_ppp[] */
164 void **xu_a_lppp;
165 void *xu_a_hwst[4]; /* opaque hardware state */
166 /* Per iov locked pages */
167 uioa_page_t xu_a_locked[UIOA_IOV_MAX];
168 } xu_aio;
171 * Copy Reduction Support -- facilate loaning / returning of
172 * filesystem cache buffers.
174 struct {
175 int xu_zc_rw; /* read or write buffer */
176 void *xu_zc_priv; /* fs specific */
177 } xu_zc;
178 } xu_ext;
179 } xuio_t;
181 #define XUIO_XUZC_PRIV(xuio) xuio->xu_ext.xu_zc.xu_zc_priv
182 #define XUIO_XUZC_RW(xuio) xuio->xu_ext.xu_zc.xu_zc_rw
184 #define UIOA_ALLOC 0x0001 /* allocated but not yet initialized */
185 #define UIOA_INIT 0x0002 /* initialized but not yet enabled */
186 #define UIOA_ENABLED 0x0004 /* enabled, asynch i/o active */
187 #define UIOA_FINI 0x0008 /* finished waiting for uioafini() */
189 #define UIOA_CLR (~0x000F) /* clear mutually exclusive bits */
191 #define UIOA_POLL 0x0010 /* need dcopy_poll() */
193 #define uio_loffset _uio_offset._f
194 #if !defined(_LP64)
195 #define uio_offset _uio_offset._p._l
196 #else
197 #define uio_offset uio_loffset
198 #endif
200 #define uio_llimit _uio_limit._f
201 #if !defined(_LP64)
202 #define uio_limit _uio_limit._p._l
203 #else
204 #define uio_limit uio_llimit
205 #endif
208 * I/O direction.
210 typedef enum uio_rw { UIO_READ, UIO_WRITE } uio_rw_t;
213 * uio_extflg: extended flags
215 * NOTE: This flag will be used in uiomove to determine if non-temporal
216 * access, ie, access bypassing caches, should be used. Filesystems that
217 * don't initialize this field could experience suboptimal performance due to
218 * the random data the field contains.
220 * NOTE: This flag is also used by uioasync callers to pass an extended
221 * uio_t (uioa_t), to uioasync enabled consumers. Unlike above all
222 * consumers of a uioa_t require the uio_extflg to be initialized.
224 #define UIO_COPY_DEFAULT 0x0000 /* no special options to copy */
225 #define UIO_COPY_CACHED 0x0001 /* copy should not bypass caches */
227 #define UIO_ASYNC 0x0002 /* uio_t is really a uioa_t */
228 #define UIO_XUIO 0x0004 /* Structure is xuio_t */
231 * Global uioasync capability shadow state.
233 typedef struct uioasync_s {
234 boolean_t enabled; /* Is uioasync enabled? */
235 size_t mincnt; /* Minimum byte count for use of */
236 } uioasync_t;
238 #endif /* !defined(_XPG4_2) || defined(__EXTENSIONS__) */
240 #if defined(_KERNEL)
242 int uiomove(void *, size_t, enum uio_rw, uio_t *);
243 void uio_prefaultpages(ssize_t, uio_t *);
244 int uiocopy(void *, size_t, enum uio_rw, uio_t *, size_t *);
245 int ureadc(int, uio_t *); /* should be errno_t in future */
246 int uwritec(struct uio *);
247 void uioskip(uio_t *, size_t);
248 int uiodup(uio_t *, uio_t *, iovec_t *, int);
250 int uioamove(void *, size_t, enum uio_rw, uioa_t *);
251 int uioainit(uio_t *, uioa_t *);
252 int uioafini(uio_t *, uioa_t *);
253 extern uioasync_t uioasync;
255 #else /* defined(_KERNEL) */
257 extern ssize_t readv(int, const struct iovec *, int);
258 extern ssize_t writev(int, const struct iovec *, int);
261 * When in the large file compilation environment,
262 * map preadv/pwritev to their 64 bit offset versions
264 #if !defined(_LP64) && _FILE_OFFSET_BITS == 64
265 #ifdef __PRAGMA_REDEFINE_EXTNAME
266 #pragma redefine_extname preadv preadv64
267 #pragma redefine_extname pwritev pwritev64
268 #else /* __PRAGMA_REDEFINE_EXTNAME */
269 #define preadv preadv64
270 #define pwritev pwritev64
271 #endif /* __PRAGMA_REDEFINE_EXTNAME */
272 #endif /* !_LP64 && _FILE_OFFSET_BITS == 64 */
274 /* In the LP64 compilation environment, the APIs are already large file */
275 #if defined(_LP64) && defined(_LARGEFILE64_SOURCE)
276 #ifdef __PRAGMA_REDEFINE_EXTNAME
277 #pragma redefine_extname preadv64 preadv
278 #pragma redefine_extname pwritev64 pwritev
279 #else /* __PRAGMA_REDEFINE_EXTNAME */
280 #define preadv64 preadv
281 #define pwritev64 pwritev
282 #endif /* __PRAGMA_REDEFINE_EXTNAME */
283 #endif /* _LP64 && _LARGEFILE64_SOURCE */
285 extern ssize_t preadv(int, const struct iovec *, int, off_t);
286 extern ssize_t pwritev(int, const struct iovec *, int, off_t);
289 * preadv64 and pwritev64 should be defined when:
290 * - Using the transitional compilation environment, and not
291 * the large file compilation environment.
293 #if defined(_LARGEFILE64_SOURCE) && !((_FILE_OFFSET_BITS == 64) && \
294 !defined(__PRAGMA_REDEFINE_EXTNAME))
295 extern ssize_t preadv64(int, const struct iovec *, int, off64_t);
296 extern ssize_t pwritev64(int, const struct iovec *, int, off64_t);
297 #endif /* _LARGEFILE64_SOURCE */
299 #endif /* defined(_KERNEL) */
301 #ifdef __cplusplus
303 #endif
305 #endif /* _SYS_UIO_H */