/*1* Copyright (c) 2000, 2001, 2002, 2003, 2004, 2005, 2008, 20092* The President and Fellows of Harvard College.3*4* Redistribution and use in source and binary forms, with or without5* modification, are permitted provided that the following conditions6* are met:7* 1. Redistributions of source code must retain the above copyright8* notice, this list of conditions and the following disclaimer.9* 2. Redistributions in binary form must reproduce the above copyright10* notice, this list of conditions and the following disclaimer in the11* documentation and/or other materials provided with the distribution.12* 3. Neither the name of the University nor the names of its contributors13* may be used to endorse or promote products derived from this software14* without specific prior written permission.15*16* THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY AND CONTRIBUTORS ``AS IS'' AND17* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE18* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE19* ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OR CONTRIBUTORS BE LIABLE20* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL21* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS22* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)23* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT24* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY25* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF26* SUCH DAMAGE.27*/2829#ifndef _UIO_H_30#define _UIO_H_3132/*33* Like BSD uio, but simplified a bit. (In BSD, there can be more than one34* iovec in a uio.)35*36* struct iovec is in <kern/iovec.h>.37*/3839#include <kern/iovec.h>4041/* Direction. */42enum uio_rw {43UIO_READ, /* From kernel to uio_seg */44UIO_WRITE, /* From uio_seg to kernel */45};4647/* Source/destination. */48enum uio_seg {49UIO_USERISPACE, /* User process code. */50UIO_USERSPACE, /* User process data. */51UIO_SYSSPACE, /* Kernel. */52};5354struct uio {55struct iovec *uio_iov; /* Data blocks */56unsigned uio_iovcnt; /* Number of iovecs */57off_t uio_offset; /* Desired offset into object */58size_t uio_resid; /* Remaining amt of data to xfer */59enum uio_seg uio_segflg; /* What kind of pointer we have */60enum uio_rw uio_rw; /* Whether op is a read or write */61struct addrspace *uio_space; /* Address space for user pointer */62};636465/*66* Copy data from a kernel buffer to a data region defined by a uio struct,67* updating the uio struct's offset and resid fields. May alter the iovec68* fields as well.69*70* Before calling this, you should71* (1) set up uio_iov to point to the buffer(s) you want to transfer72* to, and set uio_iovcnt to the number of such buffers;73* (2) initialize uio_offset as desired;74* (3) initialize uio_resid to the total amount of data that can be75* transferred through this uio;76* (4) set up uio_seg and uio_rw correctly;77* (5) if uio_seg is UIO_SYSSPACE, set uio_space to NULL; otherwise,78* initialize uio_space to the address space in which the buffer79* should be found.80*81* After calling,82* (1) the contents of uio_iov and uio_iovcnt may be altered and83* should not be interpreted;84* (2) uio_offset will have been incremented by the amount transferred;85* (3) uio_resid will have been decremented by the amount transferred;86* (4) uio_segflg, uio_rw, and uio_space will be unchanged.87*88* uiomove() may be called repeatedly on the same uio to transfer89* additional data until the available buffer space the uio refers to90* is exhausted.91*92* Note that the actual value of uio_offset is not interpreted. It is93* provided to allow for easier file seek pointer management.94*95* When uiomove is called, the address space presently in context must96* be the same as the one recorded in uio_space. This is an important97* sanity check if I/O has been queued.98*/99int uiomove(void *kbuffer, size_t len, struct uio *uio);100101/*102* Like uiomove, but sends zeros.103*/104int uiomovezeros(size_t len, struct uio *uio);105106/*107* Initialize a uio suitable for I/O from a kernel buffer.108*109* Usage example;110* char buf[128];111* struct iovec iov;112* struct uio myuio;113*114* uio_kinit(&iov, &myuio, buf, sizeof(buf), 0, UIO_READ);115* result = VOP_READ(vn, &myuio);116* ...117*/118void uio_kinit(struct iovec *, struct uio *,119void *kbuf, size_t len, off_t pos, enum uio_rw rw);120121122#endif /* _UIO_H_ */123124125