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 (c) 1994, by Sun Microsytems, Inc.
24*7c478bd9Sstevel@tonic-gate */
25*7c478bd9Sstevel@tonic-gate
26*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
27*7c478bd9Sstevel@tonic-gate
28*7c478bd9Sstevel@tonic-gate #include "libtnf.h"
29*7c478bd9Sstevel@tonic-gate
30*7c478bd9Sstevel@tonic-gate /*
31*7c478bd9Sstevel@tonic-gate * Defines
32*7c478bd9Sstevel@tonic-gate */
33*7c478bd9Sstevel@tonic-gate
34*7c478bd9Sstevel@tonic-gate #define DATUM_KIND(d) (DATUM_INFO(d)->kind)
35*7c478bd9Sstevel@tonic-gate
36*7c478bd9Sstevel@tonic-gate /*
37*7c478bd9Sstevel@tonic-gate * Declarations
38*7c478bd9Sstevel@tonic-gate */
39*7c478bd9Sstevel@tonic-gate
40*7c478bd9Sstevel@tonic-gate static int has_prop(tnf_datum_t, tag_props_t);
41*7c478bd9Sstevel@tonic-gate
42*7c478bd9Sstevel@tonic-gate /*
43*7c478bd9Sstevel@tonic-gate * Datum operations: for more debuggability
44*7c478bd9Sstevel@tonic-gate */
45*7c478bd9Sstevel@tonic-gate
46*7c478bd9Sstevel@tonic-gate #ifndef _DATUM_MACROS
47*7c478bd9Sstevel@tonic-gate
48*7c478bd9Sstevel@tonic-gate tnf_datum_t
_tnf_datum(struct taginfo * info,caddr_t val)49*7c478bd9Sstevel@tonic-gate _tnf_datum(struct taginfo *info, caddr_t val)
50*7c478bd9Sstevel@tonic-gate {
51*7c478bd9Sstevel@tonic-gate return (_DATUM(info, val));
52*7c478bd9Sstevel@tonic-gate }
53*7c478bd9Sstevel@tonic-gate
54*7c478bd9Sstevel@tonic-gate struct taginfo *
_tnf_datum_info(tnf_datum_t datum)55*7c478bd9Sstevel@tonic-gate _tnf_datum_info(tnf_datum_t datum)
56*7c478bd9Sstevel@tonic-gate {
57*7c478bd9Sstevel@tonic-gate return ((struct taginfo *)_DATUM_HI(datum));
58*7c478bd9Sstevel@tonic-gate }
59*7c478bd9Sstevel@tonic-gate
60*7c478bd9Sstevel@tonic-gate caddr_t
_tnf_datum_val(tnf_datum_t datum)61*7c478bd9Sstevel@tonic-gate _tnf_datum_val(tnf_datum_t datum)
62*7c478bd9Sstevel@tonic-gate {
63*7c478bd9Sstevel@tonic-gate return ((caddr_t)_DATUM_LO(datum));
64*7c478bd9Sstevel@tonic-gate }
65*7c478bd9Sstevel@tonic-gate
66*7c478bd9Sstevel@tonic-gate #endif
67*7c478bd9Sstevel@tonic-gate
68*7c478bd9Sstevel@tonic-gate /*
69*7c478bd9Sstevel@tonic-gate * Check for valid datum
70*7c478bd9Sstevel@tonic-gate */
71*7c478bd9Sstevel@tonic-gate
72*7c478bd9Sstevel@tonic-gate void
_tnf_check_datum(tnf_datum_t datum)73*7c478bd9Sstevel@tonic-gate _tnf_check_datum(tnf_datum_t datum)
74*7c478bd9Sstevel@tonic-gate {
75*7c478bd9Sstevel@tonic-gate caddr_t val;
76*7c478bd9Sstevel@tonic-gate TNF *tnf;
77*7c478bd9Sstevel@tonic-gate
78*7c478bd9Sstevel@tonic-gate if (datum == TNF_DATUM_NULL)
79*7c478bd9Sstevel@tonic-gate _tnf_error(NULL, TNF_ERR_BADTNF);
80*7c478bd9Sstevel@tonic-gate
81*7c478bd9Sstevel@tonic-gate val = DATUM_VAL(datum);
82*7c478bd9Sstevel@tonic-gate tnf = DATUM_TNF(datum);
83*7c478bd9Sstevel@tonic-gate
84*7c478bd9Sstevel@tonic-gate if ((val <= tnf->file_start) || (val >= tnf->file_end))
85*7c478bd9Sstevel@tonic-gate _tnf_error(tnf, TNF_ERR_BADDATUM);
86*7c478bd9Sstevel@tonic-gate }
87*7c478bd9Sstevel@tonic-gate
88*7c478bd9Sstevel@tonic-gate /*
89*7c478bd9Sstevel@tonic-gate * Retrieve datum kind from cached information
90*7c478bd9Sstevel@tonic-gate */
91*7c478bd9Sstevel@tonic-gate
92*7c478bd9Sstevel@tonic-gate tnf_kind_t
tnf_get_kind(tnf_datum_t datum)93*7c478bd9Sstevel@tonic-gate tnf_get_kind(tnf_datum_t datum)
94*7c478bd9Sstevel@tonic-gate {
95*7c478bd9Sstevel@tonic-gate CHECK_DATUM(datum);
96*7c478bd9Sstevel@tonic-gate /* The kind field is always completely initialized */
97*7c478bd9Sstevel@tonic-gate return (DATUM_KIND(datum));
98*7c478bd9Sstevel@tonic-gate }
99*7c478bd9Sstevel@tonic-gate
100*7c478bd9Sstevel@tonic-gate /*
101*7c478bd9Sstevel@tonic-gate * Classification predicates: check the cached tag props
102*7c478bd9Sstevel@tonic-gate */
103*7c478bd9Sstevel@tonic-gate
104*7c478bd9Sstevel@tonic-gate static int
has_prop(tnf_datum_t datum,tag_props_t prop)105*7c478bd9Sstevel@tonic-gate has_prop(tnf_datum_t datum, tag_props_t prop)
106*7c478bd9Sstevel@tonic-gate {
107*7c478bd9Sstevel@tonic-gate CHECK_DATUM(datum);
108*7c478bd9Sstevel@tonic-gate
109*7c478bd9Sstevel@tonic-gate /* Note: No need to get base info because props inherited */
110*7c478bd9Sstevel@tonic-gate return (INFO_PROP(DATUM_INFO(datum), prop));
111*7c478bd9Sstevel@tonic-gate }
112*7c478bd9Sstevel@tonic-gate
113*7c478bd9Sstevel@tonic-gate int
tnf_is_inline(tnf_datum_t datum)114*7c478bd9Sstevel@tonic-gate tnf_is_inline(tnf_datum_t datum)
115*7c478bd9Sstevel@tonic-gate {
116*7c478bd9Sstevel@tonic-gate return (has_prop(datum, TAG_PROP_INLINE));
117*7c478bd9Sstevel@tonic-gate }
118*7c478bd9Sstevel@tonic-gate
119*7c478bd9Sstevel@tonic-gate int
tnf_is_scalar(tnf_datum_t datum)120*7c478bd9Sstevel@tonic-gate tnf_is_scalar(tnf_datum_t datum)
121*7c478bd9Sstevel@tonic-gate {
122*7c478bd9Sstevel@tonic-gate return (has_prop(datum, TAG_PROP_SCALAR));
123*7c478bd9Sstevel@tonic-gate }
124*7c478bd9Sstevel@tonic-gate
125*7c478bd9Sstevel@tonic-gate int
tnf_is_record(tnf_datum_t datum)126*7c478bd9Sstevel@tonic-gate tnf_is_record(tnf_datum_t datum) /* XXX was: tnf_is_tagged */
127*7c478bd9Sstevel@tonic-gate {
128*7c478bd9Sstevel@tonic-gate return (has_prop(datum, TAG_PROP_TAGGED));
129*7c478bd9Sstevel@tonic-gate }
130*7c478bd9Sstevel@tonic-gate
131*7c478bd9Sstevel@tonic-gate int
tnf_is_array(tnf_datum_t datum)132*7c478bd9Sstevel@tonic-gate tnf_is_array(tnf_datum_t datum)
133*7c478bd9Sstevel@tonic-gate {
134*7c478bd9Sstevel@tonic-gate return (has_prop(datum, TAG_PROP_ARRAY));
135*7c478bd9Sstevel@tonic-gate }
136*7c478bd9Sstevel@tonic-gate
137*7c478bd9Sstevel@tonic-gate int
tnf_is_string(tnf_datum_t datum)138*7c478bd9Sstevel@tonic-gate tnf_is_string(tnf_datum_t datum)
139*7c478bd9Sstevel@tonic-gate {
140*7c478bd9Sstevel@tonic-gate return (has_prop(datum, TAG_PROP_STRING));
141*7c478bd9Sstevel@tonic-gate }
142*7c478bd9Sstevel@tonic-gate
143*7c478bd9Sstevel@tonic-gate int
tnf_is_struct(tnf_datum_t datum)144*7c478bd9Sstevel@tonic-gate tnf_is_struct(tnf_datum_t datum)
145*7c478bd9Sstevel@tonic-gate {
146*7c478bd9Sstevel@tonic-gate return (has_prop(datum, TAG_PROP_STRUCT));
147*7c478bd9Sstevel@tonic-gate }
148*7c478bd9Sstevel@tonic-gate
149*7c478bd9Sstevel@tonic-gate int
tnf_is_type(tnf_datum_t datum)150*7c478bd9Sstevel@tonic-gate tnf_is_type(tnf_datum_t datum)
151*7c478bd9Sstevel@tonic-gate {
152*7c478bd9Sstevel@tonic-gate return (has_prop(datum, TAG_PROP_TYPE));
153*7c478bd9Sstevel@tonic-gate }
154*7c478bd9Sstevel@tonic-gate
155*7c478bd9Sstevel@tonic-gate /*
156*7c478bd9Sstevel@tonic-gate * Get the type datum for any datum
157*7c478bd9Sstevel@tonic-gate */
158*7c478bd9Sstevel@tonic-gate
159*7c478bd9Sstevel@tonic-gate tnf_datum_t
tnf_get_type(tnf_datum_t datum)160*7c478bd9Sstevel@tonic-gate tnf_get_type(tnf_datum_t datum)
161*7c478bd9Sstevel@tonic-gate {
162*7c478bd9Sstevel@tonic-gate struct taginfo *info;
163*7c478bd9Sstevel@tonic-gate
164*7c478bd9Sstevel@tonic-gate CHECK_DATUM(datum);
165*7c478bd9Sstevel@tonic-gate
166*7c478bd9Sstevel@tonic-gate info = DATUM_INFO(datum);
167*7c478bd9Sstevel@tonic-gate return (DATUM(info->meta, (caddr_t)info->tag));
168*7c478bd9Sstevel@tonic-gate }
169*7c478bd9Sstevel@tonic-gate
170*7c478bd9Sstevel@tonic-gate /*
171*7c478bd9Sstevel@tonic-gate * Get the type name for any datum
172*7c478bd9Sstevel@tonic-gate * XXX Beware: this is a pointer into the file
173*7c478bd9Sstevel@tonic-gate */
174*7c478bd9Sstevel@tonic-gate
175*7c478bd9Sstevel@tonic-gate char *
tnf_get_type_name(tnf_datum_t datum)176*7c478bd9Sstevel@tonic-gate tnf_get_type_name(tnf_datum_t datum)
177*7c478bd9Sstevel@tonic-gate {
178*7c478bd9Sstevel@tonic-gate CHECK_DATUM(datum);
179*7c478bd9Sstevel@tonic-gate return (DATUM_INFO(datum)->name); /* cached */
180*7c478bd9Sstevel@tonic-gate }
181*7c478bd9Sstevel@tonic-gate
182*7c478bd9Sstevel@tonic-gate /*
183*7c478bd9Sstevel@tonic-gate * Get the size of any datum
184*7c478bd9Sstevel@tonic-gate */
185*7c478bd9Sstevel@tonic-gate
186*7c478bd9Sstevel@tonic-gate size_t
tnf_get_size(tnf_datum_t datum)187*7c478bd9Sstevel@tonic-gate tnf_get_size(tnf_datum_t datum)
188*7c478bd9Sstevel@tonic-gate {
189*7c478bd9Sstevel@tonic-gate struct taginfo *info;
190*7c478bd9Sstevel@tonic-gate size_t size;
191*7c478bd9Sstevel@tonic-gate
192*7c478bd9Sstevel@tonic-gate CHECK_DATUM(datum);
193*7c478bd9Sstevel@tonic-gate
194*7c478bd9Sstevel@tonic-gate info = DATUM_INFO(datum);
195*7c478bd9Sstevel@tonic-gate size = info->size;
196*7c478bd9Sstevel@tonic-gate
197*7c478bd9Sstevel@tonic-gate if (size == (size_t)-1) /* self sized */
198*7c478bd9Sstevel@tonic-gate /* XXX tnf_get_slot_named(datum, TNF_N_SELF_SIZE) */
199*7c478bd9Sstevel@tonic-gate /* LINTED pointer cast may result in improper alignment */
200*7c478bd9Sstevel@tonic-gate return (_tnf_get_self_size(info->tnf, DATUM_RECORD(datum)));
201*7c478bd9Sstevel@tonic-gate else
202*7c478bd9Sstevel@tonic-gate return (size);
203*7c478bd9Sstevel@tonic-gate }
204*7c478bd9Sstevel@tonic-gate
205*7c478bd9Sstevel@tonic-gate /*
206*7c478bd9Sstevel@tonic-gate * Get raw pointer to any datum
207*7c478bd9Sstevel@tonic-gate */
208*7c478bd9Sstevel@tonic-gate
209*7c478bd9Sstevel@tonic-gate caddr_t
tnf_get_raw(tnf_datum_t datum)210*7c478bd9Sstevel@tonic-gate tnf_get_raw(tnf_datum_t datum)
211*7c478bd9Sstevel@tonic-gate {
212*7c478bd9Sstevel@tonic-gate CHECK_DATUM(datum);
213*7c478bd9Sstevel@tonic-gate return (DATUM_VAL(datum));
214*7c478bd9Sstevel@tonic-gate }
215