Writing Device Drivers

uiomove( )

uiomove(9F) may be used to transfer data to some programmed I/O devices. uiomove(9F) transfers data between the user space (defined by the uio(9S) structure) and the kernel. uiomove(9F) can handle page faults, so the memory to which data is transferred need not be locked down. It also updates the uio_resid field in the uio(9S) structure. Example 9-3 shows one way to write a ramdisk read(9E) routine. It uses synchronous I/O and relies on the presence of the following fields in the ramdisk state structure:

	caddr_t			ram;			/* base address of ramdisk */
 	int			ramsize;			/* size of the ramdisk */

Example 9-3 Ramdisk read(9E) Routine Using uiomove(9F)

static int
rd_read(dev_t dev, struct uio *uiop, cred_t *credp)
 	rd_devstate_t 	*rsp;

 	rsp = ddi_get_soft_state(rd_statep, getminor(dev));
 	if (rsp == NULL)
	   	return (ENXIO);
 	if (uiop->uio_offset >= rsp->ramsize)
	   	return (EINVAL);
 	 * uiomove takes the offset into the kernel buffer,
 	 * the data transfer count (minimum of the requested and
  	 * the remaining data), the UIO_READ flag, and a pointer
 	 * to the uio structure.
 	return (uiomove(rsp->ram + uiop->uio_offset,
	   	  min(uiop->uio_resid, rsp->ramsize - uiop->uio_offset),
	   	  UIO_READ, uiop));