xref: /netbsd-src/common/lib/libprop/prop_send_ioctl.3 (revision 267197ec1eebfcb9810ea27a89625b6ddf68e3e7)
1.\"	$NetBSD: prop_send_ioctl.3,v 1.4 2008/01/21 22:15:04 christos Exp $
2.\"
3.\" Copyright (c) 2006 The NetBSD Foundation, Inc.
4.\" All rights reserved.
5.\"
6.\" This code is derived from software contributed to The NetBSD Foundation
7.\" by Jason R. Thorpe.
8.\"
9.\" Redistribution and use in source and binary forms, with or without
10.\" modification, are permitted provided that the following conditions
11.\" are met:
12.\" 1. Redistributions of source code must retain the above copyright
13.\" notice, this list of conditions and the following disclaimer.
14.\" 2. Redistributions in binary form must reproduce the above copyright
15.\" notice, this list of conditions and the following disclaimer in the
16.\" documentation and/or other materials provided with the distribution.
17.\" 3. All advertising materials mentioning features or use of this software
18.\" must display the following acknowledgement:
19.\" This product includes software developed by the NetBSD
20.\" Foundation, Inc. and its contributors.
21.\" 4. Neither the name of The NetBSD Foundation nor the names of its
22.\" contributors may be used to endorse or promote products derived
23.\" from this software without specific prior written permission.
24.\"
25.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
26.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
27.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
29.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35.\" POSSIBILITY OF SUCH DAMAGE.
36.\"
37.Dd January 21, 2008
38.Dt PROP_SEND_IOCTL 3
39.Os
40.Sh NAME
41.Nm prop_array_send_ioctl ,
42.Nm prop_array_recv_ioctl ,
43.Nm prop_dictionary_send_ioctl ,
44.Nm prop_dictionary_recv_ioctl ,
45.Nm prop_dictionary_sendrecv_ioctl
46.Nd Send and receive propertly lists to and from the kernel using ioctl
47.Sh SYNOPSIS
48.In prop/proplib.h
49.Ft int
50.Fn prop_array_send_ioctl "prop_array_t array" "int fd" "unsigned long cmd"
51.Ft int
52.Fn prop_array_recv_ioctl "int fd" "unsigned long cmd" "prop_array_t *arrayp"
53.Ft int
54.Fn prop_dictionary_send_ioctl "prop_dictionary_t dict" "int fd" \
55    "unsigned long cmd"
56.Ft int
57.Fn prop_dictionary_recv_ioctl "int fd" "unsigned long cmd" \
58    "prop_dictionary_t *dictp"
59.Fn prop_dictionary_sendrecv_ioctl "prop_dictionary_t dict" "int fd" \
60    "unsigned long cmd" "prop_dictionary_t *dictp"
61.Sh DESCRIPTION
62The
63.Nm prop_array_send_ioctl ,
64.Nm prop_array_recv_ioctl ,
65.Nm prop_dictionary_send_ioctl ,
66.Nm prop_dictionary_recv_ioctl ,
67and
68.Nm prop_dictionary_sendrecv_ioctl
69functions implement the user space side of a protocol for sending property
70lists to and from the kernel using
71.Xr ioctl 2 .
72.Sh RETURN VALUES
73If successful, functions return zero. Otherwise, an error number is returned to indicate the error.
74.Sh ERRORS
75.Fn prop_array_send_ioctl
76and
77.Fn prop_dictionary_send_ioctl
78will fail if:
79.Bl -tag -width Er
80.It Bq Er ENOMEM
81Cannot allocate memory
82.It Bq Er ENOTSUP
83Not supported
84.El
85.Pp
86.Fn prop_array_recv_ioctl
87and
88.Fn prop_dictionary_recv_ioctl
89will fail if:
90.Bl -tag -width Er
91.It Bq Er EIO
92Input/output error
93.It Bq Er ENOTSUP
94Not supported
95.El
96.Pp
97In addition to these,
98.Xr ioctl 2
99errors may be returned.
100.Sh EXAMPLES
101The following
102.Pq simplified
103example demonstrates using
104.Fn prop_dictionary_send_ioctl
105and
106.Fn prop_dictionary_recv_ioctl
107in an application:
108.Bd -literal
109void
110foo_setprops(prop_dictionary_t dict)
111{
112    int fd;
113
114    fd = open("/dev/foo", O_RDWR, 0640);
115    if (fd == -1)
116        return;
117
118    (void) prop_dictionary_send_ioctl(dict, fd, FOOSETPROPS);
119
120    (void) close(fd);
121}
122
123prop_dictionary_t
124foo_getprops(void)
125{
126    prop_dictionary_t dict;
127    int fd;
128
129    fd = open("/dev/foo", O_RDONLY, 0640);
130    if (fd == -1)
131	return (NULL);
132
133    if (prop_dictionary_recv_ioctl(fd, FOOGETPROPS, \*[Am]dict) != 0)
134        return (NULL);
135
136    (void) close(fd);
137
138    return (dict);
139}
140.Ed
141.Pp
142The
143.Nm prop_dictionary_sendrecv_ioctl
144function combines the send and receive functionality, allowing for
145ioctls that require two-way communication
146.Pq for example to specify arguments for the ioctl operation .
147.Sh SEE ALSO
148.Xr prop_array 3 ,
149.Xr prop_dictionary 3 ,
150.Xr proplib 3 ,
151.Xr prop_copyin_ioctl 9
152.Sh HISTORY
153The
154.Nm proplib
155property container object library first appeared in
156.Nx 4.0 .
157