---
name: "uiomove"
section: "9"
platform: "linux"
package: "freebsd-manpages"
version: "6.0-5"
release: "Debian 4.0 (Etch)"
platforms: ["linux", "freebsd"]
url: "https://new.carta.tech/uiomove"
---

# uiomove(9)

device driver I/O routines

## NAME

**uio**, **uiomove** – device driver I/O routines

## SYNOPSIS

**#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;
};
```

*int*\

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

## DESCRIPTION

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 boundary.

As a result of any [read(2)](/read/2.md), [write(2)](/write/2.md), [readv(2)](/readv/2.md), or [writev(2)](/writev/2.md) 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 space.

  - UIO\_SYSSPACE

    The I/O vector points into the kernel address space.

  - UIO\_NOCOPY

    Do not copy, already in object.

- *uio\_rw*

  The direction of the desired transfer, either UIO\_READ, or UIO\_WRITE.

- *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.

## RETURN VALUES

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

## EXAMPLES

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 will not work (the buffer pointer is not being advanced in case of a partial read), it is 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;
	rv = 0;
	while (uio->uio_resid > 0) {
		if (data_available > 0) {
			amnt = MIN(uio->uio_resid, data_available);
			rv = uiomove(buffer, amnt, uio);
			if (rv != 0)
				break;
			data_available -= amnt;
		} else
			tsleep(...);	/* wait for a better time */
	}
	if (rv != 0) {
		/* do error cleanup here */
	}
	return (rv);
}
```

## SEE ALSO

[read(2)](/read/2.md), [readv(2)](/readv/2.md), [write(2)](/write/2.md), [writev(2)](/writev/2.md), [copyin(9)](/copyin/9.md), [copyout(9)](/copyout/9.md), [sleep(9)](/sleep/9.md)

## HISTORY

The **uio** mechanism appeared in some early version of UNIX.

## AUTHORS

This manual page was written by Jörg Wunsch.
