1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate *
4*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate * with the License.
8*7c478bd9Sstevel@tonic-gate *
9*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate *
14*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate *
20*7c478bd9Sstevel@tonic-gate * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
24*7c478bd9Sstevel@tonic-gate * Use is subject to license terms.
25*7c478bd9Sstevel@tonic-gate */
26*7c478bd9Sstevel@tonic-gate
27*7c478bd9Sstevel@tonic-gate /*
28*7c478bd9Sstevel@tonic-gate * This module implements the PICL Interface used by PICL clients
29*7c478bd9Sstevel@tonic-gate * to access services of the PICL daemon
30*7c478bd9Sstevel@tonic-gate *
31*7c478bd9Sstevel@tonic-gate * Locking Strategy
32*7c478bd9Sstevel@tonic-gate * A single reader/writer lock (icl_lock) protects the access to the interface
33*7c478bd9Sstevel@tonic-gate * to the picl daemon, and the reference count, refcnt, variable.
34*7c478bd9Sstevel@tonic-gate * A reader lock is obtained to send a request to the daemon.
35*7c478bd9Sstevel@tonic-gate * A writer lock is obtained to initialize, reinitialize, or shutdown
36*7c478bd9Sstevel@tonic-gate * the interface.
37*7c478bd9Sstevel@tonic-gate */
38*7c478bd9Sstevel@tonic-gate
39*7c478bd9Sstevel@tonic-gate #include <stdio.h>
40*7c478bd9Sstevel@tonic-gate #include <stdlib.h>
41*7c478bd9Sstevel@tonic-gate #include <string.h>
42*7c478bd9Sstevel@tonic-gate #include <unistd.h>
43*7c478bd9Sstevel@tonic-gate #include <alloca.h>
44*7c478bd9Sstevel@tonic-gate #include <fcntl.h>
45*7c478bd9Sstevel@tonic-gate #include <libintl.h>
46*7c478bd9Sstevel@tonic-gate #include <errno.h>
47*7c478bd9Sstevel@tonic-gate #include <sys/mman.h>
48*7c478bd9Sstevel@tonic-gate #include <door.h>
49*7c478bd9Sstevel@tonic-gate #include <sys/door.h>
50*7c478bd9Sstevel@tonic-gate #include <sys/time.h>
51*7c478bd9Sstevel@tonic-gate #include <assert.h>
52*7c478bd9Sstevel@tonic-gate #include <synch.h>
53*7c478bd9Sstevel@tonic-gate #include <limits.h>
54*7c478bd9Sstevel@tonic-gate #include <picl.h>
55*7c478bd9Sstevel@tonic-gate #include "picl2door.h"
56*7c478bd9Sstevel@tonic-gate
57*7c478bd9Sstevel@tonic-gate /*
58*7c478bd9Sstevel@tonic-gate * Module variables
59*7c478bd9Sstevel@tonic-gate */
60*7c478bd9Sstevel@tonic-gate static int door_handle = -1;
61*7c478bd9Sstevel@tonic-gate static uint32_t refcnt = 0;
62*7c478bd9Sstevel@tonic-gate static rwlock_t picl_lock = DEFAULTRWLOCK;
63*7c478bd9Sstevel@tonic-gate
64*7c478bd9Sstevel@tonic-gate static char *picl_errmsg[] = {
65*7c478bd9Sstevel@tonic-gate "No error",
66*7c478bd9Sstevel@tonic-gate "General system failure",
67*7c478bd9Sstevel@tonic-gate "Daemon not responding",
68*7c478bd9Sstevel@tonic-gate "Unknown PICL service",
69*7c478bd9Sstevel@tonic-gate "Session not initialized",
70*7c478bd9Sstevel@tonic-gate "Invalid arguments",
71*7c478bd9Sstevel@tonic-gate "Argument too big",
72*7c478bd9Sstevel@tonic-gate "Property not found",
73*7c478bd9Sstevel@tonic-gate "Not a table property handle",
74*7c478bd9Sstevel@tonic-gate "Not a node handle",
75*7c478bd9Sstevel@tonic-gate "Not a property handle",
76*7c478bd9Sstevel@tonic-gate "End of property list",
77*7c478bd9Sstevel@tonic-gate "Property already exists",
78*7c478bd9Sstevel@tonic-gate "Property not writable",
79*7c478bd9Sstevel@tonic-gate "Insufficient permissions",
80*7c478bd9Sstevel@tonic-gate "Invalid handle",
81*7c478bd9Sstevel@tonic-gate "Stale handle",
82*7c478bd9Sstevel@tonic-gate "Unsupported version",
83*7c478bd9Sstevel@tonic-gate "Wait timed out",
84*7c478bd9Sstevel@tonic-gate "Attempting to destroy before delete",
85*7c478bd9Sstevel@tonic-gate "PICL Tree is busy",
86*7c478bd9Sstevel@tonic-gate "Already has a parent",
87*7c478bd9Sstevel@tonic-gate "Property name is reserved",
88*7c478bd9Sstevel@tonic-gate "Invalid reference value",
89*7c478bd9Sstevel@tonic-gate "Continue tree walk",
90*7c478bd9Sstevel@tonic-gate "Terminate tree walk",
91*7c478bd9Sstevel@tonic-gate "Node not found",
92*7c478bd9Sstevel@tonic-gate "Not enough space available",
93*7c478bd9Sstevel@tonic-gate "Property not readable",
94*7c478bd9Sstevel@tonic-gate "Property value unavailable"
95*7c478bd9Sstevel@tonic-gate };
96*7c478bd9Sstevel@tonic-gate
97*7c478bd9Sstevel@tonic-gate #define N_ERRORS (sizeof (picl_errmsg)/sizeof (picl_errmsg[0]))
98*7c478bd9Sstevel@tonic-gate #define SEND_REQ_TRYCOUNT 1
99*7c478bd9Sstevel@tonic-gate
100*7c478bd9Sstevel@tonic-gate /*
101*7c478bd9Sstevel@tonic-gate * This function sends the client request to the daemon using a door call.
102*7c478bd9Sstevel@tonic-gate * If door_handle is -1, it returns PICL_NOTINITIALIZED.
103*7c478bd9Sstevel@tonic-gate * If the door_call fails, it returns PICL_NORESPONSE. Otherwise, it
104*7c478bd9Sstevel@tonic-gate * checks the response from the daemon for error. If an error is returned
105*7c478bd9Sstevel@tonic-gate * this function returns the error code returned and unmaps any
106*7c478bd9Sstevel@tonic-gate * memory mapped by the door call. For successful results, the caller is
107*7c478bd9Sstevel@tonic-gate * responsible to unmap the mapped memory after retrieving the results.
108*7c478bd9Sstevel@tonic-gate *
109*7c478bd9Sstevel@tonic-gate * This function does not attempt to reinitialize the interface if the
110*7c478bd9Sstevel@tonic-gate * initial door_call fails. It is called from handshake() , shutdown()
111*7c478bd9Sstevel@tonic-gate * and trysend_req() routines.
112*7c478bd9Sstevel@tonic-gate */
113*7c478bd9Sstevel@tonic-gate static int
post_req(door_arg_t * dargp,void * data_ptr,size_t data_size,door_desc_t * desc_ptr,uint_t desc_num,void * rbuf,size_t rsize)114*7c478bd9Sstevel@tonic-gate post_req(door_arg_t *dargp, void *data_ptr, size_t data_size,
115*7c478bd9Sstevel@tonic-gate door_desc_t *desc_ptr, uint_t desc_num, void *rbuf, size_t rsize)
116*7c478bd9Sstevel@tonic-gate {
117*7c478bd9Sstevel@tonic-gate int err;
118*7c478bd9Sstevel@tonic-gate picl_service_t *ret;
119*7c478bd9Sstevel@tonic-gate int req_cnum;
120*7c478bd9Sstevel@tonic-gate
121*7c478bd9Sstevel@tonic-gate req_cnum = ((picl_service_t *)data_ptr)->in.cnum;
122*7c478bd9Sstevel@tonic-gate dargp->data_ptr = data_ptr;
123*7c478bd9Sstevel@tonic-gate dargp->data_size = data_size;
124*7c478bd9Sstevel@tonic-gate dargp->desc_ptr = desc_ptr;
125*7c478bd9Sstevel@tonic-gate dargp->desc_num = desc_num;
126*7c478bd9Sstevel@tonic-gate dargp->rbuf = rbuf;
127*7c478bd9Sstevel@tonic-gate dargp->rsize = rsize;
128*7c478bd9Sstevel@tonic-gate
129*7c478bd9Sstevel@tonic-gate if (door_call(door_handle, dargp) < 0)
130*7c478bd9Sstevel@tonic-gate return (PICL_NORESPONSE);
131*7c478bd9Sstevel@tonic-gate
132*7c478bd9Sstevel@tonic-gate /*LINTED*/
133*7c478bd9Sstevel@tonic-gate ret = (picl_service_t *)dargp->rbuf;
134*7c478bd9Sstevel@tonic-gate if (ret->in.cnum == req_cnum)
135*7c478bd9Sstevel@tonic-gate return (PICL_SUCCESS);
136*7c478bd9Sstevel@tonic-gate else if ((ret->in.cnum == PICL_CNUM_ERROR) &&
137*7c478bd9Sstevel@tonic-gate (ret->ret_error.in_cnum == req_cnum))
138*7c478bd9Sstevel@tonic-gate err = ret->ret_error.errnum;
139*7c478bd9Sstevel@tonic-gate else
140*7c478bd9Sstevel@tonic-gate err = PICL_UNKNOWNSERVICE;
141*7c478bd9Sstevel@tonic-gate if (dargp->rbuf != rbuf)
142*7c478bd9Sstevel@tonic-gate (void) munmap(dargp->rbuf, dargp->rsize);
143*7c478bd9Sstevel@tonic-gate return (err);
144*7c478bd9Sstevel@tonic-gate }
145*7c478bd9Sstevel@tonic-gate
146*7c478bd9Sstevel@tonic-gate /*
147*7c478bd9Sstevel@tonic-gate * This function posts an INIT message to the daemon to
148*7c478bd9Sstevel@tonic-gate * verify communication channel.
149*7c478bd9Sstevel@tonic-gate */
150*7c478bd9Sstevel@tonic-gate static int
handshake(void)151*7c478bd9Sstevel@tonic-gate handshake(void)
152*7c478bd9Sstevel@tonic-gate {
153*7c478bd9Sstevel@tonic-gate int err;
154*7c478bd9Sstevel@tonic-gate door_arg_t darg;
155*7c478bd9Sstevel@tonic-gate picl_reqinit_t req;
156*7c478bd9Sstevel@tonic-gate picl_retinit_t outargs;
157*7c478bd9Sstevel@tonic-gate
158*7c478bd9Sstevel@tonic-gate req.cnum = PICL_CNUM_INIT;
159*7c478bd9Sstevel@tonic-gate req.clrev = PICL_VERSION_1;
160*7c478bd9Sstevel@tonic-gate
161*7c478bd9Sstevel@tonic-gate if ((err = post_req(&darg, &req, sizeof (picl_reqinit_t), NULL,
162*7c478bd9Sstevel@tonic-gate 0, &outargs, sizeof (picl_retinit_t))) != PICL_SUCCESS)
163*7c478bd9Sstevel@tonic-gate return (err);
164*7c478bd9Sstevel@tonic-gate
165*7c478bd9Sstevel@tonic-gate if (darg.rbuf != (char *)&outargs)
166*7c478bd9Sstevel@tonic-gate (void) munmap(darg.rbuf, darg.rsize);
167*7c478bd9Sstevel@tonic-gate return (PICL_SUCCESS);
168*7c478bd9Sstevel@tonic-gate }
169*7c478bd9Sstevel@tonic-gate
170*7c478bd9Sstevel@tonic-gate /*
171*7c478bd9Sstevel@tonic-gate * This function calls post_req() to make door_call and reinitializes
172*7c478bd9Sstevel@tonic-gate * the interface is post_req() fails.
173*7c478bd9Sstevel@tonic-gate */
174*7c478bd9Sstevel@tonic-gate static int
trysend_req(door_arg_t * dargp,void * data_ptr,size_t data_size,door_desc_t * desc_ptr,uint_t desc_num,void * rbuf,size_t rsize,unsigned int trycount)175*7c478bd9Sstevel@tonic-gate trysend_req(door_arg_t *dargp, void *data_ptr, size_t data_size,
176*7c478bd9Sstevel@tonic-gate door_desc_t *desc_ptr, uint_t desc_num, void *rbuf, size_t rsize,
177*7c478bd9Sstevel@tonic-gate unsigned int trycount)
178*7c478bd9Sstevel@tonic-gate {
179*7c478bd9Sstevel@tonic-gate int err;
180*7c478bd9Sstevel@tonic-gate int write_locked;
181*7c478bd9Sstevel@tonic-gate
182*7c478bd9Sstevel@tonic-gate write_locked = 0;
183*7c478bd9Sstevel@tonic-gate (void) rw_rdlock(&picl_lock);
184*7c478bd9Sstevel@tonic-gate if (refcnt == 0) {
185*7c478bd9Sstevel@tonic-gate (void) rw_unlock(&picl_lock); /* read unlock */
186*7c478bd9Sstevel@tonic-gate return (PICL_NOTINITIALIZED);
187*7c478bd9Sstevel@tonic-gate }
188*7c478bd9Sstevel@tonic-gate
189*7c478bd9Sstevel@tonic-gate while ((err = post_req(dargp, data_ptr, data_size, desc_ptr, desc_num,
190*7c478bd9Sstevel@tonic-gate rbuf, rsize)) == PICL_NORESPONSE) {
191*7c478bd9Sstevel@tonic-gate if (trycount == 0) /* no more retry */
192*7c478bd9Sstevel@tonic-gate break;
193*7c478bd9Sstevel@tonic-gate
194*7c478bd9Sstevel@tonic-gate if (write_locked == 1) { /* close and open door */
195*7c478bd9Sstevel@tonic-gate (void) close(door_handle);
196*7c478bd9Sstevel@tonic-gate if ((door_handle = open(PICLD_DOOR, O_RDONLY)) < 0) {
197*7c478bd9Sstevel@tonic-gate err = PICL_NORESPONSE;
198*7c478bd9Sstevel@tonic-gate break;
199*7c478bd9Sstevel@tonic-gate }
200*7c478bd9Sstevel@tonic-gate --trycount;
201*7c478bd9Sstevel@tonic-gate continue;
202*7c478bd9Sstevel@tonic-gate }
203*7c478bd9Sstevel@tonic-gate /*
204*7c478bd9Sstevel@tonic-gate * Upgrade read to a write lock
205*7c478bd9Sstevel@tonic-gate */
206*7c478bd9Sstevel@tonic-gate (void) rw_unlock(&picl_lock);
207*7c478bd9Sstevel@tonic-gate (void) rw_wrlock(&picl_lock);
208*7c478bd9Sstevel@tonic-gate
209*7c478bd9Sstevel@tonic-gate /*
210*7c478bd9Sstevel@tonic-gate * if picl_shutdown happens during lock upgrade
211*7c478bd9Sstevel@tonic-gate */
212*7c478bd9Sstevel@tonic-gate if (refcnt == 0) {
213*7c478bd9Sstevel@tonic-gate err = PICL_NOTINITIALIZED;
214*7c478bd9Sstevel@tonic-gate break;
215*7c478bd9Sstevel@tonic-gate }
216*7c478bd9Sstevel@tonic-gate write_locked = 1;
217*7c478bd9Sstevel@tonic-gate continue;
218*7c478bd9Sstevel@tonic-gate }
219*7c478bd9Sstevel@tonic-gate (void) rw_unlock(&picl_lock); /* read or write unlock */
220*7c478bd9Sstevel@tonic-gate return (err);
221*7c478bd9Sstevel@tonic-gate }
222*7c478bd9Sstevel@tonic-gate
223*7c478bd9Sstevel@tonic-gate /*
224*7c478bd9Sstevel@tonic-gate * Initialize the PICL interface
225*7c478bd9Sstevel@tonic-gate * Increment the reference count.
226*7c478bd9Sstevel@tonic-gate */
227*7c478bd9Sstevel@tonic-gate int
picl_initialize(void)228*7c478bd9Sstevel@tonic-gate picl_initialize(void)
229*7c478bd9Sstevel@tonic-gate {
230*7c478bd9Sstevel@tonic-gate int err;
231*7c478bd9Sstevel@tonic-gate
232*7c478bd9Sstevel@tonic-gate (void) rw_wrlock(&picl_lock);
233*7c478bd9Sstevel@tonic-gate if (refcnt > 0) { /* previously initialized */
234*7c478bd9Sstevel@tonic-gate err = handshake();
235*7c478bd9Sstevel@tonic-gate if (err == PICL_SUCCESS) {
236*7c478bd9Sstevel@tonic-gate ++refcnt;
237*7c478bd9Sstevel@tonic-gate (void) rw_unlock(&picl_lock); /* write unlock */
238*7c478bd9Sstevel@tonic-gate return (err);
239*7c478bd9Sstevel@tonic-gate }
240*7c478bd9Sstevel@tonic-gate if (err != PICL_NORESPONSE) {
241*7c478bd9Sstevel@tonic-gate (void) rw_unlock(&picl_lock); /* write unlock */
242*7c478bd9Sstevel@tonic-gate return (err);
243*7c478bd9Sstevel@tonic-gate }
244*7c478bd9Sstevel@tonic-gate (void) close(door_handle); /* close bad door */
245*7c478bd9Sstevel@tonic-gate }
246*7c478bd9Sstevel@tonic-gate
247*7c478bd9Sstevel@tonic-gate /*
248*7c478bd9Sstevel@tonic-gate * Open picld door and initialize door_handle
249*7c478bd9Sstevel@tonic-gate */
250*7c478bd9Sstevel@tonic-gate if ((door_handle = open(PICLD_DOOR, O_RDONLY)) < 0) {
251*7c478bd9Sstevel@tonic-gate (void) rw_unlock(&picl_lock); /* write unlock */
252*7c478bd9Sstevel@tonic-gate return (PICL_NORESPONSE);
253*7c478bd9Sstevel@tonic-gate }
254*7c478bd9Sstevel@tonic-gate
255*7c478bd9Sstevel@tonic-gate err = handshake();
256*7c478bd9Sstevel@tonic-gate if (err != PICL_SUCCESS)
257*7c478bd9Sstevel@tonic-gate (void) close(door_handle);
258*7c478bd9Sstevel@tonic-gate else
259*7c478bd9Sstevel@tonic-gate ++refcnt;
260*7c478bd9Sstevel@tonic-gate (void) rw_unlock(&picl_lock); /* write unlock */
261*7c478bd9Sstevel@tonic-gate return (err);
262*7c478bd9Sstevel@tonic-gate }
263*7c478bd9Sstevel@tonic-gate
264*7c478bd9Sstevel@tonic-gate /*
265*7c478bd9Sstevel@tonic-gate * Shutdown the PICL interface
266*7c478bd9Sstevel@tonic-gate * Decrement the reference count and close the door_handle if refcnt is zero
267*7c478bd9Sstevel@tonic-gate */
268*7c478bd9Sstevel@tonic-gate int
picl_shutdown(void)269*7c478bd9Sstevel@tonic-gate picl_shutdown(void)
270*7c478bd9Sstevel@tonic-gate {
271*7c478bd9Sstevel@tonic-gate int err;
272*7c478bd9Sstevel@tonic-gate door_arg_t darg;
273*7c478bd9Sstevel@tonic-gate picl_reqfini_t req_fini;
274*7c478bd9Sstevel@tonic-gate picl_retfini_t outargs;
275*7c478bd9Sstevel@tonic-gate
276*7c478bd9Sstevel@tonic-gate (void) rw_wrlock(&picl_lock); /* write lock */
277*7c478bd9Sstevel@tonic-gate if (refcnt == 0) {
278*7c478bd9Sstevel@tonic-gate (void) rw_unlock(&picl_lock); /* write unlock */
279*7c478bd9Sstevel@tonic-gate return (PICL_NOTINITIALIZED);
280*7c478bd9Sstevel@tonic-gate }
281*7c478bd9Sstevel@tonic-gate req_fini.cnum = PICL_CNUM_FINI;
282*7c478bd9Sstevel@tonic-gate err = post_req(&darg, &req_fini, sizeof (picl_reqfini_t),
283*7c478bd9Sstevel@tonic-gate NULL, 0, &outargs, sizeof (picl_retfini_t));
284*7c478bd9Sstevel@tonic-gate --refcnt;
285*7c478bd9Sstevel@tonic-gate if (refcnt == 0)
286*7c478bd9Sstevel@tonic-gate (void) close(door_handle);
287*7c478bd9Sstevel@tonic-gate (void) rw_unlock(&picl_lock); /* write unlock */
288*7c478bd9Sstevel@tonic-gate if (err != PICL_SUCCESS)
289*7c478bd9Sstevel@tonic-gate return (err);
290*7c478bd9Sstevel@tonic-gate if (darg.rbuf != (char *)&outargs)
291*7c478bd9Sstevel@tonic-gate (void) munmap(darg.rbuf, darg.rsize);
292*7c478bd9Sstevel@tonic-gate return (PICL_SUCCESS);
293*7c478bd9Sstevel@tonic-gate }
294*7c478bd9Sstevel@tonic-gate
295*7c478bd9Sstevel@tonic-gate /*
296*7c478bd9Sstevel@tonic-gate * This function waits for the specified number of seconds for a PICL
297*7c478bd9Sstevel@tonic-gate * tree refresh.
298*7c478bd9Sstevel@tonic-gate */
299*7c478bd9Sstevel@tonic-gate int
picl_wait(unsigned int secs)300*7c478bd9Sstevel@tonic-gate picl_wait(unsigned int secs)
301*7c478bd9Sstevel@tonic-gate {
302*7c478bd9Sstevel@tonic-gate door_arg_t darg;
303*7c478bd9Sstevel@tonic-gate picl_reqwait_t req_wait;
304*7c478bd9Sstevel@tonic-gate picl_retwait_t outargs;
305*7c478bd9Sstevel@tonic-gate picl_service_t *ret;
306*7c478bd9Sstevel@tonic-gate int err;
307*7c478bd9Sstevel@tonic-gate
308*7c478bd9Sstevel@tonic-gate req_wait.cnum = PICL_CNUM_WAIT;
309*7c478bd9Sstevel@tonic-gate req_wait.secs = secs;
310*7c478bd9Sstevel@tonic-gate err = trysend_req(&darg, &req_wait, sizeof (picl_reqwait_t),
311*7c478bd9Sstevel@tonic-gate NULL, 0, &outargs, sizeof (picl_retwait_t), SEND_REQ_TRYCOUNT);
312*7c478bd9Sstevel@tonic-gate if (err != PICL_SUCCESS)
313*7c478bd9Sstevel@tonic-gate return (err);
314*7c478bd9Sstevel@tonic-gate
315*7c478bd9Sstevel@tonic-gate /*LINTED*/
316*7c478bd9Sstevel@tonic-gate ret = (picl_service_t *)darg.rbuf;
317*7c478bd9Sstevel@tonic-gate err = ret->ret_wait.retcode;
318*7c478bd9Sstevel@tonic-gate if (darg.rbuf != (char *)&outargs)
319*7c478bd9Sstevel@tonic-gate (void) munmap(darg.rbuf, darg.rsize);
320*7c478bd9Sstevel@tonic-gate return (err);
321*7c478bd9Sstevel@tonic-gate }
322*7c478bd9Sstevel@tonic-gate
323*7c478bd9Sstevel@tonic-gate /*
324*7c478bd9Sstevel@tonic-gate * This function copies the handle of the root node of the PICL tree into
325*7c478bd9Sstevel@tonic-gate * the buffer <rooth>
326*7c478bd9Sstevel@tonic-gate */
327*7c478bd9Sstevel@tonic-gate int
picl_get_root(picl_nodehdl_t * rooth)328*7c478bd9Sstevel@tonic-gate picl_get_root(picl_nodehdl_t *rooth)
329*7c478bd9Sstevel@tonic-gate {
330*7c478bd9Sstevel@tonic-gate door_arg_t darg;
331*7c478bd9Sstevel@tonic-gate picl_reqroot_t req_root;
332*7c478bd9Sstevel@tonic-gate picl_retroot_t outargs;
333*7c478bd9Sstevel@tonic-gate picl_service_t *ret;
334*7c478bd9Sstevel@tonic-gate int err;
335*7c478bd9Sstevel@tonic-gate
336*7c478bd9Sstevel@tonic-gate req_root.cnum = PICL_CNUM_GETROOT;
337*7c478bd9Sstevel@tonic-gate err = trysend_req(&darg, &req_root, sizeof (picl_reqroot_t), NULL,
338*7c478bd9Sstevel@tonic-gate 0, &outargs, sizeof (picl_retroot_t), SEND_REQ_TRYCOUNT);
339*7c478bd9Sstevel@tonic-gate if (err != PICL_SUCCESS)
340*7c478bd9Sstevel@tonic-gate return (err);
341*7c478bd9Sstevel@tonic-gate /*LINTED*/
342*7c478bd9Sstevel@tonic-gate ret = (picl_service_t *)darg.rbuf;
343*7c478bd9Sstevel@tonic-gate *rooth = ret->ret_root.rnode;
344*7c478bd9Sstevel@tonic-gate if (darg.rbuf != (char *)&outargs)
345*7c478bd9Sstevel@tonic-gate (void) munmap(darg.rbuf, darg.rsize);
346*7c478bd9Sstevel@tonic-gate return (PICL_SUCCESS);
347*7c478bd9Sstevel@tonic-gate }
348*7c478bd9Sstevel@tonic-gate
349*7c478bd9Sstevel@tonic-gate /*
350*7c478bd9Sstevel@tonic-gate * This function copies the value of the property specified by its handle
351*7c478bd9Sstevel@tonic-gate * into the buffer <valbuf>.
352*7c478bd9Sstevel@tonic-gate */
353*7c478bd9Sstevel@tonic-gate int
picl_get_propval(picl_prophdl_t proph,void * valbuf,size_t nbytes)354*7c478bd9Sstevel@tonic-gate picl_get_propval(picl_prophdl_t proph, void *valbuf, size_t nbytes)
355*7c478bd9Sstevel@tonic-gate {
356*7c478bd9Sstevel@tonic-gate door_arg_t darg;
357*7c478bd9Sstevel@tonic-gate picl_reqattrval_t req_attrval;
358*7c478bd9Sstevel@tonic-gate picl_service_t *ret;
359*7c478bd9Sstevel@tonic-gate picl_retattrval_t *outargs;
360*7c478bd9Sstevel@tonic-gate int err;
361*7c478bd9Sstevel@tonic-gate
362*7c478bd9Sstevel@tonic-gate req_attrval.cnum = PICL_CNUM_GETATTRVAL;
363*7c478bd9Sstevel@tonic-gate req_attrval.attr = proph;
364*7c478bd9Sstevel@tonic-gate req_attrval.bufsize = (uint32_t)nbytes;
365*7c478bd9Sstevel@tonic-gate if ((size_t)req_attrval.bufsize != nbytes)
366*7c478bd9Sstevel@tonic-gate return (PICL_VALUETOOBIG);
367*7c478bd9Sstevel@tonic-gate outargs = alloca(sizeof (picl_retattrval_t) + nbytes);
368*7c478bd9Sstevel@tonic-gate
369*7c478bd9Sstevel@tonic-gate err = trysend_req(&darg, &req_attrval, sizeof (picl_reqattrval_t),
370*7c478bd9Sstevel@tonic-gate NULL, 0, outargs, sizeof (picl_retattrval_t) + nbytes,
371*7c478bd9Sstevel@tonic-gate SEND_REQ_TRYCOUNT);
372*7c478bd9Sstevel@tonic-gate if (err != PICL_SUCCESS)
373*7c478bd9Sstevel@tonic-gate return (err);
374*7c478bd9Sstevel@tonic-gate
375*7c478bd9Sstevel@tonic-gate /*LINTED*/
376*7c478bd9Sstevel@tonic-gate ret = (picl_service_t *)darg.rbuf;
377*7c478bd9Sstevel@tonic-gate if (ret->ret_attrval.nbytes > (uint32_t)nbytes)
378*7c478bd9Sstevel@tonic-gate err = PICL_VALUETOOBIG;
379*7c478bd9Sstevel@tonic-gate else
380*7c478bd9Sstevel@tonic-gate (void) memcpy(valbuf, ret->ret_attrval.ret_buf,
381*7c478bd9Sstevel@tonic-gate (size_t)ret->ret_attrval.nbytes);
382*7c478bd9Sstevel@tonic-gate if (darg.rbuf != (char *)outargs)
383*7c478bd9Sstevel@tonic-gate (void) munmap(darg.rbuf, darg.rsize);
384*7c478bd9Sstevel@tonic-gate return (err);
385*7c478bd9Sstevel@tonic-gate }
386*7c478bd9Sstevel@tonic-gate
387*7c478bd9Sstevel@tonic-gate /*
388*7c478bd9Sstevel@tonic-gate * This function copies the value of the property specified by its
389*7c478bd9Sstevel@tonic-gate * name into the buffer <valbuf>
390*7c478bd9Sstevel@tonic-gate */
391*7c478bd9Sstevel@tonic-gate int
picl_get_propval_by_name(picl_nodehdl_t nodeh,const char * propname,void * valbuf,size_t nbytes)392*7c478bd9Sstevel@tonic-gate picl_get_propval_by_name(picl_nodehdl_t nodeh, const char *propname,
393*7c478bd9Sstevel@tonic-gate void *valbuf, size_t nbytes)
394*7c478bd9Sstevel@tonic-gate {
395*7c478bd9Sstevel@tonic-gate door_arg_t darg;
396*7c478bd9Sstevel@tonic-gate picl_reqattrvalbyname_t req_attrvalbyname;
397*7c478bd9Sstevel@tonic-gate picl_service_t *ret;
398*7c478bd9Sstevel@tonic-gate picl_retattrvalbyname_t *outargs;
399*7c478bd9Sstevel@tonic-gate int err;
400*7c478bd9Sstevel@tonic-gate
401*7c478bd9Sstevel@tonic-gate req_attrvalbyname.cnum = PICL_CNUM_GETATTRVALBYNAME;
402*7c478bd9Sstevel@tonic-gate req_attrvalbyname.nodeh = nodeh;
403*7c478bd9Sstevel@tonic-gate (void) strcpy(req_attrvalbyname.propname, propname);
404*7c478bd9Sstevel@tonic-gate req_attrvalbyname.bufsize = (uint32_t)nbytes;
405*7c478bd9Sstevel@tonic-gate if ((size_t)req_attrvalbyname.bufsize != nbytes)
406*7c478bd9Sstevel@tonic-gate return (PICL_VALUETOOBIG);
407*7c478bd9Sstevel@tonic-gate outargs = alloca(sizeof (picl_retattrvalbyname_t) + nbytes);
408*7c478bd9Sstevel@tonic-gate
409*7c478bd9Sstevel@tonic-gate err = trysend_req(&darg, &req_attrvalbyname,
410*7c478bd9Sstevel@tonic-gate sizeof (picl_reqattrvalbyname_t), NULL, 0, outargs,
411*7c478bd9Sstevel@tonic-gate sizeof (picl_retattrvalbyname_t) + nbytes, SEND_REQ_TRYCOUNT);
412*7c478bd9Sstevel@tonic-gate if (err != PICL_SUCCESS)
413*7c478bd9Sstevel@tonic-gate return (err);
414*7c478bd9Sstevel@tonic-gate
415*7c478bd9Sstevel@tonic-gate /*LINTED*/
416*7c478bd9Sstevel@tonic-gate ret = (picl_service_t *)darg.rbuf;
417*7c478bd9Sstevel@tonic-gate if (ret->ret_attrvalbyname.nbytes > (uint32_t)nbytes)
418*7c478bd9Sstevel@tonic-gate err = PICL_VALUETOOBIG;
419*7c478bd9Sstevel@tonic-gate else
420*7c478bd9Sstevel@tonic-gate (void) memcpy(valbuf, ret->ret_attrvalbyname.ret_buf,
421*7c478bd9Sstevel@tonic-gate (size_t)ret->ret_attrvalbyname.nbytes);
422*7c478bd9Sstevel@tonic-gate if (darg.rbuf != (char *)outargs)
423*7c478bd9Sstevel@tonic-gate (void) munmap(darg.rbuf, darg.rsize);
424*7c478bd9Sstevel@tonic-gate return (err);
425*7c478bd9Sstevel@tonic-gate }
426*7c478bd9Sstevel@tonic-gate
427*7c478bd9Sstevel@tonic-gate /*
428*7c478bd9Sstevel@tonic-gate * This function sets the value of the property specified by its
429*7c478bd9Sstevel@tonic-gate * handle with the value specified in <valbuf>.
430*7c478bd9Sstevel@tonic-gate */
431*7c478bd9Sstevel@tonic-gate int
picl_set_propval(picl_prophdl_t proph,void * valbuf,size_t nbytes)432*7c478bd9Sstevel@tonic-gate picl_set_propval(picl_prophdl_t proph, void *valbuf, size_t nbytes)
433*7c478bd9Sstevel@tonic-gate {
434*7c478bd9Sstevel@tonic-gate door_arg_t darg;
435*7c478bd9Sstevel@tonic-gate picl_reqsetattrval_t ret_setattrval;
436*7c478bd9Sstevel@tonic-gate picl_reqsetattrval_t *inargs;
437*7c478bd9Sstevel@tonic-gate int err;
438*7c478bd9Sstevel@tonic-gate
439*7c478bd9Sstevel@tonic-gate if (nbytes >= (size_t)PICL_PROPSIZE_MAX)
440*7c478bd9Sstevel@tonic-gate return (PICL_VALUETOOBIG);
441*7c478bd9Sstevel@tonic-gate
442*7c478bd9Sstevel@tonic-gate inargs = alloca(sizeof (picl_reqsetattrval_t) + nbytes);
443*7c478bd9Sstevel@tonic-gate inargs->cnum = PICL_CNUM_SETATTRVAL;
444*7c478bd9Sstevel@tonic-gate inargs->attr = proph;
445*7c478bd9Sstevel@tonic-gate inargs->bufsize = (uint32_t)nbytes;
446*7c478bd9Sstevel@tonic-gate if ((size_t)inargs->bufsize != nbytes)
447*7c478bd9Sstevel@tonic-gate return (PICL_VALUETOOBIG);
448*7c478bd9Sstevel@tonic-gate (void) memcpy(inargs->valbuf, valbuf, nbytes);
449*7c478bd9Sstevel@tonic-gate
450*7c478bd9Sstevel@tonic-gate err = trysend_req(&darg, inargs, sizeof (picl_reqsetattrval_t) +
451*7c478bd9Sstevel@tonic-gate nbytes, NULL, 0, &ret_setattrval,
452*7c478bd9Sstevel@tonic-gate sizeof (picl_retsetattrval_t), SEND_REQ_TRYCOUNT);
453*7c478bd9Sstevel@tonic-gate if (err != PICL_SUCCESS)
454*7c478bd9Sstevel@tonic-gate return (err);
455*7c478bd9Sstevel@tonic-gate
456*7c478bd9Sstevel@tonic-gate if (darg.rbuf != (char *)&ret_setattrval)
457*7c478bd9Sstevel@tonic-gate (void) munmap(darg.rbuf, darg.rsize);
458*7c478bd9Sstevel@tonic-gate return (PICL_SUCCESS);
459*7c478bd9Sstevel@tonic-gate }
460*7c478bd9Sstevel@tonic-gate
461*7c478bd9Sstevel@tonic-gate /*
462*7c478bd9Sstevel@tonic-gate * This function sets the value of the property specified by its
463*7c478bd9Sstevel@tonic-gate * name with the value given in <valbuf>
464*7c478bd9Sstevel@tonic-gate */
465*7c478bd9Sstevel@tonic-gate int
picl_set_propval_by_name(picl_nodehdl_t nodeh,const char * propname,void * valbuf,size_t nbytes)466*7c478bd9Sstevel@tonic-gate picl_set_propval_by_name(picl_nodehdl_t nodeh, const char *propname,
467*7c478bd9Sstevel@tonic-gate void *valbuf, size_t nbytes)
468*7c478bd9Sstevel@tonic-gate {
469*7c478bd9Sstevel@tonic-gate door_arg_t darg;
470*7c478bd9Sstevel@tonic-gate picl_retsetattrvalbyname_t ret_setattrvalbyname;
471*7c478bd9Sstevel@tonic-gate picl_reqsetattrvalbyname_t *inargs;
472*7c478bd9Sstevel@tonic-gate int err;
473*7c478bd9Sstevel@tonic-gate
474*7c478bd9Sstevel@tonic-gate if (nbytes >= (size_t)PICL_PROPSIZE_MAX)
475*7c478bd9Sstevel@tonic-gate return (PICL_VALUETOOBIG);
476*7c478bd9Sstevel@tonic-gate
477*7c478bd9Sstevel@tonic-gate inargs = alloca(sizeof (picl_reqsetattrvalbyname_t) + nbytes);
478*7c478bd9Sstevel@tonic-gate inargs->cnum = PICL_CNUM_SETATTRVALBYNAME;
479*7c478bd9Sstevel@tonic-gate inargs->nodeh = nodeh;
480*7c478bd9Sstevel@tonic-gate (void) strcpy(inargs->propname, propname);
481*7c478bd9Sstevel@tonic-gate inargs->bufsize = (uint32_t)nbytes;
482*7c478bd9Sstevel@tonic-gate if ((size_t)inargs->bufsize != nbytes)
483*7c478bd9Sstevel@tonic-gate return (PICL_VALUETOOBIG);
484*7c478bd9Sstevel@tonic-gate (void) memcpy(inargs->valbuf, valbuf, nbytes);
485*7c478bd9Sstevel@tonic-gate
486*7c478bd9Sstevel@tonic-gate err = trysend_req(&darg, inargs,
487*7c478bd9Sstevel@tonic-gate sizeof (picl_reqsetattrvalbyname_t) + nbytes, NULL, 0,
488*7c478bd9Sstevel@tonic-gate &ret_setattrvalbyname, sizeof (picl_retsetattrvalbyname_t),
489*7c478bd9Sstevel@tonic-gate SEND_REQ_TRYCOUNT);
490*7c478bd9Sstevel@tonic-gate if (err != PICL_SUCCESS)
491*7c478bd9Sstevel@tonic-gate return (err);
492*7c478bd9Sstevel@tonic-gate
493*7c478bd9Sstevel@tonic-gate if (darg.rbuf != (char *)&ret_setattrvalbyname)
494*7c478bd9Sstevel@tonic-gate (void) munmap(darg.rbuf, darg.rsize);
495*7c478bd9Sstevel@tonic-gate return (PICL_SUCCESS);
496*7c478bd9Sstevel@tonic-gate }
497*7c478bd9Sstevel@tonic-gate
498*7c478bd9Sstevel@tonic-gate /*
499*7c478bd9Sstevel@tonic-gate * This function copies the information of the specified property
500*7c478bd9Sstevel@tonic-gate * into <pinfo>
501*7c478bd9Sstevel@tonic-gate */
502*7c478bd9Sstevel@tonic-gate int
picl_get_propinfo(picl_prophdl_t proph,picl_propinfo_t * pinfo)503*7c478bd9Sstevel@tonic-gate picl_get_propinfo(picl_prophdl_t proph, picl_propinfo_t *pinfo)
504*7c478bd9Sstevel@tonic-gate {
505*7c478bd9Sstevel@tonic-gate door_arg_t darg;
506*7c478bd9Sstevel@tonic-gate picl_reqattrinfo_t req_attrinfo;
507*7c478bd9Sstevel@tonic-gate picl_service_t *ret;
508*7c478bd9Sstevel@tonic-gate picl_retattrinfo_t outargs;
509*7c478bd9Sstevel@tonic-gate int err;
510*7c478bd9Sstevel@tonic-gate
511*7c478bd9Sstevel@tonic-gate req_attrinfo.cnum = PICL_CNUM_GETATTRINFO;
512*7c478bd9Sstevel@tonic-gate req_attrinfo.attr = proph;
513*7c478bd9Sstevel@tonic-gate
514*7c478bd9Sstevel@tonic-gate err = trysend_req(&darg, &req_attrinfo,
515*7c478bd9Sstevel@tonic-gate sizeof (picl_reqattrinfo_t), NULL, 0, &outargs,
516*7c478bd9Sstevel@tonic-gate sizeof (picl_retattrinfo_t), SEND_REQ_TRYCOUNT);
517*7c478bd9Sstevel@tonic-gate if (err != PICL_SUCCESS)
518*7c478bd9Sstevel@tonic-gate return (err);
519*7c478bd9Sstevel@tonic-gate
520*7c478bd9Sstevel@tonic-gate /*LINTED*/
521*7c478bd9Sstevel@tonic-gate ret = (picl_service_t *)darg.rbuf;
522*7c478bd9Sstevel@tonic-gate pinfo->type = ret->ret_attrinfo.type;
523*7c478bd9Sstevel@tonic-gate pinfo->accessmode = ret->ret_attrinfo.accessmode;
524*7c478bd9Sstevel@tonic-gate pinfo->size = (size_t)ret->ret_attrinfo.size;
525*7c478bd9Sstevel@tonic-gate (void) strcpy(pinfo->name, ret->ret_attrinfo.name);
526*7c478bd9Sstevel@tonic-gate if (darg.rbuf != (char *)&outargs)
527*7c478bd9Sstevel@tonic-gate (void) munmap(darg.rbuf, darg.rsize);
528*7c478bd9Sstevel@tonic-gate return (PICL_SUCCESS);
529*7c478bd9Sstevel@tonic-gate }
530*7c478bd9Sstevel@tonic-gate
531*7c478bd9Sstevel@tonic-gate /*
532*7c478bd9Sstevel@tonic-gate * This function copies the handle of the first property of a node into
533*7c478bd9Sstevel@tonic-gate * <proph>
534*7c478bd9Sstevel@tonic-gate */
535*7c478bd9Sstevel@tonic-gate int
picl_get_first_prop(picl_nodehdl_t nodeh,picl_prophdl_t * proph)536*7c478bd9Sstevel@tonic-gate picl_get_first_prop(picl_nodehdl_t nodeh, picl_prophdl_t *proph)
537*7c478bd9Sstevel@tonic-gate {
538*7c478bd9Sstevel@tonic-gate door_arg_t darg;
539*7c478bd9Sstevel@tonic-gate picl_reqfirstattr_t req_firstattr;
540*7c478bd9Sstevel@tonic-gate picl_service_t *ret;
541*7c478bd9Sstevel@tonic-gate picl_retfirstattr_t outargs;
542*7c478bd9Sstevel@tonic-gate int err;
543*7c478bd9Sstevel@tonic-gate
544*7c478bd9Sstevel@tonic-gate req_firstattr.cnum = PICL_CNUM_GETFIRSTATTR;
545*7c478bd9Sstevel@tonic-gate req_firstattr.nodeh = nodeh;
546*7c478bd9Sstevel@tonic-gate
547*7c478bd9Sstevel@tonic-gate err = trysend_req(&darg, &req_firstattr,
548*7c478bd9Sstevel@tonic-gate sizeof (picl_reqfirstattr_t), NULL, 0, &outargs,
549*7c478bd9Sstevel@tonic-gate sizeof (picl_retfirstattr_t), SEND_REQ_TRYCOUNT);
550*7c478bd9Sstevel@tonic-gate if (err != PICL_SUCCESS)
551*7c478bd9Sstevel@tonic-gate return (err);
552*7c478bd9Sstevel@tonic-gate
553*7c478bd9Sstevel@tonic-gate /*LINTED*/
554*7c478bd9Sstevel@tonic-gate ret = (picl_service_t *)darg.rbuf;
555*7c478bd9Sstevel@tonic-gate *proph = ret->ret_firstattr.attr;
556*7c478bd9Sstevel@tonic-gate if (darg.rbuf != (char *)&outargs)
557*7c478bd9Sstevel@tonic-gate (void) munmap(darg.rbuf, darg.rsize);
558*7c478bd9Sstevel@tonic-gate return (PICL_SUCCESS);
559*7c478bd9Sstevel@tonic-gate }
560*7c478bd9Sstevel@tonic-gate
561*7c478bd9Sstevel@tonic-gate /*
562*7c478bd9Sstevel@tonic-gate * This function copies the handle of the next property in list
563*7c478bd9Sstevel@tonic-gate * into <nextprop>.
564*7c478bd9Sstevel@tonic-gate */
565*7c478bd9Sstevel@tonic-gate int
picl_get_next_prop(picl_prophdl_t proph,picl_prophdl_t * nextprop)566*7c478bd9Sstevel@tonic-gate picl_get_next_prop(picl_prophdl_t proph, picl_prophdl_t *nextprop)
567*7c478bd9Sstevel@tonic-gate {
568*7c478bd9Sstevel@tonic-gate door_arg_t darg;
569*7c478bd9Sstevel@tonic-gate picl_reqnextattr_t req_nextattr;
570*7c478bd9Sstevel@tonic-gate picl_service_t *ret;
571*7c478bd9Sstevel@tonic-gate picl_retnextattr_t outargs;
572*7c478bd9Sstevel@tonic-gate int err;
573*7c478bd9Sstevel@tonic-gate
574*7c478bd9Sstevel@tonic-gate
575*7c478bd9Sstevel@tonic-gate req_nextattr.cnum = PICL_CNUM_GETNEXTATTR;
576*7c478bd9Sstevel@tonic-gate req_nextattr.attr = proph;
577*7c478bd9Sstevel@tonic-gate
578*7c478bd9Sstevel@tonic-gate err = trysend_req(&darg, &req_nextattr,
579*7c478bd9Sstevel@tonic-gate sizeof (picl_reqnextattr_t), NULL, 0, &outargs,
580*7c478bd9Sstevel@tonic-gate sizeof (picl_retnextattr_t), SEND_REQ_TRYCOUNT);
581*7c478bd9Sstevel@tonic-gate if (err != PICL_SUCCESS)
582*7c478bd9Sstevel@tonic-gate return (err);
583*7c478bd9Sstevel@tonic-gate
584*7c478bd9Sstevel@tonic-gate /*LINTED*/
585*7c478bd9Sstevel@tonic-gate ret = (picl_service_t *)darg.rbuf;
586*7c478bd9Sstevel@tonic-gate *nextprop = ret->ret_nextattr.nextattr;
587*7c478bd9Sstevel@tonic-gate if (darg.rbuf != (char *)&outargs)
588*7c478bd9Sstevel@tonic-gate (void) munmap(darg.rbuf, darg.rsize);
589*7c478bd9Sstevel@tonic-gate return (PICL_SUCCESS);
590*7c478bd9Sstevel@tonic-gate }
591*7c478bd9Sstevel@tonic-gate
592*7c478bd9Sstevel@tonic-gate /*
593*7c478bd9Sstevel@tonic-gate * This function copies the handle of the property specified by its
594*7c478bd9Sstevel@tonic-gate * name into <proph>.
595*7c478bd9Sstevel@tonic-gate */
596*7c478bd9Sstevel@tonic-gate int
picl_get_prop_by_name(picl_nodehdl_t nodeh,const char * name,picl_prophdl_t * proph)597*7c478bd9Sstevel@tonic-gate picl_get_prop_by_name(picl_nodehdl_t nodeh, const char *name,
598*7c478bd9Sstevel@tonic-gate picl_prophdl_t *proph)
599*7c478bd9Sstevel@tonic-gate {
600*7c478bd9Sstevel@tonic-gate door_arg_t darg;
601*7c478bd9Sstevel@tonic-gate picl_reqattrbyname_t req_attrbyname;
602*7c478bd9Sstevel@tonic-gate picl_service_t *ret;
603*7c478bd9Sstevel@tonic-gate picl_retattrbyname_t outargs;
604*7c478bd9Sstevel@tonic-gate int err;
605*7c478bd9Sstevel@tonic-gate
606*7c478bd9Sstevel@tonic-gate req_attrbyname.cnum = PICL_CNUM_GETATTRBYNAME;
607*7c478bd9Sstevel@tonic-gate req_attrbyname.nodeh = nodeh;
608*7c478bd9Sstevel@tonic-gate (void) strcpy(req_attrbyname.propname, name);
609*7c478bd9Sstevel@tonic-gate
610*7c478bd9Sstevel@tonic-gate err = trysend_req(&darg, &req_attrbyname,
611*7c478bd9Sstevel@tonic-gate sizeof (picl_reqattrbyname_t), NULL, 0, &outargs,
612*7c478bd9Sstevel@tonic-gate sizeof (picl_retattrbyname_t), SEND_REQ_TRYCOUNT);
613*7c478bd9Sstevel@tonic-gate if (err != PICL_SUCCESS)
614*7c478bd9Sstevel@tonic-gate return (err);
615*7c478bd9Sstevel@tonic-gate
616*7c478bd9Sstevel@tonic-gate /*LINTED*/
617*7c478bd9Sstevel@tonic-gate ret = (picl_service_t *)darg.rbuf;
618*7c478bd9Sstevel@tonic-gate *proph = ret->ret_attrbyname.attr;
619*7c478bd9Sstevel@tonic-gate if (darg.rbuf != (char *)&outargs)
620*7c478bd9Sstevel@tonic-gate (void) munmap(darg.rbuf, darg.rsize);
621*7c478bd9Sstevel@tonic-gate return (PICL_SUCCESS);
622*7c478bd9Sstevel@tonic-gate }
623*7c478bd9Sstevel@tonic-gate
624*7c478bd9Sstevel@tonic-gate /*
625*7c478bd9Sstevel@tonic-gate * This function copies the handle of the next property on the same
626*7c478bd9Sstevel@tonic-gate * row of the table into <rowproph>.
627*7c478bd9Sstevel@tonic-gate * When proph is the table handle, the handle of the property that is
628*7c478bd9Sstevel@tonic-gate * in first row and first column is copied.
629*7c478bd9Sstevel@tonic-gate */
630*7c478bd9Sstevel@tonic-gate int
picl_get_next_by_row(picl_prophdl_t proph,picl_prophdl_t * rowproph)631*7c478bd9Sstevel@tonic-gate picl_get_next_by_row(picl_prophdl_t proph, picl_prophdl_t *rowproph)
632*7c478bd9Sstevel@tonic-gate {
633*7c478bd9Sstevel@tonic-gate door_arg_t darg;
634*7c478bd9Sstevel@tonic-gate picl_reqattrbyrow_t req_attrbyrow;
635*7c478bd9Sstevel@tonic-gate picl_service_t *ret;
636*7c478bd9Sstevel@tonic-gate picl_retattrbyrow_t outargs;
637*7c478bd9Sstevel@tonic-gate int err;
638*7c478bd9Sstevel@tonic-gate
639*7c478bd9Sstevel@tonic-gate req_attrbyrow.cnum = PICL_CNUM_GETATTRBYROW;
640*7c478bd9Sstevel@tonic-gate req_attrbyrow.attr = proph;
641*7c478bd9Sstevel@tonic-gate
642*7c478bd9Sstevel@tonic-gate err = trysend_req(&darg, &req_attrbyrow,
643*7c478bd9Sstevel@tonic-gate sizeof (picl_reqattrbyrow_t), NULL, 0, &outargs,
644*7c478bd9Sstevel@tonic-gate sizeof (picl_retattrbyrow_t), SEND_REQ_TRYCOUNT);
645*7c478bd9Sstevel@tonic-gate if (err != PICL_SUCCESS)
646*7c478bd9Sstevel@tonic-gate return (err);
647*7c478bd9Sstevel@tonic-gate
648*7c478bd9Sstevel@tonic-gate /*LINTED*/
649*7c478bd9Sstevel@tonic-gate ret = (picl_service_t *)darg.rbuf;
650*7c478bd9Sstevel@tonic-gate *rowproph = ret->ret_attrbyrow.rowattr;
651*7c478bd9Sstevel@tonic-gate if (darg.rbuf != (char *)&outargs)
652*7c478bd9Sstevel@tonic-gate (void) munmap(darg.rbuf, darg.rsize);
653*7c478bd9Sstevel@tonic-gate return (PICL_SUCCESS);
654*7c478bd9Sstevel@tonic-gate }
655*7c478bd9Sstevel@tonic-gate
656*7c478bd9Sstevel@tonic-gate /*
657*7c478bd9Sstevel@tonic-gate * This function copies the handle of the next property on the same
658*7c478bd9Sstevel@tonic-gate * column of the table into <colproph>.
659*7c478bd9Sstevel@tonic-gate * When proph is the table handle, the handle of the property that is
660*7c478bd9Sstevel@tonic-gate * in the first row and first column is copied.
661*7c478bd9Sstevel@tonic-gate */
662*7c478bd9Sstevel@tonic-gate int
picl_get_next_by_col(picl_prophdl_t proph,picl_prophdl_t * colproph)663*7c478bd9Sstevel@tonic-gate picl_get_next_by_col(picl_prophdl_t proph, picl_prophdl_t *colproph)
664*7c478bd9Sstevel@tonic-gate {
665*7c478bd9Sstevel@tonic-gate door_arg_t darg;
666*7c478bd9Sstevel@tonic-gate picl_reqattrbycol_t req_attrbycol;
667*7c478bd9Sstevel@tonic-gate picl_service_t *ret;
668*7c478bd9Sstevel@tonic-gate picl_retattrbycol_t outargs;
669*7c478bd9Sstevel@tonic-gate int err;
670*7c478bd9Sstevel@tonic-gate
671*7c478bd9Sstevel@tonic-gate req_attrbycol.cnum = PICL_CNUM_GETATTRBYCOL;
672*7c478bd9Sstevel@tonic-gate req_attrbycol.attr = proph;
673*7c478bd9Sstevel@tonic-gate
674*7c478bd9Sstevel@tonic-gate err = trysend_req(&darg, (char *)&req_attrbycol,
675*7c478bd9Sstevel@tonic-gate sizeof (picl_reqattrbycol_t), NULL, 0, (char *)&outargs,
676*7c478bd9Sstevel@tonic-gate sizeof (picl_retattrbycol_t), SEND_REQ_TRYCOUNT);
677*7c478bd9Sstevel@tonic-gate if (err != PICL_SUCCESS)
678*7c478bd9Sstevel@tonic-gate return (err);
679*7c478bd9Sstevel@tonic-gate
680*7c478bd9Sstevel@tonic-gate /*LINTED*/
681*7c478bd9Sstevel@tonic-gate ret = (picl_service_t *)darg.rbuf;
682*7c478bd9Sstevel@tonic-gate *colproph = ret->ret_attrbycol.colattr;
683*7c478bd9Sstevel@tonic-gate if (darg.rbuf != (char *)&outargs)
684*7c478bd9Sstevel@tonic-gate (void) munmap(darg.rbuf, darg.rsize);
685*7c478bd9Sstevel@tonic-gate return (PICL_SUCCESS);
686*7c478bd9Sstevel@tonic-gate }
687*7c478bd9Sstevel@tonic-gate
688*7c478bd9Sstevel@tonic-gate /*
689*7c478bd9Sstevel@tonic-gate * This function returns the picl error messages corresponding to the
690*7c478bd9Sstevel@tonic-gate * error number.
691*7c478bd9Sstevel@tonic-gate */
692*7c478bd9Sstevel@tonic-gate char *
picl_strerror(int err)693*7c478bd9Sstevel@tonic-gate picl_strerror(int err)
694*7c478bd9Sstevel@tonic-gate {
695*7c478bd9Sstevel@tonic-gate if ((err < N_ERRORS) && (err >= 0)) {
696*7c478bd9Sstevel@tonic-gate return (gettext(picl_errmsg[err]));
697*7c478bd9Sstevel@tonic-gate }
698*7c478bd9Sstevel@tonic-gate return ((char *)NULL);
699*7c478bd9Sstevel@tonic-gate }
700*7c478bd9Sstevel@tonic-gate
701*7c478bd9Sstevel@tonic-gate /*
702*7c478bd9Sstevel@tonic-gate * recursively visit all nodes
703*7c478bd9Sstevel@tonic-gate */
704*7c478bd9Sstevel@tonic-gate static int
do_walk(picl_nodehdl_t rooth,const char * classname,void * c_args,int (* callback_fn)(picl_nodehdl_t hdl,void * args))705*7c478bd9Sstevel@tonic-gate do_walk(picl_nodehdl_t rooth, const char *classname,
706*7c478bd9Sstevel@tonic-gate void *c_args, int (*callback_fn)(picl_nodehdl_t hdl, void *args))
707*7c478bd9Sstevel@tonic-gate {
708*7c478bd9Sstevel@tonic-gate int err;
709*7c478bd9Sstevel@tonic-gate picl_nodehdl_t chdh;
710*7c478bd9Sstevel@tonic-gate char classval[PICL_CLASSNAMELEN_MAX];
711*7c478bd9Sstevel@tonic-gate
712*7c478bd9Sstevel@tonic-gate err = picl_get_propval_by_name(rooth, PICL_PROP_CHILD, &chdh,
713*7c478bd9Sstevel@tonic-gate sizeof (chdh));
714*7c478bd9Sstevel@tonic-gate while (err == PICL_SUCCESS) {
715*7c478bd9Sstevel@tonic-gate err = picl_get_propval_by_name(chdh, PICL_PROP_CLASSNAME,
716*7c478bd9Sstevel@tonic-gate classval, sizeof (classval));
717*7c478bd9Sstevel@tonic-gate if (err != PICL_SUCCESS)
718*7c478bd9Sstevel@tonic-gate return (err);
719*7c478bd9Sstevel@tonic-gate
720*7c478bd9Sstevel@tonic-gate if ((classname == NULL) || (strcmp(classname, classval) == 0)) {
721*7c478bd9Sstevel@tonic-gate err = callback_fn(chdh, c_args);
722*7c478bd9Sstevel@tonic-gate if (err != PICL_WALK_CONTINUE)
723*7c478bd9Sstevel@tonic-gate return (err);
724*7c478bd9Sstevel@tonic-gate }
725*7c478bd9Sstevel@tonic-gate
726*7c478bd9Sstevel@tonic-gate if ((err = do_walk(chdh, classname, c_args, callback_fn)) !=
727*7c478bd9Sstevel@tonic-gate PICL_WALK_CONTINUE)
728*7c478bd9Sstevel@tonic-gate return (err);
729*7c478bd9Sstevel@tonic-gate
730*7c478bd9Sstevel@tonic-gate err = picl_get_propval_by_name(chdh, PICL_PROP_PEER, &chdh,
731*7c478bd9Sstevel@tonic-gate sizeof (chdh));
732*7c478bd9Sstevel@tonic-gate }
733*7c478bd9Sstevel@tonic-gate if (err == PICL_PROPNOTFOUND) /* end of a branch */
734*7c478bd9Sstevel@tonic-gate return (PICL_WALK_CONTINUE);
735*7c478bd9Sstevel@tonic-gate return (err);
736*7c478bd9Sstevel@tonic-gate
737*7c478bd9Sstevel@tonic-gate }
738*7c478bd9Sstevel@tonic-gate
739*7c478bd9Sstevel@tonic-gate /*
740*7c478bd9Sstevel@tonic-gate * This function walks the tree by class and invokes the callback
741*7c478bd9Sstevel@tonic-gate * function on class name matches.
742*7c478bd9Sstevel@tonic-gate */
743*7c478bd9Sstevel@tonic-gate int
picl_walk_tree_by_class(picl_nodehdl_t rooth,const char * classname,void * c_args,int (* callback_fn)(picl_nodehdl_t hdl,void * args))744*7c478bd9Sstevel@tonic-gate picl_walk_tree_by_class(picl_nodehdl_t rooth, const char *classname,
745*7c478bd9Sstevel@tonic-gate void *c_args, int (*callback_fn)(picl_nodehdl_t hdl, void *args))
746*7c478bd9Sstevel@tonic-gate {
747*7c478bd9Sstevel@tonic-gate int err;
748*7c478bd9Sstevel@tonic-gate
749*7c478bd9Sstevel@tonic-gate if (callback_fn == NULL)
750*7c478bd9Sstevel@tonic-gate return (PICL_INVALIDARG);
751*7c478bd9Sstevel@tonic-gate err = do_walk(rooth, classname, c_args, callback_fn);
752*7c478bd9Sstevel@tonic-gate if ((err == PICL_WALK_CONTINUE) || (err == PICL_WALK_TERMINATE))
753*7c478bd9Sstevel@tonic-gate return (PICL_SUCCESS);
754*7c478bd9Sstevel@tonic-gate return (err);
755*7c478bd9Sstevel@tonic-gate }
756*7c478bd9Sstevel@tonic-gate
757*7c478bd9Sstevel@tonic-gate /*
758*7c478bd9Sstevel@tonic-gate * This function gets propinfo and prop handle of the named property
759*7c478bd9Sstevel@tonic-gate */
760*7c478bd9Sstevel@tonic-gate int
picl_get_propinfo_by_name(picl_nodehdl_t nodeh,const char * prop_name,picl_propinfo_t * pinfo,picl_prophdl_t * proph)761*7c478bd9Sstevel@tonic-gate picl_get_propinfo_by_name(picl_nodehdl_t nodeh, const char *prop_name,
762*7c478bd9Sstevel@tonic-gate picl_propinfo_t *pinfo, picl_prophdl_t *proph)
763*7c478bd9Sstevel@tonic-gate {
764*7c478bd9Sstevel@tonic-gate int err;
765*7c478bd9Sstevel@tonic-gate picl_prophdl_t tmpproph;
766*7c478bd9Sstevel@tonic-gate picl_propinfo_t tmppinfo;
767*7c478bd9Sstevel@tonic-gate
768*7c478bd9Sstevel@tonic-gate err = picl_get_prop_by_name(nodeh, prop_name, &tmpproph);
769*7c478bd9Sstevel@tonic-gate if (err != PICL_SUCCESS)
770*7c478bd9Sstevel@tonic-gate return (err);
771*7c478bd9Sstevel@tonic-gate
772*7c478bd9Sstevel@tonic-gate err = picl_get_propinfo(tmpproph, &tmppinfo);
773*7c478bd9Sstevel@tonic-gate if (err != PICL_SUCCESS)
774*7c478bd9Sstevel@tonic-gate return (err);
775*7c478bd9Sstevel@tonic-gate
776*7c478bd9Sstevel@tonic-gate *proph = tmpproph;
777*7c478bd9Sstevel@tonic-gate *pinfo = tmppinfo;
778*7c478bd9Sstevel@tonic-gate return (PICL_SUCCESS);
779*7c478bd9Sstevel@tonic-gate }
780*7c478bd9Sstevel@tonic-gate
781*7c478bd9Sstevel@tonic-gate int
picl_get_node_by_path(const char * piclpath,picl_nodehdl_t * nodeh)782*7c478bd9Sstevel@tonic-gate picl_get_node_by_path(const char *piclpath, picl_nodehdl_t *nodeh)
783*7c478bd9Sstevel@tonic-gate {
784*7c478bd9Sstevel@tonic-gate door_arg_t darg;
785*7c478bd9Sstevel@tonic-gate picl_reqnodebypath_t req;
786*7c478bd9Sstevel@tonic-gate picl_retnodebypath_t out;
787*7c478bd9Sstevel@tonic-gate picl_service_t *ret;
788*7c478bd9Sstevel@tonic-gate int err;
789*7c478bd9Sstevel@tonic-gate
790*7c478bd9Sstevel@tonic-gate req.cnum = PICL_CNUM_NODEBYPATH;
791*7c478bd9Sstevel@tonic-gate req.psize = PATH_MAX;
792*7c478bd9Sstevel@tonic-gate if (strlen(piclpath) >= PATH_MAX)
793*7c478bd9Sstevel@tonic-gate return (PICL_VALUETOOBIG);
794*7c478bd9Sstevel@tonic-gate (void) strncpy(req.pathbuf, piclpath, PATH_MAX);
795*7c478bd9Sstevel@tonic-gate
796*7c478bd9Sstevel@tonic-gate err = trysend_req(&darg, &req, sizeof (req), NULL, 0, &out,
797*7c478bd9Sstevel@tonic-gate sizeof (out), SEND_REQ_TRYCOUNT);
798*7c478bd9Sstevel@tonic-gate if (err != PICL_SUCCESS)
799*7c478bd9Sstevel@tonic-gate return (err);
800*7c478bd9Sstevel@tonic-gate
801*7c478bd9Sstevel@tonic-gate /*LINTED*/
802*7c478bd9Sstevel@tonic-gate ret = (picl_service_t *)darg.rbuf;
803*7c478bd9Sstevel@tonic-gate *nodeh = ret->ret_nodebypath.nodeh;
804*7c478bd9Sstevel@tonic-gate if (darg.rbuf != (char *)&out)
805*7c478bd9Sstevel@tonic-gate (void) munmap(darg.rbuf, darg.rsize);
806*7c478bd9Sstevel@tonic-gate return (err);
807*7c478bd9Sstevel@tonic-gate }
808*7c478bd9Sstevel@tonic-gate
809*7c478bd9Sstevel@tonic-gate int
picl_find_node(picl_nodehdl_t rooth,char * pname,picl_prop_type_t ptype,void * pval,size_t valsize,picl_nodehdl_t * retnodeh)810*7c478bd9Sstevel@tonic-gate picl_find_node(picl_nodehdl_t rooth, char *pname, picl_prop_type_t ptype,
811*7c478bd9Sstevel@tonic-gate void *pval, size_t valsize, picl_nodehdl_t *retnodeh)
812*7c478bd9Sstevel@tonic-gate {
813*7c478bd9Sstevel@tonic-gate door_arg_t darg;
814*7c478bd9Sstevel@tonic-gate picl_reqfindnode_t *req;
815*7c478bd9Sstevel@tonic-gate picl_service_t *ret;
816*7c478bd9Sstevel@tonic-gate picl_retfindnode_t out;
817*7c478bd9Sstevel@tonic-gate int err;
818*7c478bd9Sstevel@tonic-gate
819*7c478bd9Sstevel@tonic-gate req = alloca(sizeof (picl_reqfindnode_t) + valsize);
820*7c478bd9Sstevel@tonic-gate req->cnum = PICL_CNUM_FINDNODE;
821*7c478bd9Sstevel@tonic-gate req->nodeh = rooth;
822*7c478bd9Sstevel@tonic-gate if (strlen(pname) >= PICL_PROPNAMELEN_MAX)
823*7c478bd9Sstevel@tonic-gate return (PICL_VALUETOOBIG);
824*7c478bd9Sstevel@tonic-gate (void) strncpy(req->propname, pname, PICL_PROPNAMELEN_MAX);
825*7c478bd9Sstevel@tonic-gate req->ptype = ptype;
826*7c478bd9Sstevel@tonic-gate req->valsize = (uint32_t)valsize;
827*7c478bd9Sstevel@tonic-gate if ((size_t)req->valsize != valsize)
828*7c478bd9Sstevel@tonic-gate return (PICL_VALUETOOBIG);
829*7c478bd9Sstevel@tonic-gate (void) memcpy(req->valbuf, pval, valsize);
830*7c478bd9Sstevel@tonic-gate
831*7c478bd9Sstevel@tonic-gate err = trysend_req(&darg, req, sizeof (picl_reqfindnode_t) + valsize,
832*7c478bd9Sstevel@tonic-gate NULL, 0, &out, sizeof (out), SEND_REQ_TRYCOUNT);
833*7c478bd9Sstevel@tonic-gate if (err != PICL_SUCCESS)
834*7c478bd9Sstevel@tonic-gate return (err);
835*7c478bd9Sstevel@tonic-gate
836*7c478bd9Sstevel@tonic-gate /*LINTED*/
837*7c478bd9Sstevel@tonic-gate ret = (picl_service_t *)darg.rbuf;
838*7c478bd9Sstevel@tonic-gate *retnodeh = ret->ret_findnode.rnodeh;
839*7c478bd9Sstevel@tonic-gate if (darg.rbuf != (char *)&out)
840*7c478bd9Sstevel@tonic-gate (void) munmap(darg.rbuf, darg.rsize);
841*7c478bd9Sstevel@tonic-gate return (err);
842*7c478bd9Sstevel@tonic-gate }
843*7c478bd9Sstevel@tonic-gate
844*7c478bd9Sstevel@tonic-gate int
picl_get_frutree_parent(picl_nodehdl_t devh,picl_nodehdl_t * fruh)845*7c478bd9Sstevel@tonic-gate picl_get_frutree_parent(picl_nodehdl_t devh, picl_nodehdl_t *fruh)
846*7c478bd9Sstevel@tonic-gate {
847*7c478bd9Sstevel@tonic-gate door_arg_t darg;
848*7c478bd9Sstevel@tonic-gate picl_reqfruparent_t req;
849*7c478bd9Sstevel@tonic-gate picl_retfruparent_t out;
850*7c478bd9Sstevel@tonic-gate picl_service_t *ret;
851*7c478bd9Sstevel@tonic-gate int err;
852*7c478bd9Sstevel@tonic-gate
853*7c478bd9Sstevel@tonic-gate req.cnum = PICL_CNUM_FRUTREEPARENT;
854*7c478bd9Sstevel@tonic-gate req.devh = devh;
855*7c478bd9Sstevel@tonic-gate
856*7c478bd9Sstevel@tonic-gate err = trysend_req(&darg, &req, sizeof (req), NULL, 0, &out,
857*7c478bd9Sstevel@tonic-gate sizeof (out), SEND_REQ_TRYCOUNT);
858*7c478bd9Sstevel@tonic-gate if (err != PICL_SUCCESS)
859*7c478bd9Sstevel@tonic-gate return (err);
860*7c478bd9Sstevel@tonic-gate
861*7c478bd9Sstevel@tonic-gate /*LINTED*/
862*7c478bd9Sstevel@tonic-gate ret = (picl_service_t *)darg.rbuf;
863*7c478bd9Sstevel@tonic-gate *fruh = ret->ret_fruparent.fruh;
864*7c478bd9Sstevel@tonic-gate if (darg.rbuf != (char *)&out)
865*7c478bd9Sstevel@tonic-gate (void) munmap(darg.rbuf, darg.rsize);
866*7c478bd9Sstevel@tonic-gate return (err);
867*7c478bd9Sstevel@tonic-gate }
868