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"
31 * File header operations
35 tnf_get_file_header(TNF
*tnf
)
37 return (DATUM(tnf
->file_header_info
, (caddr_t
)tnf
->file_header
));
41 * Block access operations
45 tnf_get_block_count(TNF
*tnf
)
47 return (tnf
->block_count
);
51 tnf_get_block_absolute(TNF
*tnf
, unsigned index
)
53 if (index
>= tnf
->block_count
)
55 * access to non-existent block:
56 * no error as per spec
58 return (TNF_DATUM_NULL
);
61 * XXX Require a single block header tag
63 /* LINTED pointer cast may result in improper alignment */
64 return (DATUM(tnf
->block_header_info
,
65 (caddr_t
)_GET_INDEX_BLOCK(tnf
, index
)));
69 tnf_get_block_relative(tnf_datum_t datum
, int adjust
)
77 tnf
= DATUM_TNF(datum
);
78 bhdr
= _GET_BLOCK(tnf
, DATUM_VAL(datum
));
79 index
= _GET_BLOCK_INDEX(tnf
, bhdr
);
81 return (tnf_get_block_absolute(tnf
, index
+ adjust
));
85 tnf_is_block_header(tnf_datum_t datum
)
93 info
= DATUM_INFO(datum
);
94 val
= DATUM_VAL(datum
);
95 bhdr
= _GET_BLOCK(info
->tnf
, val
);
97 return (((caddr_t
)bhdr
== val
) &&
98 (info
== info
->tnf
->block_header_info
));
102 tnf_get_block_header(tnf_datum_t datum
)
109 tnf
= DATUM_TNF(datum
);
110 val
= DATUM_VAL(datum
);
112 * XXX Require a single block header tag
114 return (DATUM(tnf
->block_header_info
, (caddr_t
)_GET_BLOCK(tnf
, val
)));
118 * Sequential record access
122 tnf_get_next_record(tnf_datum_t datum
)
125 tnf_ref32_t
*bhdr
, *cell
, ref32
;
126 caddr_t val
, nval
, bval
, blim
;
131 tnf
= DATUM_TNF(datum
);
132 val
= DATUM_VAL(datum
);
134 size
= tnf_get_size(datum
);
137 /* Check file bounds */
138 if (nval
< tnf
->data_start
)
139 return (tnf_get_block_absolute(tnf
, 0));
140 else if (nval
>= tnf
->file_end
)
141 return (TNF_DATUM_NULL
);
144 * OK, nval is in data area, start looking in block
146 bhdr
= _GET_BLOCK(tnf
, nval
);
147 /* LINTED pointer cast may result in improper alignment */
148 bytes
= _GET_BLOCK_BYTES_VALID(tnf
, bhdr
);
149 bval
= (caddr_t
)bhdr
;
152 /* sequentially examine valid cells in block from nval onwards */
153 while (nval
< blim
) {
154 /* LINTED pointer cast may result in improper alignment */
155 cell
= (tnf_ref32_t
*)nval
;
156 ref32
= _GET_INT32(tnf
, cell
);
158 switch (TNF_REF32_TYPE(ref32
)) {
159 case TNF_REF32_T_FWD
: /* skip forwarding cells */
160 nval
+= sizeof (tnf_ref32_t
);
162 case TNF_REF32_T_RSVD
: /* catch bogus cells */
163 _tnf_error(tnf
, TNF_ERR_BADTNF
);
164 return (TNF_DATUM_NULL
);
165 default: /* PAIR or TAG: record header */
166 return (RECORD_DATUM(tnf
, cell
));
171 * Couldn't find it: return next non-zero block header
173 while ((bval
+= tnf
->block_size
) < tnf
->file_end
)
174 /* Gotta check that there is a real bhdr here */
175 /* LINTED pointer cast may result in improper alignment */
176 if (*(tnf_ref32_t
*)bval
!= TNF_NULL
)
177 /* LINTED pointer cast may result in improper alignment */
178 return (RECORD_DATUM(tnf
, (tnf_ref32_t
*)bval
));
181 * default: we're off the end of the file
183 return (TNF_DATUM_NULL
);