Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ copyin(D3DK) — Motorola System V 88k Release 4 Version 4.3

Media Vault

Software Library

Restoration Projects

Artifacts Sought

copyin(D3DK)  —  

.IX \f4copyin\fP(D3DK)

NAME

copyin − copy data from a user buffer to a driver buffer

SYNOPSIS

#include <sys/types.h>
int copyin(caddr_t userbuf, caddr_t driverbuf, size_t count);

ARGUMENTS

userbufUser source address from which copy is made. 

driverbufDriver destination address to which copy is made. 

countNumber of bytes to copy. 

DESCRIPTION

copyin copies count bytes of data from the user virtual address specified by userbuf to the kernel virtual address specified by driverbuf.  The driver must ensure that adequate space is allocated for the destination address. 

copyin chooses the best algorithm based on address alignment and number of bytes to copy.  Although the source and destination addresses are not required to be word aligned, word aligned addresses may result in a more efficient copy. 

RETURN VALUE

If the copy is successful, 0 is returned.  Otherwise, −1 is returned to indicate that the specified user address range is not valid. 

LEVEL

Base Only. 

NOTES

May sleep. 

Drivers usually convert a return value of −1 into an EFAULT error. 

Driver-defined basic locks and read/write locks may not be held across calls to this function. 

Driver-defined sleep locks may be held across calls to this function. 

When holding sleep locks across calls to this function, drivers must be careful to avoid creating a deadlock.  During the data transfer, page fault resolution might result in another I/O to the same device.  For example, this could occur if the driver controls the disk drive used as the swap device. 

The driver destination buffer must be completely within the kernel address space, or the system can panic. 

SEE ALSO

bcopy(D3DK), copyout(D3DK), uiomove(D3DK), ureadc(D3DK), uwritec(D3DK)

EXAMPLE

.IX \f4copyin\fP(D3DK), example
.IX \f4ioctl\fP(D2DK), example
A driver ioctl(D2DK) routine (line 5) can be used to get or set device attributes or registers.  If the specified command is XX_SETREGS (line 9), the driver copies user data to the device registers (line 11).  If the user address is invalid, an error code is returned. 

 1  struct  device {/∗ device registers layout ∗/
...
 2  int command;/∗ device command word ∗/
 3  };
  4  extern struct device xx_dev[];/∗ physical device registers ∗/
    ...
 5  xxioctl(dev_t dev, int cmd, void ∗arg, int mode, cred_t ∗crp, int ∗rvp)
 6  {
 7register struct device ∗dp;
  8switch (cmd) {
 9case XX_SETREGS:/∗ copy user program data to device registers ∗/
10dp = &xx_dev[getminor(dev)];
11if (copyin(arg, (caddr_t)dp, sizeof(struct device)))
12return (EFAULT);
13break;

DDI/DKI

Typewritten Software • bear@typewritten.org • Edmonds, WA 98026