4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright (c) 1994, by Sun Microsytems, Inc.
26 #pragma ident "%Z%%M% %I% %E% SMI"
34 static struct slotinfo
*get_slotinfo(tnf_datum_t
);
35 static struct slot
* get_slot_named(struct slotinfo
*, char *);
36 static struct slot
* get_slot_indexed(struct slotinfo
*, unsigned);
37 static tnf_datum_t
get_slot(tnf_datum_t
, struct slot
*);
44 _tnf_check_slots(tnf_datum_t datum
)
50 info
= DATUM_INFO(datum
);
52 /* Must be an aggregate */
53 if (!(INFO_STRUCT(info
) || INFO_ARRAY(info
)))
54 _tnf_error(DATUM_TNF(datum
), TNF_ERR_TYPEMISMATCH
);
61 static struct slotinfo
*
62 get_slotinfo(tnf_datum_t datum
)
64 struct taginfo
*info
, *base_info
;
66 info
= DATUM_INFO(datum
);
67 base_info
= INFO_DERIVED(info
)? info
->base
: info
;
69 /* XXX base must not be a scalar tag */
70 if (INFO_SCALAR(base_info
))
71 _tnf_error(DATUM_TNF(datum
), TNF_ERR_BADTNF
);
73 return (base_info
->slotinfo
);
77 get_slot_indexed(struct slotinfo
*slotinfo
, unsigned index
)
81 count
= slotinfo
->slot_count
;
85 return (&slotinfo
->slots
[index
]);
89 get_slot_named(struct slotinfo
*slotinfo
, char *name
)
93 count
= slotinfo
->slot_count
;
95 for (i
= 0; i
< count
; i
++)
96 if (strcmp(name
, slotinfo
->slots
[i
].slot_name
) == 0)
97 return (&slotinfo
->slots
[i
]);
103 get_slot(tnf_datum_t datum
, struct slot
*slot
)
106 _tnf_error(DATUM_TNF(datum
), TNF_ERR_BADSLOT
); /* XXX */
107 return (TNF_DATUM_NULL
);
109 } else if (INFO_TAGGED(slot
->slot_type
)) {
113 tnf
= DATUM_TNF(datum
);
114 /* LINTED pointer cast may result in improper alignment */
115 rec
= _GET_REF32(tnf
, (tnf_ref32_t
*)
116 (DATUM_VAL(datum
) + slot
->slot_offset
));
117 /* NULL slots are allowed */
118 return ((rec
== TNF_NULL
)? TNF_DATUM_NULL
:
119 RECORD_DATUM(tnf
, rec
));
122 return DATUM(slot
->slot_type
,
123 DATUM_VAL(datum
) + slot
->slot_offset
);
131 tnf_get_slot_count(tnf_datum_t datum
)
133 struct slotinfo
*slotinfo
;
137 slotinfo
= get_slotinfo(datum
);
138 return (slotinfo
->slot_count
);
146 tnf_get_slot_index(tnf_datum_t datum
, char *name
)
148 struct slotinfo
*slotinfo
;
153 slotinfo
= get_slotinfo(datum
);
154 slot
= get_slot_named(slotinfo
, name
);
157 _tnf_error(DATUM_TNF(datum
), TNF_ERR_BADSLOT
); /* XXX */
158 return (((unsigned)-1));
160 return (((char *)slot
- (char *)&slotinfo
->slots
[0])
161 / sizeof (struct slot
));
169 tnf_get_slot_name(tnf_datum_t datum
, unsigned index
)
171 struct slotinfo
*slotinfo
;
176 slotinfo
= get_slotinfo(datum
);
177 slot
= get_slot_indexed(slotinfo
, index
);
180 _tnf_error(DATUM_TNF(datum
), TNF_ERR_BADSLOT
); /* XXX */
181 return ((char *)NULL
);
183 return (slot
->slot_name
);
191 tnf_get_slot_named(tnf_datum_t datum
, char *name
)
193 struct slotinfo
*slotinfo
;
198 slotinfo
= get_slotinfo(datum
);
199 slot
= get_slot_named(slotinfo
, name
);
201 return (get_slot(datum
, slot
));
209 tnf_get_slot_indexed(tnf_datum_t datum
, unsigned index
)
211 struct slotinfo
*slotinfo
;
216 slotinfo
= get_slotinfo(datum
);
217 slot
= get_slot_indexed(slotinfo
, index
);
219 return (get_slot(datum
, slot
));