1*86d7f5d3SJohn Marino.\" $NetBSD: prop_copyin_ioctl.9,v 1.8 2011/01/19 20:34:23 bouyer Exp $ 2*86d7f5d3SJohn Marino.\" 3*86d7f5d3SJohn Marino.\" Copyright (c) 2006, 2009 The NetBSD Foundation, Inc. 4*86d7f5d3SJohn Marino.\" All rights reserved. 5*86d7f5d3SJohn Marino.\" 6*86d7f5d3SJohn Marino.\" This code is derived from software contributed to The NetBSD Foundation 7*86d7f5d3SJohn Marino.\" by Jason R. Thorpe. 8*86d7f5d3SJohn Marino.\" 9*86d7f5d3SJohn Marino.\" Redistribution and use in source and binary forms, with or without 10*86d7f5d3SJohn Marino.\" modification, are permitted provided that the following conditions 11*86d7f5d3SJohn Marino.\" are met: 12*86d7f5d3SJohn Marino.\" 1. Redistributions of source code must retain the above copyright 13*86d7f5d3SJohn Marino.\" notice, this list of conditions and the following disclaimer. 14*86d7f5d3SJohn Marino.\" 2. Redistributions in binary form must reproduce the above copyright 15*86d7f5d3SJohn Marino.\" notice, this list of conditions and the following disclaimer in the 16*86d7f5d3SJohn Marino.\" documentation and/or other materials provided with the distribution. 17*86d7f5d3SJohn Marino.\" 18*86d7f5d3SJohn Marino.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 19*86d7f5d3SJohn Marino.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 20*86d7f5d3SJohn Marino.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21*86d7f5d3SJohn Marino.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 22*86d7f5d3SJohn Marino.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23*86d7f5d3SJohn Marino.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24*86d7f5d3SJohn Marino.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25*86d7f5d3SJohn Marino.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26*86d7f5d3SJohn Marino.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27*86d7f5d3SJohn Marino.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28*86d7f5d3SJohn Marino.\" POSSIBILITY OF SUCH DAMAGE. 29*86d7f5d3SJohn Marino.\" 30*86d7f5d3SJohn Marino.Dd January 17, 2011 31*86d7f5d3SJohn Marino.Dt PROP_COPYIN_IOCTL 9 32*86d7f5d3SJohn Marino.Os 33*86d7f5d3SJohn Marino.Sh NAME 34*86d7f5d3SJohn Marino.Nm prop_array_copyin_ioctl , 35*86d7f5d3SJohn Marino.Nm prop_array_copyout_ioctl , 36*86d7f5d3SJohn Marino.Nm prop_array_copyin , 37*86d7f5d3SJohn Marino.Nm prop_array_copyout , 38*86d7f5d3SJohn Marino.Nm prop_dictionary_copyin_ioctl , 39*86d7f5d3SJohn Marino.Nm prop_dictionary_copyout_ioctl , 40*86d7f5d3SJohn Marino.Nm prop_dictionary_copyin , 41*86d7f5d3SJohn Marino.Nm prop_dictionary_copyout 42*86d7f5d3SJohn Marino.Nd Copy property lists to and from kernel space 43*86d7f5d3SJohn Marino.Sh SYNOPSIS 44*86d7f5d3SJohn Marino.In libprop/proplib.h 45*86d7f5d3SJohn Marino.Ft int 46*86d7f5d3SJohn Marino.Fn prop_array_copyin_ioctl "const struct plistref *pref" \ 47*86d7f5d3SJohn Marino "const u_long cmd" "prop_array_t *arrayp" 48*86d7f5d3SJohn Marino.Ft int 49*86d7f5d3SJohn Marino.Fn prop_array_copyin "const struct plistref *pref" \ 50*86d7f5d3SJohn Marino "prop_array_t *arrayp" 51*86d7f5d3SJohn Marino.Ft int 52*86d7f5d3SJohn Marino.Fn prop_array_copyout_ioctl "struct plistref *pref" \ 53*86d7f5d3SJohn Marino "const u_long cmd" "prop_array_t array" 54*86d7f5d3SJohn Marino.Ft int 55*86d7f5d3SJohn Marino.Fn prop_array_copyout "struct plistref *pref" \ 56*86d7f5d3SJohn Marino "prop_array_t array" 57*86d7f5d3SJohn Marino.Ft int 58*86d7f5d3SJohn Marino.Fn prop_dictionary_copyin_ioctl "const struct plistref *pref" \ 59*86d7f5d3SJohn Marino "const u_long cmd" "prop_dictionary_t *dictp" 60*86d7f5d3SJohn Marino.Ft int 61*86d7f5d3SJohn Marino.Fn prop_dictionary_copyin "const struct plistref *pref" \ 62*86d7f5d3SJohn Marino "prop_dictionary_t *dictp" 63*86d7f5d3SJohn Marino.Ft int 64*86d7f5d3SJohn Marino.Fn prop_dictionary_copyout_ioctl "struct plistref *pref" \ 65*86d7f5d3SJohn Marino "const u_long cmd" "prop_dictionary_t dict" 66*86d7f5d3SJohn Marino.Ft int 67*86d7f5d3SJohn Marino.Fn prop_dictionary_copyout "struct plistref *pref" \ 68*86d7f5d3SJohn Marino "prop_dictionary_t dict" 69*86d7f5d3SJohn Marino.Sh DESCRIPTION 70*86d7f5d3SJohn MarinoThe 71*86d7f5d3SJohn Marino.Nm prop_array_copyin_ioctl , 72*86d7f5d3SJohn Marino.Nm prop_array_copyout_ioctl , 73*86d7f5d3SJohn Marino.Nm prop_dictionary_copyin_ioctl , 74*86d7f5d3SJohn Marinoand 75*86d7f5d3SJohn Marino.Nm prop_dictionary_copyout_ioctl 76*86d7f5d3SJohn Marinofunctions implement the kernel side of a protocol for copying property lists 77*86d7f5d3SJohn Marinoto and from the kernel using 78*86d7f5d3SJohn Marino.Xr ioctl 2 . 79*86d7f5d3SJohn MarinoThe functions 80*86d7f5d3SJohn Marino.Nm prop_array_copyin , 81*86d7f5d3SJohn Marino.Nm prop_array_copyout , 82*86d7f5d3SJohn Marino.Nm prop_dictionary_copyin , 83*86d7f5d3SJohn Marinoand 84*86d7f5d3SJohn Marino.Nm prop_dictionary_copyout 85*86d7f5d3SJohn Marinoimplement the kernel side of a protocol for copying property lists to the 86*86d7f5d3SJohn Marinokernel as arguments of normal system calls. 87*86d7f5d3SJohn Marino.Pp 88*86d7f5d3SJohn MarinoA kernel routine receiving or returning a property list will be passed a 89*86d7f5d3SJohn Marinopointer to a 90*86d7f5d3SJohn Marino.Vt struct plistref . 91*86d7f5d3SJohn MarinoThis structure encapsulates the reference to the property list in externalized 92*86d7f5d3SJohn Marinoform. 93*86d7f5d3SJohn Marino.Sh RETURN VALUES 94*86d7f5d3SJohn MarinoIf successful, functions return zero. 95*86d7f5d3SJohn MarinoOtherwise, an error number will be returned to indicate the error. 96*86d7f5d3SJohn Marino.Sh EXAMPLES 97*86d7f5d3SJohn MarinoThe following 98*86d7f5d3SJohn Marino.Pq simplified 99*86d7f5d3SJohn Marinoexample demonstrates using 100*86d7f5d3SJohn Marino.Fn prop_dictionary_copyin_ioctl 101*86d7f5d3SJohn Marinoand 102*86d7f5d3SJohn Marino.Fn prop_dictionary_copyout_ioctl 103*86d7f5d3SJohn Marinoin an ioctl routine: 104*86d7f5d3SJohn Marino.Bd -literal 105*86d7f5d3SJohn Marinoextern prop_dictionary_t fooprops; 106*86d7f5d3SJohn Marino 107*86d7f5d3SJohn Marinoint 108*86d7f5d3SJohn Marinofooioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct lwp *l) 109*86d7f5d3SJohn Marino{ 110*86d7f5d3SJohn Marino prop_dictionary_t dict, odict; 111*86d7f5d3SJohn Marino int error; 112*86d7f5d3SJohn Marino 113*86d7f5d3SJohn Marino switch (cmd) { 114*86d7f5d3SJohn Marino case FOOSETPROPS: { 115*86d7f5d3SJohn Marino const struct plistref *pref = (const struct plistref *) data; 116*86d7f5d3SJohn Marino error = prop_dictionary_copyin_ioctl(pref, cmd, \*[Am]dict); 117*86d7f5d3SJohn Marino if (error) 118*86d7f5d3SJohn Marino return (error); 119*86d7f5d3SJohn Marino odict = fooprops; 120*86d7f5d3SJohn Marino fooprops = dict; 121*86d7f5d3SJohn Marino prop_object_release(odict); 122*86d7f5d3SJohn Marino break; 123*86d7f5d3SJohn Marino } 124*86d7f5d3SJohn Marino 125*86d7f5d3SJohn Marino case FOOGETPROPS: { 126*86d7f5d3SJohn Marino struct plistref *pref = (struct plistref *) data; 127*86d7f5d3SJohn Marino error = prop_dictionary_copyout_ioctl(pref, cmd, fooprops); 128*86d7f5d3SJohn Marino break; 129*86d7f5d3SJohn Marino } 130*86d7f5d3SJohn Marino 131*86d7f5d3SJohn Marino default: 132*86d7f5d3SJohn Marino return (EPASSTHROUGH); 133*86d7f5d3SJohn Marino } 134*86d7f5d3SJohn Marino return (error); 135*86d7f5d3SJohn Marino} 136*86d7f5d3SJohn Marino.Ed 137*86d7f5d3SJohn Marino.Pp 138*86d7f5d3SJohn MarinoThe following 139*86d7f5d3SJohn Marino.Pq simplified 140*86d7f5d3SJohn Marinoexample demonstrates using 141*86d7f5d3SJohn Marino.Fn prop_array_copyin 142*86d7f5d3SJohn Marinoin a routine: 143*86d7f5d3SJohn Marino.Bd -literal 144*86d7f5d3SJohn Marinoint 145*86d7f5d3SJohn Marinofoocopyin(const struct plistref *pref)) 146*86d7f5d3SJohn Marino{ 147*86d7f5d3SJohn Marino prop_array_t array; 148*86d7f5d3SJohn Marino int error; 149*86d7f5d3SJohn Marino 150*86d7f5d3SJohn Marino error = prop_array_copyin(pref, \*[Am]array); 151*86d7f5d3SJohn Marino if (error) 152*86d7f5d3SJohn Marino return (error); 153*86d7f5d3SJohn Marino ... 154*86d7f5d3SJohn Marino} 155*86d7f5d3SJohn Marino.Ed 156*86d7f5d3SJohn Marino.Sh ERRORS 157*86d7f5d3SJohn Marino.Fn prop_array_copyin_ioctl 158*86d7f5d3SJohn Marinoand 159*86d7f5d3SJohn Marino.Fn prop_dictionary_copyin_ioctl 160*86d7f5d3SJohn Marinowill fail if: 161*86d7f5d3SJohn Marino.Bl -tag -width Er 162*86d7f5d3SJohn Marino.It Bq Er EFAULT 163*86d7f5d3SJohn MarinoBad address 164*86d7f5d3SJohn Marino.It Bq Er EIO 165*86d7f5d3SJohn MarinoInput/output error 166*86d7f5d3SJohn Marino.It Bq Er ENOMEM 167*86d7f5d3SJohn MarinoCannot allocate memory 168*86d7f5d3SJohn Marino.It Bq Er ENOTSUP 169*86d7f5d3SJohn MarinoNot supported 170*86d7f5d3SJohn Marino.El 171*86d7f5d3SJohn Marino.Pp 172*86d7f5d3SJohn Marino.Fn prop_array_copyout_ioctl 173*86d7f5d3SJohn Marinoand 174*86d7f5d3SJohn Marino.Fn prop_dictionary_copyout_ioctl 175*86d7f5d3SJohn Marinowill fail if: 176*86d7f5d3SJohn Marino.Bl -tag -width Er 177*86d7f5d3SJohn Marino.It Bq Er EFAULT 178*86d7f5d3SJohn MarinoBad address 179*86d7f5d3SJohn Marino.It Bq Er ENOMEM 180*86d7f5d3SJohn MarinoCannot allocate memory 181*86d7f5d3SJohn Marino.It Bq Er ENOTSUP 182*86d7f5d3SJohn MarinoNot supported 183*86d7f5d3SJohn Marino.El 184*86d7f5d3SJohn Marino.Sh SEE ALSO 185*86d7f5d3SJohn Marino.Xr prop_array 3 , 186*86d7f5d3SJohn Marino.Xr prop_dictionary 3 , 187*86d7f5d3SJohn Marino.Xr prop_send_ioctl 3 , 188*86d7f5d3SJohn Marino.Xr prop_send_syscall 3 , 189*86d7f5d3SJohn Marino.Xr proplib 3 190*86d7f5d3SJohn Marino.Sh HISTORY 191*86d7f5d3SJohn MarinoThe 192*86d7f5d3SJohn Marino.Nm proplib 193*86d7f5d3SJohn Marinoproperty container object library first appeared in 194*86d7f5d3SJohn Marino.Nx 4.0 . 195