xref: /xnu-10002.41.9/bsd/man/man9/copy.9 (revision 699cd48037512bf4380799317ca44ca453c82f57)
1*699cd480SApple OSS Distributions.\"
2*699cd480SApple OSS Distributions.\" Copyright (c) 2008 Apple Inc.  All rights reserved.
3*699cd480SApple OSS Distributions.\"
4*699cd480SApple OSS Distributions.\" @APPLE_LICENSE_HEADER_START@
5*699cd480SApple OSS Distributions.\"
6*699cd480SApple OSS Distributions.\" This file contains Original Code and/or Modifications of Original Code
7*699cd480SApple OSS Distributions.\" as defined in and that are subject to the Apple Public Source License
8*699cd480SApple OSS Distributions.\" Version 2.0 (the 'License'). You may not use this file except in
9*699cd480SApple OSS Distributions.\" compliance with the License. Please obtain a copy of the License at
10*699cd480SApple OSS Distributions.\" http://www.opensource.apple.com/apsl/ and read it before using this
11*699cd480SApple OSS Distributions.\" file.
12*699cd480SApple OSS Distributions.\"
13*699cd480SApple OSS Distributions.\" The Original Code and all software distributed under the License are
14*699cd480SApple OSS Distributions.\" distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15*699cd480SApple OSS Distributions.\" EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16*699cd480SApple OSS Distributions.\" INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17*699cd480SApple OSS Distributions.\" FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18*699cd480SApple OSS Distributions.\" Please see the License for the specific language governing rights and
19*699cd480SApple OSS Distributions.\" limitations under the License.
20*699cd480SApple OSS Distributions.\"
21*699cd480SApple OSS Distributions.\" @APPLE_LICENSE_HEADER_END@
22*699cd480SApple OSS Distributions.\"
23*699cd480SApple OSS Distributions.\"
24*699cd480SApple OSS Distributions.\"	$NetBSD: copy.9,v 1.2 1996/01/09 03:23:04 thorpej Exp $
25*699cd480SApple OSS Distributions.\"
26*699cd480SApple OSS Distributions.\" Copyright (c) 1996 Jason R. Thorpe.
27*699cd480SApple OSS Distributions.\" All rights reserved.
28*699cd480SApple OSS Distributions.\"
29*699cd480SApple OSS Distributions.\" This code is derived from software contributed by Kenneth Stailey.
30*699cd480SApple OSS Distributions.\"
31*699cd480SApple OSS Distributions.\" Redistribution and use in source and binary forms, with or without
32*699cd480SApple OSS Distributions.\" modification, are permitted provided that the following conditions
33*699cd480SApple OSS Distributions.\" are met:
34*699cd480SApple OSS Distributions.\" 1. Redistributions of source code must retain the above copyright
35*699cd480SApple OSS Distributions.\"    notice, this list of conditions and the following disclaimer.
36*699cd480SApple OSS Distributions.\" 2. Redistributions in binary form must reproduce the above copyright
37*699cd480SApple OSS Distributions.\"    notice, this list of conditions and the following disclaimer in the
38*699cd480SApple OSS Distributions.\"    documentation and/or other materials provided with the distribution.
39*699cd480SApple OSS Distributions.\" 3. All advertising materials mentioning features or use of this software
40*699cd480SApple OSS Distributions.\"    must display the following acknowledgement:
41*699cd480SApple OSS Distributions.\"	This product includes software developed for the NetBSD Project
42*699cd480SApple OSS Distributions.\"	by Jason R. Thorpe.
43*699cd480SApple OSS Distributions.\" 4. The name of the author may not be used to endorse or promote products
44*699cd480SApple OSS Distributions.\"    derived from this software without specific prior written permission.
45*699cd480SApple OSS Distributions.\"
46*699cd480SApple OSS Distributions.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
47*699cd480SApple OSS Distributions.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
48*699cd480SApple OSS Distributions.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
49*699cd480SApple OSS Distributions.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
50*699cd480SApple OSS Distributions.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
51*699cd480SApple OSS Distributions.\" BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
52*699cd480SApple OSS Distributions.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
53*699cd480SApple OSS Distributions.\" AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
54*699cd480SApple OSS Distributions.\" OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
55*699cd480SApple OSS Distributions.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
56*699cd480SApple OSS Distributions.\" SUCH DAMAGE.
57*699cd480SApple OSS Distributions.\"
58*699cd480SApple OSS Distributions.\" $FreeBSD: src/share/man/man9/copy.9,v 1.6.2.5 2001/12/17 11:30:18 ru Exp $
59*699cd480SApple OSS Distributions.\"
60*699cd480SApple OSS Distributions.Dd October 2, 2008
61*699cd480SApple OSS Distributions.Dt COPY 9
62*699cd480SApple OSS Distributions.Os
63*699cd480SApple OSS Distributions.Sh NAME
64*699cd480SApple OSS Distributions.Nm copy ,
65*699cd480SApple OSS Distributions.Nm copyin ,
66*699cd480SApple OSS Distributions.Nm copyinstr ,
67*699cd480SApple OSS Distributions.Nm copyout ,
68*699cd480SApple OSS Distributions.Nm copystr
69*699cd480SApple OSS Distributions.Nd kernel copy functions
70*699cd480SApple OSS Distributions.Sh SYNOPSIS
71*699cd480SApple OSS Distributions.In sys/types.h
72*699cd480SApple OSS Distributions.In sys/systm.h
73*699cd480SApple OSS Distributions.Ft int
74*699cd480SApple OSS Distributions.Fo copyin
75*699cd480SApple OSS Distributions.Fa "const void *uaddr"
76*699cd480SApple OSS Distributions.Fa "void *kaddr"
77*699cd480SApple OSS Distributions.Fa "size_t len"
78*699cd480SApple OSS Distributions.Fc
79*699cd480SApple OSS Distributions.Ft int
80*699cd480SApple OSS Distributions.Fo copyinstr
81*699cd480SApple OSS Distributions.Fa "const void *uaddr"
82*699cd480SApple OSS Distributions.Fa "void *kaddr"
83*699cd480SApple OSS Distributions.Fa "size_t len"
84*699cd480SApple OSS Distributions.Fa "size_t *done"
85*699cd480SApple OSS Distributions.Fc
86*699cd480SApple OSS Distributions.Ft int
87*699cd480SApple OSS Distributions.Fo copyout
88*699cd480SApple OSS Distributions.Fa "const void *kaddr"
89*699cd480SApple OSS Distributions.Fa "void *uaddr"
90*699cd480SApple OSS Distributions.Fa "size_t len"
91*699cd480SApple OSS Distributions.Fc
92*699cd480SApple OSS Distributions.\" .Ft int
93*699cd480SApple OSS Distributions.\" .Fn copyoutstr
94*699cd480SApple OSS Distributions.\" .Fa "const void *kaddr"
95*699cd480SApple OSS Distributions.\" .Fa "void *uaddr"
96*699cd480SApple OSS Distributions.\" .Fa "size_t len"
97*699cd480SApple OSS Distributions.\" .Fa "size_t *done"
98*699cd480SApple OSS Distributions.\" .Fc
99*699cd480SApple OSS Distributions.Ft int
100*699cd480SApple OSS Distributions.Fo copystr
101*699cd480SApple OSS Distributions.Fa "const void *kfaddr"
102*699cd480SApple OSS Distributions.Fa "void *kdaddr"
103*699cd480SApple OSS Distributions.Fa "size_t len"
104*699cd480SApple OSS Distributions.Fa "size_t *done"
105*699cd480SApple OSS Distributions.Fc
106*699cd480SApple OSS Distributions.Sh DESCRIPTION
107*699cd480SApple OSS DistributionsThe
108*699cd480SApple OSS Distributions.Nm
109*699cd480SApple OSS Distributionsfunctions are designed to copy contiguous data from one address
110*699cd480SApple OSS Distributionsto another.
111*699cd480SApple OSS DistributionsAll but
112*699cd480SApple OSS Distributions.Fn copystr
113*699cd480SApple OSS Distributionscopy data from user-space to kernel-space or vice-versa.
114*699cd480SApple OSS Distributions.Pp
115*699cd480SApple OSS DistributionsThe
116*699cd480SApple OSS Distributions.Nm
117*699cd480SApple OSS Distributionsroutines provide the following functionality:
118*699cd480SApple OSS Distributions.Bl -tag -width "copyoutstr()"
119*699cd480SApple OSS Distributions.\" ========
120*699cd480SApple OSS Distributions.It Fn copyin
121*699cd480SApple OSS DistributionsCopies
122*699cd480SApple OSS Distributions.Pa len
123*699cd480SApple OSS Distributionsbytes of data from the user-space address
124*699cd480SApple OSS Distributions.Pa uaddr
125*699cd480SApple OSS Distributionsto the kernel-space address
126*699cd480SApple OSS Distributions.Pa kaddr .
127*699cd480SApple OSS Distributions.\" ========
128*699cd480SApple OSS Distributions.It Fn copyinstr
129*699cd480SApple OSS DistributionsCopies a NUL-terminated string, at most
130*699cd480SApple OSS Distributions.Pa len
131*699cd480SApple OSS Distributionsbytes long, from user-space address
132*699cd480SApple OSS Distributions.Pa uaddr
133*699cd480SApple OSS Distributionsto kernel-space address
134*699cd480SApple OSS Distributions.Pa kaddr .
135*699cd480SApple OSS DistributionsThe number of bytes actually copied, including the terminating
136*699cd480SApple OSS DistributionsNUL, is returned in
137*699cd480SApple OSS Distributions.Pa *done .
138*699cd480SApple OSS Distributions.\" ========
139*699cd480SApple OSS Distributions.It Fn copyout
140*699cd480SApple OSS DistributionsCopies
141*699cd480SApple OSS Distributions.Pa len
142*699cd480SApple OSS Distributionsbytes of data from the kernel-space address
143*699cd480SApple OSS Distributions.Pa kaddr
144*699cd480SApple OSS Distributionsto the user-space address
145*699cd480SApple OSS Distributions.Pa uaddr .
146*699cd480SApple OSS Distributions.\" ========
147*699cd480SApple OSS Distributions.\" .It Fn copyoutstr
148*699cd480SApple OSS Distributions.\" Copies a NUL-terminated string, at most
149*699cd480SApple OSS Distributions.\" bytes long, from kernel-space address
150*699cd480SApple OSS Distributions.\" .Pa kaddr
151*699cd480SApple OSS Distributions.\" to user-space address
152*699cd480SApple OSS Distributions.\" .Pa uaddr .
153*699cd480SApple OSS Distributions.\" The number of bytes actually copied, including the terminating
154*699cd480SApple OSS Distributions.\" NUL, is returned in
155*699cd480SApple OSS Distributions.\" .Pa *done .
156*699cd480SApple OSS Distributions.\" ========
157*699cd480SApple OSS Distributions.It Fn copystr
158*699cd480SApple OSS DistributionsCopies a NUL-terminated string, at most
159*699cd480SApple OSS Distributions.Pa len
160*699cd480SApple OSS Distributionsbytes long, from kernel-space address
161*699cd480SApple OSS Distributions.Pa kfaddr
162*699cd480SApple OSS Distributionsto kernel-space address
163*699cd480SApple OSS Distributions.Pa kdaddr .
164*699cd480SApple OSS DistributionsThe number of bytes actually copied, including the terminating
165*699cd480SApple OSS DistributionsNUL, is returned in
166*699cd480SApple OSS Distributions.Pa *done .
167*699cd480SApple OSS Distributions.El
168*699cd480SApple OSS Distributions.Sh RETURN VALUES
169*699cd480SApple OSS DistributionsThe
170*699cd480SApple OSS Distributions.Nm
171*699cd480SApple OSS Distributionsfunctions return 0 on success or the following error on failure:
172*699cd480SApple OSS Distributions.\" ========
173*699cd480SApple OSS Distributions.Bl -tag -width Er
174*699cd480SApple OSS Distributions.It Bq EFAULT
175*699cd480SApple OSS DistributionsIf a bad address is encountered.
176*699cd480SApple OSS DistributionsWhen this error is returned, the contents of the destination buffer (
177*699cd480SApple OSS Distributions.Fa *kaddr
178*699cd480SApple OSS Distributionsfor
179*699cd480SApple OSS Distributions.Fn copyin ,
180*699cd480SApple OSS Distributions.Fn copyinstr ,
181*699cd480SApple OSS Distributionsand
182*699cd480SApple OSS Distributions.Fn copystr ;
183*699cd480SApple OSS Distributions.Fa *uaddr
184*699cd480SApple OSS Distributionsfor
185*699cd480SApple OSS Distributions.Fn copyout )
186*699cd480SApple OSS Distributionsare undefined.
187*699cd480SApple OSS DistributionsFor
188*699cd480SApple OSS Distributions.Fn copyinstr
189*699cd480SApple OSS Distributionsand
190*699cd480SApple OSS Distributions.Fn copystr ,
191*699cd480SApple OSS Distributionsthe contents of the
192*699cd480SApple OSS Distributions.Fa *done
193*699cd480SApple OSS Distributionsparameter are also undefined on a return of EFAULT.
194*699cd480SApple OSS Distributions.El
195*699cd480SApple OSS Distributions.Pp
196*699cd480SApple OSS DistributionsIn addition to EFAULT,
197*699cd480SApple OSS Distributions.\" .Fn copystr ,
198*699cd480SApple OSS Distributions.\" .Fn copyinstr ,
199*699cd480SApple OSS Distributions.\" and
200*699cd480SApple OSS Distributions.\" .Fn copyoutstr
201*699cd480SApple OSS Distributions.Fn copystr
202*699cd480SApple OSS Distributionsand
203*699cd480SApple OSS Distributions.Fn copyinstr
204*699cd480SApple OSS Distributionson failure will return:
205*699cd480SApple OSS Distributions.\" ========
206*699cd480SApple OSS Distributions.Bl -tag -width Er
207*699cd480SApple OSS Distributions.It Bq ENAMETOLONG
208*699cd480SApple OSS DistributionsWhen the string is longer than
209*699cd480SApple OSS Distributions.Pa len
210*699cd480SApple OSS Distributionsbytes.
211*699cd480SApple OSS DistributionsOn this error return, the destination buffer is not null-terminated, but the
212*699cd480SApple OSS Distributions.Fa *done
213*699cd480SApple OSS Distributionsparameter is maintained.
214*699cd480SApple OSS Distributions.El
215*699cd480SApple OSS Distributions.Sh SEE ALSO
216*699cd480SApple OSS Distributions.Xr fetch 9 ,
217*699cd480SApple OSS Distributions.Xr store 9
218