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