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
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or https://opensource.org/licenses/CDDL-1.0.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
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]
23 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
28 /* All Rights Reserved */
31 * University Copyright- Copyright (c) 1982, 1986, 1988
32 * The Regents of the University of California
35 * University Acknowledgment- Portions of this document are derived from
36 * software developed by the University of California, Berkeley, and its
40 #ifndef _LIBSPL_SYS_UIO_H
41 #define _LIBSPL_SYS_UIO_H
43 #include <sys/types.h>
44 #include_next <sys/uio.h>
47 #include <sys/_types/_iovec_t.h>
51 typedef struct iovec iovec_t
;
53 #if defined(__linux__) || defined(__APPLE__)
54 typedef enum zfs_uio_rw
{
59 typedef enum zfs_uio_seg
{
64 #elif defined(__FreeBSD__)
65 typedef enum uio_seg zfs_uio_seg_t
;
68 typedef struct zfs_uio
{
69 struct iovec
*uio_iov
; /* pointer to array of iovecs */
70 int uio_iovcnt
; /* number of iovecs */
71 offset_t uio_loffset
; /* file offset */
72 zfs_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 */
75 ssize_t uio_resid
; /* residual count */
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
85 static inline boolean_t
86 zfs_dio_page_aligned(void *buf
)
88 return ((((unsigned long)(buf
) & (PAGESIZE
- 1)) == 0) ?
92 static inline boolean_t
93 zfs_dio_offset_aligned(uint64_t offset
, uint64_t blksz
)
95 return ((IS_P2ALIGNED(offset
, blksz
)) ? B_TRUE
: B_FALSE
);
98 static inline boolean_t
99 zfs_dio_size_aligned(uint64_t size
, uint64_t blksz
)
101 return (((size
% blksz
) == 0) ? B_TRUE
: B_FALSE
);
104 static inline boolean_t
105 zfs_dio_aligned(uint64_t offset
, uint64_t size
, uint64_t blksz
)
107 return ((zfs_dio_offset_aligned(offset
, blksz
) &&
108 zfs_dio_size_aligned(size
, blksz
)) ? B_TRUE
: B_FALSE
);
112 zfs_uio_iov_at_index(zfs_uio_t
*uio
, uint_t idx
, void **base
, uint64_t *len
)
114 *base
= zfs_uio_iovbase(uio
, idx
);
115 *len
= zfs_uio_iovlen(uio
, idx
);
119 zfs_uio_advance(zfs_uio_t
*uio
, ssize_t size
)
121 uio
->uio_resid
-= size
;
122 uio
->uio_loffset
+= size
;
125 static inline offset_t
126 zfs_uio_index_at_offset(zfs_uio_t
*uio
, offset_t off
, uint_t
*vec_idx
)
129 while (*vec_idx
< (uint_t
)zfs_uio_iovcnt(uio
) &&
130 off
>= (offset_t
)zfs_uio_iovlen(uio
, *vec_idx
)) {
131 off
-= zfs_uio_iovlen(uio
, *vec_idx
);
138 #endif /* _SYS_UIO_H */