uio uiomove - device driver I/O routines
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 */
int 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);
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
Vt 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 Vt uio structure are:
/* 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);
}
|
Закладки на сайте Проследить за страницей |
Created 1996-2025 by Maxim Chirkov Добавить, Поддержать, Вебмастеру |