*nix Documentation Project
·  Home
 +   man pages
·  Linux HOWTOs
·  FreeBSD Tips
·  *niX Forums

  man pages->FreeBSD man pages -> uio (9)              



NAME    [Toc]    [Back]

     uio, uiomove -- device driver I/O routines

SYNOPSIS    [Toc]    [Back]

     #include <sys/types.h>
     #include <sys/uio.h>

     struct uio {
	     struct  iovec *uio_iov;
	     int     uio_iovcnt;
	     off_t   uio_offset;
	     int     uio_resid;
	     enum    uio_seg uio_segflg;
	     enum    uio_rw uio_rw;
	     struct  thread *uio_td;

     uiomove(void *buf, int howmuch, struct uio *uiop);

DESCRIPTION    [Toc]    [Back]

     The function uiomove() is used to handle transfer of data between buffers
     and I/O vectors that might possibly also cross the user/kernel space

     As a result of any read(2), write(2), readv(2), or writev(2) system call
     that is being passed to a character-device driver, the appropriate driver
     d_read or d_write entry will be called with a pointer to a struct uio
     being passed.  The transfer request is encoded in this structure.	The
     driver itself should use uiomove() to get at the data in this structure.

     The fields in the uio structure are:

     uio_iov	 The array of I/O vectors to be processed.  In the case of
		 scatter/gather I/O, this will be more than one vector.

     uio_iovcnt  The number of I/O vectors present.

     uio_offset  The offset into the device.

     uio_resid	 The number of bytes to process.

     uio_segflg  One of the following flags:

		 UIO_USERSPACE	The I/O vector points into a process's address

		 UIO_SYSSPACE	The I/O vector points into the kernel address

		 UIO_NOCOPY	Don't copy, already in object.

     uio_rw	 The direction of the desired transfer, either UIO_READ, or

     uio_td	 The pointer to a struct thread for the associated thread;
		 used if uio_segflg indicates that the transfer is to be made
		 from/to a process's address space.

EXAMPLES    [Toc]    [Back]

     The idea is that the driver maintains a private buffer for its data, and
     processes the request in chunks of maximal the size of this buffer.  Note
     that the buffer handling below is very simplified and won't work (the
     buffer pointer is not being advanced in case of a partial read), it's
     just here to demonstrate the uio handling.

     /* MIN() can be found there: */
     #include <sys/param.h>

     #define BUFSIZE 512
     static char buffer[BUFSIZE];

     static int data_available;      /* amount of data that can be read */

     static int
     fooread(dev_t dev, struct uio *uio, int flag)
	     int rv, amnt;

	     while (uio->uio_resid > 0) {
		     if (data_available > 0) {
			     amnt = MIN(uio->uio_resid, data_available);
			     if ((rv = uiomove(buffer, amnt, uio))
				 != 0)
				     goto error;
			     data_available -= amnt;
		     } else {
			     tsleep(...);    /* wait for a better time */
	     return 0;
	     /* do error cleanup here */
	     return rv;

RETURN VALUES    [Toc]    [Back]

     uiomove() can return EFAULT from the invoked copyin(9) or copyout(9) in
     case the transfer was to/from a process's address space.

SEE ALSO    [Toc]    [Back]

     read(2), readv(2), write(2), writev(2), copyin(9), copyout(9), sleep(9)

HISTORY    [Toc]    [Back]

     The uio mechanism appeared in some early version of UNIX.

AUTHORS    [Toc]    [Back]

     This man page was written by Jorg Wunsch.

FreeBSD 5.2.1		       February 2, 1997 		 FreeBSD 5.2.1
[ Back ]
 Similar pages
Name OS Title
el FreeBSD Ethernet driver for 3Com Etherlink 3C501 device driver
hil HP-UX HP-HIL device driver
ed FreeBSD ethernet device driver
wavelan Linux AT&T GIS WaveLAN ISA device driver
bus_child_present FreeBSD ask the bus driver to see if this device is still really present
driver NetBSD description of a device driver
ie FreeBSD ethernet device driver
if_ed FreeBSD ethernet device driver
iic FreeBSD I2C generic i/o device driver
uaudio OpenBSD USB audio device driver
Copyright © 2004-2005 DeniX Solutions SRL
newsletter delivery service