|
NAMEuio , uiomove ,
uiomove_frombuf ,
uiomove_nofault —
device driver I/O routines
SYNOPSIS#include <sys/types.h>
#include <sys/uio.h>
struct uio { struct iovec *uio_iov; /* scatter/gather list */ int uio_iovcnt; /* length of scatter/gather list */ off_t uio_offset; /* offset in target object */ ssize_t uio_resid; /* remaining bytes to copy */ enum uio_seg uio_segflg; /* address space */ enum uio_rw uio_rw; /* operation */ struct thread *uio_td; /* owner */ }; int uiomove (void
*buf, int howmuch,
struct uio *uiop);
int
int
DESCRIPTIONThe functionsuiomove (),
uiomove_frombuf (), and
uiomove_nofault () are used to transfer data between
buffers and I/O vectors that might possibly cross the user/kernel space
boundary.
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
The fields in the uio structure are:
The function The RETURN VALUESOn successuiomove (),
uiomove_frombuf (), and
uiomove_nofault () will return 0; on error they will
return an appropriate error code.
EXAMPLESThe 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 theuio 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(struct cdev *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); } ERRORSuiomove () and uiomove_nofault ()
will fail and return the following error code if:
In addition,
SEE ALSOread(2), readv(2), write(2), writev(2), copyin(9), copyout(9), sleep(9)HISTORYTheuio mechanism appeared in some early version of
UNIX.
AUTHORSThis manual page was written by Jörg Wunsch.
Visit the GSP FreeBSD Man Page Interface. |