1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate * CDDL HEADER START
3*0Sstevel@tonic-gate *
4*0Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5*0Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
6*0Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance
7*0Sstevel@tonic-gate * with the License.
8*0Sstevel@tonic-gate *
9*0Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*0Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
11*0Sstevel@tonic-gate * See the License for the specific language governing permissions
12*0Sstevel@tonic-gate * and limitations under the License.
13*0Sstevel@tonic-gate *
14*0Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
15*0Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*0Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
17*0Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
18*0Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
19*0Sstevel@tonic-gate *
20*0Sstevel@tonic-gate * CDDL HEADER END
21*0Sstevel@tonic-gate */
22*0Sstevel@tonic-gate /*
23*0Sstevel@tonic-gate * Copyright (c) 1994, by Sun Microsytems, Inc.
24*0Sstevel@tonic-gate */
25*0Sstevel@tonic-gate
26*0Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
27*0Sstevel@tonic-gate
28*0Sstevel@tonic-gate #ifndef DEBUG
29*0Sstevel@tonic-gate #define NDEBUG 1
30*0Sstevel@tonic-gate #endif
31*0Sstevel@tonic-gate
32*0Sstevel@tonic-gate #ifdef _KERNEL
33*0Sstevel@tonic-gate #include <sys/param.h>
34*0Sstevel@tonic-gate #include <sys/systm.h>
35*0Sstevel@tonic-gate #include <sys/tnf_com.h>
36*0Sstevel@tonic-gate #include <sys/tnf_writer.h>
37*0Sstevel@tonic-gate #include <sys/debug.h>
38*0Sstevel@tonic-gate #include "tnf_types.h"
39*0Sstevel@tonic-gate #include "tnf_trace.h"
40*0Sstevel@tonic-gate #else /* _KERNEL */
41*0Sstevel@tonic-gate #include <stdlib.h>
42*0Sstevel@tonic-gate #include <string.h>
43*0Sstevel@tonic-gate #include <tnf/com.h>
44*0Sstevel@tonic-gate #include <tnf/writer.h>
45*0Sstevel@tonic-gate #include <assert.h>
46*0Sstevel@tonic-gate #include "tnf_types.h"
47*0Sstevel@tonic-gate #include <tnf_trace.h>
48*0Sstevel@tonic-gate #endif /* _KERNEL */
49*0Sstevel@tonic-gate
50*0Sstevel@tonic-gate /*
51*0Sstevel@tonic-gate * Defines
52*0Sstevel@tonic-gate */
53*0Sstevel@tonic-gate
54*0Sstevel@tonic-gate #ifdef _KERNEL
55*0Sstevel@tonic-gate #define TNF_ASSERT(expr) ASSERT(expr)
56*0Sstevel@tonic-gate #else
57*0Sstevel@tonic-gate #define TNF_ASSERT(expr) assert(expr)
58*0Sstevel@tonic-gate #endif
59*0Sstevel@tonic-gate
60*0Sstevel@tonic-gate /*
61*0Sstevel@tonic-gate * Local functions
62*0Sstevel@tonic-gate */
63*0Sstevel@tonic-gate
64*0Sstevel@tonic-gate static tnf_record_p tnf_root_tag_1(tnf_ops_t *, tnf_tag_data_t *);
65*0Sstevel@tonic-gate
66*0Sstevel@tonic-gate /*
67*0Sstevel@tonic-gate * TNF tag version 1
68*0Sstevel@tonic-gate */
69*0Sstevel@tonic-gate
70*0Sstevel@tonic-gate tnf_tag_version_t __tnf_tag_version_1_info = {
71*0Sstevel@tonic-gate sizeof (tnf_tag_version_t),
72*0Sstevel@tonic-gate sizeof (tnf_tag_data_t)
73*0Sstevel@tonic-gate };
74*0Sstevel@tonic-gate
75*0Sstevel@tonic-gate /*
76*0Sstevel@tonic-gate * Pure abstract types
77*0Sstevel@tonic-gate */
78*0Sstevel@tonic-gate
79*0Sstevel@tonic-gate TNF_ABSTRACT_TAG(tnf_inline);
80*0Sstevel@tonic-gate TNF_ABSTRACT_TAG(tnf_tagged);
81*0Sstevel@tonic-gate
82*0Sstevel@tonic-gate /*
83*0Sstevel@tonic-gate * Scalar types
84*0Sstevel@tonic-gate */
85*0Sstevel@tonic-gate
86*0Sstevel@tonic-gate static tnf_tag_data_t **std_scalar_properties[] = {
87*0Sstevel@tonic-gate &TAG_DATA(tnf_inline),
88*0Sstevel@tonic-gate &TAG_DATA(tnf_scalar),
89*0Sstevel@tonic-gate 0};
90*0Sstevel@tonic-gate
91*0Sstevel@tonic-gate tnf_tag_data_t ***tnf_scalar_properties = std_scalar_properties;
92*0Sstevel@tonic-gate
93*0Sstevel@tonic-gate TNF_SCALAR_TAG(tnf_scalar, 0, 0, TNF_UNKNOWN);
94*0Sstevel@tonic-gate
95*0Sstevel@tonic-gate TNF_STD_SCALAR_TAG(tnf_char, TNF_UNKNOWN); /* XXX */
96*0Sstevel@tonic-gate TNF_STD_SCALAR_TAG(tnf_int8, TNF_INT32);
97*0Sstevel@tonic-gate TNF_STD_SCALAR_TAG(tnf_uint8, TNF_UINT32);
98*0Sstevel@tonic-gate TNF_STD_SCALAR_TAG(tnf_int16, TNF_INT32);
99*0Sstevel@tonic-gate TNF_STD_SCALAR_TAG(tnf_uint16, TNF_UINT32);
100*0Sstevel@tonic-gate TNF_STD_SCALAR_TAG(tnf_int32, TNF_INT32);
101*0Sstevel@tonic-gate TNF_STD_SCALAR_TAG(tnf_uint32, TNF_UINT32);
102*0Sstevel@tonic-gate TNF_STD_SCALAR_TAG(tnf_int64, TNF_INT64);
103*0Sstevel@tonic-gate TNF_STD_SCALAR_TAG(tnf_uint64, TNF_UINT64);
104*0Sstevel@tonic-gate
105*0Sstevel@tonic-gate TNF_STD_SCALAR_TAG(tnf_float32, TNF_FLOAT32);
106*0Sstevel@tonic-gate TNF_STD_SCALAR_TAG(tnf_float64, TNF_FLOAT64);
107*0Sstevel@tonic-gate
108*0Sstevel@tonic-gate /*
109*0Sstevel@tonic-gate * Array types
110*0Sstevel@tonic-gate */
111*0Sstevel@tonic-gate
112*0Sstevel@tonic-gate static tnf_tag_data_t **array_properties[] = {
113*0Sstevel@tonic-gate &TAG_DATA(tnf_array),
114*0Sstevel@tonic-gate 0
115*0Sstevel@tonic-gate };
116*0Sstevel@tonic-gate static tnf_tag_data_t ***abstract_array_properties = array_properties;
117*0Sstevel@tonic-gate
118*0Sstevel@tonic-gate static tnf_tag_data_t **std_array_properties[] = {
119*0Sstevel@tonic-gate &TAG_DATA(tnf_array),
120*0Sstevel@tonic-gate &TAG_DATA(tnf_tagged),
121*0Sstevel@tonic-gate 0
122*0Sstevel@tonic-gate };
123*0Sstevel@tonic-gate /* Exported */
124*0Sstevel@tonic-gate tnf_tag_data_t ***tnf_array_properties = std_array_properties;
125*0Sstevel@tonic-gate
126*0Sstevel@tonic-gate /* Exported */
127*0Sstevel@tonic-gate tnf_tag_data_t **tnf_array_slots[] = {
128*0Sstevel@tonic-gate &TAG_DATA(tnf_tag),
129*0Sstevel@tonic-gate &TAG_DATA(tnf_self_size),
130*0Sstevel@tonic-gate 0
131*0Sstevel@tonic-gate };
132*0Sstevel@tonic-gate
133*0Sstevel@tonic-gate TNF_ARRAY_TAG(tnf_array, TNF_NULL, abstract_array_properties,
134*0Sstevel@tonic-gate TNF_NULL, TNF_UNKNOWN);
135*0Sstevel@tonic-gate
136*0Sstevel@tonic-gate TNF_STD_ARRAY_TAG(tnf_string, tnf_char, TNF_STRING);
137*0Sstevel@tonic-gate TNF_STD_ARRAY_TAG(tnf_type_array, tnf_type, TNF_ARRAY);
138*0Sstevel@tonic-gate TNF_STD_ARRAY_TAG(tnf_name_array, tnf_name, TNF_ARRAY);
139*0Sstevel@tonic-gate
140*0Sstevel@tonic-gate /*
141*0Sstevel@tonic-gate * Derived types
142*0Sstevel@tonic-gate */
143*0Sstevel@tonic-gate
144*0Sstevel@tonic-gate static tnf_tag_data_t **derived_properties[] = {
145*0Sstevel@tonic-gate &TAG_DATA(tnf_derived),
146*0Sstevel@tonic-gate 0
147*0Sstevel@tonic-gate };
148*0Sstevel@tonic-gate /* Exported */
149*0Sstevel@tonic-gate tnf_tag_data_t ***tnf_derived_properties = derived_properties;
150*0Sstevel@tonic-gate
151*0Sstevel@tonic-gate TNF_DERIVED_TAG(tnf_derived, TNF_NULL,
152*0Sstevel@tonic-gate tnf_derived_properties, TNF_NULL, TNF_NULL, TNF_UNKNOWN);
153*0Sstevel@tonic-gate
154*0Sstevel@tonic-gate TNF_STD_DERIVED_TAG(tnf_align, tnf_uint32,
155*0Sstevel@tonic-gate tnf_derived_properties, TNF_UINT32);
156*0Sstevel@tonic-gate
157*0Sstevel@tonic-gate TNF_STD_DERIVED_TAG(tnf_derived_base, tnf_type,
158*0Sstevel@tonic-gate tnf_derived_properties, TNF_OPAQUE);
159*0Sstevel@tonic-gate
160*0Sstevel@tonic-gate TNF_STD_DERIVED_TAG(tnf_element_type, tnf_type,
161*0Sstevel@tonic-gate tnf_derived_properties, TNF_OPAQUE);
162*0Sstevel@tonic-gate
163*0Sstevel@tonic-gate TNF_STD_DERIVED_TAG(tnf_header_size, tnf_uint32,
164*0Sstevel@tonic-gate tnf_derived_properties, TNF_UINT32);
165*0Sstevel@tonic-gate
166*0Sstevel@tonic-gate TNF_STD_DERIVED_TAG(tnf_name, tnf_string,
167*0Sstevel@tonic-gate tnf_derived_properties, TNF_STRING);
168*0Sstevel@tonic-gate
169*0Sstevel@tonic-gate #if defined(_LP64)
170*0Sstevel@tonic-gate
171*0Sstevel@tonic-gate TNF_STD_DERIVED_TAG(tnf_opaque, tnf_uint64,
172*0Sstevel@tonic-gate tnf_derived_properties, TNF_OPAQUE);
173*0Sstevel@tonic-gate
174*0Sstevel@tonic-gate #else
175*0Sstevel@tonic-gate
176*0Sstevel@tonic-gate TNF_STD_DERIVED_TAG(tnf_opaque, tnf_uint32,
177*0Sstevel@tonic-gate tnf_derived_properties, TNF_OPAQUE);
178*0Sstevel@tonic-gate
179*0Sstevel@tonic-gate #endif /* defined(_LP64) */
180*0Sstevel@tonic-gate
181*0Sstevel@tonic-gate TNF_STD_DERIVED_TAG(tnf_properties, tnf_type_array,
182*0Sstevel@tonic-gate tnf_derived_properties, TNF_ARRAY);
183*0Sstevel@tonic-gate
184*0Sstevel@tonic-gate TNF_STD_DERIVED_TAG(tnf_self_size, tnf_uint32,
185*0Sstevel@tonic-gate tnf_derived_properties, TNF_UINT32);
186*0Sstevel@tonic-gate
187*0Sstevel@tonic-gate TNF_STD_DERIVED_TAG(tnf_size, tnf_ulong,
188*0Sstevel@tonic-gate tnf_derived_properties, TNF_ULONG);
189*0Sstevel@tonic-gate
190*0Sstevel@tonic-gate TNF_STD_DERIVED_TAG(tnf_slot_names, tnf_name_array,
191*0Sstevel@tonic-gate tnf_derived_properties, TNF_ARRAY);
192*0Sstevel@tonic-gate
193*0Sstevel@tonic-gate TNF_STD_DERIVED_TAG(tnf_slot_types, tnf_type_array,
194*0Sstevel@tonic-gate tnf_derived_properties, TNF_ARRAY);
195*0Sstevel@tonic-gate
196*0Sstevel@tonic-gate TNF_STD_DERIVED_TAG(tnf_tag, tnf_type,
197*0Sstevel@tonic-gate tnf_derived_properties, TNF_OPAQUE);
198*0Sstevel@tonic-gate
199*0Sstevel@tonic-gate TNF_STD_DERIVED_TAG(tnf_tag_arg, tnf_tagged,
200*0Sstevel@tonic-gate tnf_derived_properties, TNF_OPAQUE);
201*0Sstevel@tonic-gate
202*0Sstevel@tonic-gate TNF_STD_DERIVED_TAG(tnf_type_size, tnf_uint32,
203*0Sstevel@tonic-gate tnf_derived_properties, TNF_UINT32);
204*0Sstevel@tonic-gate
205*0Sstevel@tonic-gate /*
206*0Sstevel@tonic-gate * Struct types
207*0Sstevel@tonic-gate */
208*0Sstevel@tonic-gate
209*0Sstevel@tonic-gate static tnf_tag_data_t **no_properties[] = { 0 };
210*0Sstevel@tonic-gate tnf_tag_data_t ***tnf_no_properties = no_properties;
211*0Sstevel@tonic-gate
212*0Sstevel@tonic-gate static tnf_tag_data_t **no_slots[] = { 0 };
213*0Sstevel@tonic-gate
214*0Sstevel@tonic-gate static tnf_tag_data_t **std_struct_properties[] = {
215*0Sstevel@tonic-gate &TAG_DATA(tnf_tagged),
216*0Sstevel@tonic-gate &TAG_DATA(tnf_struct),
217*0Sstevel@tonic-gate 0};
218*0Sstevel@tonic-gate /* Exported */
219*0Sstevel@tonic-gate tnf_tag_data_t ***tnf_struct_properties = std_struct_properties;
220*0Sstevel@tonic-gate
221*0Sstevel@tonic-gate TNF_STRUCT_TAG(tnf_struct, tnf_no_properties, no_slots, 0, 0);
222*0Sstevel@tonic-gate
223*0Sstevel@tonic-gate /*
224*0Sstevel@tonic-gate * File header - CAUTION - has to be in sync with com.h
225*0Sstevel@tonic-gate */
226*0Sstevel@tonic-gate
227*0Sstevel@tonic-gate static char *file_header_slot_names[] = {
228*0Sstevel@tonic-gate TNF_N_TAG,
229*0Sstevel@tonic-gate TNF_N_FILE_VERSION,
230*0Sstevel@tonic-gate TNF_N_FILE_HEADER_SIZE,
231*0Sstevel@tonic-gate TNF_N_FILE_LOGICAL_SIZE,
232*0Sstevel@tonic-gate TNF_N_BLOCK_HEADER_SIZE,
233*0Sstevel@tonic-gate TNF_N_BLOCK_SIZE,
234*0Sstevel@tonic-gate TNF_N_DIRECTORY_SIZE,
235*0Sstevel@tonic-gate TNF_N_BLOCK_COUNT,
236*0Sstevel@tonic-gate TNF_N_BLOCKS_VALID,
237*0Sstevel@tonic-gate /* XXX add writer-specific opaque slots here for reader */
238*0Sstevel@tonic-gate 0};
239*0Sstevel@tonic-gate
240*0Sstevel@tonic-gate static tnf_tag_data_t **file_header_slots[] = {
241*0Sstevel@tonic-gate &TAG_DATA(tnf_tag), /* tag */
242*0Sstevel@tonic-gate &TAG_DATA(tnf_uint32), /* file_version */
243*0Sstevel@tonic-gate &TAG_DATA(tnf_uint32), /* file_header_size */
244*0Sstevel@tonic-gate &TAG_DATA(tnf_uint32), /* file_logical_size */
245*0Sstevel@tonic-gate &TAG_DATA(tnf_uint32), /* block_header_size */
246*0Sstevel@tonic-gate &TAG_DATA(tnf_uint32), /* block_size */
247*0Sstevel@tonic-gate &TAG_DATA(tnf_uint32), /* directory_size */
248*0Sstevel@tonic-gate &TAG_DATA(tnf_uint32), /* block_count */
249*0Sstevel@tonic-gate &TAG_DATA(tnf_uint32), /* blocks_valid */
250*0Sstevel@tonic-gate /* XXX add writer-specific opaque slots here for reader */
251*0Sstevel@tonic-gate 0};
252*0Sstevel@tonic-gate
253*0Sstevel@tonic-gate /* size of tnf_file_header has the size of the magic number subtracted */
254*0Sstevel@tonic-gate TNF_STD_STRUCT_TAG(tnf_file_header,
255*0Sstevel@tonic-gate file_header_slots,
256*0Sstevel@tonic-gate file_header_slot_names,
257*0Sstevel@tonic-gate sizeof (tnf_buf_file_header_t) - sizeof (tnf_uint32_t));
258*0Sstevel@tonic-gate
259*0Sstevel@tonic-gate /*
260*0Sstevel@tonic-gate * Block header - CAUTION - has to be in sync with com.h
261*0Sstevel@tonic-gate */
262*0Sstevel@tonic-gate
263*0Sstevel@tonic-gate static char *block_header_slot_names[] = {
264*0Sstevel@tonic-gate TNF_N_TAG,
265*0Sstevel@tonic-gate TNF_N_GENERATION,
266*0Sstevel@tonic-gate TNF_N_BYTES_VALID,
267*0Sstevel@tonic-gate "A_lock", /* XXX */
268*0Sstevel@tonic-gate "B_lock", /* XXX */
269*0Sstevel@tonic-gate "next_block", /* XXX */
270*0Sstevel@tonic-gate 0};
271*0Sstevel@tonic-gate
272*0Sstevel@tonic-gate static tnf_tag_data_t **block_header_slots[] = {
273*0Sstevel@tonic-gate &TAG_DATA(tnf_tag), /* tag */
274*0Sstevel@tonic-gate &TAG_DATA(tnf_uint32), /* generation */
275*0Sstevel@tonic-gate &TAG_DATA(tnf_uint16), /* bytes_valid */
276*0Sstevel@tonic-gate &TAG_DATA(tnf_uint8), /* A_lock */
277*0Sstevel@tonic-gate &TAG_DATA(tnf_uint8), /* B_lock */
278*0Sstevel@tonic-gate &TAG_DATA(tnf_opaque), /* next_block */
279*0Sstevel@tonic-gate 0};
280*0Sstevel@tonic-gate
281*0Sstevel@tonic-gate TNF_STD_STRUCT_TAG(tnf_block_header,
282*0Sstevel@tonic-gate block_header_slots,
283*0Sstevel@tonic-gate block_header_slot_names,
284*0Sstevel@tonic-gate sizeof (tnf_block_header_t));
285*0Sstevel@tonic-gate
286*0Sstevel@tonic-gate /*
287*0Sstevel@tonic-gate * Metatypes
288*0Sstevel@tonic-gate */
289*0Sstevel@tonic-gate
290*0Sstevel@tonic-gate static tnf_tag_data_t **type_properties[] = {
291*0Sstevel@tonic-gate &TAG_DATA(tnf_tagged),
292*0Sstevel@tonic-gate &TAG_DATA(tnf_struct),
293*0Sstevel@tonic-gate &TAG_DATA(tnf_type),
294*0Sstevel@tonic-gate 0};
295*0Sstevel@tonic-gate /* Exported */
296*0Sstevel@tonic-gate tnf_tag_data_t ***tnf_type_properties = type_properties;
297*0Sstevel@tonic-gate
298*0Sstevel@tonic-gate static tnf_tag_data_t **type_slots[] = {
299*0Sstevel@tonic-gate &TAG_DATA(tnf_tag),
300*0Sstevel@tonic-gate &TAG_DATA(tnf_name),
301*0Sstevel@tonic-gate &TAG_DATA(tnf_properties),
302*0Sstevel@tonic-gate 0};
303*0Sstevel@tonic-gate
304*0Sstevel@tonic-gate TNF_METATAG(tnf_type, tnf_type_properties, type_slots, tnf_struct_tag_1);
305*0Sstevel@tonic-gate
306*0Sstevel@tonic-gate static tnf_tag_data_t **array_type_slots[] = {
307*0Sstevel@tonic-gate &TAG_DATA(tnf_tag),
308*0Sstevel@tonic-gate &TAG_DATA(tnf_name),
309*0Sstevel@tonic-gate &TAG_DATA(tnf_properties),
310*0Sstevel@tonic-gate &TAG_DATA(tnf_slot_types),
311*0Sstevel@tonic-gate &TAG_DATA(tnf_header_size),
312*0Sstevel@tonic-gate &TAG_DATA(tnf_element_type),
313*0Sstevel@tonic-gate 0};
314*0Sstevel@tonic-gate
315*0Sstevel@tonic-gate TNF_METATAG(tnf_array_type, tnf_type_properties,
316*0Sstevel@tonic-gate array_type_slots, tnf_struct_tag_1);
317*0Sstevel@tonic-gate
318*0Sstevel@tonic-gate static tnf_tag_data_t **derived_type_slots[] = {
319*0Sstevel@tonic-gate &TAG_DATA(tnf_tag),
320*0Sstevel@tonic-gate &TAG_DATA(tnf_name),
321*0Sstevel@tonic-gate &TAG_DATA(tnf_properties),
322*0Sstevel@tonic-gate &TAG_DATA(tnf_derived_base),
323*0Sstevel@tonic-gate 0};
324*0Sstevel@tonic-gate
325*0Sstevel@tonic-gate TNF_METATAG(tnf_derived_type, tnf_type_properties,
326*0Sstevel@tonic-gate derived_type_slots, tnf_struct_tag_1);
327*0Sstevel@tonic-gate
328*0Sstevel@tonic-gate static tnf_tag_data_t **scalar_type_slots[] = {
329*0Sstevel@tonic-gate &TAG_DATA(tnf_tag),
330*0Sstevel@tonic-gate &TAG_DATA(tnf_name),
331*0Sstevel@tonic-gate &TAG_DATA(tnf_properties),
332*0Sstevel@tonic-gate &TAG_DATA(tnf_type_size),
333*0Sstevel@tonic-gate &TAG_DATA(tnf_align),
334*0Sstevel@tonic-gate 0};
335*0Sstevel@tonic-gate
336*0Sstevel@tonic-gate TNF_METATAG(tnf_scalar_type, tnf_type_properties,
337*0Sstevel@tonic-gate scalar_type_slots, tnf_struct_tag_1);
338*0Sstevel@tonic-gate
339*0Sstevel@tonic-gate static tnf_tag_data_t **struct_type_slots[] = {
340*0Sstevel@tonic-gate &TAG_DATA(tnf_tag),
341*0Sstevel@tonic-gate &TAG_DATA(tnf_name),
342*0Sstevel@tonic-gate &TAG_DATA(tnf_properties),
343*0Sstevel@tonic-gate &TAG_DATA(tnf_slot_types),
344*0Sstevel@tonic-gate &TAG_DATA(tnf_type_size),
345*0Sstevel@tonic-gate &TAG_DATA(tnf_slot_names),
346*0Sstevel@tonic-gate 0};
347*0Sstevel@tonic-gate
348*0Sstevel@tonic-gate TNF_METATAG(tnf_struct_type, tnf_type_properties,
349*0Sstevel@tonic-gate struct_type_slots, tnf_root_tag_1);
350*0Sstevel@tonic-gate
351*0Sstevel@tonic-gate
352*0Sstevel@tonic-gate /*
353*0Sstevel@tonic-gate * Generic tnf reference - does checking on whether destination is
354*0Sstevel@tonic-gate * a permanent block or not
355*0Sstevel@tonic-gate */
356*0Sstevel@tonic-gate
357*0Sstevel@tonic-gate #ifdef _KERNEL
358*0Sstevel@tonic-gate
359*0Sstevel@tonic-gate /*ARGSUSED0*/
360*0Sstevel@tonic-gate tnf_ref32_t
tnf_ref32_1(tnf_ops_t * ops,tnf_record_p item,tnf_record_p reference)361*0Sstevel@tonic-gate tnf_ref32_1(tnf_ops_t *ops, tnf_record_p item, tnf_record_p reference)
362*0Sstevel@tonic-gate {
363*0Sstevel@tonic-gate tnf_ref32_t offset_delta, gen_delta;
364*0Sstevel@tonic-gate tnf_block_header_t *dest_header_p, *src_header_p;
365*0Sstevel@tonic-gate tnf_ref32_t result;
366*0Sstevel@tonic-gate unsigned int offset_shift =
367*0Sstevel@tonic-gate /* LINTED pointer cast may result in improper alignment */
368*0Sstevel@tonic-gate ((tnf_buf_file_header_t *)tnf_buf)->com.file_log_size;
369*0Sstevel@tonic-gate
370*0Sstevel@tonic-gate dest_header_p = (tnf_block_header_t *)
371*0Sstevel@tonic-gate ((uintptr_t)item & TNF_BLOCK_MASK);
372*0Sstevel@tonic-gate
373*0Sstevel@tonic-gate if (((char *)dest_header_p < (tnf_buf + TNF_DIRECTORY_SIZE)) ||
374*0Sstevel@tonic-gate (dest_header_p->generation == TNF_TAG_GENERATION_NUM)) {
375*0Sstevel@tonic-gate /* reference to a permanent block */
376*0Sstevel@tonic-gate /* LINTED ast from 64-bit integer to 32-bit integer */
377*0Sstevel@tonic-gate offset_delta = (tnf_ref32_t)(item - tnf_buf);
378*0Sstevel@tonic-gate
379*0Sstevel@tonic-gate return (TNF_REF32_MAKE_PERMANENT(offset_delta));
380*0Sstevel@tonic-gate } else {
381*0Sstevel@tonic-gate /* reference to a reclaimable block */
382*0Sstevel@tonic-gate /* LINTED ast from 64-bit integer to 32-bit integer */
383*0Sstevel@tonic-gate offset_delta = (tnf_ref32_t)(item - reference);
384*0Sstevel@tonic-gate
385*0Sstevel@tonic-gate src_header_p = (tnf_block_header_t *)
386*0Sstevel@tonic-gate ((uintptr_t)reference & TNF_BLOCK_MASK);
387*0Sstevel@tonic-gate gen_delta = dest_header_p->generation -
388*0Sstevel@tonic-gate src_header_p->generation;
389*0Sstevel@tonic-gate
390*0Sstevel@tonic-gate result = (gen_delta << offset_shift) + offset_delta;
391*0Sstevel@tonic-gate return (TNF_REF32_MAKE_RECLAIMABLE(result));
392*0Sstevel@tonic-gate }
393*0Sstevel@tonic-gate }
394*0Sstevel@tonic-gate
395*0Sstevel@tonic-gate #else
396*0Sstevel@tonic-gate
397*0Sstevel@tonic-gate /*ARGSUSED0*/
398*0Sstevel@tonic-gate tnf_ref32_t
tnf_ref32_1(tnf_ops_t * ops,tnf_record_p item,tnf_record_p reference)399*0Sstevel@tonic-gate tnf_ref32_1(tnf_ops_t *ops, tnf_record_p item, tnf_record_p reference)
400*0Sstevel@tonic-gate {
401*0Sstevel@tonic-gate volatile char *file_start = _tnfw_b_control->tnf_buffer;
402*0Sstevel@tonic-gate tnf_ref32_t offset_delta, gen_delta;
403*0Sstevel@tonic-gate tnf_block_header_t *dest_header_p, *src_header_p;
404*0Sstevel@tonic-gate tnf_ref32_t result;
405*0Sstevel@tonic-gate unsigned int offset_shift =
406*0Sstevel@tonic-gate /* LINTED pointer cast may result in improper alignment */
407*0Sstevel@tonic-gate ((tnf_buf_file_header_t *)file_start)->com.file_log_size;
408*0Sstevel@tonic-gate
409*0Sstevel@tonic-gate dest_header_p = (tnf_block_header_t *)
410*0Sstevel@tonic-gate ((uintptr_t)item & TNF_BLOCK_MASK);
411*0Sstevel@tonic-gate
412*0Sstevel@tonic-gate if (((char *)dest_header_p < (file_start + TNFW_B_FW_ZONE)) ||
413*0Sstevel@tonic-gate (dest_header_p->generation == TNF_TAG_GENERATION_NUM)) {
414*0Sstevel@tonic-gate /* reference to a permanent block */
415*0Sstevel@tonic-gate /* LINTED ast from 64-bit integer to 32-bit integer */
416*0Sstevel@tonic-gate offset_delta = (tnf_ref32_t)(item - (tnf_record_p) file_start);
417*0Sstevel@tonic-gate
418*0Sstevel@tonic-gate return (TNF_REF32_MAKE_PERMANENT(offset_delta));
419*0Sstevel@tonic-gate } else {
420*0Sstevel@tonic-gate /* reference to a reclaimable block */
421*0Sstevel@tonic-gate /* LINTED ast from 64-bit integer to 32-bit integer */
422*0Sstevel@tonic-gate offset_delta = (tnf_ref32_t)(item - reference);
423*0Sstevel@tonic-gate
424*0Sstevel@tonic-gate src_header_p = (tnf_block_header_t *)
425*0Sstevel@tonic-gate ((uintptr_t)reference & TNF_BLOCK_MASK);
426*0Sstevel@tonic-gate gen_delta = dest_header_p->generation -
427*0Sstevel@tonic-gate src_header_p->generation;
428*0Sstevel@tonic-gate
429*0Sstevel@tonic-gate result = (gen_delta << offset_shift) + offset_delta;
430*0Sstevel@tonic-gate return (TNF_REF32_MAKE_RECLAIMABLE(result));
431*0Sstevel@tonic-gate }
432*0Sstevel@tonic-gate }
433*0Sstevel@tonic-gate
434*0Sstevel@tonic-gate #endif
435*0Sstevel@tonic-gate
436*0Sstevel@tonic-gate /*
437*0Sstevel@tonic-gate * Tag descriptors
438*0Sstevel@tonic-gate */
439*0Sstevel@tonic-gate
440*0Sstevel@tonic-gate /*
441*0Sstevel@tonic-gate * Write instances of tnf_type
442*0Sstevel@tonic-gate */
443*0Sstevel@tonic-gate
444*0Sstevel@tonic-gate tnf_record_p
tnf_abstract_tag_1(tnf_ops_t * ops,tnf_tag_data_t * tag_data)445*0Sstevel@tonic-gate tnf_abstract_tag_1(tnf_ops_t *ops, tnf_tag_data_t *tag_data)
446*0Sstevel@tonic-gate {
447*0Sstevel@tonic-gate tnf_tag_data_t *metatag_data;
448*0Sstevel@tonic-gate tnf_record_p metatag_index;
449*0Sstevel@tonic-gate tnf_type_prototype_t *buffer;
450*0Sstevel@tonic-gate enum tnf_alloc_mode saved_mode;
451*0Sstevel@tonic-gate
452*0Sstevel@tonic-gate saved_mode = ops->mode;
453*0Sstevel@tonic-gate ops->mode = TNF_ALLOC_FIXED;
454*0Sstevel@tonic-gate /* LINTED assignment of 32-bit integer to 8-bit integer */
455*0Sstevel@tonic-gate ALLOC(ops, sizeof (*buffer), buffer, tag_data->tag_index,
456*0Sstevel@tonic-gate saved_mode);
457*0Sstevel@tonic-gate
458*0Sstevel@tonic-gate metatag_data = TAG_DATA(tnf_type);
459*0Sstevel@tonic-gate metatag_index = metatag_data->tag_index ? metatag_data->tag_index :
460*0Sstevel@tonic-gate metatag_data->tag_desc(ops, metatag_data);
461*0Sstevel@tonic-gate
462*0Sstevel@tonic-gate ASSIGN(buffer, tag, metatag_index);
463*0Sstevel@tonic-gate ASSIGN(buffer, name, tag_data->tag_name);
464*0Sstevel@tonic-gate ASSIGN(buffer, properties, tag_data->tag_props);
465*0Sstevel@tonic-gate /* LINTED assignment of 32-bit integer to 8-bit integer */
466*0Sstevel@tonic-gate ops->mode = saved_mode;
467*0Sstevel@tonic-gate return (tag_data->tag_index);
468*0Sstevel@tonic-gate }
469*0Sstevel@tonic-gate
470*0Sstevel@tonic-gate /*
471*0Sstevel@tonic-gate * Write instances of tnf_scalar_type
472*0Sstevel@tonic-gate */
473*0Sstevel@tonic-gate
474*0Sstevel@tonic-gate tnf_record_p
tnf_scalar_tag_1(tnf_ops_t * ops,tnf_tag_data_t * tag_data)475*0Sstevel@tonic-gate tnf_scalar_tag_1(tnf_ops_t *ops, tnf_tag_data_t *tag_data)
476*0Sstevel@tonic-gate {
477*0Sstevel@tonic-gate tnf_tag_data_t *metatag_data;
478*0Sstevel@tonic-gate tnf_record_p metatag_index;
479*0Sstevel@tonic-gate enum tnf_alloc_mode saved_mode;
480*0Sstevel@tonic-gate tnf_scalar_type_prototype_t *buffer;
481*0Sstevel@tonic-gate
482*0Sstevel@tonic-gate saved_mode = ops->mode;
483*0Sstevel@tonic-gate ops->mode = TNF_ALLOC_FIXED;
484*0Sstevel@tonic-gate /* LINTED assignment of 32-bit integer to 8-bit integer */
485*0Sstevel@tonic-gate ALLOC(ops, sizeof (*buffer), buffer, tag_data->tag_index,
486*0Sstevel@tonic-gate saved_mode);
487*0Sstevel@tonic-gate
488*0Sstevel@tonic-gate metatag_data = TAG_DATA(tnf_scalar_type);
489*0Sstevel@tonic-gate metatag_index = metatag_data->tag_index ? metatag_data->tag_index :
490*0Sstevel@tonic-gate metatag_data->tag_desc(ops, metatag_data);
491*0Sstevel@tonic-gate
492*0Sstevel@tonic-gate ASSIGN(buffer, tag, metatag_index);
493*0Sstevel@tonic-gate ASSIGN(buffer, name, tag_data->tag_name);
494*0Sstevel@tonic-gate ASSIGN(buffer, properties, tag_data->tag_props);
495*0Sstevel@tonic-gate /* LINTED assignment of 32-bit integer to 8-bit integer */
496*0Sstevel@tonic-gate ASSIGN(buffer, type_size, tag_data->tag_size);
497*0Sstevel@tonic-gate /* LINTED assignment of 64-bit integer to 32-bit integer */
498*0Sstevel@tonic-gate ASSIGN(buffer, align, tag_data->tag_align);
499*0Sstevel@tonic-gate
500*0Sstevel@tonic-gate /* LINTED assignment of 32-bit integer to 8-bit integer */
501*0Sstevel@tonic-gate ops->mode = saved_mode;
502*0Sstevel@tonic-gate return (tag_data->tag_index);
503*0Sstevel@tonic-gate }
504*0Sstevel@tonic-gate
505*0Sstevel@tonic-gate /*
506*0Sstevel@tonic-gate * Write instances of tnf_derived_type
507*0Sstevel@tonic-gate */
508*0Sstevel@tonic-gate
509*0Sstevel@tonic-gate tnf_record_p
tnf_derived_tag_1(tnf_ops_t * ops,tnf_tag_data_t * tag_data)510*0Sstevel@tonic-gate tnf_derived_tag_1(tnf_ops_t *ops, tnf_tag_data_t *tag_data)
511*0Sstevel@tonic-gate {
512*0Sstevel@tonic-gate tnf_tag_data_t *metatag_data;
513*0Sstevel@tonic-gate tnf_record_p metatag_index;
514*0Sstevel@tonic-gate enum tnf_alloc_mode saved_mode;
515*0Sstevel@tonic-gate tnf_derived_type_prototype_t *buffer;
516*0Sstevel@tonic-gate
517*0Sstevel@tonic-gate saved_mode = ops->mode;
518*0Sstevel@tonic-gate ops->mode = TNF_ALLOC_FIXED;
519*0Sstevel@tonic-gate /* LINTED assignment of 32-bit integer to 8-bit integer */
520*0Sstevel@tonic-gate ALLOC(ops, sizeof (*buffer), buffer, tag_data->tag_index,
521*0Sstevel@tonic-gate saved_mode);
522*0Sstevel@tonic-gate
523*0Sstevel@tonic-gate metatag_data = TAG_DATA(tnf_derived_type);
524*0Sstevel@tonic-gate metatag_index = metatag_data->tag_index ? metatag_data->tag_index:
525*0Sstevel@tonic-gate metatag_data->tag_desc(ops, metatag_data);
526*0Sstevel@tonic-gate
527*0Sstevel@tonic-gate ASSIGN(buffer, tag, metatag_index);
528*0Sstevel@tonic-gate ASSIGN(buffer, name, tag_data->tag_name);
529*0Sstevel@tonic-gate ASSIGN(buffer, properties, tag_data->tag_props);
530*0Sstevel@tonic-gate ASSIGN(buffer, derived_base, tag_data->tag_base);
531*0Sstevel@tonic-gate /* LINTED assignment of 32-bit integer to 8-bit integer */
532*0Sstevel@tonic-gate ops->mode = saved_mode;
533*0Sstevel@tonic-gate return (tag_data->tag_index);
534*0Sstevel@tonic-gate }
535*0Sstevel@tonic-gate
536*0Sstevel@tonic-gate /*
537*0Sstevel@tonic-gate * Write instances of tnf_struct_type (except root)
538*0Sstevel@tonic-gate */
539*0Sstevel@tonic-gate
540*0Sstevel@tonic-gate tnf_record_p
tnf_struct_tag_1(tnf_ops_t * ops,tnf_tag_data_t * tag_data)541*0Sstevel@tonic-gate tnf_struct_tag_1(tnf_ops_t *ops, tnf_tag_data_t *tag_data)
542*0Sstevel@tonic-gate {
543*0Sstevel@tonic-gate tnf_tag_data_t *metatag_data;
544*0Sstevel@tonic-gate tnf_record_p metatag_index;
545*0Sstevel@tonic-gate enum tnf_alloc_mode saved_mode;
546*0Sstevel@tonic-gate tnf_struct_type_prototype_t *buffer;
547*0Sstevel@tonic-gate
548*0Sstevel@tonic-gate saved_mode = ops->mode;
549*0Sstevel@tonic-gate ops->mode = TNF_ALLOC_FIXED;
550*0Sstevel@tonic-gate /* LINTED assignment of 32-bit integer to 8-bit integer */
551*0Sstevel@tonic-gate ALLOC(ops, sizeof (*buffer), buffer, tag_data->tag_index,
552*0Sstevel@tonic-gate saved_mode);
553*0Sstevel@tonic-gate
554*0Sstevel@tonic-gate metatag_data = TAG_DATA(tnf_struct_type);
555*0Sstevel@tonic-gate metatag_index = metatag_data->tag_index ? metatag_data->tag_index:
556*0Sstevel@tonic-gate metatag_data->tag_desc(ops, metatag_data);
557*0Sstevel@tonic-gate
558*0Sstevel@tonic-gate ASSIGN(buffer, tag, metatag_index);
559*0Sstevel@tonic-gate ASSIGN(buffer, name, tag_data->tag_name);
560*0Sstevel@tonic-gate ASSIGN(buffer, properties, tag_data->tag_props);
561*0Sstevel@tonic-gate ASSIGN(buffer, slot_types, tag_data->tag_slots);
562*0Sstevel@tonic-gate /* LINTED assignment of 64-bit integer to 32-bit integer */
563*0Sstevel@tonic-gate ASSIGN(buffer, type_size, tag_data->tag_size);
564*0Sstevel@tonic-gate ASSIGN(buffer, slot_names, tag_data->tag_slot_names);
565*0Sstevel@tonic-gate /* LINTED assignment of 32-bit integer to 8-bit integer */
566*0Sstevel@tonic-gate ops->mode = saved_mode;
567*0Sstevel@tonic-gate return (tag_data->tag_index);
568*0Sstevel@tonic-gate }
569*0Sstevel@tonic-gate
570*0Sstevel@tonic-gate /*
571*0Sstevel@tonic-gate * Write instances of tnf_array_type
572*0Sstevel@tonic-gate */
573*0Sstevel@tonic-gate
574*0Sstevel@tonic-gate tnf_record_p
tnf_array_tag_1(tnf_ops_t * ops,tnf_tag_data_t * tag_data)575*0Sstevel@tonic-gate tnf_array_tag_1(tnf_ops_t *ops, tnf_tag_data_t *tag_data)
576*0Sstevel@tonic-gate {
577*0Sstevel@tonic-gate tnf_tag_data_t *metatag_data;
578*0Sstevel@tonic-gate tnf_record_p metatag_index;
579*0Sstevel@tonic-gate enum tnf_alloc_mode saved_mode;
580*0Sstevel@tonic-gate tnf_array_type_prototype_t *buffer;
581*0Sstevel@tonic-gate
582*0Sstevel@tonic-gate saved_mode = ops->mode;
583*0Sstevel@tonic-gate ops->mode = TNF_ALLOC_FIXED;
584*0Sstevel@tonic-gate /* LINTED assignment of 32-bit integer to 8-bit integer */
585*0Sstevel@tonic-gate ALLOC(ops, sizeof (*buffer), buffer, tag_data->tag_index,
586*0Sstevel@tonic-gate saved_mode);
587*0Sstevel@tonic-gate
588*0Sstevel@tonic-gate metatag_data = TAG_DATA(tnf_array_type);
589*0Sstevel@tonic-gate metatag_index = metatag_data->tag_index ? metatag_data->tag_index :
590*0Sstevel@tonic-gate metatag_data->tag_desc(ops, metatag_data);
591*0Sstevel@tonic-gate
592*0Sstevel@tonic-gate ASSIGN(buffer, tag, metatag_index);
593*0Sstevel@tonic-gate ASSIGN(buffer, name, tag_data->tag_name);
594*0Sstevel@tonic-gate ASSIGN(buffer, properties, tag_data->tag_props);
595*0Sstevel@tonic-gate ASSIGN(buffer, slot_types, tag_data->tag_slots);
596*0Sstevel@tonic-gate /* LINTED assignment of 64-bit integer to 32-bit integer */
597*0Sstevel@tonic-gate ASSIGN(buffer, header_size, tag_data->tag_size);
598*0Sstevel@tonic-gate ASSIGN(buffer, element_type, tag_data->tag_base);
599*0Sstevel@tonic-gate /* LINTED assignment of 32-bit integer to 8-bit integer */
600*0Sstevel@tonic-gate ops->mode = saved_mode;
601*0Sstevel@tonic-gate return (tag_data->tag_index);
602*0Sstevel@tonic-gate }
603*0Sstevel@tonic-gate
604*0Sstevel@tonic-gate /*
605*0Sstevel@tonic-gate * Write the root metatype, and some critical bootstrap types
606*0Sstevel@tonic-gate */
607*0Sstevel@tonic-gate
608*0Sstevel@tonic-gate static tnf_record_p
tnf_root_tag_1(tnf_ops_t * ops,tnf_tag_data_t * tag_data)609*0Sstevel@tonic-gate tnf_root_tag_1(tnf_ops_t *ops, tnf_tag_data_t *tag_data)
610*0Sstevel@tonic-gate {
611*0Sstevel@tonic-gate enum tnf_alloc_mode saved_mode;
612*0Sstevel@tonic-gate tnf_tag_t *fw_p;
613*0Sstevel@tonic-gate tnf_struct_type_prototype_t *buffer;
614*0Sstevel@tonic-gate
615*0Sstevel@tonic-gate saved_mode = ops->mode;
616*0Sstevel@tonic-gate ops->mode = TNF_ALLOC_FIXED;
617*0Sstevel@tonic-gate /* LINTED assignment of 32-bit integer to 8-bit integer */
618*0Sstevel@tonic-gate ALLOC(ops, sizeof (*buffer), buffer, tag_data->tag_index,
619*0Sstevel@tonic-gate saved_mode);
620*0Sstevel@tonic-gate
621*0Sstevel@tonic-gate /*
622*0Sstevel@tonic-gate * update the root forwarding pointer to point to this root
623*0Sstevel@tonic-gate * CAUTION: Do this before anything else...
624*0Sstevel@tonic-gate */
625*0Sstevel@tonic-gate
626*0Sstevel@tonic-gate #ifdef _KERNEL
627*0Sstevel@tonic-gate /* LINTED pointer cast may result in improper alignment */
628*0Sstevel@tonic-gate fw_p = (tnf_tag_t *)(tnf_buf + TNF_DIRENT_ROOT);
629*0Sstevel@tonic-gate *fw_p = tnf_ref32(ops, tag_data->tag_index, (tnf_record_p)fw_p);
630*0Sstevel@tonic-gate tag_data->tag_index = (tnf_record_p)fw_p;
631*0Sstevel@tonic-gate #else
632*0Sstevel@tonic-gate /* LINTED pointer cast may result in improper alignment */
633*0Sstevel@tonic-gate fw_p = (tnf_tag_t *)_tnf_buf_headers_p->fw_root;
634*0Sstevel@tonic-gate if (fw_p) {
635*0Sstevel@tonic-gate *fw_p = tnf_ref32(ops, tag_data->tag_index,
636*0Sstevel@tonic-gate (tnf_record_p) fw_p);
637*0Sstevel@tonic-gate tag_data->tag_index = (tnf_record_p)fw_p;
638*0Sstevel@tonic-gate }
639*0Sstevel@tonic-gate #endif
640*0Sstevel@tonic-gate
641*0Sstevel@tonic-gate #ifdef _KERNEL
642*0Sstevel@tonic-gate /* LINTED constant truncated by assignment */
643*0Sstevel@tonic-gate buffer->tag = TNF_ROOT_TAG;
644*0Sstevel@tonic-gate #else
645*0Sstevel@tonic-gate ASSIGN(buffer, tag, tag_data->tag_index); /* ROOT */
646*0Sstevel@tonic-gate #endif
647*0Sstevel@tonic-gate ASSIGN(buffer, name, tag_data->tag_name);
648*0Sstevel@tonic-gate ASSIGN(buffer, properties, tag_data->tag_props);
649*0Sstevel@tonic-gate ASSIGN(buffer, slot_types, tag_data->tag_slots);
650*0Sstevel@tonic-gate /* LINTED assignment of 64-bit integer to 32-bit integer */
651*0Sstevel@tonic-gate ASSIGN(buffer, type_size, tag_data->tag_size);
652*0Sstevel@tonic-gate ASSIGN(buffer, slot_names, tag_data->tag_slot_names);
653*0Sstevel@tonic-gate
654*0Sstevel@tonic-gate /*
655*0Sstevel@tonic-gate * Write some additional bootstrap types
656*0Sstevel@tonic-gate */
657*0Sstevel@tonic-gate {
658*0Sstevel@tonic-gate static tnf_tag_data_t *bootstrap_types[] = {
659*0Sstevel@tonic-gate &_TAG_DATA(tnf_uint16),
660*0Sstevel@tonic-gate &_TAG_DATA(tnf_int32),
661*0Sstevel@tonic-gate &_TAG_DATA(tnf_tag),
662*0Sstevel@tonic-gate &_TAG_DATA(tnf_file_header),
663*0Sstevel@tonic-gate &_TAG_DATA(tnf_block_header),
664*0Sstevel@tonic-gate 0};
665*0Sstevel@tonic-gate tnf_tag_data_t **list_p, *tag_p;
666*0Sstevel@tonic-gate
667*0Sstevel@tonic-gate list_p = bootstrap_types;
668*0Sstevel@tonic-gate
669*0Sstevel@tonic-gate while (tag_p = *list_p++) {
670*0Sstevel@tonic-gate if (!tag_p->tag_index) /* not written */
671*0Sstevel@tonic-gate tag_p->tag_desc(ops, tag_p);
672*0Sstevel@tonic-gate }
673*0Sstevel@tonic-gate }
674*0Sstevel@tonic-gate
675*0Sstevel@tonic-gate
676*0Sstevel@tonic-gate /*
677*0Sstevel@tonic-gate * fix for circularity in filling in file header tag and block
678*0Sstevel@tonic-gate * header tag. REMIND: should also fix tag_index of
679*0Sstevel@tonic-gate * file_header.
680*0Sstevel@tonic-gate */
681*0Sstevel@tonic-gate
682*0Sstevel@tonic-gate #ifdef _KERNEL
683*0Sstevel@tonic-gate
684*0Sstevel@tonic-gate /* LINTED pointer cast may result in improper alignment */
685*0Sstevel@tonic-gate fw_p = (tnf_tag_t *)(tnf_buf + TNF_DIRENT_FILE_HEADER);
686*0Sstevel@tonic-gate *fw_p = tnf_ref32(ops, _TAG_DATA(tnf_file_header).tag_index,
687*0Sstevel@tonic-gate (tnf_record_p)fw_p);
688*0Sstevel@tonic-gate
689*0Sstevel@tonic-gate /* LINTED pointer cast may result in improper alignment */
690*0Sstevel@tonic-gate fw_p = (tnf_tag_t *)(tnf_buf + TNF_DIRENT_BLOCK_HEADER);
691*0Sstevel@tonic-gate *fw_p = tnf_ref32(ops, _TAG_DATA(tnf_block_header).tag_index,
692*0Sstevel@tonic-gate (tnf_record_p)fw_p);
693*0Sstevel@tonic-gate
694*0Sstevel@tonic-gate #else
695*0Sstevel@tonic-gate
696*0Sstevel@tonic-gate /* LINTED pointer cast may result in improper alignment */
697*0Sstevel@tonic-gate fw_p = (tnf_tag_t *)_tnf_buf_headers_p->fw_file_header;
698*0Sstevel@tonic-gate if (fw_p) {
699*0Sstevel@tonic-gate *fw_p = tnf_ref32(ops, _TAG_DATA(tnf_file_header).tag_index,
700*0Sstevel@tonic-gate (tnf_record_p)fw_p);
701*0Sstevel@tonic-gate }
702*0Sstevel@tonic-gate /* LINTED pointer cast may result in improper alignment */
703*0Sstevel@tonic-gate fw_p = (tnf_tag_t *)_tnf_buf_headers_p->fw_block_header;
704*0Sstevel@tonic-gate if (fw_p) {
705*0Sstevel@tonic-gate *fw_p = tnf_ref32(ops, _TAG_DATA(tnf_block_header).tag_index,
706*0Sstevel@tonic-gate (tnf_record_p) fw_p);
707*0Sstevel@tonic-gate }
708*0Sstevel@tonic-gate
709*0Sstevel@tonic-gate #endif
710*0Sstevel@tonic-gate
711*0Sstevel@tonic-gate /* LINTED assignment of 32-bit integer to 8-bit integer */
712*0Sstevel@tonic-gate ops->mode = saved_mode;
713*0Sstevel@tonic-gate return (tag_data->tag_index);
714*0Sstevel@tonic-gate }
715*0Sstevel@tonic-gate
716*0Sstevel@tonic-gate
717*0Sstevel@tonic-gate /*
718*0Sstevel@tonic-gate * Data encoders
719*0Sstevel@tonic-gate */
720*0Sstevel@tonic-gate
721*0Sstevel@tonic-gate /*
722*0Sstevel@tonic-gate * Strings and derivatives
723*0Sstevel@tonic-gate */
724*0Sstevel@tonic-gate
725*0Sstevel@tonic-gate tnf_reference_t
tnf_string_1(tnf_ops_t * ops,const char * string,tnf_record_p reference,tnf_tag_data_t * tag_data)726*0Sstevel@tonic-gate tnf_string_1(tnf_ops_t *ops, const char *string, tnf_record_p reference,
727*0Sstevel@tonic-gate tnf_tag_data_t *tag_data)
728*0Sstevel@tonic-gate {
729*0Sstevel@tonic-gate tnf_record_p tag_index;
730*0Sstevel@tonic-gate size_t string_size, record_size;
731*0Sstevel@tonic-gate tnf_array_header_t *bufhdr;
732*0Sstevel@tonic-gate
733*0Sstevel@tonic-gate tag_index = tag_data->tag_index ? tag_data->tag_index :
734*0Sstevel@tonic-gate tag_data->tag_desc(ops, tag_data);
735*0Sstevel@tonic-gate
736*0Sstevel@tonic-gate if (!string)
737*0Sstevel@tonic-gate return ((tnf_reference_t)TNF_NULL);
738*0Sstevel@tonic-gate
739*0Sstevel@tonic-gate string_size = strlen(string); /* excludes terminating NUL */
740*0Sstevel@tonic-gate if (string_size > TNF_STRING_LIMIT)
741*0Sstevel@tonic-gate string_size = TNF_STRING_LIMIT;
742*0Sstevel@tonic-gate /* Allocate space for terminating NUL as well */
743*0Sstevel@tonic-gate record_size = sizeof (*bufhdr) + TNF_STRING_ROUNDUP(string_size + 1);
744*0Sstevel@tonic-gate
745*0Sstevel@tonic-gate ALLOC2(ops, record_size, bufhdr, ops->mode);
746*0Sstevel@tonic-gate
747*0Sstevel@tonic-gate ASSIGN(bufhdr, tag, tag_index);
748*0Sstevel@tonic-gate /* LINTED assignment of 64-bit integer to 32-bit integer */
749*0Sstevel@tonic-gate ASSIGN(bufhdr, self_size, record_size);
750*0Sstevel@tonic-gate
751*0Sstevel@tonic-gate #ifdef _KERNEL
752*0Sstevel@tonic-gate (void) bcopy((caddr_t)string, (char *)bufhdr + sizeof (*bufhdr),
753*0Sstevel@tonic-gate string_size);
754*0Sstevel@tonic-gate #else
755*0Sstevel@tonic-gate (void) memcpy((char *)bufhdr + sizeof (*bufhdr), string, string_size);
756*0Sstevel@tonic-gate #endif
757*0Sstevel@tonic-gate /* NUL-terminate */
758*0Sstevel@tonic-gate ((char *)bufhdr + sizeof (*bufhdr))[string_size] = '\0';
759*0Sstevel@tonic-gate
760*0Sstevel@tonic-gate return (tnf_ref32(ops, (tnf_record_p)bufhdr, reference));
761*0Sstevel@tonic-gate }
762*0Sstevel@tonic-gate
763*0Sstevel@tonic-gate /*
764*0Sstevel@tonic-gate * Array of strings and derivatives
765*0Sstevel@tonic-gate */
766*0Sstevel@tonic-gate
767*0Sstevel@tonic-gate tnf_reference_t
tnf_string_array_1(tnf_ops_t * ops,char ** strings,tnf_record_p reference,tnf_tag_data_t * tag_data)768*0Sstevel@tonic-gate tnf_string_array_1(tnf_ops_t *ops, char **strings, tnf_record_p reference,
769*0Sstevel@tonic-gate tnf_tag_data_t *tag_data)
770*0Sstevel@tonic-gate {
771*0Sstevel@tonic-gate tnf_record_p tag_index;
772*0Sstevel@tonic-gate size_t record_size;
773*0Sstevel@tonic-gate char **tmp;
774*0Sstevel@tonic-gate tnf_reference_t *ref_p;
775*0Sstevel@tonic-gate tnf_array_header_t *bufhdr;
776*0Sstevel@tonic-gate
777*0Sstevel@tonic-gate tag_index = tag_data->tag_index ? tag_data->tag_index :
778*0Sstevel@tonic-gate tag_data->tag_desc(ops, tag_data);
779*0Sstevel@tonic-gate
780*0Sstevel@tonic-gate if (!strings)
781*0Sstevel@tonic-gate return ((tnf_reference_t)TNF_NULL);
782*0Sstevel@tonic-gate
783*0Sstevel@tonic-gate record_size = sizeof (*bufhdr);
784*0Sstevel@tonic-gate tmp = strings;
785*0Sstevel@tonic-gate while (*tmp++)
786*0Sstevel@tonic-gate record_size += sizeof (tnf_string_t);
787*0Sstevel@tonic-gate
788*0Sstevel@tonic-gate ALLOC2(ops, record_size, bufhdr, ops->mode);
789*0Sstevel@tonic-gate
790*0Sstevel@tonic-gate ASSIGN(bufhdr, tag, tag_index);
791*0Sstevel@tonic-gate /* LINTED assignment of 64-bit integer to 32-bit integer */
792*0Sstevel@tonic-gate ASSIGN(bufhdr, self_size, record_size);
793*0Sstevel@tonic-gate
794*0Sstevel@tonic-gate tmp = strings;
795*0Sstevel@tonic-gate /* LINTED pointer cast may result in improper alignment */
796*0Sstevel@tonic-gate ref_p = (tnf_reference_t *)((char *)bufhdr + sizeof (*bufhdr));
797*0Sstevel@tonic-gate while (*tmp) {
798*0Sstevel@tonic-gate *ref_p = tnf_string(ops, *tmp, (tnf_record_p)ref_p);
799*0Sstevel@tonic-gate tmp++;
800*0Sstevel@tonic-gate ref_p++;
801*0Sstevel@tonic-gate }
802*0Sstevel@tonic-gate
803*0Sstevel@tonic-gate return (tnf_ref32(ops, (tnf_record_p) bufhdr, reference));
804*0Sstevel@tonic-gate }
805*0Sstevel@tonic-gate
806*0Sstevel@tonic-gate /*
807*0Sstevel@tonic-gate * Type record as generic (not tag) reference
808*0Sstevel@tonic-gate */
809*0Sstevel@tonic-gate
810*0Sstevel@tonic-gate tnf_reference_t
tnf_tag_element_1(tnf_ops_t * ops,tnf_tag_data_t ** tag_data_p,tnf_record_p reference,tnf_tag_data_t * aux_tag_data)811*0Sstevel@tonic-gate tnf_tag_element_1(tnf_ops_t *ops, tnf_tag_data_t **tag_data_p,
812*0Sstevel@tonic-gate tnf_record_p reference, tnf_tag_data_t *aux_tag_data)
813*0Sstevel@tonic-gate {
814*0Sstevel@tonic-gate tnf_tag_data_t *tag_data;
815*0Sstevel@tonic-gate
816*0Sstevel@tonic-gate if (aux_tag_data)
817*0Sstevel@tonic-gate if (!aux_tag_data->tag_index)
818*0Sstevel@tonic-gate aux_tag_data->tag_desc(ops, aux_tag_data);
819*0Sstevel@tonic-gate
820*0Sstevel@tonic-gate /* tnf_derived has derived_base == TNF_NULL */
821*0Sstevel@tonic-gate if (!tag_data_p)
822*0Sstevel@tonic-gate return ((tnf_reference_t)TNF_NULL);
823*0Sstevel@tonic-gate
824*0Sstevel@tonic-gate tag_data = *tag_data_p;
825*0Sstevel@tonic-gate if (!tag_data->tag_index)
826*0Sstevel@tonic-gate tag_data->tag_desc(ops, tag_data);
827*0Sstevel@tonic-gate
828*0Sstevel@tonic-gate return (tnf_ref32(ops, tag_data->tag_index, reference));
829*0Sstevel@tonic-gate }
830*0Sstevel@tonic-gate
831*0Sstevel@tonic-gate
832*0Sstevel@tonic-gate /*
833*0Sstevel@tonic-gate * Array of type records as generic (not tag) references
834*0Sstevel@tonic-gate */
835*0Sstevel@tonic-gate
836*0Sstevel@tonic-gate tnf_reference_t
tnf_tag_array_1(tnf_ops_t * ops,tnf_tag_data_t *** tag_data_array,tnf_record_p reference,tnf_tag_data_t * tag_data)837*0Sstevel@tonic-gate tnf_tag_array_1(tnf_ops_t *ops,
838*0Sstevel@tonic-gate tnf_tag_data_t ***tag_data_array,
839*0Sstevel@tonic-gate tnf_record_p reference,
840*0Sstevel@tonic-gate tnf_tag_data_t *tag_data)
841*0Sstevel@tonic-gate {
842*0Sstevel@tonic-gate tnf_record_p tag_index;
843*0Sstevel@tonic-gate size_t record_size;
844*0Sstevel@tonic-gate tnf_array_header_t *bufhdr;
845*0Sstevel@tonic-gate tnf_tag_data_t ***tmp;
846*0Sstevel@tonic-gate tnf_reference_t *ref_p;
847*0Sstevel@tonic-gate
848*0Sstevel@tonic-gate tag_index = tag_data->tag_index ? tag_data->tag_index :
849*0Sstevel@tonic-gate tag_data->tag_desc(ops, tag_data);
850*0Sstevel@tonic-gate
851*0Sstevel@tonic-gate if (!tag_data_array)
852*0Sstevel@tonic-gate return ((tnf_reference_t)TNF_NULL);
853*0Sstevel@tonic-gate
854*0Sstevel@tonic-gate record_size = sizeof (*bufhdr);
855*0Sstevel@tonic-gate tmp = tag_data_array;
856*0Sstevel@tonic-gate while (*tmp++)
857*0Sstevel@tonic-gate record_size += sizeof (tnf_reference_t);
858*0Sstevel@tonic-gate
859*0Sstevel@tonic-gate ALLOC2(ops, record_size, bufhdr, ops->mode);
860*0Sstevel@tonic-gate
861*0Sstevel@tonic-gate ASSIGN(bufhdr, tag, tag_index);
862*0Sstevel@tonic-gate /* LINTED assignment of 64-bit integer to 32-bit integer */
863*0Sstevel@tonic-gate ASSIGN(bufhdr, self_size, record_size);
864*0Sstevel@tonic-gate
865*0Sstevel@tonic-gate tmp = tag_data_array;
866*0Sstevel@tonic-gate /* LINTED pointer cast may result in improper alignment */
867*0Sstevel@tonic-gate ref_p = (tnf_reference_t *)((char *)bufhdr + sizeof (*bufhdr));
868*0Sstevel@tonic-gate while (*tmp) {
869*0Sstevel@tonic-gate *ref_p = tnf_tag_element_1(ops, *tmp, (tnf_record_p)ref_p,
870*0Sstevel@tonic-gate TNF_NULL);
871*0Sstevel@tonic-gate tmp++;
872*0Sstevel@tonic-gate ref_p++;
873*0Sstevel@tonic-gate }
874*0Sstevel@tonic-gate
875*0Sstevel@tonic-gate return (tnf_ref32(ops, (tnf_record_p)bufhdr, reference));
876*0Sstevel@tonic-gate }
877*0Sstevel@tonic-gate
878*0Sstevel@tonic-gate /*
879*0Sstevel@tonic-gate * Array of properties (type records)
880*0Sstevel@tonic-gate */
881*0Sstevel@tonic-gate
882*0Sstevel@tonic-gate tnf_reference_t
tnf_tag_properties_1(tnf_ops_t * ops,tnf_tag_data_t **** tag_data_array,tnf_record_p reference,tnf_tag_data_t * tag_data)883*0Sstevel@tonic-gate tnf_tag_properties_1(tnf_ops_t *ops,
884*0Sstevel@tonic-gate tnf_tag_data_t ****tag_data_array,
885*0Sstevel@tonic-gate tnf_record_p reference,
886*0Sstevel@tonic-gate tnf_tag_data_t *tag_data)
887*0Sstevel@tonic-gate {
888*0Sstevel@tonic-gate if (!(tag_data->tag_index))
889*0Sstevel@tonic-gate tag_data->tag_desc(ops, tag_data);
890*0Sstevel@tonic-gate
891*0Sstevel@tonic-gate if (!tag_data_array)
892*0Sstevel@tonic-gate return ((tnf_reference_t)TNF_NULL);
893*0Sstevel@tonic-gate
894*0Sstevel@tonic-gate return (tnf_tag_array_1(ops, *tag_data_array, reference, tag_data));
895*0Sstevel@tonic-gate }
896*0Sstevel@tonic-gate
897*0Sstevel@tonic-gate #ifdef _KERNEL
898*0Sstevel@tonic-gate /*
899*0Sstevel@tonic-gate * Initialize all core tag pointers defined in this file.
900*0Sstevel@tonic-gate * CAUTION: tnf_tag_core_init is a function for kernel compilation.
901*0Sstevel@tonic-gate */
902*0Sstevel@tonic-gate
903*0Sstevel@tonic-gate void
tnf_tag_core_init(void)904*0Sstevel@tonic-gate tnf_tag_core_init(void)
905*0Sstevel@tonic-gate {
906*0Sstevel@tonic-gate #endif
907*0Sstevel@tonic-gate TAG_SET(tnf_inline);
908*0Sstevel@tonic-gate TAG_SET(tnf_tagged);
909*0Sstevel@tonic-gate
910*0Sstevel@tonic-gate TAG_SET(tnf_scalar);
911*0Sstevel@tonic-gate TAG_SET(tnf_char);
912*0Sstevel@tonic-gate TAG_SET(tnf_int8);
913*0Sstevel@tonic-gate TAG_SET(tnf_uint8);
914*0Sstevel@tonic-gate TAG_SET(tnf_int16);
915*0Sstevel@tonic-gate TAG_SET(tnf_uint16);
916*0Sstevel@tonic-gate TAG_SET(tnf_int32);
917*0Sstevel@tonic-gate TAG_SET(tnf_uint32);
918*0Sstevel@tonic-gate TAG_SET(tnf_int64);
919*0Sstevel@tonic-gate TAG_SET(tnf_uint64);
920*0Sstevel@tonic-gate
921*0Sstevel@tonic-gate TAG_SET(tnf_float32);
922*0Sstevel@tonic-gate TAG_SET(tnf_float64);
923*0Sstevel@tonic-gate
924*0Sstevel@tonic-gate TAG_SET(tnf_array);
925*0Sstevel@tonic-gate TAG_SET(tnf_string);
926*0Sstevel@tonic-gate TAG_SET(tnf_type_array);
927*0Sstevel@tonic-gate TAG_SET(tnf_name_array);
928*0Sstevel@tonic-gate
929*0Sstevel@tonic-gate TAG_SET(tnf_derived);
930*0Sstevel@tonic-gate TAG_SET(tnf_align);
931*0Sstevel@tonic-gate TAG_SET(tnf_derived_base);
932*0Sstevel@tonic-gate TAG_SET(tnf_element_type);
933*0Sstevel@tonic-gate TAG_SET(tnf_header_size);
934*0Sstevel@tonic-gate TAG_SET(tnf_name);
935*0Sstevel@tonic-gate TAG_SET(tnf_opaque);
936*0Sstevel@tonic-gate TAG_SET(tnf_properties);
937*0Sstevel@tonic-gate TAG_SET(tnf_self_size);
938*0Sstevel@tonic-gate TAG_SET(tnf_size);
939*0Sstevel@tonic-gate TAG_SET(tnf_slot_names);
940*0Sstevel@tonic-gate TAG_SET(tnf_slot_types);
941*0Sstevel@tonic-gate TAG_SET(tnf_tag);
942*0Sstevel@tonic-gate TAG_SET(tnf_tag_arg);
943*0Sstevel@tonic-gate TAG_SET(tnf_type_size);
944*0Sstevel@tonic-gate
945*0Sstevel@tonic-gate TAG_SET(tnf_struct);
946*0Sstevel@tonic-gate TAG_SET(tnf_file_header);
947*0Sstevel@tonic-gate TAG_SET(tnf_block_header);
948*0Sstevel@tonic-gate
949*0Sstevel@tonic-gate TAG_SET(tnf_type);
950*0Sstevel@tonic-gate TAG_SET(tnf_array_type);
951*0Sstevel@tonic-gate TAG_SET(tnf_derived_type);
952*0Sstevel@tonic-gate TAG_SET(tnf_scalar_type);
953*0Sstevel@tonic-gate TAG_SET(tnf_struct_type);
954*0Sstevel@tonic-gate
955*0Sstevel@tonic-gate #ifdef _KERNEL
956*0Sstevel@tonic-gate
957*0Sstevel@tonic-gate /* Snap exported properties */
958*0Sstevel@tonic-gate tnf_user_struct_properties = std_struct_properties;
959*0Sstevel@tonic-gate
960*0Sstevel@tonic-gate }
961*0Sstevel@tonic-gate
962*0Sstevel@tonic-gate #else /* _KERNEL */
963*0Sstevel@tonic-gate
964*0Sstevel@tonic-gate tnf_tag_data_t ***tnf_user_struct_properties = std_struct_properties;
965*0Sstevel@tonic-gate
966*0Sstevel@tonic-gate #endif /* _KERNEL */
967