]>
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 | |
1d3ba0bf | 10 | * or https://opensource.org/licenses/CDDL-1.0. |
a26baf28 BB |
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__) |
d0cd9a5c | 54 | typedef enum zfs_uio_rw { |
d1d7e268 MK |
55 | UIO_READ = 0, |
56 | UIO_WRITE = 1, | |
d0cd9a5c | 57 | } zfs_uio_rw_t; |
a26baf28 | 58 | |
d0cd9a5c | 59 | typedef enum zfs_uio_seg { |
d1d7e268 MK |
60 | UIO_USERSPACE = 0, |
61 | UIO_SYSSPACE = 1, | |
d0cd9a5c | 62 | } zfs_uio_seg_t; |
a26baf28 | 63 | |
883a40ff | 64 | #elif defined(__FreeBSD__) |
d0cd9a5c | 65 | typedef enum uio_seg zfs_uio_seg_t; |
883a40ff JL |
66 | #endif |
67 | ||
d0cd9a5c | 68 | typedef struct zfs_uio { |
a26baf28 BB |
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 */ |
d0cd9a5c | 72 | zfs_uio_seg_t uio_segflg; /* address space (kernel or user) */ |
a26baf28 BB |
73 | uint16_t uio_fmode; /* file mode flags */ |
74 | uint16_t uio_extflg; /* extended flags */ | |
a26baf28 | 75 | ssize_t uio_resid; /* residual count */ |
d0cd9a5c | 76 | } zfs_uio_t; |
a26baf28 | 77 | |
d0cd9a5c BA |
78 | #define zfs_uio_segflg(uio) (uio)->uio_segflg |
79 | #define zfs_uio_offset(uio) (uio)->uio_loffset | |
80 | #define zfs_uio_resid(uio) (uio)->uio_resid | |
81 | #define zfs_uio_iovcnt(uio) (uio)->uio_iovcnt | |
82 | #define zfs_uio_iovlen(uio, idx) (uio)->uio_iov[(idx)].iov_len | |
83 | #define zfs_uio_iovbase(uio, idx) (uio)->uio_iov[(idx)].iov_base | |
883a40ff JL |
84 | |
85 | static inline void | |
d0cd9a5c | 86 | zfs_uio_iov_at_index(zfs_uio_t *uio, uint_t idx, void **base, uint64_t *len) |
883a40ff | 87 | { |
d0cd9a5c BA |
88 | *base = zfs_uio_iovbase(uio, idx); |
89 | *len = zfs_uio_iovlen(uio, idx); | |
883a40ff JL |
90 | } |
91 | ||
92 | static inline void | |
9b1677fb | 93 | zfs_uio_advance(zfs_uio_t *uio, ssize_t size) |
883a40ff JL |
94 | { |
95 | uio->uio_resid -= size; | |
96 | uio->uio_loffset += size; | |
97 | } | |
98 | ||
99 | static inline offset_t | |
d0cd9a5c | 100 | zfs_uio_index_at_offset(zfs_uio_t *uio, offset_t off, uint_t *vec_idx) |
883a40ff JL |
101 | { |
102 | *vec_idx = 0; | |
d0cd9a5c BA |
103 | while (*vec_idx < (uint_t)zfs_uio_iovcnt(uio) && |
104 | off >= (offset_t)zfs_uio_iovlen(uio, *vec_idx)) { | |
105 | off -= zfs_uio_iovlen(uio, *vec_idx); | |
883a40ff JL |
106 | (*vec_idx)++; |
107 | } | |
108 | ||
109 | return (off); | |
110 | } | |
111 | ||
a26baf28 | 112 | #endif /* _SYS_UIO_H */ |