1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
|
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright (c) 1999-2001 by Sun Microsystems, Inc.
* All rights reserved.
*/
#ifndef _PTREE_IMPL_H
#define _PTREE_IMPL_H
#pragma ident "%Z%%M% %I% %E% SMI"
#ifdef __cplusplus
extern "C" {
#endif
#include <synch.h>
#include <pthread.h>
typedef uint64_t picl_hdl_t;
/*
* Hash table size of Ptree and PICL tables
*/
#define HASH_TBL_SIZE 128
#define HASH_INDEX(s, x) ((int)((x) & ((s) - 1)))
/*
* Invalid PICL handle
*/
#define PICL_INVALID_PICLHDL (picl_hdl_t)0
/*
* Is the object PICLized?
*/
#define IS_PICLIZED(x) ((x)->picl_hdl != NULL)
/*
* A handle is a 64-bit quantity with the daemon's pid value in top 32 bits
* and the raw handle value in the lower 32 bits.
*/
#define HASH_VAL(x) ((x) & 0xFFFFFFFF)
#define GET_PID(x) ((x) >> 32)
#define MAKE_HANDLE(x, y) (((picl_hdl_t)(x) << 32) | (y))
/*
* Lock type when locking a node
*/
#define RDLOCK_NODE 1
#define WRLOCK_NODE 2
/*
* Property access operation
*/
#define PROP_READ 1
#define PROP_WRITE 2
/*
* PICL object type
*/
typedef struct picl_obj picl_obj_t;
/*
* Hash table structure
*/
struct hash_elem {
uint32_t hdl;
union {
void *data;
uint32_t ptreeh;
} u;
struct hash_elem *next;
};
typedef struct hash_elem hash_elem_t;
#define hash_obj u.data
#define hash_hdl u.ptreeh
typedef struct {
int hash_size;
hash_elem_t **tbl;
} hash_t;
/*
* Property expression list
*/
typedef struct prop_list {
char *pname;
char *pval;
struct prop_list *next;
} prop_list_t;
/*
* PICL property (scalar or a table entry)
*/
struct picl_prop {
ptree_propinfo_t info;
void *pvalue;
picl_obj_t *nodep; /* prop's node or table */
picl_obj_t *next_in_list;
picl_obj_t *next_by_row;
picl_obj_t *next_by_col;
};
typedef struct picl_prop picl_prop_t;
/*
* PICL node
*/
struct picl_node {
rwlock_t rwlock; /* protects properties */
picl_obj_t *firstprop;
char *classname;
picl_obj_t *parent; /* protected by ptree lock */
picl_obj_t *child; /* protected by ptree lock */
picl_obj_t *sibling; /* protected by ptree lock */
};
typedef struct picl_node picl_node_t;
/*
* PICL object types
*/
#define PICL_OBJ_NODE 0x1
#define PICL_OBJ_PROP 0x2
#define PICL_OBJ_TABLE 0x4
#define PICL_OBJ_TABLEENTRY 0x8
/*
* PICL object
*/
struct picl_obj {
uint32_t obj_type;
picl_hdl_t ptree_hdl; /* ptree handle */
picl_hdl_t picl_hdl; /* client handle */
union {
picl_node_t node;
picl_prop_t prop;
} u;
};
#define pinfo_ver u.prop.info.version
#define prop_type u.prop.info.piclinfo.type
#define prop_size u.prop.info.piclinfo.size
#define prop_mode u.prop.info.piclinfo.accessmode
#define prop_name u.prop.info.piclinfo.name
#define prop_val u.prop.pvalue
#define next_row u.prop.next_by_row
#define next_col u.prop.next_by_col
#define next_prop u.prop.next_in_list
#define table_prop u.prop.next_in_list
#define prop_node u.prop.nodep
#define prop_table u.prop.nodep
#define read_func u.prop.info.read
#define write_func u.prop.info.write
#define first_prop u.node.firstprop
#define node_lock u.node.rwlock
#define child_node u.node.child
#define sibling_node u.node.sibling
#define parent_node u.node.parent
#define node_classname u.node.classname
/*
* PICL event queue structures
*/
struct eventq {
const char *ename;
const void *earg;
size_t size;
void (*completion_handler)(char *ename, void *earg,
size_t size);
struct eventq *next;
};
typedef struct eventq eventq_t;
/*
* Event handler list
*/
struct eh_list {
char *ename;
void *cookie;
void (*evt_handler)(const char *ename, const void *earg,
size_t size, void *cookie);
short execflg;
short wakeupflg;
pthread_cond_t cv;
struct eh_list *next;
};
typedef struct eh_list evt_handler_t;
#define SUPER_USER 0
#define MIN(x, y) ((x) < (y) ? (x) : (y))
typedef struct picld_plugin_reg_list {
picld_plugin_reg_t reg;
struct picld_plugin_reg_list *next;
} picld_plugin_reg_list_t;
typedef struct picld_plinfo {
char *libname;
char *pathname;
void *dlh;
struct picld_plinfo *next;
} picld_plugin_desc_t;
extern int xptree_initialize(int);
extern void xptree_destroy(void);
extern int xptree_reinitialize(void);
extern int xptree_refresh_notify(uint32_t secs);
extern int cvt_picl2ptree(picl_hdl_t piclh, picl_hdl_t *ptreeh);
extern void cvt_ptree2picl(picl_hdl_t *vbuf);
extern int xptree_get_propinfo_by_name(picl_nodehdl_t nodeh,
const char *pname, ptree_propinfo_t *pinfo);
extern int xptree_get_propval_with_cred(picl_prophdl_t proph, void *valbuf,
size_t size, door_cred_t cred);
extern int xptree_get_propval_by_name_with_cred(picl_nodehdl_t nodeh,
const char *propname, void *valbuf, size_t sz,
door_cred_t cred);
extern int xptree_update_propval_with_cred(picl_prophdl_t proph,
const void *valbuf, size_t sz, door_cred_t cred);
extern int xptree_update_propval_by_name_with_cred(picl_nodehdl_t nodeh,
const char *propname, const void *valbuf, size_t sz,
door_cred_t cred);
/*
* PICL daemon verbose level flag
*/
extern int verbose_level;
extern void dbg_print(int level, const char *fmt, ...);
extern void dbg_exec(int level, void (*fn)(void *), void *arg);
#ifdef __cplusplus
}
#endif
#endif /* _PTREE_IMPL_H */
|