17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 517169044Sbrutus * Common Development and Distribution License (the "License"). 617169044Sbrutus * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 217c478bd9Sstevel@tonic-gate /* 22ba3594baSGarrett D'Amore * Copyright 2014 Garrett D'Amore <garrett@damore.org> 23ba3594baSGarrett D'Amore * 24c242f9a0Schunli zhang - Sun Microsystems - Irvine United States * Copyright 2010 Sun Microsystems, Inc. All rights reserved. 257c478bd9Sstevel@tonic-gate * Use is subject to license terms. 26*fca543caSDJ Hoffman * Copyright (c) 2015, Joyent, Inc. All rights reserved. 277c478bd9Sstevel@tonic-gate */ 287c478bd9Sstevel@tonic-gate 297c478bd9Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 307c478bd9Sstevel@tonic-gate /* All Rights Reserved */ 317c478bd9Sstevel@tonic-gate 327c478bd9Sstevel@tonic-gate /* 337c478bd9Sstevel@tonic-gate * University Copyright- Copyright (c) 1982, 1986, 1988 347c478bd9Sstevel@tonic-gate * The Regents of the University of California 357c478bd9Sstevel@tonic-gate * All Rights Reserved 367c478bd9Sstevel@tonic-gate * 377c478bd9Sstevel@tonic-gate * University Acknowledgment- Portions of this document are derived from 387c478bd9Sstevel@tonic-gate * software developed by the University of California, Berkeley, and its 397c478bd9Sstevel@tonic-gate * contributors. 407c478bd9Sstevel@tonic-gate */ 417c478bd9Sstevel@tonic-gate 427c478bd9Sstevel@tonic-gate #ifndef _SYS_UIO_H 437c478bd9Sstevel@tonic-gate #define _SYS_UIO_H 447c478bd9Sstevel@tonic-gate 457c478bd9Sstevel@tonic-gate #include <sys/feature_tests.h> 467c478bd9Sstevel@tonic-gate 477c478bd9Sstevel@tonic-gate #ifdef __cplusplus 487c478bd9Sstevel@tonic-gate extern "C" { 497c478bd9Sstevel@tonic-gate #endif 507c478bd9Sstevel@tonic-gate 517c478bd9Sstevel@tonic-gate #include <sys/types.h> 527c478bd9Sstevel@tonic-gate 537c478bd9Sstevel@tonic-gate /* 547c478bd9Sstevel@tonic-gate * I/O parameter information. A uio structure describes the I/O which 557c478bd9Sstevel@tonic-gate * is to be performed by an operation. Typically the data movement will 567c478bd9Sstevel@tonic-gate * be performed by a routine such as uiomove(), which updates the uio 577c478bd9Sstevel@tonic-gate * structure to reflect what was done. 587c478bd9Sstevel@tonic-gate */ 597c478bd9Sstevel@tonic-gate 607c478bd9Sstevel@tonic-gate #if defined(_XPG4_2) 617c478bd9Sstevel@tonic-gate typedef struct iovec { 627c478bd9Sstevel@tonic-gate void *iov_base; 637c478bd9Sstevel@tonic-gate size_t iov_len; 647c478bd9Sstevel@tonic-gate } iovec_t; 657c478bd9Sstevel@tonic-gate #else 667c478bd9Sstevel@tonic-gate typedef struct iovec { 677c478bd9Sstevel@tonic-gate caddr_t iov_base; 687c478bd9Sstevel@tonic-gate #if defined(_LP64) 697c478bd9Sstevel@tonic-gate size_t iov_len; 707c478bd9Sstevel@tonic-gate #else 717c478bd9Sstevel@tonic-gate long iov_len; 727c478bd9Sstevel@tonic-gate #endif 737c478bd9Sstevel@tonic-gate } iovec_t; 747c478bd9Sstevel@tonic-gate #endif /* defined(_XPG4_2) */ 757c478bd9Sstevel@tonic-gate 767c478bd9Sstevel@tonic-gate #if defined(_SYSCALL32) 777c478bd9Sstevel@tonic-gate 787c478bd9Sstevel@tonic-gate /* Kernel's view of user ILP32 iovec struct */ 797c478bd9Sstevel@tonic-gate 807c478bd9Sstevel@tonic-gate typedef struct iovec32 { 817c478bd9Sstevel@tonic-gate caddr32_t iov_base; 827c478bd9Sstevel@tonic-gate int32_t iov_len; 837c478bd9Sstevel@tonic-gate } iovec32_t; 847c478bd9Sstevel@tonic-gate 857c478bd9Sstevel@tonic-gate #endif /* _SYSCALL32 */ 867c478bd9Sstevel@tonic-gate 877c478bd9Sstevel@tonic-gate #if !defined(_XPG4_2) || defined(__EXTENSIONS__) 887c478bd9Sstevel@tonic-gate /* 897c478bd9Sstevel@tonic-gate * Segment flag values. 907c478bd9Sstevel@tonic-gate */ 917c478bd9Sstevel@tonic-gate typedef enum uio_seg { UIO_USERSPACE, UIO_SYSSPACE, UIO_USERISPACE } uio_seg_t; 927c478bd9Sstevel@tonic-gate 937c478bd9Sstevel@tonic-gate typedef struct uio { 947c478bd9Sstevel@tonic-gate iovec_t *uio_iov; /* pointer to array of iovecs */ 957c478bd9Sstevel@tonic-gate int uio_iovcnt; /* number of iovecs */ 967c478bd9Sstevel@tonic-gate lloff_t _uio_offset; /* file offset */ 977c478bd9Sstevel@tonic-gate uio_seg_t uio_segflg; /* address space (kernel or user) */ 987c478bd9Sstevel@tonic-gate uint16_t uio_fmode; /* file mode flags */ 997c478bd9Sstevel@tonic-gate uint16_t uio_extflg; /* extended flags */ 1007c478bd9Sstevel@tonic-gate lloff_t _uio_limit; /* u-limit (maximum byte offset) */ 1017c478bd9Sstevel@tonic-gate ssize_t uio_resid; /* residual count */ 1027c478bd9Sstevel@tonic-gate } uio_t; 1037c478bd9Sstevel@tonic-gate 10417169044Sbrutus /* 10517169044Sbrutus * Extended uio_t uioa_t used for asynchronous uio. 10617169044Sbrutus * 10717169044Sbrutus * Note: UIOA_IOV_MAX is defined and used as it is in "fs/vncalls.c" 10817169044Sbrutus * as there isn't a formal definition of IOV_MAX for the kernel. 10917169044Sbrutus */ 11017169044Sbrutus #define UIOA_IOV_MAX 16 11117169044Sbrutus 11217169044Sbrutus typedef struct uioa_page_s { /* locked uio_iov state */ 11317169044Sbrutus int uioa_pfncnt; /* count of pfn_t(s) in *uioa_ppp */ 11417169044Sbrutus void **uioa_ppp; /* page_t or pfn_t arrary */ 11517169044Sbrutus caddr_t uioa_base; /* address base */ 11617169044Sbrutus size_t uioa_len; /* span length */ 11717169044Sbrutus } uioa_page_t; 11817169044Sbrutus 11917169044Sbrutus typedef struct uioa_s { 12017169044Sbrutus iovec_t *uio_iov; /* pointer to array of iovecs */ 12117169044Sbrutus int uio_iovcnt; /* number of iovecs */ 12217169044Sbrutus lloff_t _uio_offset; /* file offset */ 12317169044Sbrutus uio_seg_t uio_segflg; /* address space (kernel or user) */ 12417169044Sbrutus uint16_t uio_fmode; /* file mode flags */ 12517169044Sbrutus uint16_t uio_extflg; /* extended flags */ 12617169044Sbrutus lloff_t _uio_limit; /* u-limit (maximum byte offset) */ 12717169044Sbrutus ssize_t uio_resid; /* residual count */ 12817169044Sbrutus /* 12917169044Sbrutus * uioa extended members. 13017169044Sbrutus */ 13117169044Sbrutus uint32_t uioa_state; /* state of asynch i/o */ 13296e0e3daSYu Xiangning ssize_t uioa_mbytes; /* bytes that have been uioamove()ed */ 13317169044Sbrutus uioa_page_t *uioa_lcur; /* pointer into uioa_locked[] */ 13417169044Sbrutus void **uioa_lppp; /* pointer into lcur->uioa_ppp[] */ 13517169044Sbrutus void *uioa_hwst[4]; /* opaque hardware state */ 13617169044Sbrutus uioa_page_t uioa_locked[UIOA_IOV_MAX]; /* Per iov locked pages */ 13717169044Sbrutus } uioa_t; 13817169044Sbrutus 139c242f9a0Schunli zhang - Sun Microsystems - Irvine United States /* 140c242f9a0Schunli zhang - Sun Microsystems - Irvine United States * uio extensions 141c242f9a0Schunli zhang - Sun Microsystems - Irvine United States * 142c242f9a0Schunli zhang - Sun Microsystems - Irvine United States * PSARC 2009/478: Copy Reduction Interfaces 143c242f9a0Schunli zhang - Sun Microsystems - Irvine United States */ 144c242f9a0Schunli zhang - Sun Microsystems - Irvine United States typedef enum xuio_type { 145c242f9a0Schunli zhang - Sun Microsystems - Irvine United States UIOTYPE_ASYNCIO, 146c242f9a0Schunli zhang - Sun Microsystems - Irvine United States UIOTYPE_ZEROCOPY 147c242f9a0Schunli zhang - Sun Microsystems - Irvine United States } xuio_type_t; 148c242f9a0Schunli zhang - Sun Microsystems - Irvine United States 149c242f9a0Schunli zhang - Sun Microsystems - Irvine United States typedef struct xuio { 150c242f9a0Schunli zhang - Sun Microsystems - Irvine United States uio_t xu_uio; /* Embedded UIO structure */ 151c242f9a0Schunli zhang - Sun Microsystems - Irvine United States 152c242f9a0Schunli zhang - Sun Microsystems - Irvine United States /* Extended uio fields */ 153c242f9a0Schunli zhang - Sun Microsystems - Irvine United States enum xuio_type xu_type; /* What kind of uio structure? */ 154c242f9a0Schunli zhang - Sun Microsystems - Irvine United States union { 155c242f9a0Schunli zhang - Sun Microsystems - Irvine United States /* Async I/O Support, intend to replace uioa_t. */ 156c242f9a0Schunli zhang - Sun Microsystems - Irvine United States struct { 157c242f9a0Schunli zhang - Sun Microsystems - Irvine United States uint32_t xu_a_state; /* state of async i/o */ 158c242f9a0Schunli zhang - Sun Microsystems - Irvine United States /* bytes that have been uioamove()ed */ 159c242f9a0Schunli zhang - Sun Microsystems - Irvine United States ssize_t xu_a_mbytes; 160c242f9a0Schunli zhang - Sun Microsystems - Irvine United States uioa_page_t *xu_a_lcur; /* pointer into uioa_locked[] */ 161c242f9a0Schunli zhang - Sun Microsystems - Irvine United States /* pointer into lcur->uioa_ppp[] */ 162c242f9a0Schunli zhang - Sun Microsystems - Irvine United States void **xu_a_lppp; 163c242f9a0Schunli zhang - Sun Microsystems - Irvine United States void *xu_a_hwst[4]; /* opaque hardware state */ 164c242f9a0Schunli zhang - Sun Microsystems - Irvine United States /* Per iov locked pages */ 165c242f9a0Schunli zhang - Sun Microsystems - Irvine United States uioa_page_t xu_a_locked[UIOA_IOV_MAX]; 166c242f9a0Schunli zhang - Sun Microsystems - Irvine United States } xu_aio; 167c242f9a0Schunli zhang - Sun Microsystems - Irvine United States 168c242f9a0Schunli zhang - Sun Microsystems - Irvine United States /* 169c242f9a0Schunli zhang - Sun Microsystems - Irvine United States * Copy Reduction Support -- facilate loaning / returning of 170c242f9a0Schunli zhang - Sun Microsystems - Irvine United States * filesystem cache buffers. 171c242f9a0Schunli zhang - Sun Microsystems - Irvine United States */ 172c242f9a0Schunli zhang - Sun Microsystems - Irvine United States struct { 173c242f9a0Schunli zhang - Sun Microsystems - Irvine United States int xu_zc_rw; /* read or write buffer */ 174c242f9a0Schunli zhang - Sun Microsystems - Irvine United States void *xu_zc_priv; /* fs specific */ 175c242f9a0Schunli zhang - Sun Microsystems - Irvine United States } xu_zc; 176c242f9a0Schunli zhang - Sun Microsystems - Irvine United States } xu_ext; 177c242f9a0Schunli zhang - Sun Microsystems - Irvine United States } xuio_t; 178c242f9a0Schunli zhang - Sun Microsystems - Irvine United States 179c242f9a0Schunli zhang - Sun Microsystems - Irvine United States #define XUIO_XUZC_PRIV(xuio) xuio->xu_ext.xu_zc.xu_zc_priv 180c242f9a0Schunli zhang - Sun Microsystems - Irvine United States #define XUIO_XUZC_RW(xuio) xuio->xu_ext.xu_zc.xu_zc_rw 181c242f9a0Schunli zhang - Sun Microsystems - Irvine United States 18217169044Sbrutus #define UIOA_ALLOC 0x0001 /* allocated but not yet initialized */ 18317169044Sbrutus #define UIOA_INIT 0x0002 /* initialized but not yet enabled */ 18417169044Sbrutus #define UIOA_ENABLED 0x0004 /* enabled, asynch i/o active */ 18517169044Sbrutus #define UIOA_FINI 0x0008 /* finished waiting for uioafini() */ 18617169044Sbrutus 18717169044Sbrutus #define UIOA_CLR (~0x000F) /* clear mutually exclusive bits */ 18817169044Sbrutus 18917169044Sbrutus #define UIOA_POLL 0x0010 /* need dcopy_poll() */ 19017169044Sbrutus 1917c478bd9Sstevel@tonic-gate #define uio_loffset _uio_offset._f 1927c478bd9Sstevel@tonic-gate #if !defined(_LP64) 1937c478bd9Sstevel@tonic-gate #define uio_offset _uio_offset._p._l 1947c478bd9Sstevel@tonic-gate #else 1957c478bd9Sstevel@tonic-gate #define uio_offset uio_loffset 1967c478bd9Sstevel@tonic-gate #endif 1977c478bd9Sstevel@tonic-gate 1987c478bd9Sstevel@tonic-gate #define uio_llimit _uio_limit._f 1997c478bd9Sstevel@tonic-gate #if !defined(_LP64) 2007c478bd9Sstevel@tonic-gate #define uio_limit _uio_limit._p._l 2017c478bd9Sstevel@tonic-gate #else 2027c478bd9Sstevel@tonic-gate #define uio_limit uio_llimit 2037c478bd9Sstevel@tonic-gate #endif 2047c478bd9Sstevel@tonic-gate 2057c478bd9Sstevel@tonic-gate /* 2067c478bd9Sstevel@tonic-gate * I/O direction. 2077c478bd9Sstevel@tonic-gate */ 2087c478bd9Sstevel@tonic-gate typedef enum uio_rw { UIO_READ, UIO_WRITE } uio_rw_t; 2097c478bd9Sstevel@tonic-gate 2107c478bd9Sstevel@tonic-gate /* 2117c478bd9Sstevel@tonic-gate * uio_extflg: extended flags 2127c478bd9Sstevel@tonic-gate * 2137c478bd9Sstevel@tonic-gate * NOTE: This flag will be used in uiomove to determine if non-temporal 2147c478bd9Sstevel@tonic-gate * access, ie, access bypassing caches, should be used. Filesystems that 2157c478bd9Sstevel@tonic-gate * don't initialize this field could experience suboptimal performance due to 2167c478bd9Sstevel@tonic-gate * the random data the field contains. 21717169044Sbrutus * 21817169044Sbrutus * NOTE: This flag is also used by uioasync callers to pass an extended 21917169044Sbrutus * uio_t (uioa_t), to uioasync enabled consumers. Unlike above all 22017169044Sbrutus * consumers of a uioa_t require the uio_extflg to be initialized. 2217c478bd9Sstevel@tonic-gate */ 2227c478bd9Sstevel@tonic-gate #define UIO_COPY_DEFAULT 0x0000 /* no special options to copy */ 2237c478bd9Sstevel@tonic-gate #define UIO_COPY_CACHED 0x0001 /* copy should not bypass caches */ 2247c478bd9Sstevel@tonic-gate 22517169044Sbrutus #define UIO_ASYNC 0x0002 /* uio_t is really a uioa_t */ 226c242f9a0Schunli zhang - Sun Microsystems - Irvine United States #define UIO_XUIO 0x0004 /* Structure is xuio_t */ 22717169044Sbrutus 22817169044Sbrutus /* 22917169044Sbrutus * Global uioasync capability shadow state. 23017169044Sbrutus */ 23117169044Sbrutus typedef struct uioasync_s { 23217169044Sbrutus boolean_t enabled; /* Is uioasync enabled? */ 23317169044Sbrutus size_t mincnt; /* Minimum byte count for use of */ 23417169044Sbrutus } uioasync_t; 23517169044Sbrutus 2367c478bd9Sstevel@tonic-gate #endif /* !defined(_XPG4_2) || defined(__EXTENSIONS__) */ 2377c478bd9Sstevel@tonic-gate 2387c478bd9Sstevel@tonic-gate #if defined(_KERNEL) 2397c478bd9Sstevel@tonic-gate 2407c478bd9Sstevel@tonic-gate int uiomove(void *, size_t, enum uio_rw, uio_t *); 2416f5f1c63SDonghai Qiao void uio_prefaultpages(ssize_t, uio_t *); 2422fdbea25SAleksandr Guzovskiy int uiocopy(void *, size_t, enum uio_rw, uio_t *, size_t *); 2437c478bd9Sstevel@tonic-gate int ureadc(int, uio_t *); /* should be errno_t in future */ 2447c478bd9Sstevel@tonic-gate int uwritec(struct uio *); 2457c478bd9Sstevel@tonic-gate void uioskip(uio_t *, size_t); 2467c478bd9Sstevel@tonic-gate int uiodup(uio_t *, uio_t *, iovec_t *, int); 2477c478bd9Sstevel@tonic-gate 24817169044Sbrutus int uioamove(void *, size_t, enum uio_rw, uioa_t *); 24917169044Sbrutus int uioainit(uio_t *, uioa_t *); 25017169044Sbrutus int uioafini(uio_t *, uioa_t *); 25117169044Sbrutus extern uioasync_t uioasync; 25217169044Sbrutus 2537c478bd9Sstevel@tonic-gate #else /* defined(_KERNEL) */ 2547c478bd9Sstevel@tonic-gate 2557c478bd9Sstevel@tonic-gate extern ssize_t readv(int, const struct iovec *, int); 2567c478bd9Sstevel@tonic-gate extern ssize_t writev(int, const struct iovec *, int); 2577c478bd9Sstevel@tonic-gate 258*fca543caSDJ Hoffman /* 259*fca543caSDJ Hoffman * When in the large file compilation environment, 260*fca543caSDJ Hoffman * map preadv/pwritev to their 64 bit offset versions 261*fca543caSDJ Hoffman */ 262*fca543caSDJ Hoffman #if !defined(_LP64) && _FILE_OFFSET_BITS == 64 263*fca543caSDJ Hoffman #ifdef __PRAGMA_REDEFINE_EXTNAME 264*fca543caSDJ Hoffman #pragma redefine_extname preadv preadv64 265*fca543caSDJ Hoffman #pragma redefine_extname pwritev pwritev64 266*fca543caSDJ Hoffman #else /* __PRAGMA_REDEFINE_EXTNAME */ 267*fca543caSDJ Hoffman #define preadv preadv64 268*fca543caSDJ Hoffman #define pwritev pwritev64 269*fca543caSDJ Hoffman #endif /* __PRAGMA_REDEFINE_EXTNAME */ 270*fca543caSDJ Hoffman #endif /* !_LP64 && _FILE_OFFSET_BITS == 64 */ 271*fca543caSDJ Hoffman 272*fca543caSDJ Hoffman /* In the LP64 compilation environment, the APIs are already large file */ 273*fca543caSDJ Hoffman #if defined(_LP64) && defined(_LARGEFILE64_SOURCE) 274*fca543caSDJ Hoffman #ifdef __PRAGMA_REDEFINE_EXTNAME 275*fca543caSDJ Hoffman #pragma redefine_extname preadv64 preadv 276*fca543caSDJ Hoffman #pragma redefine_extname pwritev64 pwritev 277*fca543caSDJ Hoffman #else /* __PRAGMA_REDEFINE_EXTNAME */ 278*fca543caSDJ Hoffman #define preadv64 preadv 279*fca543caSDJ Hoffman #define pwritev64 pwritev 280*fca543caSDJ Hoffman #endif /* __PRAGMA_REDEFINE_EXTNAME */ 281*fca543caSDJ Hoffman #endif /* _LP64 && _LARGEFILE64_SOURCE */ 282*fca543caSDJ Hoffman 283*fca543caSDJ Hoffman extern ssize_t preadv(int, const struct iovec *, int, off_t); 284*fca543caSDJ Hoffman extern ssize_t pwritev(int, const struct iovec *, int, off_t); 285*fca543caSDJ Hoffman 286*fca543caSDJ Hoffman /* 287*fca543caSDJ Hoffman * preadv64 and pwritev64 should be defined when: 288*fca543caSDJ Hoffman * - Using the transitional compilation environment, and not 289*fca543caSDJ Hoffman * the large file compilation environment. 290*fca543caSDJ Hoffman */ 291*fca543caSDJ Hoffman #if defined(_LARGEFILE64_SOURCE) && !((_FILE_OFFSET_BITS == 64) && \ 292*fca543caSDJ Hoffman !defined(__PRAGMA_REDEFINE_EXTNAME)) 293*fca543caSDJ Hoffman extern ssize_t preadv64(int, const struct iovec *, int, off64_t); 294*fca543caSDJ Hoffman extern ssize_t pwritev64(int, const struct iovec *, int, off64_t); 295*fca543caSDJ Hoffman #endif /* _LARGEFILE64_SOURCE */ 296*fca543caSDJ Hoffman 2977c478bd9Sstevel@tonic-gate #endif /* defined(_KERNEL) */ 2987c478bd9Sstevel@tonic-gate 2997c478bd9Sstevel@tonic-gate #ifdef __cplusplus 3007c478bd9Sstevel@tonic-gate } 3017c478bd9Sstevel@tonic-gate #endif 3027c478bd9Sstevel@tonic-gate 3037c478bd9Sstevel@tonic-gate #endif /* _SYS_UIO_H */ 304