xref: /titanic_50/usr/src/lib/libtnf/tnf.h (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
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 #ifndef _TNF_TNF_H
27*7c478bd9Sstevel@tonic-gate #define	_TNF_TNF_H
28*7c478bd9Sstevel@tonic-gate 
29*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
30*7c478bd9Sstevel@tonic-gate 
31*7c478bd9Sstevel@tonic-gate #include <sys/types.h>
32*7c478bd9Sstevel@tonic-gate #include <tnf/com.h>
33*7c478bd9Sstevel@tonic-gate 
34*7c478bd9Sstevel@tonic-gate #ifdef __cplusplus
35*7c478bd9Sstevel@tonic-gate extern "C" {
36*7c478bd9Sstevel@tonic-gate #endif
37*7c478bd9Sstevel@tonic-gate 
38*7c478bd9Sstevel@tonic-gate /*
39*7c478bd9Sstevel@tonic-gate  * Opaque TNF handle
40*7c478bd9Sstevel@tonic-gate  */
41*7c478bd9Sstevel@tonic-gate 
42*7c478bd9Sstevel@tonic-gate typedef struct TNF	TNF;
43*7c478bd9Sstevel@tonic-gate 
44*7c478bd9Sstevel@tonic-gate /*
45*7c478bd9Sstevel@tonic-gate  * Opaque data handle
46*7c478bd9Sstevel@tonic-gate  */
47*7c478bd9Sstevel@tonic-gate 
48*7c478bd9Sstevel@tonic-gate typedef	unsigned long long	tnf_datum_t;
49*7c478bd9Sstevel@tonic-gate 
50*7c478bd9Sstevel@tonic-gate #define	TNF_DATUM_NULL	((tnf_datum_t)0)
51*7c478bd9Sstevel@tonic-gate 
52*7c478bd9Sstevel@tonic-gate /*
53*7c478bd9Sstevel@tonic-gate  * Reader data classification
54*7c478bd9Sstevel@tonic-gate  */
55*7c478bd9Sstevel@tonic-gate 
56*7c478bd9Sstevel@tonic-gate typedef enum {
57*7c478bd9Sstevel@tonic-gate 	TNF_K_UNKNOWN,			/* unknown or error */
58*7c478bd9Sstevel@tonic-gate 	TNF_K_SCALAR,			/* unclassified scalar */
59*7c478bd9Sstevel@tonic-gate 	TNF_K_CHAR,			/* char */
60*7c478bd9Sstevel@tonic-gate 	TNF_K_INT8,			/* int8 */
61*7c478bd9Sstevel@tonic-gate 	TNF_K_INT16,			/* int16 */
62*7c478bd9Sstevel@tonic-gate 	TNF_K_INT32,			/* int32 */
63*7c478bd9Sstevel@tonic-gate 	TNF_K_UINT8,			/* uint8 */
64*7c478bd9Sstevel@tonic-gate 	TNF_K_UINT16,			/* uint16 */
65*7c478bd9Sstevel@tonic-gate 	TNF_K_UINT32,			/* uint32 */
66*7c478bd9Sstevel@tonic-gate 	TNF_K_INT64,			/* int64 */
67*7c478bd9Sstevel@tonic-gate 	TNF_K_UINT64,			/* uint64 */
68*7c478bd9Sstevel@tonic-gate 	TNF_K_FLOAT32,			/* float32 */
69*7c478bd9Sstevel@tonic-gate 	TNF_K_FLOAT64,			/* float64 */
70*7c478bd9Sstevel@tonic-gate 	TNF_K_ARRAY,			/* array */
71*7c478bd9Sstevel@tonic-gate 	TNF_K_STRING,			/* string */
72*7c478bd9Sstevel@tonic-gate 	TNF_K_STRUCT,			/* struct */
73*7c478bd9Sstevel@tonic-gate 	TNF_K_TYPE			/* type */
74*7c478bd9Sstevel@tonic-gate } tnf_kind_t;
75*7c478bd9Sstevel@tonic-gate 
76*7c478bd9Sstevel@tonic-gate /*
77*7c478bd9Sstevel@tonic-gate  * Error codes
78*7c478bd9Sstevel@tonic-gate  */
79*7c478bd9Sstevel@tonic-gate 
80*7c478bd9Sstevel@tonic-gate typedef enum {
81*7c478bd9Sstevel@tonic-gate 	TNF_ERR_NONE = 0,
82*7c478bd9Sstevel@tonic-gate 
83*7c478bd9Sstevel@tonic-gate 	/* 1 through 1023 reserved for errno values */
84*7c478bd9Sstevel@tonic-gate #define	TNF_ERRNO_MAX 		1023
85*7c478bd9Sstevel@tonic-gate 
86*7c478bd9Sstevel@tonic-gate 	TNF_ERR_NOTTNF 		= 1024,	/* not TNF file */
87*7c478bd9Sstevel@tonic-gate 	TNF_ERR_BADDATUM 	= 1025,	/* bad or NULL data handle */
88*7c478bd9Sstevel@tonic-gate 	TNF_ERR_TYPEMISMATCH 	= 1026,	/* type mismatch */
89*7c478bd9Sstevel@tonic-gate 	TNF_ERR_BADINDEX 	= 1027,	/* array index out of bounds */
90*7c478bd9Sstevel@tonic-gate 	TNF_ERR_BADSLOT 	= 1028,	/* slot missing */
91*7c478bd9Sstevel@tonic-gate 	TNF_ERR_BADREFTYPE 	= 1029,	/* invalid reference type  */
92*7c478bd9Sstevel@tonic-gate 	TNF_ERR_ALLOCFAIL 	= 1030,	/* memory allocation failure */
93*7c478bd9Sstevel@tonic-gate 	TNF_ERR_BADTNF 		= 1031,	/* bad TNF file */
94*7c478bd9Sstevel@tonic-gate 	TNF_ERR_INTERNAL 	= 1032	/* internal error */
95*7c478bd9Sstevel@tonic-gate } tnf_errcode_t;
96*7c478bd9Sstevel@tonic-gate 
97*7c478bd9Sstevel@tonic-gate typedef void 	tnf_error_handler_t(void *, TNF *, tnf_errcode_t);
98*7c478bd9Sstevel@tonic-gate 
99*7c478bd9Sstevel@tonic-gate /*
100*7c478bd9Sstevel@tonic-gate  * TNF file interface
101*7c478bd9Sstevel@tonic-gate  */
102*7c478bd9Sstevel@tonic-gate 
103*7c478bd9Sstevel@tonic-gate tnf_errcode_t	tnf_reader_begin(caddr_t, size_t, TNF **);
104*7c478bd9Sstevel@tonic-gate tnf_errcode_t	tnf_reader_end(TNF *);
105*7c478bd9Sstevel@tonic-gate 
106*7c478bd9Sstevel@tonic-gate /*
107*7c478bd9Sstevel@tonic-gate  * Error interface
108*7c478bd9Sstevel@tonic-gate  */
109*7c478bd9Sstevel@tonic-gate 
110*7c478bd9Sstevel@tonic-gate void		tnf_set_error_handler(tnf_error_handler_t *, void *);
111*7c478bd9Sstevel@tonic-gate char *		tnf_error_message(tnf_errcode_t);
112*7c478bd9Sstevel@tonic-gate 
113*7c478bd9Sstevel@tonic-gate tnf_error_handler_t	tnf_default_error_handler;
114*7c478bd9Sstevel@tonic-gate 
115*7c478bd9Sstevel@tonic-gate /*
116*7c478bd9Sstevel@tonic-gate  * Data block access
117*7c478bd9Sstevel@tonic-gate  */
118*7c478bd9Sstevel@tonic-gate 
119*7c478bd9Sstevel@tonic-gate unsigned	tnf_get_block_count(TNF *);
120*7c478bd9Sstevel@tonic-gate tnf_datum_t	tnf_get_block_absolute(TNF *, unsigned);
121*7c478bd9Sstevel@tonic-gate tnf_datum_t	tnf_get_block_relative(tnf_datum_t, int);
122*7c478bd9Sstevel@tonic-gate int		tnf_is_block_header(tnf_datum_t);
123*7c478bd9Sstevel@tonic-gate 
124*7c478bd9Sstevel@tonic-gate /*
125*7c478bd9Sstevel@tonic-gate  * Record access
126*7c478bd9Sstevel@tonic-gate  */
127*7c478bd9Sstevel@tonic-gate 
128*7c478bd9Sstevel@tonic-gate tnf_datum_t	tnf_get_next_record(tnf_datum_t);
129*7c478bd9Sstevel@tonic-gate tnf_datum_t	tnf_get_block_header(tnf_datum_t);
130*7c478bd9Sstevel@tonic-gate tnf_datum_t	tnf_get_file_header(TNF *);
131*7c478bd9Sstevel@tonic-gate 
132*7c478bd9Sstevel@tonic-gate /*
133*7c478bd9Sstevel@tonic-gate  * Data classification predicates
134*7c478bd9Sstevel@tonic-gate  */
135*7c478bd9Sstevel@tonic-gate 
136*7c478bd9Sstevel@tonic-gate int		tnf_is_inline(tnf_datum_t);
137*7c478bd9Sstevel@tonic-gate int		tnf_is_scalar(tnf_datum_t);
138*7c478bd9Sstevel@tonic-gate int		tnf_is_record(tnf_datum_t);
139*7c478bd9Sstevel@tonic-gate int		tnf_is_array(tnf_datum_t);
140*7c478bd9Sstevel@tonic-gate int		tnf_is_string(tnf_datum_t);
141*7c478bd9Sstevel@tonic-gate int		tnf_is_struct(tnf_datum_t);
142*7c478bd9Sstevel@tonic-gate int		tnf_is_type(tnf_datum_t);
143*7c478bd9Sstevel@tonic-gate 
144*7c478bd9Sstevel@tonic-gate /*
145*7c478bd9Sstevel@tonic-gate  * Data operations
146*7c478bd9Sstevel@tonic-gate  */
147*7c478bd9Sstevel@tonic-gate 
148*7c478bd9Sstevel@tonic-gate tnf_kind_t	tnf_get_kind(tnf_datum_t);
149*7c478bd9Sstevel@tonic-gate size_t		tnf_get_size(tnf_datum_t);
150*7c478bd9Sstevel@tonic-gate tnf_datum_t	tnf_get_type(tnf_datum_t);
151*7c478bd9Sstevel@tonic-gate char *		tnf_get_type_name(tnf_datum_t);
152*7c478bd9Sstevel@tonic-gate caddr_t		tnf_get_raw(tnf_datum_t);
153*7c478bd9Sstevel@tonic-gate 
154*7c478bd9Sstevel@tonic-gate /*
155*7c478bd9Sstevel@tonic-gate  * Record operations
156*7c478bd9Sstevel@tonic-gate  */
157*7c478bd9Sstevel@tonic-gate 
158*7c478bd9Sstevel@tonic-gate tnf_datum_t	tnf_get_tag_arg(tnf_datum_t);
159*7c478bd9Sstevel@tonic-gate 
160*7c478bd9Sstevel@tonic-gate /*
161*7c478bd9Sstevel@tonic-gate  * Array operations
162*7c478bd9Sstevel@tonic-gate  */
163*7c478bd9Sstevel@tonic-gate 
164*7c478bd9Sstevel@tonic-gate unsigned	tnf_get_element_count(tnf_datum_t);
165*7c478bd9Sstevel@tonic-gate tnf_datum_t	tnf_get_element(tnf_datum_t, unsigned);
166*7c478bd9Sstevel@tonic-gate tnf_datum_t	tnf_get_element_type(tnf_datum_t);
167*7c478bd9Sstevel@tonic-gate caddr_t		tnf_get_elements(tnf_datum_t);
168*7c478bd9Sstevel@tonic-gate char *		tnf_get_chars(tnf_datum_t);
169*7c478bd9Sstevel@tonic-gate 
170*7c478bd9Sstevel@tonic-gate /*
171*7c478bd9Sstevel@tonic-gate  * Struct operations
172*7c478bd9Sstevel@tonic-gate  */
173*7c478bd9Sstevel@tonic-gate 
174*7c478bd9Sstevel@tonic-gate unsigned	tnf_get_slot_count(tnf_datum_t);
175*7c478bd9Sstevel@tonic-gate char *		tnf_get_slot_name(tnf_datum_t, unsigned);
176*7c478bd9Sstevel@tonic-gate unsigned	tnf_get_slot_index(tnf_datum_t, char *);
177*7c478bd9Sstevel@tonic-gate tnf_datum_t	tnf_get_slot_named(tnf_datum_t, char *);
178*7c478bd9Sstevel@tonic-gate tnf_datum_t	tnf_get_slot_indexed(tnf_datum_t, unsigned);
179*7c478bd9Sstevel@tonic-gate 
180*7c478bd9Sstevel@tonic-gate /*
181*7c478bd9Sstevel@tonic-gate  * Scalar data conversions
182*7c478bd9Sstevel@tonic-gate  */
183*7c478bd9Sstevel@tonic-gate 
184*7c478bd9Sstevel@tonic-gate char		tnf_get_char(tnf_datum_t);
185*7c478bd9Sstevel@tonic-gate tnf_int8_t	tnf_get_int8(tnf_datum_t);
186*7c478bd9Sstevel@tonic-gate tnf_int16_t	tnf_get_int16(tnf_datum_t);
187*7c478bd9Sstevel@tonic-gate tnf_int32_t	tnf_get_int32(tnf_datum_t);
188*7c478bd9Sstevel@tonic-gate tnf_int64_t	tnf_get_int64(tnf_datum_t);
189*7c478bd9Sstevel@tonic-gate tnf_float32_t	tnf_get_float32(tnf_datum_t);
190*7c478bd9Sstevel@tonic-gate tnf_float64_t	tnf_get_float64(tnf_datum_t);
191*7c478bd9Sstevel@tonic-gate 
192*7c478bd9Sstevel@tonic-gate /*
193*7c478bd9Sstevel@tonic-gate  * Type (tag) record operations
194*7c478bd9Sstevel@tonic-gate  */
195*7c478bd9Sstevel@tonic-gate 
196*7c478bd9Sstevel@tonic-gate tnf_kind_t	tnf_type_get_kind(tnf_datum_t);
197*7c478bd9Sstevel@tonic-gate char *		tnf_type_get_name(tnf_datum_t);
198*7c478bd9Sstevel@tonic-gate size_t		tnf_type_get_size(tnf_datum_t);
199*7c478bd9Sstevel@tonic-gate tnf_datum_t	tnf_type_get_property(tnf_datum_t, char *);
200*7c478bd9Sstevel@tonic-gate tnf_datum_t	tnf_type_get_base(tnf_datum_t);
201*7c478bd9Sstevel@tonic-gate 
202*7c478bd9Sstevel@tonic-gate #ifdef __cplusplus
203*7c478bd9Sstevel@tonic-gate }
204*7c478bd9Sstevel@tonic-gate #endif
205*7c478bd9Sstevel@tonic-gate 
206*7c478bd9Sstevel@tonic-gate #endif /* _TNF_TNF_H */
207