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