]>
Commit | Line | Data |
---|---|---|
a26baf28 BB |
1 | /* |
2 | * CDDL HEADER START | |
3 | * | |
4 | * The contents of this file are subject to the terms of the | |
5 | * Common Development and Distribution License, Version 1.0 only | |
6 | * (the "License"). You may not use this file except in compliance | |
7 | * with the License. | |
8 | * | |
9 | * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE | |
10 | * or http://www.opensolaris.org/os/licensing. | |
11 | * See the License for the specific language governing permissions | |
12 | * and limitations under the License. | |
13 | * | |
14 | * When distributing Covered Code, include this CDDL HEADER in each | |
15 | * file and include the License file at usr/src/OPENSOLARIS.LICENSE. | |
16 | * If applicable, add the following below this CDDL HEADER, with the | |
17 | * fields enclosed by brackets "[]" replaced with your own identifying | |
18 | * information: Portions Copyright [yyyy] [name of copyright owner] | |
19 | * | |
20 | * CDDL HEADER END | |
21 | */ | |
22 | /* | |
23 | * Copyright 2005 Sun Microsystems, Inc. All rights reserved. | |
24 | * Use is subject to license terms. | |
25 | */ | |
26 | ||
27 | /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ | |
28 | /* All Rights Reserved */ | |
29 | ||
30 | /* | |
31 | * University Copyright- Copyright (c) 1982, 1986, 1988 | |
32 | * The Regents of the University of California | |
33 | * All Rights Reserved | |
34 | * | |
35 | * University Acknowledgment- Portions of this document are derived from | |
36 | * software developed by the University of California, Berkeley, and its | |
37 | * contributors. | |
38 | */ | |
39 | ||
40 | #ifndef _LIBSPL_SYS_UIO_H | |
41 | #define _LIBSPL_SYS_UIO_H | |
42 | ||
d31277ab | 43 | #include <sys/types.h> |
a26baf28 BB |
44 | #include_next <sys/uio.h> |
45 | ||
883a40ff JL |
46 | #ifdef __APPLE__ |
47 | #include <sys/_types/_iovec_t.h> | |
48 | #endif | |
49 | ||
d31277ab | 50 | #include <stdint.h> |
a26baf28 BB |
51 | typedef struct iovec iovec_t; |
52 | ||
883a40ff | 53 | #if defined(__linux__) || defined(__APPLE__) |
a26baf28 | 54 | typedef enum uio_rw { |
d1d7e268 MK |
55 | UIO_READ = 0, |
56 | UIO_WRITE = 1, | |
a26baf28 BB |
57 | } uio_rw_t; |
58 | ||
59 | typedef enum uio_seg { | |
d1d7e268 MK |
60 | UIO_USERSPACE = 0, |
61 | UIO_SYSSPACE = 1, | |
a26baf28 BB |
62 | } uio_seg_t; |
63 | ||
883a40ff JL |
64 | #elif defined(__FreeBSD__) |
65 | typedef enum uio_seg uio_seg_t; | |
66 | #endif | |
67 | ||
a26baf28 BB |
68 | typedef struct uio { |
69 | struct iovec *uio_iov; /* pointer to array of iovecs */ | |
70 | int uio_iovcnt; /* number of iovecs */ | |
883a40ff | 71 | offset_t uio_loffset; /* file offset */ |
a26baf28 BB |
72 | uio_seg_t uio_segflg; /* address space (kernel or user) */ |
73 | uint16_t uio_fmode; /* file mode flags */ | |
74 | uint16_t uio_extflg; /* extended flags */ | |
a26baf28 BB |
75 | ssize_t uio_resid; /* residual count */ |
76 | } uio_t; | |
77 | ||
883a40ff JL |
78 | #define uio_segflg(uio) (uio)->uio_segflg |
79 | #define uio_offset(uio) (uio)->uio_loffset | |
80 | #define uio_resid(uio) (uio)->uio_resid | |
81 | #define uio_iovcnt(uio) (uio)->uio_iovcnt | |
82 | #define uio_iovlen(uio, idx) (uio)->uio_iov[(idx)].iov_len | |
83 | #define uio_iovbase(uio, idx) (uio)->uio_iov[(idx)].iov_base | |
84 | ||
85 | static inline void | |
86 | uio_iov_at_index(uio_t *uio, uint_t idx, void **base, uint64_t *len) | |
87 | { | |
88 | *base = uio_iovbase(uio, idx); | |
89 | *len = uio_iovlen(uio, idx); | |
90 | } | |
91 | ||
92 | static inline void | |
93 | uio_advance(uio_t *uio, size_t size) | |
94 | { | |
95 | uio->uio_resid -= size; | |
96 | uio->uio_loffset += size; | |
97 | } | |
98 | ||
99 | static inline offset_t | |
100 | uio_index_at_offset(uio_t *uio, offset_t off, uint_t *vec_idx) | |
101 | { | |
102 | *vec_idx = 0; | |
47ed79ff MM |
103 | while (*vec_idx < (uint_t)uio_iovcnt(uio) && |
104 | off >= (offset_t)uio_iovlen(uio, *vec_idx)) { | |
883a40ff JL |
105 | off -= uio_iovlen(uio, *vec_idx); |
106 | (*vec_idx)++; | |
107 | } | |
108 | ||
109 | return (off); | |
110 | } | |
111 | ||
a26baf28 | 112 | #endif /* _SYS_UIO_H */ |