Developing a Device Drive
10-15
To transfer characters to the user’s I/O buffers, the driver calls the uiomove(D3) kernel
function and sets the read–write flag to UIO_READ. Reference information on the
uiomove() routine is provided in the corresponding system manual page.
Following is a code fragment that illustrates this operation:
#include <sys/types.h>
#include <sys/conf.h>
#include <sys/errno.h>
#include <sys/uio.h>
#include <sys/user.h>
#include <sys/cred.h>
#include <sys/cmn_err.h>
#include <sys/ddi.h>
static char xyzbuf[]=
"DATA READY TO BE READ IN KERNEL ADDRESS SPACE\n";
int xyzdevflag=0;
int xyzinit()
{
(void) cmn_err(CE_NOTE, "xyzinit:Testing uiomove");
}
int xyzread(dev_t dev, uio_t *uio_p, cred_t *cred_p)
{
if (uiomove(
&xyzbuf[uio_p->uio_offset % sizeof(xyzmsg)],
/* src buffer in kernel address
indexed by uio_offset
*/
sizeof(xyzbuf) -(uio_p->uio_offset % sizeof(xyzbuf)),
/* number of bytes to copy */
UIO_READ,
/* from kernel address TO
wherever uio parameter points
*/
uio_p
/* uio structure passed determines
location and layout of the user’s I/O buffers
within user address space */
))
return EFAULT; /* bad address */
}
return 0;
}
Comments to this Manuals