Deleted Added
full compact
ffs_bswap.c (186261) ffs_bswap.c (186334)
1/* $NetBSD: ffs_bswap.c,v 1.28 2004/05/25 14:54:59 hannken Exp $ */
2
3/*
4 * Copyright (c) 1998 Manuel Bouyer.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. All advertising materials mentioning features or use of this software
15 * must display the following acknowledgement:
16 * This product includes software developed by Manuel Bouyer.
17 * 4. The name of the author may not be used to endorse or promote products
18 * derived from this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 *
31 */
32
33#include <sys/cdefs.h>
1/* $NetBSD: ffs_bswap.c,v 1.28 2004/05/25 14:54:59 hannken Exp $ */
2
3/*
4 * Copyright (c) 1998 Manuel Bouyer.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. All advertising materials mentioning features or use of this software
15 * must display the following acknowledgement:
16 * This product includes software developed by Manuel Bouyer.
17 * 4. The name of the author may not be used to endorse or promote products
18 * derived from this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 *
31 */
32
33#include <sys/cdefs.h>
34#if 0
35__KERNEL_RCSID(0, "$NetBSD: ffs_bswap.c,v 1.28 2004/05/25 14:54:59 hannken Exp $");
36#endif
37__FBSDID("$FreeBSD$");
34__FBSDID("$FreeBSD: projects/makefs/ffs/ffs_bswap.c 186334 2008-12-19 18:45:43Z sam $");
38
39#include <sys/param.h>
40#if defined(_KERNEL)
41#include <sys/systm.h>
42#endif
43
44#include <ufs/ufs/dinode.h>
45#include "ffs/ufs_bswap.h"
46#include <ufs/ffs/fs.h>
47/* XXX temporary */
48struct ufsmount;
49struct bufobj;
50struct mount;
51struct vnode;
52typedef int vfs_vget_t(struct mount *mp, ino_t ino, int flags,
53 struct vnode **vpp);
54#include <ufs/ffs/ffs_extern.h>
55
56#if !defined(_KERNEL)
57#include <stddef.h>
58#include <stdio.h>
59#include <stdlib.h>
60#include <string.h>
61#define panic(x) printf("%s\n", (x)), abort()
62#endif
63
64#define fs_old_postbloff fs_spare5[0]
65#define fs_old_rotbloff fs_spare5[1]
66#define fs_old_postbl_start fs_maxbsize
67#define fs_old_headswitch fs_id[0]
68#define fs_old_trkseek fs_id[1]
69#define fs_old_csmask fs_spare1[0]
70#define fs_old_csshift fs_spare1[1]
71
72#define FS_42POSTBLFMT -1 /* 4.2BSD rotational table format */
73#define FS_DYNAMICPOSTBLFMT 1 /* dynamic rotational table format */
74
75void ffs_csum_swap(struct csum *o, struct csum *n, int size);
76void ffs_csumtotal_swap(struct csum_total *o, struct csum_total *n);
77
78void
79ffs_sb_swap(struct fs *o, struct fs *n)
80{
81 int i;
82 u_int32_t *o32, *n32;
83
84 /*
85 * In order to avoid a lot of lines, as the first N fields (52)
86 * of the superblock up to fs_fmod are u_int32_t, we just loop
87 * here to convert them.
88 */
89 o32 = (u_int32_t *)o;
90 n32 = (u_int32_t *)n;
91 for (i = 0; i < offsetof(struct fs, fs_fmod) / sizeof(u_int32_t); i++)
92 n32[i] = bswap32(o32[i]);
93
94 n->fs_swuid = bswap64(o->fs_swuid);
95 n->fs_cgrotor = bswap32(o->fs_cgrotor); /* Unused */
96 n->fs_old_cpc = bswap32(o->fs_old_cpc);
97
98 /* These fields overlap with a possible location for the
99 * historic FS_DYNAMICPOSTBLFMT postbl table, and with the
100 * first half of the historic FS_42POSTBLFMT postbl table.
101 */
102 n->fs_maxbsize = bswap32(o->fs_maxbsize);
103 n->fs_sblockloc = bswap64(o->fs_sblockloc);
104 ffs_csumtotal_swap(&o->fs_cstotal, &n->fs_cstotal);
105 n->fs_time = bswap64(o->fs_time);
106 n->fs_size = bswap64(o->fs_size);
107 n->fs_dsize = bswap64(o->fs_dsize);
108 n->fs_csaddr = bswap64(o->fs_csaddr);
109 n->fs_pendingblocks = bswap64(o->fs_pendingblocks);
110 n->fs_pendinginodes = bswap32(o->fs_pendinginodes);
111
112 /* These fields overlap with the second half of the
113 * historic FS_42POSTBLFMT postbl table
114 */
115 for (i = 0; i < FSMAXSNAP; i++)
116 n->fs_snapinum[i] = bswap32(o->fs_snapinum[i]);
117 n->fs_avgfilesize = bswap32(o->fs_avgfilesize);
118 n->fs_avgfpdir = bswap32(o->fs_avgfpdir);
119 /* fs_sparecon[28] - ignore for now */
120 n->fs_flags = bswap32(o->fs_flags);
121 n->fs_contigsumsize = bswap32(o->fs_contigsumsize);
122 n->fs_maxsymlinklen = bswap32(o->fs_maxsymlinklen);
123 n->fs_old_inodefmt = bswap32(o->fs_old_inodefmt);
124 n->fs_maxfilesize = bswap64(o->fs_maxfilesize);
125 n->fs_qbmask = bswap64(o->fs_qbmask);
126 n->fs_qfmask = bswap64(o->fs_qfmask);
127 n->fs_state = bswap32(o->fs_state);
128 n->fs_old_postblformat = bswap32(o->fs_old_postblformat);
129 n->fs_old_nrpos = bswap32(o->fs_old_nrpos);
130 n->fs_old_postbloff = bswap32(o->fs_old_postbloff);
131 n->fs_old_rotbloff = bswap32(o->fs_old_rotbloff);
132
133 n->fs_magic = bswap32(o->fs_magic);
134}
135
136void
137ffs_dinode1_swap(struct ufs1_dinode *o, struct ufs1_dinode *n)
138{
139
140 n->di_mode = bswap16(o->di_mode);
141 n->di_nlink = bswap16(o->di_nlink);
142 n->di_u.oldids[0] = bswap16(o->di_u.oldids[0]);
143 n->di_u.oldids[1] = bswap16(o->di_u.oldids[1]);
144 n->di_size = bswap64(o->di_size);
145 n->di_atime = bswap32(o->di_atime);
146 n->di_atimensec = bswap32(o->di_atimensec);
147 n->di_mtime = bswap32(o->di_mtime);
148 n->di_mtimensec = bswap32(o->di_mtimensec);
149 n->di_ctime = bswap32(o->di_ctime);
150 n->di_ctimensec = bswap32(o->di_ctimensec);
151 memcpy(n->di_db, o->di_db, (NDADDR + NIADDR) * sizeof(u_int32_t));
152 n->di_flags = bswap32(o->di_flags);
153 n->di_blocks = bswap32(o->di_blocks);
154 n->di_gen = bswap32(o->di_gen);
155 n->di_uid = bswap32(o->di_uid);
156 n->di_gid = bswap32(o->di_gid);
157}
158
159void
160ffs_dinode2_swap(struct ufs2_dinode *o, struct ufs2_dinode *n)
161{
162 n->di_mode = bswap16(o->di_mode);
163 n->di_nlink = bswap16(o->di_nlink);
164 n->di_uid = bswap32(o->di_uid);
165 n->di_gid = bswap32(o->di_gid);
166 n->di_blksize = bswap32(o->di_blksize);
167 n->di_size = bswap64(o->di_size);
168 n->di_blocks = bswap64(o->di_blocks);
169 n->di_atime = bswap64(o->di_atime);
170 n->di_atimensec = bswap32(o->di_atimensec);
171 n->di_mtime = bswap64(o->di_mtime);
172 n->di_mtimensec = bswap32(o->di_mtimensec);
173 n->di_ctime = bswap64(o->di_ctime);
174 n->di_ctimensec = bswap32(o->di_ctimensec);
175 n->di_birthtime = bswap64(o->di_ctime);
176 n->di_birthnsec = bswap32(o->di_ctimensec);
177 n->di_gen = bswap32(o->di_gen);
178 n->di_kernflags = bswap32(o->di_kernflags);
179 n->di_flags = bswap32(o->di_flags);
180 n->di_extsize = bswap32(o->di_extsize);
181 memcpy(n->di_extb, o->di_extb, (NXADDR + NDADDR + NIADDR) * 8);
182}
183
184void
185ffs_csum_swap(struct csum *o, struct csum *n, int size)
186{
187 int i;
188 u_int32_t *oint, *nint;
189
190 oint = (u_int32_t*)o;
191 nint = (u_int32_t*)n;
192
193 for (i = 0; i < size / sizeof(u_int32_t); i++)
194 nint[i] = bswap32(oint[i]);
195}
196
197void
198ffs_csumtotal_swap(struct csum_total *o, struct csum_total *n)
199{
200 n->cs_ndir = bswap64(o->cs_ndir);
201 n->cs_nbfree = bswap64(o->cs_nbfree);
202 n->cs_nifree = bswap64(o->cs_nifree);
203 n->cs_nffree = bswap64(o->cs_nffree);
204}
205
206/*
207 * Note that ffs_cg_swap may be called with o == n.
208 */
209void
210ffs_cg_swap(struct cg *o, struct cg *n, struct fs *fs)
211{
212 int i;
213 u_int32_t *n32, *o32;
214 u_int16_t *n16, *o16;
215 int32_t btotoff, boff, clustersumoff;
216
217 n->cg_firstfield = bswap32(o->cg_firstfield);
218 n->cg_magic = bswap32(o->cg_magic);
219 n->cg_old_time = bswap32(o->cg_old_time);
220 n->cg_cgx = bswap32(o->cg_cgx);
221 n->cg_old_ncyl = bswap16(o->cg_old_ncyl);
222 n->cg_old_niblk = bswap16(o->cg_old_niblk);
223 n->cg_ndblk = bswap32(o->cg_ndblk);
224 n->cg_cs.cs_ndir = bswap32(o->cg_cs.cs_ndir);
225 n->cg_cs.cs_nbfree = bswap32(o->cg_cs.cs_nbfree);
226 n->cg_cs.cs_nifree = bswap32(o->cg_cs.cs_nifree);
227 n->cg_cs.cs_nffree = bswap32(o->cg_cs.cs_nffree);
228 n->cg_rotor = bswap32(o->cg_rotor);
229 n->cg_frotor = bswap32(o->cg_frotor);
230 n->cg_irotor = bswap32(o->cg_irotor);
231 for (i = 0; i < MAXFRAG; i++)
232 n->cg_frsum[i] = bswap32(o->cg_frsum[i]);
233
234 n->cg_old_btotoff = bswap32(o->cg_old_btotoff);
235 n->cg_old_boff = bswap32(o->cg_old_boff);
236 n->cg_iusedoff = bswap32(o->cg_iusedoff);
237 n->cg_freeoff = bswap32(o->cg_freeoff);
238 n->cg_nextfreeoff = bswap32(o->cg_nextfreeoff);
239 n->cg_clustersumoff = bswap32(o->cg_clustersumoff);
240 n->cg_clusteroff = bswap32(o->cg_clusteroff);
241 n->cg_nclusterblks = bswap32(o->cg_nclusterblks);
242 n->cg_niblk = bswap32(o->cg_niblk);
243 n->cg_initediblk = bswap32(o->cg_initediblk);
244 n->cg_time = bswap64(o->cg_time);
245
246 if (fs->fs_magic == FS_UFS2_MAGIC)
247 return;
248
249 if (n->cg_magic == CG_MAGIC) {
250 btotoff = n->cg_old_btotoff;
251 boff = n->cg_old_boff;
252 clustersumoff = n->cg_clustersumoff;
253 } else {
254 btotoff = bswap32(n->cg_old_btotoff);
255 boff = bswap32(n->cg_old_boff);
256 clustersumoff = bswap32(n->cg_clustersumoff);
257 }
258 n32 = (u_int32_t *)((u_int8_t *)n + btotoff);
259 o32 = (u_int32_t *)((u_int8_t *)o + btotoff);
260 n16 = (u_int16_t *)((u_int8_t *)n + boff);
261 o16 = (u_int16_t *)((u_int8_t *)o + boff);
262
263 for (i = 0; i < fs->fs_old_cpg; i++)
264 n32[i] = bswap32(o32[i]);
265
266 for (i = 0; i < fs->fs_old_cpg * fs->fs_old_nrpos; i++)
267 n16[i] = bswap16(o16[i]);
268
269 n32 = (u_int32_t *)((u_int8_t *)n + clustersumoff);
270 o32 = (u_int32_t *)((u_int8_t *)o + clustersumoff);
271 for (i = 1; i < fs->fs_contigsumsize + 1; i++)
272 n32[i] = bswap32(o32[i]);
273}
35
36#include <sys/param.h>
37#if defined(_KERNEL)
38#include <sys/systm.h>
39#endif
40
41#include <ufs/ufs/dinode.h>
42#include "ffs/ufs_bswap.h"
43#include <ufs/ffs/fs.h>
44/* XXX temporary */
45struct ufsmount;
46struct bufobj;
47struct mount;
48struct vnode;
49typedef int vfs_vget_t(struct mount *mp, ino_t ino, int flags,
50 struct vnode **vpp);
51#include <ufs/ffs/ffs_extern.h>
52
53#if !defined(_KERNEL)
54#include <stddef.h>
55#include <stdio.h>
56#include <stdlib.h>
57#include <string.h>
58#define panic(x) printf("%s\n", (x)), abort()
59#endif
60
61#define fs_old_postbloff fs_spare5[0]
62#define fs_old_rotbloff fs_spare5[1]
63#define fs_old_postbl_start fs_maxbsize
64#define fs_old_headswitch fs_id[0]
65#define fs_old_trkseek fs_id[1]
66#define fs_old_csmask fs_spare1[0]
67#define fs_old_csshift fs_spare1[1]
68
69#define FS_42POSTBLFMT -1 /* 4.2BSD rotational table format */
70#define FS_DYNAMICPOSTBLFMT 1 /* dynamic rotational table format */
71
72void ffs_csum_swap(struct csum *o, struct csum *n, int size);
73void ffs_csumtotal_swap(struct csum_total *o, struct csum_total *n);
74
75void
76ffs_sb_swap(struct fs *o, struct fs *n)
77{
78 int i;
79 u_int32_t *o32, *n32;
80
81 /*
82 * In order to avoid a lot of lines, as the first N fields (52)
83 * of the superblock up to fs_fmod are u_int32_t, we just loop
84 * here to convert them.
85 */
86 o32 = (u_int32_t *)o;
87 n32 = (u_int32_t *)n;
88 for (i = 0; i < offsetof(struct fs, fs_fmod) / sizeof(u_int32_t); i++)
89 n32[i] = bswap32(o32[i]);
90
91 n->fs_swuid = bswap64(o->fs_swuid);
92 n->fs_cgrotor = bswap32(o->fs_cgrotor); /* Unused */
93 n->fs_old_cpc = bswap32(o->fs_old_cpc);
94
95 /* These fields overlap with a possible location for the
96 * historic FS_DYNAMICPOSTBLFMT postbl table, and with the
97 * first half of the historic FS_42POSTBLFMT postbl table.
98 */
99 n->fs_maxbsize = bswap32(o->fs_maxbsize);
100 n->fs_sblockloc = bswap64(o->fs_sblockloc);
101 ffs_csumtotal_swap(&o->fs_cstotal, &n->fs_cstotal);
102 n->fs_time = bswap64(o->fs_time);
103 n->fs_size = bswap64(o->fs_size);
104 n->fs_dsize = bswap64(o->fs_dsize);
105 n->fs_csaddr = bswap64(o->fs_csaddr);
106 n->fs_pendingblocks = bswap64(o->fs_pendingblocks);
107 n->fs_pendinginodes = bswap32(o->fs_pendinginodes);
108
109 /* These fields overlap with the second half of the
110 * historic FS_42POSTBLFMT postbl table
111 */
112 for (i = 0; i < FSMAXSNAP; i++)
113 n->fs_snapinum[i] = bswap32(o->fs_snapinum[i]);
114 n->fs_avgfilesize = bswap32(o->fs_avgfilesize);
115 n->fs_avgfpdir = bswap32(o->fs_avgfpdir);
116 /* fs_sparecon[28] - ignore for now */
117 n->fs_flags = bswap32(o->fs_flags);
118 n->fs_contigsumsize = bswap32(o->fs_contigsumsize);
119 n->fs_maxsymlinklen = bswap32(o->fs_maxsymlinklen);
120 n->fs_old_inodefmt = bswap32(o->fs_old_inodefmt);
121 n->fs_maxfilesize = bswap64(o->fs_maxfilesize);
122 n->fs_qbmask = bswap64(o->fs_qbmask);
123 n->fs_qfmask = bswap64(o->fs_qfmask);
124 n->fs_state = bswap32(o->fs_state);
125 n->fs_old_postblformat = bswap32(o->fs_old_postblformat);
126 n->fs_old_nrpos = bswap32(o->fs_old_nrpos);
127 n->fs_old_postbloff = bswap32(o->fs_old_postbloff);
128 n->fs_old_rotbloff = bswap32(o->fs_old_rotbloff);
129
130 n->fs_magic = bswap32(o->fs_magic);
131}
132
133void
134ffs_dinode1_swap(struct ufs1_dinode *o, struct ufs1_dinode *n)
135{
136
137 n->di_mode = bswap16(o->di_mode);
138 n->di_nlink = bswap16(o->di_nlink);
139 n->di_u.oldids[0] = bswap16(o->di_u.oldids[0]);
140 n->di_u.oldids[1] = bswap16(o->di_u.oldids[1]);
141 n->di_size = bswap64(o->di_size);
142 n->di_atime = bswap32(o->di_atime);
143 n->di_atimensec = bswap32(o->di_atimensec);
144 n->di_mtime = bswap32(o->di_mtime);
145 n->di_mtimensec = bswap32(o->di_mtimensec);
146 n->di_ctime = bswap32(o->di_ctime);
147 n->di_ctimensec = bswap32(o->di_ctimensec);
148 memcpy(n->di_db, o->di_db, (NDADDR + NIADDR) * sizeof(u_int32_t));
149 n->di_flags = bswap32(o->di_flags);
150 n->di_blocks = bswap32(o->di_blocks);
151 n->di_gen = bswap32(o->di_gen);
152 n->di_uid = bswap32(o->di_uid);
153 n->di_gid = bswap32(o->di_gid);
154}
155
156void
157ffs_dinode2_swap(struct ufs2_dinode *o, struct ufs2_dinode *n)
158{
159 n->di_mode = bswap16(o->di_mode);
160 n->di_nlink = bswap16(o->di_nlink);
161 n->di_uid = bswap32(o->di_uid);
162 n->di_gid = bswap32(o->di_gid);
163 n->di_blksize = bswap32(o->di_blksize);
164 n->di_size = bswap64(o->di_size);
165 n->di_blocks = bswap64(o->di_blocks);
166 n->di_atime = bswap64(o->di_atime);
167 n->di_atimensec = bswap32(o->di_atimensec);
168 n->di_mtime = bswap64(o->di_mtime);
169 n->di_mtimensec = bswap32(o->di_mtimensec);
170 n->di_ctime = bswap64(o->di_ctime);
171 n->di_ctimensec = bswap32(o->di_ctimensec);
172 n->di_birthtime = bswap64(o->di_ctime);
173 n->di_birthnsec = bswap32(o->di_ctimensec);
174 n->di_gen = bswap32(o->di_gen);
175 n->di_kernflags = bswap32(o->di_kernflags);
176 n->di_flags = bswap32(o->di_flags);
177 n->di_extsize = bswap32(o->di_extsize);
178 memcpy(n->di_extb, o->di_extb, (NXADDR + NDADDR + NIADDR) * 8);
179}
180
181void
182ffs_csum_swap(struct csum *o, struct csum *n, int size)
183{
184 int i;
185 u_int32_t *oint, *nint;
186
187 oint = (u_int32_t*)o;
188 nint = (u_int32_t*)n;
189
190 for (i = 0; i < size / sizeof(u_int32_t); i++)
191 nint[i] = bswap32(oint[i]);
192}
193
194void
195ffs_csumtotal_swap(struct csum_total *o, struct csum_total *n)
196{
197 n->cs_ndir = bswap64(o->cs_ndir);
198 n->cs_nbfree = bswap64(o->cs_nbfree);
199 n->cs_nifree = bswap64(o->cs_nifree);
200 n->cs_nffree = bswap64(o->cs_nffree);
201}
202
203/*
204 * Note that ffs_cg_swap may be called with o == n.
205 */
206void
207ffs_cg_swap(struct cg *o, struct cg *n, struct fs *fs)
208{
209 int i;
210 u_int32_t *n32, *o32;
211 u_int16_t *n16, *o16;
212 int32_t btotoff, boff, clustersumoff;
213
214 n->cg_firstfield = bswap32(o->cg_firstfield);
215 n->cg_magic = bswap32(o->cg_magic);
216 n->cg_old_time = bswap32(o->cg_old_time);
217 n->cg_cgx = bswap32(o->cg_cgx);
218 n->cg_old_ncyl = bswap16(o->cg_old_ncyl);
219 n->cg_old_niblk = bswap16(o->cg_old_niblk);
220 n->cg_ndblk = bswap32(o->cg_ndblk);
221 n->cg_cs.cs_ndir = bswap32(o->cg_cs.cs_ndir);
222 n->cg_cs.cs_nbfree = bswap32(o->cg_cs.cs_nbfree);
223 n->cg_cs.cs_nifree = bswap32(o->cg_cs.cs_nifree);
224 n->cg_cs.cs_nffree = bswap32(o->cg_cs.cs_nffree);
225 n->cg_rotor = bswap32(o->cg_rotor);
226 n->cg_frotor = bswap32(o->cg_frotor);
227 n->cg_irotor = bswap32(o->cg_irotor);
228 for (i = 0; i < MAXFRAG; i++)
229 n->cg_frsum[i] = bswap32(o->cg_frsum[i]);
230
231 n->cg_old_btotoff = bswap32(o->cg_old_btotoff);
232 n->cg_old_boff = bswap32(o->cg_old_boff);
233 n->cg_iusedoff = bswap32(o->cg_iusedoff);
234 n->cg_freeoff = bswap32(o->cg_freeoff);
235 n->cg_nextfreeoff = bswap32(o->cg_nextfreeoff);
236 n->cg_clustersumoff = bswap32(o->cg_clustersumoff);
237 n->cg_clusteroff = bswap32(o->cg_clusteroff);
238 n->cg_nclusterblks = bswap32(o->cg_nclusterblks);
239 n->cg_niblk = bswap32(o->cg_niblk);
240 n->cg_initediblk = bswap32(o->cg_initediblk);
241 n->cg_time = bswap64(o->cg_time);
242
243 if (fs->fs_magic == FS_UFS2_MAGIC)
244 return;
245
246 if (n->cg_magic == CG_MAGIC) {
247 btotoff = n->cg_old_btotoff;
248 boff = n->cg_old_boff;
249 clustersumoff = n->cg_clustersumoff;
250 } else {
251 btotoff = bswap32(n->cg_old_btotoff);
252 boff = bswap32(n->cg_old_boff);
253 clustersumoff = bswap32(n->cg_clustersumoff);
254 }
255 n32 = (u_int32_t *)((u_int8_t *)n + btotoff);
256 o32 = (u_int32_t *)((u_int8_t *)o + btotoff);
257 n16 = (u_int16_t *)((u_int8_t *)n + boff);
258 o16 = (u_int16_t *)((u_int8_t *)o + boff);
259
260 for (i = 0; i < fs->fs_old_cpg; i++)
261 n32[i] = bswap32(o32[i]);
262
263 for (i = 0; i < fs->fs_old_cpg * fs->fs_old_nrpos; i++)
264 n16[i] = bswap16(o16[i]);
265
266 n32 = (u_int32_t *)((u_int8_t *)n + clustersumoff);
267 o32 = (u_int32_t *)((u_int8_t *)o + clustersumoff);
268 for (i = 1; i < fs->fs_contigsumsize + 1; i++)
269 n32[i] = bswap32(o32[i]);
270}