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) 1999 by Sun Microsystems, Inc.
24*7c478bd9Sstevel@tonic-gate * All rights reserved.
25*7c478bd9Sstevel@tonic-gate */
26*7c478bd9Sstevel@tonic-gate
27*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
28*7c478bd9Sstevel@tonic-gate
29*7c478bd9Sstevel@tonic-gate /*
30*7c478bd9Sstevel@tonic-gate * Library of support routines for UDFS data structures and conversions.
31*7c478bd9Sstevel@tonic-gate */
32*7c478bd9Sstevel@tonic-gate #include <stdio.h>
33*7c478bd9Sstevel@tonic-gate #include <string.h>
34*7c478bd9Sstevel@tonic-gate #include <strings.h>
35*7c478bd9Sstevel@tonic-gate #include <sys/time.h>
36*7c478bd9Sstevel@tonic-gate #include <sys/mutex.h>
37*7c478bd9Sstevel@tonic-gate #include <sys/vnode.h>
38*7c478bd9Sstevel@tonic-gate #include <sys/fs/udf_volume.h>
39*7c478bd9Sstevel@tonic-gate #include "udfs.h"
40*7c478bd9Sstevel@tonic-gate
41*7c478bd9Sstevel@tonic-gate char *tagerrs[] = {
42*7c478bd9Sstevel@tonic-gate "no error",
43*7c478bd9Sstevel@tonic-gate "invalid checksum", /* TAGERR_CKSUM */
44*7c478bd9Sstevel@tonic-gate "unknown tag id", /* TAGERR_ID */
45*7c478bd9Sstevel@tonic-gate "invalid version", /* TAGERR_VERSION */
46*7c478bd9Sstevel@tonic-gate "CRC length too large", /* TAGERR_TOOBIG */
47*7c478bd9Sstevel@tonic-gate "invalid CRC", /* TAGERR_CRC */
48*7c478bd9Sstevel@tonic-gate "location mismatch" /* TAGERR_LOC */
49*7c478bd9Sstevel@tonic-gate };
50*7c478bd9Sstevel@tonic-gate
51*7c478bd9Sstevel@tonic-gate #ifdef sparc
52*7c478bd9Sstevel@tonic-gate #define SWAP16(x) (((x) & 0xff) << 8 | ((x) >> 8) & 0xff)
53*7c478bd9Sstevel@tonic-gate #define SWAP32(x) (((x) & 0xff) << 24 | ((x) & 0xff00) << 8 | \
54*7c478bd9Sstevel@tonic-gate ((x) & 0xff0000) >> 8 | ((x) >> 24) & 0xff)
55*7c478bd9Sstevel@tonic-gate #define SWAP64(x) (SWAP32((x) >> 32) & 0xffffffff | SWAP32(x) << 32)
56*7c478bd9Sstevel@tonic-gate #else
57*7c478bd9Sstevel@tonic-gate #define SWAP16(x) (x)
58*7c478bd9Sstevel@tonic-gate #define SWAP32(x) (x)
59*7c478bd9Sstevel@tonic-gate #define SWAP64(x) (x)
60*7c478bd9Sstevel@tonic-gate #endif
61*7c478bd9Sstevel@tonic-gate
62*7c478bd9Sstevel@tonic-gate static void ud_swap_ext_ad(struct extent_ad *);
63*7c478bd9Sstevel@tonic-gate static void ud_swap_tstamp(struct tstamp *);
64*7c478bd9Sstevel@tonic-gate static void ud_swap_icb_tag(struct icb_tag *);
65*7c478bd9Sstevel@tonic-gate void ud_swap_short_ad(struct short_ad *);
66*7c478bd9Sstevel@tonic-gate void ud_swap_long_ad(struct long_ad *);
67*7c478bd9Sstevel@tonic-gate static void ud_swap_pri_vol_desc(struct pri_vol_desc *);
68*7c478bd9Sstevel@tonic-gate static void ud_swap_vdp(struct vol_desc_ptr *);
69*7c478bd9Sstevel@tonic-gate static void ud_swap_iuvd(struct iuvd_desc *);
70*7c478bd9Sstevel@tonic-gate static void ud_swap_avdp(struct anch_vol_desc_ptr *);
71*7c478bd9Sstevel@tonic-gate static void ud_swap_part_desc(struct part_desc *);
72*7c478bd9Sstevel@tonic-gate static void ud_swap_log_desc(struct log_vol_desc *);
73*7c478bd9Sstevel@tonic-gate static void ud_swap_unall_desc(struct unall_spc_desc *);
74*7c478bd9Sstevel@tonic-gate static void ud_swap_lvint(struct log_vol_int_desc *);
75*7c478bd9Sstevel@tonic-gate static void ud_swap_fileset_desc(struct file_set_desc *);
76*7c478bd9Sstevel@tonic-gate static void ud_swap_term_desc(struct term_desc *);
77*7c478bd9Sstevel@tonic-gate static void ud_swap_file_id(struct file_id *);
78*7c478bd9Sstevel@tonic-gate static void ud_swap_file_entry(struct file_entry *, int);
79*7c478bd9Sstevel@tonic-gate static void ud_swap_alloc_ext(struct alloc_ext_desc *);
80*7c478bd9Sstevel@tonic-gate static void ud_swap_tstamp(tstamp_t *);
81*7c478bd9Sstevel@tonic-gate static void ud_swap_space_bitmap(struct space_bmap_desc *);
82*7c478bd9Sstevel@tonic-gate static uint16_t crc16(uint8_t *, int32_t, int32_t);
83*7c478bd9Sstevel@tonic-gate
84*7c478bd9Sstevel@tonic-gate extern uint32_t ecma_version;
85*7c478bd9Sstevel@tonic-gate
86*7c478bd9Sstevel@tonic-gate void
maketag(struct tag * itp,struct tag * otp)87*7c478bd9Sstevel@tonic-gate maketag(struct tag *itp, struct tag *otp)
88*7c478bd9Sstevel@tonic-gate {
89*7c478bd9Sstevel@tonic-gate int32_t sum, i;
90*7c478bd9Sstevel@tonic-gate uint8_t *cp;
91*7c478bd9Sstevel@tonic-gate
92*7c478bd9Sstevel@tonic-gate if (itp != otp) {
93*7c478bd9Sstevel@tonic-gate bcopy((unsigned char *)(itp + 1), (unsigned char *)(otp + 1),
94*7c478bd9Sstevel@tonic-gate itp->tag_crc_len);
95*7c478bd9Sstevel@tonic-gate }
96*7c478bd9Sstevel@tonic-gate
97*7c478bd9Sstevel@tonic-gate /* Swap fields */
98*7c478bd9Sstevel@tonic-gate switch (itp->tag_id) {
99*7c478bd9Sstevel@tonic-gate case UD_PRI_VOL_DESC:
100*7c478bd9Sstevel@tonic-gate ud_swap_pri_vol_desc((struct pri_vol_desc *)otp);
101*7c478bd9Sstevel@tonic-gate break;
102*7c478bd9Sstevel@tonic-gate case UD_ANCH_VOL_DESC:
103*7c478bd9Sstevel@tonic-gate ud_swap_avdp((struct anch_vol_desc_ptr *)otp);
104*7c478bd9Sstevel@tonic-gate break;
105*7c478bd9Sstevel@tonic-gate case UD_VOL_DESC_PTR:
106*7c478bd9Sstevel@tonic-gate ud_swap_vdp((struct vol_desc_ptr *)otp);
107*7c478bd9Sstevel@tonic-gate break;
108*7c478bd9Sstevel@tonic-gate case UD_IMPL_USE_DESC:
109*7c478bd9Sstevel@tonic-gate ud_swap_iuvd((struct iuvd_desc *)otp);
110*7c478bd9Sstevel@tonic-gate break;
111*7c478bd9Sstevel@tonic-gate case UD_PART_DESC:
112*7c478bd9Sstevel@tonic-gate ud_swap_part_desc((struct part_desc *)otp);
113*7c478bd9Sstevel@tonic-gate break;
114*7c478bd9Sstevel@tonic-gate case UD_LOG_VOL_DESC:
115*7c478bd9Sstevel@tonic-gate ud_swap_log_desc((struct log_vol_desc *)otp);
116*7c478bd9Sstevel@tonic-gate break;
117*7c478bd9Sstevel@tonic-gate case UD_UNALL_SPA_DESC:
118*7c478bd9Sstevel@tonic-gate ud_swap_unall_desc((struct unall_spc_desc *)otp);
119*7c478bd9Sstevel@tonic-gate break;
120*7c478bd9Sstevel@tonic-gate case UD_TERM_DESC:
121*7c478bd9Sstevel@tonic-gate ud_swap_term_desc((struct term_desc *)otp);
122*7c478bd9Sstevel@tonic-gate break;
123*7c478bd9Sstevel@tonic-gate case UD_LOG_VOL_INT:
124*7c478bd9Sstevel@tonic-gate /* LINTED */
125*7c478bd9Sstevel@tonic-gate ud_swap_lvint((struct log_vol_int_desc *)otp);
126*7c478bd9Sstevel@tonic-gate break;
127*7c478bd9Sstevel@tonic-gate case UD_FILE_SET_DESC:
128*7c478bd9Sstevel@tonic-gate ud_swap_fileset_desc((struct file_set_desc *)otp);
129*7c478bd9Sstevel@tonic-gate break;
130*7c478bd9Sstevel@tonic-gate case UD_FILE_ID_DESC:
131*7c478bd9Sstevel@tonic-gate ud_swap_file_id((struct file_id *)otp);
132*7c478bd9Sstevel@tonic-gate break;
133*7c478bd9Sstevel@tonic-gate case UD_ALLOC_EXT_DESC:
134*7c478bd9Sstevel@tonic-gate break;
135*7c478bd9Sstevel@tonic-gate case UD_INDIRECT_ENT:
136*7c478bd9Sstevel@tonic-gate break;
137*7c478bd9Sstevel@tonic-gate case UD_TERMINAL_ENT:
138*7c478bd9Sstevel@tonic-gate break;
139*7c478bd9Sstevel@tonic-gate case UD_FILE_ENTRY:
140*7c478bd9Sstevel@tonic-gate /* LINTED */
141*7c478bd9Sstevel@tonic-gate ud_swap_file_entry((struct file_entry *)otp, 0);
142*7c478bd9Sstevel@tonic-gate break;
143*7c478bd9Sstevel@tonic-gate case UD_EXT_ATTR_HDR:
144*7c478bd9Sstevel@tonic-gate break;
145*7c478bd9Sstevel@tonic-gate case UD_UNALL_SPA_ENT:
146*7c478bd9Sstevel@tonic-gate break;
147*7c478bd9Sstevel@tonic-gate case UD_SPA_BMAP_DESC:
148*7c478bd9Sstevel@tonic-gate ud_swap_space_bitmap((struct space_bmap_desc *)otp);
149*7c478bd9Sstevel@tonic-gate break;
150*7c478bd9Sstevel@tonic-gate case UD_PART_INT_DESC:
151*7c478bd9Sstevel@tonic-gate break;
152*7c478bd9Sstevel@tonic-gate }
153*7c478bd9Sstevel@tonic-gate otp->tag_id = SWAP16(itp->tag_id);
154*7c478bd9Sstevel@tonic-gate otp->tag_desc_ver = SWAP16(itp->tag_desc_ver);
155*7c478bd9Sstevel@tonic-gate otp->tag_cksum = otp->tag_res = 0;
156*7c478bd9Sstevel@tonic-gate otp->tag_sno = SWAP16(itp->tag_sno);
157*7c478bd9Sstevel@tonic-gate otp->tag_crc = SWAP16(crc16((unsigned char *)(otp+1),
158*7c478bd9Sstevel@tonic-gate itp->tag_crc_len, 0));
159*7c478bd9Sstevel@tonic-gate otp->tag_crc_len = SWAP16(itp->tag_crc_len);
160*7c478bd9Sstevel@tonic-gate otp->tag_loc = SWAP32(itp->tag_loc);
161*7c478bd9Sstevel@tonic-gate
162*7c478bd9Sstevel@tonic-gate /*
163*7c478bd9Sstevel@tonic-gate * Now do checksum on tag itself
164*7c478bd9Sstevel@tonic-gate */
165*7c478bd9Sstevel@tonic-gate cp = (unsigned char *)otp;
166*7c478bd9Sstevel@tonic-gate sum = 0;
167*7c478bd9Sstevel@tonic-gate for (i = 0; i < sizeof (*otp); i++)
168*7c478bd9Sstevel@tonic-gate sum += *cp++;
169*7c478bd9Sstevel@tonic-gate otp->tag_cksum = sum;
170*7c478bd9Sstevel@tonic-gate }
171*7c478bd9Sstevel@tonic-gate
172*7c478bd9Sstevel@tonic-gate
173*7c478bd9Sstevel@tonic-gate int32_t
verifytag(struct tag * tp,uint32_t loc,struct tag * otp,int expect)174*7c478bd9Sstevel@tonic-gate verifytag(struct tag *tp, uint32_t loc, struct tag *otp, int expect)
175*7c478bd9Sstevel@tonic-gate {
176*7c478bd9Sstevel@tonic-gate uint8_t *cp;
177*7c478bd9Sstevel@tonic-gate uint32_t id, vers, length, tloc;
178*7c478bd9Sstevel@tonic-gate int sum, i;
179*7c478bd9Sstevel@tonic-gate
180*7c478bd9Sstevel@tonic-gate sum = -tp->tag_cksum;
181*7c478bd9Sstevel@tonic-gate cp = (unsigned char *)tp;
182*7c478bd9Sstevel@tonic-gate for (i = 0; i < sizeof (*tp); i++)
183*7c478bd9Sstevel@tonic-gate sum += *cp++;
184*7c478bd9Sstevel@tonic-gate if ((sum & 0xff) != tp->tag_cksum)
185*7c478bd9Sstevel@tonic-gate return (TAGERR_CKSUM);
186*7c478bd9Sstevel@tonic-gate id = SWAP16(tp->tag_id);
187*7c478bd9Sstevel@tonic-gate if (id > 9 && id < 256 || id > 266 || (expect > 0 && id != expect))
188*7c478bd9Sstevel@tonic-gate return (TAGERR_ID);
189*7c478bd9Sstevel@tonic-gate vers = SWAP16(tp->tag_desc_ver);
190*7c478bd9Sstevel@tonic-gate if (vers > ecma_version)
191*7c478bd9Sstevel@tonic-gate return (TAGERR_VERSION);
192*7c478bd9Sstevel@tonic-gate length = SWAP16(tp->tag_crc_len);
193*7c478bd9Sstevel@tonic-gate if (length > MAXBSIZE)
194*7c478bd9Sstevel@tonic-gate return (TAGERR_TOOBIG);
195*7c478bd9Sstevel@tonic-gate if (crc16((unsigned char *)(tp+1), length, SWAP16(tp->tag_crc)) != 0)
196*7c478bd9Sstevel@tonic-gate return (TAGERR_CRC);
197*7c478bd9Sstevel@tonic-gate tloc = SWAP32(tp->tag_loc);
198*7c478bd9Sstevel@tonic-gate if ((int)loc != -1 && tloc != loc)
199*7c478bd9Sstevel@tonic-gate return (TAGERR_LOC);
200*7c478bd9Sstevel@tonic-gate if (!otp)
201*7c478bd9Sstevel@tonic-gate return (0);
202*7c478bd9Sstevel@tonic-gate otp->tag_id = id;
203*7c478bd9Sstevel@tonic-gate otp->tag_desc_ver = vers;
204*7c478bd9Sstevel@tonic-gate otp->tag_cksum = tp->tag_cksum;
205*7c478bd9Sstevel@tonic-gate otp->tag_res = 0;
206*7c478bd9Sstevel@tonic-gate otp->tag_sno = SWAP16(tp->tag_sno);
207*7c478bd9Sstevel@tonic-gate otp->tag_crc = SWAP16(tp->tag_crc);
208*7c478bd9Sstevel@tonic-gate otp->tag_crc_len = length;
209*7c478bd9Sstevel@tonic-gate otp->tag_loc = tloc;
210*7c478bd9Sstevel@tonic-gate
211*7c478bd9Sstevel@tonic-gate if (tp != otp)
212*7c478bd9Sstevel@tonic-gate bcopy((unsigned char *)(tp + 1), (unsigned char *)(otp + 1),
213*7c478bd9Sstevel@tonic-gate otp->tag_crc_len);
214*7c478bd9Sstevel@tonic-gate /* Swap fields */
215*7c478bd9Sstevel@tonic-gate switch (otp->tag_id) {
216*7c478bd9Sstevel@tonic-gate case UD_PRI_VOL_DESC:
217*7c478bd9Sstevel@tonic-gate ud_swap_pri_vol_desc((struct pri_vol_desc *)otp);
218*7c478bd9Sstevel@tonic-gate break;
219*7c478bd9Sstevel@tonic-gate case UD_ANCH_VOL_DESC:
220*7c478bd9Sstevel@tonic-gate ud_swap_avdp((struct anch_vol_desc_ptr *)otp);
221*7c478bd9Sstevel@tonic-gate break;
222*7c478bd9Sstevel@tonic-gate case UD_VOL_DESC_PTR:
223*7c478bd9Sstevel@tonic-gate ud_swap_vdp((struct vol_desc_ptr *)otp);
224*7c478bd9Sstevel@tonic-gate break;
225*7c478bd9Sstevel@tonic-gate case UD_IMPL_USE_DESC:
226*7c478bd9Sstevel@tonic-gate ud_swap_iuvd((struct iuvd_desc *)otp);
227*7c478bd9Sstevel@tonic-gate break;
228*7c478bd9Sstevel@tonic-gate case UD_PART_DESC:
229*7c478bd9Sstevel@tonic-gate ud_swap_part_desc((struct part_desc *)otp);
230*7c478bd9Sstevel@tonic-gate break;
231*7c478bd9Sstevel@tonic-gate case UD_LOG_VOL_DESC:
232*7c478bd9Sstevel@tonic-gate ud_swap_log_desc((struct log_vol_desc *)otp);
233*7c478bd9Sstevel@tonic-gate break;
234*7c478bd9Sstevel@tonic-gate case UD_UNALL_SPA_DESC:
235*7c478bd9Sstevel@tonic-gate ud_swap_unall_desc((struct unall_spc_desc *)otp);
236*7c478bd9Sstevel@tonic-gate break;
237*7c478bd9Sstevel@tonic-gate case UD_TERM_DESC:
238*7c478bd9Sstevel@tonic-gate ud_swap_term_desc((struct term_desc *)otp);
239*7c478bd9Sstevel@tonic-gate break;
240*7c478bd9Sstevel@tonic-gate case UD_LOG_VOL_INT:
241*7c478bd9Sstevel@tonic-gate /* LINTED */
242*7c478bd9Sstevel@tonic-gate ud_swap_lvint((struct log_vol_int_desc *)otp);
243*7c478bd9Sstevel@tonic-gate break;
244*7c478bd9Sstevel@tonic-gate case UD_FILE_SET_DESC:
245*7c478bd9Sstevel@tonic-gate ud_swap_fileset_desc((struct file_set_desc *)otp);
246*7c478bd9Sstevel@tonic-gate break;
247*7c478bd9Sstevel@tonic-gate case UD_FILE_ID_DESC:
248*7c478bd9Sstevel@tonic-gate ud_swap_file_id((struct file_id *)otp);
249*7c478bd9Sstevel@tonic-gate break;
250*7c478bd9Sstevel@tonic-gate case UD_ALLOC_EXT_DESC:
251*7c478bd9Sstevel@tonic-gate ud_swap_alloc_ext((struct alloc_ext_desc *)otp);
252*7c478bd9Sstevel@tonic-gate break;
253*7c478bd9Sstevel@tonic-gate case UD_INDIRECT_ENT:
254*7c478bd9Sstevel@tonic-gate break;
255*7c478bd9Sstevel@tonic-gate case UD_TERMINAL_ENT:
256*7c478bd9Sstevel@tonic-gate break;
257*7c478bd9Sstevel@tonic-gate case UD_FILE_ENTRY:
258*7c478bd9Sstevel@tonic-gate /* LINTED */
259*7c478bd9Sstevel@tonic-gate ud_swap_file_entry((struct file_entry *)otp, 1);
260*7c478bd9Sstevel@tonic-gate break;
261*7c478bd9Sstevel@tonic-gate case UD_EXT_ATTR_HDR:
262*7c478bd9Sstevel@tonic-gate break;
263*7c478bd9Sstevel@tonic-gate case UD_UNALL_SPA_ENT:
264*7c478bd9Sstevel@tonic-gate break;
265*7c478bd9Sstevel@tonic-gate case UD_SPA_BMAP_DESC:
266*7c478bd9Sstevel@tonic-gate ud_swap_space_bitmap((struct space_bmap_desc *)otp);
267*7c478bd9Sstevel@tonic-gate break;
268*7c478bd9Sstevel@tonic-gate case UD_PART_INT_DESC:
269*7c478bd9Sstevel@tonic-gate break;
270*7c478bd9Sstevel@tonic-gate }
271*7c478bd9Sstevel@tonic-gate return (0);
272*7c478bd9Sstevel@tonic-gate }
273*7c478bd9Sstevel@tonic-gate
274*7c478bd9Sstevel@tonic-gate static void
ud_swap_ext_ad(struct extent_ad * p)275*7c478bd9Sstevel@tonic-gate ud_swap_ext_ad(struct extent_ad *p)
276*7c478bd9Sstevel@tonic-gate {
277*7c478bd9Sstevel@tonic-gate p->ext_len = SWAP32(p->ext_len);
278*7c478bd9Sstevel@tonic-gate p->ext_loc = SWAP32(p->ext_loc);
279*7c478bd9Sstevel@tonic-gate }
280*7c478bd9Sstevel@tonic-gate
281*7c478bd9Sstevel@tonic-gate
282*7c478bd9Sstevel@tonic-gate /* ARGSUSED */
283*7c478bd9Sstevel@tonic-gate static void
ud_swap_regid(struct regid * p)284*7c478bd9Sstevel@tonic-gate ud_swap_regid(struct regid *p)
285*7c478bd9Sstevel@tonic-gate {
286*7c478bd9Sstevel@tonic-gate }
287*7c478bd9Sstevel@tonic-gate
288*7c478bd9Sstevel@tonic-gate static void
ud_swap_icb_tag(struct icb_tag * p)289*7c478bd9Sstevel@tonic-gate ud_swap_icb_tag(struct icb_tag *p)
290*7c478bd9Sstevel@tonic-gate {
291*7c478bd9Sstevel@tonic-gate p->itag_prnde = SWAP32(p->itag_prnde);
292*7c478bd9Sstevel@tonic-gate p->itag_strategy = SWAP16(p->itag_strategy);
293*7c478bd9Sstevel@tonic-gate p->itag_param = SWAP16(p->itag_param);
294*7c478bd9Sstevel@tonic-gate p->itag_max_ent = SWAP16(p->itag_max_ent);
295*7c478bd9Sstevel@tonic-gate p->itag_lb_loc = SWAP32(p->itag_lb_loc);
296*7c478bd9Sstevel@tonic-gate p->itag_lb_prn = SWAP16(p->itag_lb_prn);
297*7c478bd9Sstevel@tonic-gate p->itag_flags = SWAP16(p->itag_flags);
298*7c478bd9Sstevel@tonic-gate }
299*7c478bd9Sstevel@tonic-gate
300*7c478bd9Sstevel@tonic-gate void
ud_swap_short_ad(struct short_ad * p)301*7c478bd9Sstevel@tonic-gate ud_swap_short_ad(struct short_ad *p)
302*7c478bd9Sstevel@tonic-gate {
303*7c478bd9Sstevel@tonic-gate p->sad_ext_len = SWAP32(p->sad_ext_len);
304*7c478bd9Sstevel@tonic-gate p->sad_ext_loc = SWAP32(p->sad_ext_loc);
305*7c478bd9Sstevel@tonic-gate }
306*7c478bd9Sstevel@tonic-gate
307*7c478bd9Sstevel@tonic-gate void
ud_swap_long_ad(struct long_ad * p)308*7c478bd9Sstevel@tonic-gate ud_swap_long_ad(struct long_ad *p)
309*7c478bd9Sstevel@tonic-gate {
310*7c478bd9Sstevel@tonic-gate p->lad_ext_len = SWAP32(p->lad_ext_len);
311*7c478bd9Sstevel@tonic-gate p->lad_ext_loc = SWAP32(p->lad_ext_loc);
312*7c478bd9Sstevel@tonic-gate p->lad_ext_prn = SWAP16(p->lad_ext_prn);
313*7c478bd9Sstevel@tonic-gate }
314*7c478bd9Sstevel@tonic-gate
315*7c478bd9Sstevel@tonic-gate static void
ud_swap_pri_vol_desc(struct pri_vol_desc * p)316*7c478bd9Sstevel@tonic-gate ud_swap_pri_vol_desc(struct pri_vol_desc *p)
317*7c478bd9Sstevel@tonic-gate {
318*7c478bd9Sstevel@tonic-gate p->pvd_vdsn = SWAP32(p->pvd_vdsn);
319*7c478bd9Sstevel@tonic-gate p->pvd_pvdn = SWAP32(p->pvd_pvdn);
320*7c478bd9Sstevel@tonic-gate p->pvd_vsn = SWAP16(p->pvd_vsn);
321*7c478bd9Sstevel@tonic-gate p->pvd_mvsn = SWAP16(p->pvd_mvsn);
322*7c478bd9Sstevel@tonic-gate p->pvd_il = SWAP16(p->pvd_il);
323*7c478bd9Sstevel@tonic-gate p->pvd_mil = SWAP16(p->pvd_mil);
324*7c478bd9Sstevel@tonic-gate p->pvd_csl = SWAP32(p->pvd_csl);
325*7c478bd9Sstevel@tonic-gate p->pvd_mcsl = SWAP32(p->pvd_mcsl);
326*7c478bd9Sstevel@tonic-gate ud_swap_ext_ad(&p->pvd_vol_abs);
327*7c478bd9Sstevel@tonic-gate ud_swap_ext_ad(&p->pvd_vcn);
328*7c478bd9Sstevel@tonic-gate ud_swap_regid(&p->pvd_appl_id);
329*7c478bd9Sstevel@tonic-gate ud_swap_tstamp(&p->pvd_time);
330*7c478bd9Sstevel@tonic-gate ud_swap_regid(&p->pvd_ii);
331*7c478bd9Sstevel@tonic-gate p->pvd_pvdsl = SWAP32(p->pvd_pvdsl);
332*7c478bd9Sstevel@tonic-gate p->pvd_flags = SWAP16(p->pvd_flags);
333*7c478bd9Sstevel@tonic-gate }
334*7c478bd9Sstevel@tonic-gate
335*7c478bd9Sstevel@tonic-gate static void
ud_swap_iuvd(struct iuvd_desc * p)336*7c478bd9Sstevel@tonic-gate ud_swap_iuvd(struct iuvd_desc *p)
337*7c478bd9Sstevel@tonic-gate {
338*7c478bd9Sstevel@tonic-gate p->iuvd_vdsn = SWAP32(p->iuvd_vdsn);
339*7c478bd9Sstevel@tonic-gate ud_swap_regid(&p->iuvd_ii);
340*7c478bd9Sstevel@tonic-gate ud_swap_regid(&p->iuvd_iid);
341*7c478bd9Sstevel@tonic-gate }
342*7c478bd9Sstevel@tonic-gate
343*7c478bd9Sstevel@tonic-gate static void
ud_swap_vdp(struct vol_desc_ptr * p)344*7c478bd9Sstevel@tonic-gate ud_swap_vdp(struct vol_desc_ptr *p)
345*7c478bd9Sstevel@tonic-gate {
346*7c478bd9Sstevel@tonic-gate p->vdp_vdsn = SWAP32(p->vdp_vdsn);
347*7c478bd9Sstevel@tonic-gate ud_swap_ext_ad(&p->vdp_nvdse);
348*7c478bd9Sstevel@tonic-gate }
349*7c478bd9Sstevel@tonic-gate
350*7c478bd9Sstevel@tonic-gate static void
ud_swap_avdp(struct anch_vol_desc_ptr * p)351*7c478bd9Sstevel@tonic-gate ud_swap_avdp(struct anch_vol_desc_ptr *p)
352*7c478bd9Sstevel@tonic-gate {
353*7c478bd9Sstevel@tonic-gate ud_swap_ext_ad(&p->avd_main_vdse);
354*7c478bd9Sstevel@tonic-gate ud_swap_ext_ad(&p->avd_res_vdse);
355*7c478bd9Sstevel@tonic-gate }
356*7c478bd9Sstevel@tonic-gate
357*7c478bd9Sstevel@tonic-gate static void
ud_swap_part_desc(struct part_desc * p)358*7c478bd9Sstevel@tonic-gate ud_swap_part_desc(struct part_desc *p)
359*7c478bd9Sstevel@tonic-gate {
360*7c478bd9Sstevel@tonic-gate struct phdr_desc *php;
361*7c478bd9Sstevel@tonic-gate
362*7c478bd9Sstevel@tonic-gate p->pd_vdsn = SWAP32(p->pd_vdsn);
363*7c478bd9Sstevel@tonic-gate p->pd_pflags = SWAP16(p->pd_pflags);
364*7c478bd9Sstevel@tonic-gate p->pd_pnum = SWAP16(p->pd_pnum);
365*7c478bd9Sstevel@tonic-gate ud_swap_regid(&p->pd_pcontents);
366*7c478bd9Sstevel@tonic-gate p->pd_acc_type = SWAP32(p->pd_acc_type);
367*7c478bd9Sstevel@tonic-gate p->pd_part_start = SWAP32(p->pd_part_start);
368*7c478bd9Sstevel@tonic-gate p->pd_part_length = SWAP32(p->pd_part_length);
369*7c478bd9Sstevel@tonic-gate ud_swap_regid(&p->pd_ii);
370*7c478bd9Sstevel@tonic-gate if (strncmp(p->pd_pcontents.reg_id, "+NSR", 4) == 0) {
371*7c478bd9Sstevel@tonic-gate /* LINTED */
372*7c478bd9Sstevel@tonic-gate php = (struct phdr_desc *)p->pd_pc_use;
373*7c478bd9Sstevel@tonic-gate ud_swap_short_ad(&php->phdr_ust);
374*7c478bd9Sstevel@tonic-gate ud_swap_short_ad(&php->phdr_usb);
375*7c478bd9Sstevel@tonic-gate ud_swap_short_ad(&php->phdr_it);
376*7c478bd9Sstevel@tonic-gate ud_swap_short_ad(&php->phdr_fst);
377*7c478bd9Sstevel@tonic-gate ud_swap_short_ad(&php->phdr_fsb);
378*7c478bd9Sstevel@tonic-gate }
379*7c478bd9Sstevel@tonic-gate }
380*7c478bd9Sstevel@tonic-gate
381*7c478bd9Sstevel@tonic-gate static void
ud_swap_log_desc(struct log_vol_desc * p)382*7c478bd9Sstevel@tonic-gate ud_swap_log_desc(struct log_vol_desc *p)
383*7c478bd9Sstevel@tonic-gate {
384*7c478bd9Sstevel@tonic-gate p->lvd_vdsn = SWAP32(p->lvd_vdsn);
385*7c478bd9Sstevel@tonic-gate p->lvd_log_bsize = SWAP32(p->lvd_log_bsize);
386*7c478bd9Sstevel@tonic-gate ud_swap_regid(&p->lvd_dom_id);
387*7c478bd9Sstevel@tonic-gate ud_swap_long_ad(&p->lvd_lvcu);
388*7c478bd9Sstevel@tonic-gate p->lvd_mtbl_len = SWAP32(p->lvd_mtbl_len);
389*7c478bd9Sstevel@tonic-gate p->lvd_num_pmaps = SWAP32(p->lvd_num_pmaps);
390*7c478bd9Sstevel@tonic-gate ud_swap_regid(&p->lvd_ii);
391*7c478bd9Sstevel@tonic-gate ud_swap_ext_ad(&p->lvd_int_seq_ext);
392*7c478bd9Sstevel@tonic-gate }
393*7c478bd9Sstevel@tonic-gate
394*7c478bd9Sstevel@tonic-gate static void
ud_swap_unall_desc(struct unall_spc_desc * p)395*7c478bd9Sstevel@tonic-gate ud_swap_unall_desc(struct unall_spc_desc *p)
396*7c478bd9Sstevel@tonic-gate {
397*7c478bd9Sstevel@tonic-gate p->ua_vdsn = SWAP32(p->ua_vdsn);
398*7c478bd9Sstevel@tonic-gate p->ua_nad = SWAP32(p->ua_nad);
399*7c478bd9Sstevel@tonic-gate }
400*7c478bd9Sstevel@tonic-gate
401*7c478bd9Sstevel@tonic-gate static void
ud_swap_lvint(struct log_vol_int_desc * p)402*7c478bd9Sstevel@tonic-gate ud_swap_lvint(struct log_vol_int_desc *p)
403*7c478bd9Sstevel@tonic-gate {
404*7c478bd9Sstevel@tonic-gate struct lvid_iu *lvup;
405*7c478bd9Sstevel@tonic-gate
406*7c478bd9Sstevel@tonic-gate ud_swap_tstamp(&p->lvid_tstamp);
407*7c478bd9Sstevel@tonic-gate p->lvid_int_type = SWAP32(p->lvid_int_type);
408*7c478bd9Sstevel@tonic-gate ud_swap_ext_ad(&p->lvid_nie);
409*7c478bd9Sstevel@tonic-gate p->lvid_npart = SWAP32(p->lvid_npart);
410*7c478bd9Sstevel@tonic-gate p->lvid_liu = SWAP32(p->lvid_liu);
411*7c478bd9Sstevel@tonic-gate p->lvid_uniqid = SWAP64(p->lvid_uniqid);
412*7c478bd9Sstevel@tonic-gate p->lvid_fst[0] = SWAP32(p->lvid_fst[0]);
413*7c478bd9Sstevel@tonic-gate p->lvid_fst[1] = SWAP32(p->lvid_fst[1]);
414*7c478bd9Sstevel@tonic-gate
415*7c478bd9Sstevel@tonic-gate lvup = (struct lvid_iu *)&p->lvid_fst[2];
416*7c478bd9Sstevel@tonic-gate ud_swap_regid(&lvup->lvidiu_regid);
417*7c478bd9Sstevel@tonic-gate lvup->lvidiu_nfiles = SWAP32(lvup->lvidiu_nfiles);
418*7c478bd9Sstevel@tonic-gate lvup->lvidiu_ndirs = SWAP32(lvup->lvidiu_ndirs);
419*7c478bd9Sstevel@tonic-gate lvup->lvidiu_mread = SWAP16(lvup->lvidiu_mread);
420*7c478bd9Sstevel@tonic-gate lvup->lvidiu_mwrite = SWAP16(lvup->lvidiu_mwrite);
421*7c478bd9Sstevel@tonic-gate lvup->lvidiu_maxwr = SWAP16(lvup->lvidiu_maxwr);
422*7c478bd9Sstevel@tonic-gate }
423*7c478bd9Sstevel@tonic-gate
424*7c478bd9Sstevel@tonic-gate static void
ud_swap_fileset_desc(struct file_set_desc * p)425*7c478bd9Sstevel@tonic-gate ud_swap_fileset_desc(struct file_set_desc *p)
426*7c478bd9Sstevel@tonic-gate {
427*7c478bd9Sstevel@tonic-gate ud_swap_tstamp(&p->fsd_time);
428*7c478bd9Sstevel@tonic-gate p->fsd_ilevel = SWAP16(p->fsd_ilevel);
429*7c478bd9Sstevel@tonic-gate p->fsd_mi_level = SWAP16(p->fsd_mi_level);
430*7c478bd9Sstevel@tonic-gate p->fsd_cs_list = SWAP32(p->fsd_cs_list);
431*7c478bd9Sstevel@tonic-gate p->fsd_mcs_list = SWAP32(p->fsd_mcs_list);
432*7c478bd9Sstevel@tonic-gate p->fsd_fs_no = SWAP32(p->fsd_fs_no);
433*7c478bd9Sstevel@tonic-gate p->fsd_fsd_no = SWAP32(p->fsd_fsd_no);
434*7c478bd9Sstevel@tonic-gate ud_swap_long_ad(&p->fsd_root_icb);
435*7c478bd9Sstevel@tonic-gate ud_swap_regid(&p->fsd_did);
436*7c478bd9Sstevel@tonic-gate ud_swap_long_ad(&p->fsd_next);
437*7c478bd9Sstevel@tonic-gate }
438*7c478bd9Sstevel@tonic-gate
439*7c478bd9Sstevel@tonic-gate /* ARGSUSED */
440*7c478bd9Sstevel@tonic-gate static void
ud_swap_term_desc(struct term_desc * p)441*7c478bd9Sstevel@tonic-gate ud_swap_term_desc(struct term_desc *p)
442*7c478bd9Sstevel@tonic-gate {
443*7c478bd9Sstevel@tonic-gate }
444*7c478bd9Sstevel@tonic-gate
445*7c478bd9Sstevel@tonic-gate static void
ud_swap_file_id(struct file_id * p)446*7c478bd9Sstevel@tonic-gate ud_swap_file_id(struct file_id *p)
447*7c478bd9Sstevel@tonic-gate {
448*7c478bd9Sstevel@tonic-gate p->fid_ver = SWAP16(p->fid_ver);
449*7c478bd9Sstevel@tonic-gate ud_swap_long_ad(&p->fid_icb);
450*7c478bd9Sstevel@tonic-gate p->fid_iulen = SWAP16(p->fid_iulen);
451*7c478bd9Sstevel@tonic-gate }
452*7c478bd9Sstevel@tonic-gate
453*7c478bd9Sstevel@tonic-gate static void
ud_swap_alloc_ext(struct alloc_ext_desc * p)454*7c478bd9Sstevel@tonic-gate ud_swap_alloc_ext(struct alloc_ext_desc *p)
455*7c478bd9Sstevel@tonic-gate {
456*7c478bd9Sstevel@tonic-gate p->aed_rev_ael = SWAP32(p->aed_rev_ael);
457*7c478bd9Sstevel@tonic-gate p->aed_len_aed = SWAP32(p->aed_len_aed);
458*7c478bd9Sstevel@tonic-gate }
459*7c478bd9Sstevel@tonic-gate
460*7c478bd9Sstevel@tonic-gate static void
ud_swap_space_bitmap(struct space_bmap_desc * p)461*7c478bd9Sstevel@tonic-gate ud_swap_space_bitmap(struct space_bmap_desc *p)
462*7c478bd9Sstevel@tonic-gate {
463*7c478bd9Sstevel@tonic-gate p->sbd_nbits = SWAP32(p->sbd_nbits);
464*7c478bd9Sstevel@tonic-gate p->sbd_nbytes = SWAP32(p->sbd_nbytes);
465*7c478bd9Sstevel@tonic-gate }
466*7c478bd9Sstevel@tonic-gate
467*7c478bd9Sstevel@tonic-gate static void
ud_swap_file_entry(struct file_entry * p,int32_t rdflag)468*7c478bd9Sstevel@tonic-gate ud_swap_file_entry(struct file_entry *p, int32_t rdflag)
469*7c478bd9Sstevel@tonic-gate {
470*7c478bd9Sstevel@tonic-gate int32_t i;
471*7c478bd9Sstevel@tonic-gate short_ad_t *sap;
472*7c478bd9Sstevel@tonic-gate long_ad_t *lap;
473*7c478bd9Sstevel@tonic-gate
474*7c478bd9Sstevel@tonic-gate /* Do Extended Attributes and Allocation Descriptors */
475*7c478bd9Sstevel@tonic-gate if (rdflag) {
476*7c478bd9Sstevel@tonic-gate p->fe_len_adesc = SWAP32(p->fe_len_adesc);
477*7c478bd9Sstevel@tonic-gate p->fe_len_ear = SWAP32(p->fe_len_ear);
478*7c478bd9Sstevel@tonic-gate ud_swap_icb_tag(&p->fe_icb_tag);
479*7c478bd9Sstevel@tonic-gate }
480*7c478bd9Sstevel@tonic-gate switch (p->fe_icb_tag.itag_flags & 0x3) {
481*7c478bd9Sstevel@tonic-gate case ICB_FLAG_SHORT_AD:
482*7c478bd9Sstevel@tonic-gate /* LINTED */
483*7c478bd9Sstevel@tonic-gate sap = (short_ad_t *)(p->fe_spec + p->fe_len_ear);
484*7c478bd9Sstevel@tonic-gate for (i = 0; i < p->fe_len_adesc / sizeof (short_ad_t);
485*7c478bd9Sstevel@tonic-gate i++, sap++)
486*7c478bd9Sstevel@tonic-gate ud_swap_short_ad(sap);
487*7c478bd9Sstevel@tonic-gate break;
488*7c478bd9Sstevel@tonic-gate case ICB_FLAG_LONG_AD:
489*7c478bd9Sstevel@tonic-gate /* LINTED */
490*7c478bd9Sstevel@tonic-gate lap = (long_ad_t *)(p->fe_spec + p->fe_len_ear);
491*7c478bd9Sstevel@tonic-gate for (i = 0; i < p->fe_len_adesc / sizeof (long_ad_t);
492*7c478bd9Sstevel@tonic-gate i++, lap++)
493*7c478bd9Sstevel@tonic-gate ud_swap_long_ad(lap);
494*7c478bd9Sstevel@tonic-gate break;
495*7c478bd9Sstevel@tonic-gate case ICB_FLAG_EXT_AD:
496*7c478bd9Sstevel@tonic-gate break;
497*7c478bd9Sstevel@tonic-gate case ICB_FLAG_ONE_AD:
498*7c478bd9Sstevel@tonic-gate break;
499*7c478bd9Sstevel@tonic-gate }
500*7c478bd9Sstevel@tonic-gate p->fe_uid = SWAP32(p->fe_uid);
501*7c478bd9Sstevel@tonic-gate p->fe_gid = SWAP32(p->fe_gid);
502*7c478bd9Sstevel@tonic-gate p->fe_perms = SWAP32(p->fe_perms);
503*7c478bd9Sstevel@tonic-gate p->fe_lcount = SWAP16(p->fe_lcount);
504*7c478bd9Sstevel@tonic-gate p->fe_rec_len = SWAP32(p->fe_rec_len);
505*7c478bd9Sstevel@tonic-gate p->fe_info_len = SWAP64(p->fe_info_len);
506*7c478bd9Sstevel@tonic-gate p->fe_lbr = SWAP64(p->fe_lbr);
507*7c478bd9Sstevel@tonic-gate ud_swap_tstamp(&p->fe_acc_time);
508*7c478bd9Sstevel@tonic-gate ud_swap_tstamp(&p->fe_mod_time);
509*7c478bd9Sstevel@tonic-gate ud_swap_tstamp(&p->fe_attr_time);
510*7c478bd9Sstevel@tonic-gate p->fe_ckpoint = SWAP32(p->fe_ckpoint);
511*7c478bd9Sstevel@tonic-gate ud_swap_long_ad(&p->fe_ea_icb);
512*7c478bd9Sstevel@tonic-gate ud_swap_regid(&p->fe_impl_id);
513*7c478bd9Sstevel@tonic-gate p->fe_uniq_id = SWAP64(p->fe_uniq_id);
514*7c478bd9Sstevel@tonic-gate if (!rdflag) {
515*7c478bd9Sstevel@tonic-gate p->fe_len_adesc = SWAP32(p->fe_len_adesc);
516*7c478bd9Sstevel@tonic-gate p->fe_len_ear = SWAP32(p->fe_len_ear);
517*7c478bd9Sstevel@tonic-gate ud_swap_icb_tag(&p->fe_icb_tag);
518*7c478bd9Sstevel@tonic-gate }
519*7c478bd9Sstevel@tonic-gate }
520*7c478bd9Sstevel@tonic-gate
521*7c478bd9Sstevel@tonic-gate static void
ud_swap_tstamp(tstamp_t * tp)522*7c478bd9Sstevel@tonic-gate ud_swap_tstamp(tstamp_t *tp)
523*7c478bd9Sstevel@tonic-gate {
524*7c478bd9Sstevel@tonic-gate tp->ts_tzone = SWAP16(tp->ts_tzone);
525*7c478bd9Sstevel@tonic-gate tp->ts_year = SWAP16(tp->ts_year);
526*7c478bd9Sstevel@tonic-gate }
527*7c478bd9Sstevel@tonic-gate
528*7c478bd9Sstevel@tonic-gate void
setcharspec(struct charspec * cp,int32_t type,uint8_t * info)529*7c478bd9Sstevel@tonic-gate setcharspec(struct charspec *cp, int32_t type, uint8_t *info)
530*7c478bd9Sstevel@tonic-gate {
531*7c478bd9Sstevel@tonic-gate cp->cs_type = type;
532*7c478bd9Sstevel@tonic-gate bzero(cp->cs_info, sizeof (cp->cs_info));
533*7c478bd9Sstevel@tonic-gate (void) strncpy(cp->cs_info, (int8_t *)info, sizeof (cp->cs_info));
534*7c478bd9Sstevel@tonic-gate }
535*7c478bd9Sstevel@tonic-gate
536*7c478bd9Sstevel@tonic-gate static unsigned short crctab[] = {
537*7c478bd9Sstevel@tonic-gate 0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50a5, 0x60c6, 0x70e7,
538*7c478bd9Sstevel@tonic-gate 0x8108, 0x9129, 0xa14a, 0xb16b, 0xc18c, 0xd1ad, 0xe1ce, 0xf1ef,
539*7c478bd9Sstevel@tonic-gate 0x1231, 0x0210, 0x3273, 0x2252, 0x52b5, 0x4294, 0x72f7, 0x62d6,
540*7c478bd9Sstevel@tonic-gate 0x9339, 0x8318, 0xb37b, 0xa35a, 0xd3bd, 0xc39c, 0xf3ff, 0xe3de,
541*7c478bd9Sstevel@tonic-gate 0x2462, 0x3443, 0x0420, 0x1401, 0x64e6, 0x74c7, 0x44a4, 0x5485,
542*7c478bd9Sstevel@tonic-gate 0xa56a, 0xb54b, 0x8528, 0x9509, 0xe5ee, 0xf5cf, 0xc5ac, 0xd58d,
543*7c478bd9Sstevel@tonic-gate 0x3653, 0x2672, 0x1611, 0x0630, 0x76d7, 0x66f6, 0x5695, 0x46b4,
544*7c478bd9Sstevel@tonic-gate 0xb75b, 0xa77a, 0x9719, 0x8738, 0xf7df, 0xe7fe, 0xd79d, 0xc7bc,
545*7c478bd9Sstevel@tonic-gate 0x48c4, 0x58e5, 0x6886, 0x78a7, 0x0840, 0x1861, 0x2802, 0x3823,
546*7c478bd9Sstevel@tonic-gate 0xc9cc, 0xd9ed, 0xe98e, 0xf9af, 0x8948, 0x9969, 0xa90a, 0xb92b,
547*7c478bd9Sstevel@tonic-gate 0x5af5, 0x4ad4, 0x7ab7, 0x6a96, 0x1a71, 0x0a50, 0x3a33, 0x2a12,
548*7c478bd9Sstevel@tonic-gate 0xdbfd, 0xcbdc, 0xfbbf, 0xeb9e, 0x9b79, 0x8b58, 0xbb3b, 0xab1a,
549*7c478bd9Sstevel@tonic-gate 0x6ca6, 0x7c87, 0x4ce4, 0x5cc5, 0x2c22, 0x3c03, 0x0c60, 0x1c41,
550*7c478bd9Sstevel@tonic-gate 0xedae, 0xfd8f, 0xcdec, 0xddcd, 0xad2a, 0xbd0b, 0x8d68, 0x9d49,
551*7c478bd9Sstevel@tonic-gate 0x7e97, 0x6eb6, 0x5ed5, 0x4ef4, 0x3e13, 0x2e32, 0x1e51, 0x0e70,
552*7c478bd9Sstevel@tonic-gate 0xff9f, 0xefbe, 0xdfdd, 0xcffc, 0xbf1b, 0xaf3a, 0x9f59, 0x8f78,
553*7c478bd9Sstevel@tonic-gate 0x9188, 0x81a9, 0xb1ca, 0xa1eb, 0xd10c, 0xc12d, 0xf14e, 0xe16f,
554*7c478bd9Sstevel@tonic-gate 0x1080, 0x00a1, 0x30c2, 0x20e3, 0x5004, 0x4025, 0x7046, 0x6067,
555*7c478bd9Sstevel@tonic-gate 0x83b9, 0x9398, 0xa3fb, 0xb3da, 0xc33d, 0xd31c, 0xe37f, 0xf35e,
556*7c478bd9Sstevel@tonic-gate 0x02b1, 0x1290, 0x22f3, 0x32d2, 0x4235, 0x5214, 0x6277, 0x7256,
557*7c478bd9Sstevel@tonic-gate 0xb5ea, 0xa5cb, 0x95a8, 0x8589, 0xf56e, 0xe54f, 0xd52c, 0xc50d,
558*7c478bd9Sstevel@tonic-gate 0x34e2, 0x24c3, 0x14a0, 0x0481, 0x7466, 0x6447, 0x5424, 0x4405,
559*7c478bd9Sstevel@tonic-gate 0xa7db, 0xb7fa, 0x8799, 0x97b8, 0xe75f, 0xf77e, 0xc71d, 0xd73c,
560*7c478bd9Sstevel@tonic-gate 0x26d3, 0x36f2, 0x0691, 0x16b0, 0x6657, 0x7676, 0x4615, 0x5634,
561*7c478bd9Sstevel@tonic-gate 0xd94c, 0xc96d, 0xf90e, 0xe92f, 0x99c8, 0x89e9, 0xb98a, 0xa9ab,
562*7c478bd9Sstevel@tonic-gate 0x5844, 0x4865, 0x7806, 0x6827, 0x18c0, 0x08e1, 0x3882, 0x28a3,
563*7c478bd9Sstevel@tonic-gate 0xcb7d, 0xdb5c, 0xeb3f, 0xfb1e, 0x8bf9, 0x9bd8, 0xabbb, 0xbb9a,
564*7c478bd9Sstevel@tonic-gate 0x4a75, 0x5a54, 0x6a37, 0x7a16, 0x0af1, 0x1ad0, 0x2ab3, 0x3a92,
565*7c478bd9Sstevel@tonic-gate 0xfd2e, 0xed0f, 0xdd6c, 0xcd4d, 0xbdaa, 0xad8b, 0x9de8, 0x8dc9,
566*7c478bd9Sstevel@tonic-gate 0x7c26, 0x6c07, 0x5c64, 0x4c45, 0x3ca2, 0x2c83, 0x1ce0, 0x0cc1,
567*7c478bd9Sstevel@tonic-gate 0xef1f, 0xff3e, 0xcf5d, 0xdf7c, 0xaf9b, 0xbfba, 0x8fd9, 0x9ff8,
568*7c478bd9Sstevel@tonic-gate 0x6e17, 0x7e36, 0x4e55, 0x5e74, 0x2e93, 0x3eb2, 0x0ed1, 0x1ef0
569*7c478bd9Sstevel@tonic-gate };
570*7c478bd9Sstevel@tonic-gate
571*7c478bd9Sstevel@tonic-gate static uint16_t
crc16(uint8_t * buf,int32_t size,int32_t rem)572*7c478bd9Sstevel@tonic-gate crc16(uint8_t *buf, int32_t size, int32_t rem)
573*7c478bd9Sstevel@tonic-gate {
574*7c478bd9Sstevel@tonic-gate uint16_t crc = 0;
575*7c478bd9Sstevel@tonic-gate
576*7c478bd9Sstevel@tonic-gate while (size-- > 0)
577*7c478bd9Sstevel@tonic-gate crc = (crc << 8) ^ crctab[((crc >> 8) ^ *buf++) & 0xff];
578*7c478bd9Sstevel@tonic-gate return ((crc ^ rem) & 0xffff);
579*7c478bd9Sstevel@tonic-gate }
580