1/*
2 * CDDL HEADER START
3 *
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
7 * with the License.
8 *
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.
13 *
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]
19 *
20 * CDDL HEADER END
21 */
22/*
23 *	Copyright (c) 1994, by Sun Microsytems, Inc.
24 */
25
26#pragma	ident	"%Z%%M%	%I%	%E% SMI"
27
28#include "libtnf.h"
29
30/*
31 * All types are struct records
32 */
33
34void
35_tnf_check_type(tnf_datum_t datum)
36{
37	CHECK_RECORD(datum);
38	CHECK_SLOTS(datum);
39
40	if (!INFO_TYPE(DATUM_INFO(datum)))
41		_tnf_error(DATUM_TNF(datum), TNF_ERR_TYPEMISMATCH);
42}
43
44/*
45 * Get data kind of a type record
46 */
47
48tnf_kind_t
49tnf_type_get_kind(tnf_datum_t datum)
50{
51	struct taginfo	*info;
52
53	CHECK_TYPE(datum);
54
55	/* Note: DATUM_RECORD(), not DATUM_TAG() */
56	/* LINTED pointer cast may result in improper alignment */
57	info = _tnf_get_info(DATUM_TNF(datum), DATUM_RECORD(datum));
58	return (info->kind);
59}
60
61/*
62 * Retrieve type name for datum type record
63 */
64
65char *
66tnf_type_get_name(tnf_datum_t datum)
67{
68	CHECK_TYPE(datum);
69	/* XXX Dispatch to ABI routine; faster than taginfo lookup? */
70	/* LINTED pointer cast may result in improper alignment */
71	return (_tnf_get_name(DATUM_TNF(datum), DATUM_RECORD(datum)));
72}
73
74/*
75 * Fetch size member of info for datum type record
76 */
77
78size_t
79tnf_type_get_size(tnf_datum_t datum)
80{
81	struct taginfo	*info;
82
83	CHECK_TYPE(datum);
84
85	/* Note: DATUM_RECORD(), not DATUM_TAG() */
86	/* LINTED pointer cast may result in improper alignment */
87	info = _tnf_get_info(DATUM_TNF(datum), DATUM_RECORD(datum));
88
89	if (INFO_ARRAY(info))
90		/* XXX All arrays are self-sized */
91		return ((size_t)-1);
92	else
93		return (info->size);
94}
95
96/*
97 * Get the base type of a type
98 */
99
100tnf_datum_t
101tnf_type_get_base(tnf_datum_t datum)
102{
103	struct taginfo	*info;
104
105	CHECK_TYPE(datum);
106
107	/* Note: DATUM_RECORD(), not DATUM_TAG() */
108	/* LINTED pointer cast may result in improper alignment */
109	info = _tnf_get_info(DATUM_TNF(datum), DATUM_RECORD(datum));
110
111	if (INFO_DERIVED(info))
112		return (DATUM(info->base->meta, (caddr_t)info->base->tag));
113	else
114		return (datum);
115}
116
117/*
118 * If type record has named property, return a datum for it
119 */
120
121tnf_datum_t
122tnf_type_get_property(tnf_datum_t datum, char *name)
123{
124	tnf_ref32_t	*property;
125
126	CHECK_TYPE(datum);
127
128	/* Note: DATUM_RECORD(), not DATUM_TAG() */
129	property = _tnf_get_property(DATUM_TNF(datum),
130		/* LINTED pointer cast may result in improper alignment */
131			DATUM_RECORD(datum), name);
132
133	if (property == TNF_NULL)
134		return (TNF_DATUM_NULL);
135	else
136		return (RECORD_DATUM(DATUM_TNF(datum), property));
137}
138