Cleaning up uio headers
[zfs.git] / include / os / linux / spl / sys / uio.h
blob66af2b0b534c05b86fd3b7b91863c4144a3e370d
1 /*
2 * Copyright (C) 2007-2010 Lawrence Livermore National Security, LLC.
3 * Copyright (C) 2007 The Regents of the University of California.
4 * Copyright (c) 2015 by Chunwei Chen. All rights reserved.
5 * Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER).
6 * Written by Brian Behlendorf <behlendorf1@llnl.gov>.
7 * UCRL-CODE-235197
9 * This file is part of the SPL, Solaris Porting Layer.
11 * The SPL is free software; you can redistribute it and/or modify it
12 * under the terms of the GNU General Public License as published by the
13 * Free Software Foundation; either version 2 of the License, or (at your
14 * option) any later version.
16 * The SPL is distributed in the hope that it will be useful, but WITHOUT
17 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19 * for more details.
21 * You should have received a copy of the GNU General Public License along
22 * with the SPL. If not, see <http://www.gnu.org/licenses/>.
25 #ifndef _SPL_UIO_H
26 #define _SPL_UIO_H
28 #include <sys/debug.h>
29 #include <linux/uio.h>
30 #include <linux/blkdev.h>
31 #include <linux/blkdev_compat.h>
32 #include <linux/mm.h>
33 #include <linux/bio.h>
34 #include <asm/uaccess.h>
35 #include <sys/types.h>
37 typedef struct iovec iovec_t;
39 typedef enum zfs_uio_rw {
40 UIO_READ = 0,
41 UIO_WRITE = 1,
42 } zfs_uio_rw_t;
44 typedef enum zfs_uio_seg {
45 UIO_USERSPACE = 0,
46 UIO_SYSSPACE = 1,
47 UIO_BVEC = 2,
48 #if defined(HAVE_VFS_IOV_ITER)
49 UIO_ITER = 3,
50 #endif
51 } zfs_uio_seg_t;
53 typedef struct zfs_uio {
54 union {
55 const struct iovec *uio_iov;
56 const struct bio_vec *uio_bvec;
57 #if defined(HAVE_VFS_IOV_ITER)
58 struct iov_iter *uio_iter;
59 #endif
61 int uio_iovcnt;
62 offset_t uio_loffset;
63 zfs_uio_seg_t uio_segflg;
64 boolean_t uio_fault_disable;
65 uint16_t uio_fmode;
66 uint16_t uio_extflg;
67 ssize_t uio_resid;
68 size_t uio_skip;
69 } zfs_uio_t;
71 #define zfs_uio_segflg(u) (u)->uio_segflg
72 #define zfs_uio_offset(u) (u)->uio_loffset
73 #define zfs_uio_resid(u) (u)->uio_resid
74 #define zfs_uio_iovcnt(u) (u)->uio_iovcnt
75 #define zfs_uio_iovlen(u, idx) (u)->uio_iov[(idx)].iov_len
76 #define zfs_uio_iovbase(u, idx) (u)->uio_iov[(idx)].iov_base
77 #define zfs_uio_fault_disable(u, set) (u)->uio_fault_disable = set
78 #define zfs_uio_rlimit_fsize(z, u) (0)
79 #define zfs_uio_fault_move(p, n, rw, u) zfs_uiomove((p), (n), (rw), (u))
81 extern int zfs_uio_prefaultpages(ssize_t, zfs_uio_t *);
83 static inline void
84 zfs_uio_setoffset(zfs_uio_t *uio, offset_t off)
86 uio->uio_loffset = off;
89 static inline void
90 zfs_uio_advance(zfs_uio_t *uio, size_t size)
92 uio->uio_resid -= size;
93 uio->uio_loffset += size;
96 static inline void
97 zfs_uio_iovec_init(zfs_uio_t *uio, const struct iovec *iov,
98 unsigned long nr_segs, offset_t offset, zfs_uio_seg_t seg, ssize_t resid,
99 size_t skip)
101 ASSERT(seg == UIO_USERSPACE || seg == UIO_SYSSPACE);
103 uio->uio_iov = iov;
104 uio->uio_iovcnt = nr_segs;
105 uio->uio_loffset = offset;
106 uio->uio_segflg = seg;
107 uio->uio_fault_disable = B_FALSE;
108 uio->uio_fmode = 0;
109 uio->uio_extflg = 0;
110 uio->uio_resid = resid;
111 uio->uio_skip = skip;
114 static inline void
115 zfs_uio_bvec_init(zfs_uio_t *uio, struct bio *bio)
117 uio->uio_bvec = &bio->bi_io_vec[BIO_BI_IDX(bio)];
118 uio->uio_iovcnt = bio->bi_vcnt - BIO_BI_IDX(bio);
119 uio->uio_loffset = BIO_BI_SECTOR(bio) << 9;
120 uio->uio_segflg = UIO_BVEC;
121 uio->uio_fault_disable = B_FALSE;
122 uio->uio_fmode = 0;
123 uio->uio_extflg = 0;
124 uio->uio_resid = BIO_BI_SIZE(bio);
125 uio->uio_skip = BIO_BI_SKIP(bio);
128 #if defined(HAVE_VFS_IOV_ITER)
129 static inline void
130 zfs_uio_iov_iter_init(zfs_uio_t *uio, struct iov_iter *iter, offset_t offset,
131 ssize_t resid, size_t skip)
133 uio->uio_iter = iter;
134 uio->uio_iovcnt = iter->nr_segs;
135 uio->uio_loffset = offset;
136 uio->uio_segflg = UIO_ITER;
137 uio->uio_fault_disable = B_FALSE;
138 uio->uio_fmode = 0;
139 uio->uio_extflg = 0;
140 uio->uio_resid = resid;
141 uio->uio_skip = skip;
143 #endif
145 #endif /* SPL_UIO_H */