Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

uio(9s) [opensolaris man page]

uio(9S) 						    Data Structures for Drivers 						   uio(9S)

NAME
uio - scatter/gather I/O request structure SYNOPSIS
#include <sys/uio.h> INTERFACE LEVEL
Architecture independent level 1 (DDI/DKI) DESCRIPTION
A uio structure describes an I/O request that can be broken up into different data storage areas (scatter/gather I/O). A request is a list of iovec structures (base-length pairs) indicating where in user space or kernel space the I/O data is to be read or written. The contents of uio structures passed to the driver through the entry points should not be written by the driver. The uiomove(9F) func- tion takes care of all overhead related to maintaining the state of the uio structure. uio structures allocated by the driver should be initialized to zero before use, by bzero(9F), kmem_zalloc(9F), or an equivalent. STRUCTURE MEMBERS
iovec_t *uio_iov; /* pointer to start of iovec */ /* list for uio struc. */ int uio_iovcnt; /* number of iovecs in list */ off_t uio_offset; /* 32-bit offset into file where /* data is xferred. See NOTES. */ offset_t uio_loffset; /* 64-bit offset into file where */ /* data is xferred. See NOTES. */ uio_seg_t uio_segflg; /* ID's type of I/O transfer: */ /* UIO_SYSSPACE: kernel <-> kernel */ /* UIO_USERSPACE: kernel <-> user */ short uio_fmode; /* file mode flags (not driver setable) */ daddr_t uio_limit; /* 32-bit ulimit for file (max. block */ /* offset). not driver setable. */ /* See NOTES. */ diskaddr_t uio_llimit; /* 64-bit ulimit for file (max. block */ /* offset). not driver setable. */ /* See NOTES */ int uio_resid; /* residual count */ The uio_iov member is a pointer to the beginning of the iovec(9S) list for the uio. When the uio structure is passed to the driver through an entry point, the driver should not set uio_iov. When the uio structure is created by the driver, uio_iov should be initial- ized by the driver and not written to afterward. SEE ALSO
aread(9E), awrite(9E), read(9E), write(9E), bzero(9F), kmem_zalloc(9F), uiomove(9F), cb_ops(9S), iovec(9S) Writing Device Drivers NOTES
Only one structure, uio_offset or uio_loffset, should be interpreted by the driver. Which field the driver interprets is dependent upon the settings in the cb_ops(9S) structure. Only one structure, uio_limit or uio_llimit, should be interpreted by the driver. Which field the driver interprets is dependent upon the settings in the cb_ops(9S) structure. When performing I/O on a seekable device, the driver should not modify either the uio_offset or the uio_loffset field of the uio structure. I/O to such a device is constrained by the maximum offset value. When performing I/O on a device on which the concept of position has no relevance, the driver may preserve the uio_offset or uio_loffset, perform the I/O operation, then restore the uio_offset or uio_loffset to the field's initial value. I/O performed to a device in this manner is not constrained. SunOS 5.11 28 Mar 1997 uio(9S)

Check Out this Related Man Page

UIO(9)							   BSD Kernel Developer's Manual						    UIO(9)

NAME
uio, uiomove -- 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); 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), 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 struc- ture. 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 remaining number of bytes to process, updated after transfer. 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
On success uiomove() will return 0, on error it will return an appropriate errno. ERRORS
uiomove() will fail and return the following error code if: [EFAULT] The invoked copyin(9) or copyout(9) returned EFAULT 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), readv(2), write(2), writev(2), copyin(9), copyout(9), sleep(9) HISTORY
The uio mechanism appeared in some early version of UNIX. AUTHORS
This manual page was written by Jorg Wunsch. BSD
March 21, 2010 BSD
Man Page

Featured Tech Videos