Writing Device Drivers

Copying Data

These interfaces are data copying utilities, used both for copying data within the kernel, and for copying data between the kernel and an application.

void bcopy(const void *from, void *to, size_t bcount);

bcopy(9F) copies count bytes from the location pointed to by from to the location pointed to by to.

int copyin(const void *userbuf, void *driverbuf,  	size_t cn);

copyin(9F) copies data from an application's virtual address space to the kernel virtual address space, where the driver can address the data. The driver developer must ensure that adequate space is allocated for driverbuf.

int copyout(const void *driverbuf, void *userbuf,  	size_t cn);

copyout(9F) copies data from the kernel virtual address space to an application program's virtual address space.

int ddi_copyin(const void *buf, void *driverbuf, 
			size_t cn, int flags);

This routine is designed for use in driver ioctl(9E) routines. It copies data from a source address to a driver buffer. The driver developer must ensure that adequate space is allocated for the destination address.

The flags argument is used to determine the address space information about buf. If the FKIOCTL flag is set, it indicates that buf is a kernel address, and ddi_copyin(9F) behaves like bcopy(9F). Otherwise, buf is interpreted as a user buffer address, and ddi_copyin(9F) behaves like copyin(9F).

The value of the flags argument to ddi_copyin(9F) should be passed directly from the mode argument of ioctl(9E) untranslated.

int ddi_copyout(const void *driverbuf, void *buf, size_t cn, 
			int flags);

This routine is designed for use in driver ioctl(9E) routines for drivers that support layered I/O controls. ddi_copyout(9F) copies data from a driver buffer to a destination address, buf.

The flags argument is used to determine the address space information about buf. If the FKIOCTL flag is set, it indicates that buf is a kernel address, and ddi_copyout(9F) behaves like bcopy(9F). Otherwise, buf is interpreted as a user buffer address, and ddi_copyin(9F) behaves like copyout(9F).

The value of the flags argument to ddi_copyout(9F) should be passed directly from the mode argument of ioctl(9E) untranslated.