|
|
#include <sys/types.h>int copyin(caddr_t src, caddr_t dst, int cnt);
int copyout(caddr_t src, caddr_t dst, int cnt);
The copyout( ) function copies the specified number of bytes from kernel space to user space.
u.u_base
or the third argument (arg)
passed to a driver's
ioctl(D2oddi)
routine.
For copyout( ), a pointer to the kernel address (in the buffer) from which the data is transferred.
For copyout( ), a 32-bit pointer that contains the user address to which the data is copied.
u.u_base
and u.u_offset
by
the number of bytes transferred,
and decrease u.u_count
by
the number of bytes transferred
after the call completes:
u.u_count -= cnt; u.u_offset += cnt; u.u_base += cnt;If an error code is returned by one of these functions, call seterror(D3oddi) with argument EFAULT to return EFAULT to the user process calling your driver.
The driver is not required to supply word-aligned addresses to these routines.
``Data, copying'' in HDK Technical Reference
#include <sys/types.h> #include <sys/errno.h>The following example illustrates how to use copyout( ) to copy from kernel data space to user data space in an ioctl(D2oddi) routine. In this case, the src argument uses the arg argument passed as an argument to ioctl( ):xxioctl(dev_t dev, int cmd, caddr_t arg, int mode); { struct foo dst; . . / other ioctl code / . / copy from arg to dst / if ( copyin(arg, &dst, sizeof(struct foo)) == -1) { seterror(EFAULT); return; }
#include <sys/types.h> #include <sys/errno.h>xxioctl(dev_t dev, int cmd, caddr_t arg, int mode); { struct foo dst; . . / other ioctl code / .
/* copy from dst to arg */ if (copyout(&dst, arg, sizeof(struct foo)) == -1) { seterror(EFAULT); return; } . . }