os161-1.99
 All Data Structures
uio.h
00001 /*
00002  * Copyright (c) 2000, 2001, 2002, 2003, 2004, 2005, 2008, 2009
00003  *      The President and Fellows of Harvard College.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions
00007  * are met:
00008  * 1. Redistributions of source code must retain the above copyright
00009  *    notice, this list of conditions and the following disclaimer.
00010  * 2. Redistributions in binary form must reproduce the above copyright
00011  *    notice, this list of conditions and the following disclaimer in the
00012  *    documentation and/or other materials provided with the distribution.
00013  * 3. Neither the name of the University nor the names of its contributors
00014  *    may be used to endorse or promote products derived from this software
00015  *    without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY AND CONTRIBUTORS ``AS IS'' AND
00018  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00020  * ARE DISCLAIMED.  IN NO EVENT SHALL THE UNIVERSITY OR CONTRIBUTORS BE LIABLE
00021  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00022  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
00023  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00024  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00025  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
00026  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00027  * SUCH DAMAGE.
00028  */
00029 
00030 #ifndef _UIO_H_
00031 #define _UIO_H_
00032 
00033 /*
00034  * Like BSD uio, but simplified a bit. (In BSD, there can be more than one
00035  * iovec in a uio.)
00036  *
00037  * struct iovec is in <kern/iovec.h>.
00038  */
00039 
00040 #include <kern/iovec.h>
00041 
00042 /* Direction. */
00043 enum uio_rw {
00044         UIO_READ,                       /* From kernel to uio_seg */
00045         UIO_WRITE,                      /* From uio_seg to kernel */
00046 };
00047 
00048 /* Source/destination. */
00049 enum uio_seg {
00050         UIO_USERISPACE,                 /* User process code. */
00051         UIO_USERSPACE,                  /* User process data. */
00052         UIO_SYSSPACE,                   /* Kernel. */
00053 };
00054 
00055 struct uio {
00056         struct iovec     *uio_iov;      /* Data blocks */
00057         unsigned          uio_iovcnt;   /* Number of iovecs */
00058         off_t             uio_offset;   /* Desired offset into object */
00059         size_t            uio_resid;    /* Remaining amt of data to xfer */
00060         enum uio_seg      uio_segflg;   /* What kind of pointer we have */
00061         enum uio_rw       uio_rw;       /* Whether op is a read or write */
00062         struct addrspace *uio_space;    /* Address space for user pointer */
00063 };
00064 
00065 
00066 /*
00067  * Copy data from a kernel buffer to a data region defined by a uio struct,
00068  * updating the uio struct's offset and resid fields. May alter the iovec
00069  * fields as well.
00070  *
00071  * Before calling this, you should
00072  *   (1) set up uio_iov to point to the buffer(s) you want to transfer
00073  *       to, and set uio_iovcnt to the number of such buffers;
00074  *   (2) initialize uio_offset as desired;
00075  *   (3) initialize uio_resid to the total amount of data that can be 
00076  *       transferred through this uio;
00077  *   (4) set up uio_seg and uio_rw correctly;
00078  *   (5) if uio_seg is UIO_SYSSPACE, set uio_space to NULL; otherwise,
00079  *       initialize uio_space to the address space in which the buffer
00080  *       should be found.
00081  *
00082  * After calling, 
00083  *   (1) the contents of uio_iov and uio_iovcnt may be altered and
00084  *       should not be interpreted;
00085  *   (2) uio_offset will have been incremented by the amount transferred;
00086  *   (3) uio_resid will have been decremented by the amount transferred;
00087  *   (4) uio_segflg, uio_rw, and uio_space will be unchanged.
00088  *
00089  * uiomove() may be called repeatedly on the same uio to transfer
00090  * additional data until the available buffer space the uio refers to
00091  * is exhausted.
00092  *
00093  * Note that the actual value of uio_offset is not interpreted. It is
00094  * provided to allow for easier file seek pointer management.
00095  *
00096  * When uiomove is called, the address space presently in context must
00097  * be the same as the one recorded in uio_space. This is an important
00098  * sanity check if I/O has been queued.
00099  */
00100 int uiomove(void *kbuffer, size_t len, struct uio *uio);
00101 
00102 /*
00103  * Like uiomove, but sends zeros.
00104  */
00105 int uiomovezeros(size_t len, struct uio *uio);
00106 
00107 /*
00108  * Initialize a uio suitable for I/O from a kernel buffer.
00109  *
00110  * Usage example;
00111  *      char buf[128];
00112  *      struct iovec iov;
00113  *      struct uio myuio;
00114  *
00115  *      uio_kinit(&iov, &myuio, buf, sizeof(buf), 0, UIO_READ);
00116  *      result = VOP_READ(vn, &myuio);
00117  *      ...
00118  */
00119 void uio_kinit(struct iovec *, struct uio *,
00120                void *kbuf, size_t len, off_t pos, enum uio_rw rw);
00121 
00122 
00123 #endif /* _UIO_H_ */
 All Data Structures