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