DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 
SCO OpenServer

copyin(D3oddi)


copyin, copyout -- copy bytes between user and kernel space

Synopsis

#include <sys/types.h>

int copyin(caddr_t src, caddr_t dst, int cnt);

int copyout(caddr_t src, caddr_t dst, int cnt);

Description

The copyin( ) function copies the specified number of bytes from user space to kernel space.

The copyout( ) function copies the specified number of bytes from kernel space to user space.

Arguments


src
For copyin( ), a 32-bit pointer that contains the user address from which the data is copied. Often, src is obtained from either 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.


dst
For copyin( ), a pointer to the kernel address (buffer address) to which the data is transferred.

For copyout( ), a 32-bit pointer that contains the user address to which the data is copied.


cnt
Number of bytes of data to be copied.

Return values

If successful, these routines perform the specified data transfer. Otherwise, -1 is returned for one of the following reasons:

Usage

When these functions are called from the read(D2oddi) or write(D2oddi) entry point, the driver code must increase 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.

Context and synchronization

User context.

Hardware applicability

All

Version applicability

oddi: 1, 2, 2mp, 3, 3mp, 4, 4mp, 5, 5mp, 6, 6mp

SVR5 DDI compatibility

copyin(D3) and copyout(D3) are the DDI equivalents of these functions.

References

copyio(D3oddi), cpass(D3oddi), fubyte(D3oddi), fuword(D3oddi), passc(D3oddi), seterror(D3oddi), subyte(D3oddi), suword(D3oddi)

``Data, copying'' in HDK Technical Reference

Examples

The following example illustrates how to use copyin( ) to copy from user data space to kernel data space in an ioctl(D2oddi) routine. In this case, the src argument uses the arg argument passed as an argument to ioctl( ):
   #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 arg to dst */ if ( copyin(arg, &dst, sizeof(struct foo)) == -1) { seterror(EFAULT); return; }

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( ):
   #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; } . . }


19 June 2005
© 2005 The SCO Group, Inc. All rights reserved.
OpenServer 5 HDK - June 2005