1.\" $NetBSD: copy.9,v 1.2 1996/01/09 03:23:04 thorpej Exp $ 2.\" 3.\" Copyright (c) 1996 Jason R. Thorpe. 4.\" All rights reserved. 5.\" 6.\" This code is derived from software contributed by Kenneth Stailey. 7.\" 8.\" Redistribution and use in source and binary forms, with or without 9.\" modification, are permitted provided that the following conditions 10.\" are met: 11.\" 1. Redistributions of source code must retain the above copyright 12.\" notice, this list of conditions and the following disclaimer. 13.\" 2. Redistributions in binary form must reproduce the above copyright 14.\" notice, this list of conditions and the following disclaimer in the 15.\" documentation and/or other materials provided with the distribution. 16.\" 3. All advertising materials mentioning features or use of this software 17.\" must display the following acknowledgement: 18.\" This product includes software developed for the NetBSD Project 19.\" by Jason R. Thorpe. 20.\" 4. The name of the author may not be used to endorse or promote products 21.\" derived from this software without specific prior written permission. 22.\" 23.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 24.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 25.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 26.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 27.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 28.\" BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 29.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 30.\" AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 31.\" OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 32.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 33.\" SUCH DAMAGE. 34.\" 35.Dd Jan 7, 1996 36.Dt COPY 9 37.Os NetBSD 38.Sh NAME 39.Nm copy 40.Nd kernel copy functions 41.Sh SYNOPSIS 42.Fd #include <sys/types.h> 43.Fd #include <sys/systm.h> 44.Ft int 45.Fn copyin "void *uaddr" "void *kaddr" "size_t len" 46.Ft int 47.Fn copyout "void *kaddr" "void *uaddr" "size_t len" 48.Ft int 49.Fn copystr "void *kfaddr" "void *kdaddr" "size_t len" "size_t *done" 50.Ft int 51.Fn copyinstr "void *uaddr" "void *kaddr" "size_t len" "size_t *done" 52.Ft int 53.Fn copyoutstr "void *kaddr" "void *uaddr" "size_t len" "size_t *done" 54.Sh DESCRIPTION 55The 56.Nm 57functions are designed to copy contiguous data from one address 58to another. All but 59.Fn copystr 60copy data from user-space to kernel-space or vice-versa. 61.Pp 62The 63.Nm 64routines provide the following functionality: 65.Bl -tag -width "copyoutstr()" 66.It Fn copyin 67Copies 68.Pa len 69bytes of data from the user-space address 70.Pa uaddr 71to the kernel-space address 72.Pa kaddr . 73.It Fn copyout 74Copies 75.Pa len 76bytes of data from the kernel-space address 77.Pa kaddr 78to the user-space address 79.Pa uaddr . 80.It Fn copystr 81Copies a NULL-terminated string, at most 82.Pa len 83bytes long, from kernel-space address 84.Pa kfaddr 85to kernel-space address 86.Pa kdaddr . 87The number of bytes actually copied, including the terminating 88NULL, is returned in 89.Pa *done . 90.It Fn copyinstr 91Copies a NULL-terminated string, at most 92.Pa len 93bytes long, from user-space address 94.Pa uaddr 95to kernel-space address 96.Pa kaddr . 97The number of bytes actually copied, including the terminating 98NULL, is returned in 99.Pa *done . 100.It Fn copyoutstr 101Copies a NULL-terminated string, at most 102bytes long, from kernel-space address 103.Pa kaddr 104to user-space address 105.Pa uaddr . 106The number of bytes actually copied, including the terminating 107NULL, is returned in 108.Pa *done . 109.El 110.Sh RETURN VALUES 111The 112.Nm 113functions return 0 on success or EFAULT if a bad address is encountered. 114In addition, the 115.Fn copystr , 116.Fn copyinstr , 117and 118.Fn copyoutstr 119funtions return ENAMETOOLONG if the string is longer than 120.Pa len 121bytes. 122.Sh SEE ALSO 123.Xr fetch 9 , 124.Xr store 9 . 125