DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 
SVR5

bcopy(D3)


bcopy -- copy data between address locations in the kernel

Synopsis

   #include <sys/types.h>
   #include <sys/ddi.h>
   

void bcopy(caddr_t from, caddr_t to, size_t bcount);

Description

bcopy copies bcount bytes from one kernel address to another. It chooses the best algorithm based on address alignment and number of bytes to copy.

Arguments


from
Source address from which the copy is made.

to
Destination address to which the copy is made.

bcount
Number of bytes to be copied.

Return values

None

Usage

If the input and output addresses overlap, the function executes, but the results are undefined.

The source and destination address ranges must both be within the kernel address space and must be memory resident. No range checking is done. Since there is no mechanism by which DDI conformant drivers can obtain and use a kernel address that is not memory resident (an address that is paged out), DDI conforming drivers can assume that any address to which they have access is memory resident and therefore a valid argument to bcopy( ). Addresses within user address space are not valid arguments, and specifying such an address may cause the driver to corrupt the system in an unpredictable way. For copying between kernel and user space, drivers must use an appropriate function defined for that purpose (such as copyin(D3), copyout(D3), uiomove(D3), ureadc(D3), or uwritec(D3)).

DDI 8 drivers can use bcopy( ) to access memory above the 4GB boundary that was allocated with kmem_alloc_phys(D3) or msgphysreq(D3str).

Context and synchronization

All contexts.

Examples

An I/O request is made for data stored in a RAM disk. If the I/O operation is a read request, data are copied from the RAM disk to a buffer (line 9). If it is a write request, data are copied from a buffer to the RAM disk (line 15). The

bcopy function is used since both the RAM disk and the buffer are part of the kernel address space.

    1  #define RAMDNBLK    1000           /* number of blocks in the RAM disk */
    2  #define RAMDBSIZ    NBPSCTR        /* bytes per block */
    3  char ramdblks[RAMDNBLK][RAMDBSIZ]; /* blocks forming RAM disk */
          ...
    4
    5  if (bp->b_flags & B_READ) {
    6          /*
    7           * read request - copy data from RAM disk to system buffer
    8           */
    9          bcopy(ramdblks[bp->b_blkno], bp->b_un.b_addr, bp->b_bcount);
   10
   11  } else {
   12          /*
   13           * write request - copy data from system buffer to RAM disk
   14           */
   15          bcopy(bp->b_un.b_addr, ramdblks[bp->b_blkno], bp->b_bcount);
   16  }

Hardware applicability

All

Version applicability

ddi: 1, 2, 3, 4, 5, 5mp, 6, 6mp, 7, 7mp, 7.1, 7.1mp, 8, 8mp

Differences between versions

References

copyin(D3), copyout(D3), ovbcopy(D3), uiomove(D3), ureadc(D3), uwritec(D3)

``Data, copying'' in HDK Technical Reference
``Memory-mapped I/O'' in HDK Technical Reference


19 June 2005
© 2005 The SCO Group, Inc. All rights reserved.
OpenServer 6 and UnixWare (SVR5) HDK - June 2005