OpenCores
URL https://opencores.org/ocsvn/eco32/eco32/trunk

Subversion Repositories eco32

[/] [eco32/] [tags/] [eco32-0.24/] [disk/] [tools/] [fs-NetBSD/] [makefs/] [ffs_bswap.c] - Blame information for rev 211

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 17 hellwig
/*      $NetBSD: ffs_bswap.c,v 1.35 2011/03/06 17:08:38 bouyer 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
 *
15
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25
 *
26
 */
27
 
28
#if HAVE_NBTOOL_CONFIG_H
29
#include "nbtool_config.h"
30
#endif
31
 
32
#include <sys/cdefs.h>
33
#if defined(__KERNEL_RCSID) && !defined(__lint)
34
__KERNEL_RCSID(0, "$NetBSD: ffs_bswap.c,v 1.35 2011/03/06 17:08:38 bouyer Exp $");
35
#endif
36
 
37
#include <sys/param.h>
38
#if defined(_KERNEL)
39
#include <sys/systm.h>
40
#endif
41
 
42
#include "common.h"
43
 
44
#include "dinode.h"
45
#include "ufs_inode.h"
46
//#include <ufs/ufs/quota.h>
47
#include "ufs_bswap.h"
48
#include "fs.h"
49
#include "ffs_extern.h"
50
 
51
#if !defined(_KERNEL)
52
#include <stddef.h>
53
#include <stdio.h>
54
#include <stdlib.h>
55
#include <string.h>
56
#define panic(x)        printf("%s\n", (x)), abort()
57
#endif
58
 
59
void
60
ffs_csumtotal_swap(struct csum_total *o, struct csum_total *n);
61
 
62
void
63
ffs_sb_swap(struct fs *o, struct fs *n)
64
{
65
        size_t i;
66
        u_int32_t *o32, *n32;
67
 
68
        /*
69
         * In order to avoid a lot of lines, as the first N fields (52)
70
         * of the superblock up to fs_fmod are u_int32_t, we just loop
71
         * here to convert them.
72
         */
73
        o32 = (u_int32_t *)o;
74
        n32 = (u_int32_t *)n;
75
        for (i = 0; i < offsetof(struct fs, fs_fmod) / sizeof(u_int32_t); i++)
76
                n32[i] = bswap32(o32[i]);
77
 
78
        n->fs_swuid = bswap64(o->fs_swuid);
79
        n->fs_cgrotor = bswap32(o->fs_cgrotor); /* Unused */
80
        n->fs_old_cpc = bswap32(o->fs_old_cpc);
81
 
82
        /* These fields overlap with a possible location for the
83
         * historic FS_DYNAMICPOSTBLFMT postbl table, and with the
84
         * first half of the historic FS_42POSTBLFMT postbl table.
85
         */
86
        n->fs_maxbsize = bswap32(o->fs_maxbsize);
87
        /* XXX journal */
88
        n->fs_quota_magic = bswap32(o->fs_quota_magic);
89
        for (i = 0; i < MAXQUOTAS; i++)
90
                n->fs_quotafile[i] = bswap64(o->fs_quotafile[i]);
91
        n->fs_sblockloc = bswap64(o->fs_sblockloc);
92
        ffs_csumtotal_swap(&o->fs_cstotal, &n->fs_cstotal);
93
        n->fs_time = bswap64(o->fs_time);
94
        n->fs_size = bswap64(o->fs_size);
95
        n->fs_dsize = bswap64(o->fs_dsize);
96
        n->fs_csaddr = bswap64(o->fs_csaddr);
97
        n->fs_pendingblocks = bswap64(o->fs_pendingblocks);
98
        n->fs_pendinginodes = bswap32(o->fs_pendinginodes);
99
 
100
        /* These fields overlap with the second half of the
101
         * historic FS_42POSTBLFMT postbl table
102
         */
103
        for (i = 0; i < FSMAXSNAP; i++)
104
                n->fs_snapinum[i] = bswap32(o->fs_snapinum[i]);
105
        n->fs_avgfilesize = bswap32(o->fs_avgfilesize);
106
        n->fs_avgfpdir = bswap32(o->fs_avgfpdir);
107
        /* fs_sparecon[28] - ignore for now */
108
        n->fs_flags = bswap32(o->fs_flags);
109
        n->fs_contigsumsize = bswap32(o->fs_contigsumsize);
110
        n->fs_maxsymlinklen = bswap32(o->fs_maxsymlinklen);
111
        n->fs_old_inodefmt = bswap32(o->fs_old_inodefmt);
112
        n->fs_maxfilesize = bswap64(o->fs_maxfilesize);
113
        n->fs_qbmask = bswap64(o->fs_qbmask);
114
        n->fs_qfmask = bswap64(o->fs_qfmask);
115
        n->fs_state = bswap32(o->fs_state);
116
        n->fs_old_postblformat = bswap32(o->fs_old_postblformat);
117
        n->fs_old_nrpos = bswap32(o->fs_old_nrpos);
118
        n->fs_old_postbloff = bswap32(o->fs_old_postbloff);
119
        n->fs_old_rotbloff = bswap32(o->fs_old_rotbloff);
120
 
121
        n->fs_magic = bswap32(o->fs_magic);
122
}
123
 
124
void
125
ffs_dinode1_swap(struct ufs1_dinode *o, struct ufs1_dinode *n)
126
{
127
 
128
        n->di_mode = bswap16(o->di_mode);
129
        n->di_nlink = bswap16(o->di_nlink);
130
        n->di_u.oldids[0] = bswap16(o->di_u.oldids[0]);
131
        n->di_u.oldids[1] = bswap16(o->di_u.oldids[1]);
132
        n->di_size = bswap64(o->di_size);
133
        n->di_atime = bswap32(o->di_atime);
134
        n->di_atimensec = bswap32(o->di_atimensec);
135
        n->di_mtime = bswap32(o->di_mtime);
136
        n->di_mtimensec = bswap32(o->di_mtimensec);
137
        n->di_ctime = bswap32(o->di_ctime);
138
        n->di_ctimensec = bswap32(o->di_ctimensec);
139
        memcpy(n->di_db, o->di_db, (NDADDR + NIADDR) * sizeof(u_int32_t));
140
        n->di_flags = bswap32(o->di_flags);
141
        n->di_blocks = bswap32(o->di_blocks);
142
        n->di_gen = bswap32(o->di_gen);
143
        n->di_uid = bswap32(o->di_uid);
144
        n->di_gid = bswap32(o->di_gid);
145
}
146
 
147
void
148
ffs_dinode2_swap(struct ufs2_dinode *o, struct ufs2_dinode *n)
149
{
150
        n->di_mode = bswap16(o->di_mode);
151
        n->di_nlink = bswap16(o->di_nlink);
152
        n->di_uid = bswap32(o->di_uid);
153
        n->di_gid = bswap32(o->di_gid);
154
        n->di_blksize = bswap32(o->di_blksize);
155
        n->di_size = bswap64(o->di_size);
156
        n->di_blocks = bswap64(o->di_blocks);
157
        n->di_atime = bswap64(o->di_atime);
158
        n->di_atimensec = bswap32(o->di_atimensec);
159
        n->di_mtime = bswap64(o->di_mtime);
160
        n->di_mtimensec = bswap32(o->di_mtimensec);
161
        n->di_ctime = bswap64(o->di_ctime);
162
        n->di_ctimensec = bswap32(o->di_ctimensec);
163
        n->di_birthtime = bswap64(o->di_birthtime);
164
        n->di_birthnsec = bswap32(o->di_birthnsec);
165
        n->di_gen = bswap32(o->di_gen);
166
        n->di_kernflags = bswap32(o->di_kernflags);
167
        n->di_flags = bswap32(o->di_flags);
168
        n->di_extsize = bswap32(o->di_extsize);
169
        memcpy(n->di_extb, o->di_extb, (NXADDR + NDADDR + NIADDR) * 8);
170
}
171
 
172
void
173
ffs_csum_swap(struct csum *o, struct csum *n, int size)
174
{
175
        size_t i;
176
        u_int32_t *oint, *nint;
177
 
178
        oint = (u_int32_t*)o;
179
        nint = (u_int32_t*)n;
180
 
181
        for (i = 0; i < size / sizeof(u_int32_t); i++)
182
                nint[i] = bswap32(oint[i]);
183
}
184
 
185
void
186
ffs_csumtotal_swap(struct csum_total *o, struct csum_total *n)
187
{
188
        n->cs_ndir = bswap64(o->cs_ndir);
189
        n->cs_nbfree = bswap64(o->cs_nbfree);
190
        n->cs_nifree = bswap64(o->cs_nifree);
191
        n->cs_nffree = bswap64(o->cs_nffree);
192
}
193
 
194
/*
195
 * Note that ffs_cg_swap may be called with o == n.
196
 */
197
void
198
ffs_cg_swap(struct cg *o, struct cg *n, struct fs *fs)
199
{
200
        int i;
201
        u_int32_t *n32, *o32;
202
        u_int16_t *n16, *o16;
203
        int32_t btotoff, boff, clustersumoff;
204
 
205
        n->cg_firstfield = bswap32(o->cg_firstfield);
206
        n->cg_magic = bswap32(o->cg_magic);
207
        n->cg_old_time = bswap32(o->cg_old_time);
208
        n->cg_cgx = bswap32(o->cg_cgx);
209
        n->cg_old_ncyl = bswap16(o->cg_old_ncyl);
210
        n->cg_old_niblk = bswap16(o->cg_old_niblk);
211
        n->cg_ndblk = bswap32(o->cg_ndblk);
212
        n->cg_cs.cs_ndir = bswap32(o->cg_cs.cs_ndir);
213
        n->cg_cs.cs_nbfree = bswap32(o->cg_cs.cs_nbfree);
214
        n->cg_cs.cs_nifree = bswap32(o->cg_cs.cs_nifree);
215
        n->cg_cs.cs_nffree = bswap32(o->cg_cs.cs_nffree);
216
        n->cg_rotor = bswap32(o->cg_rotor);
217
        n->cg_frotor = bswap32(o->cg_frotor);
218
        n->cg_irotor = bswap32(o->cg_irotor);
219
        for (i = 0; i < MAXFRAG; i++)
220
                n->cg_frsum[i] = bswap32(o->cg_frsum[i]);
221
 
222
        if ((fs->fs_magic != FS_UFS2_MAGIC) &&
223
                        (fs->fs_old_postblformat == FS_42POSTBLFMT)) { /* old format */
224
                struct ocg *on, *oo;
225
                int j;
226
                on = (struct ocg *)n;
227
                oo = (struct ocg *)o;
228
 
229
                for (i = 0; i < 32; i++) {
230
                        on->cg_btot[i] = bswap32(oo->cg_btot[i]);
231
                        for (j = 0; j < 8; j++)
232
                                on->cg_b[i][j] = bswap16(oo->cg_b[i][j]);
233
                }
234
                memmove(on->cg_iused, oo->cg_iused, 256);
235
                on->cg_magic = bswap32(oo->cg_magic);
236
        } else {  /* new format */
237
 
238
                n->cg_old_btotoff = bswap32(o->cg_old_btotoff);
239
                n->cg_old_boff = bswap32(o->cg_old_boff);
240
                n->cg_iusedoff = bswap32(o->cg_iusedoff);
241
                n->cg_freeoff = bswap32(o->cg_freeoff);
242
                n->cg_nextfreeoff = bswap32(o->cg_nextfreeoff);
243
                n->cg_clustersumoff = bswap32(o->cg_clustersumoff);
244
                n->cg_clusteroff = bswap32(o->cg_clusteroff);
245
                n->cg_nclusterblks = bswap32(o->cg_nclusterblks);
246
                n->cg_niblk = bswap32(o->cg_niblk);
247
                n->cg_initediblk = bswap32(o->cg_initediblk);
248
                n->cg_time = bswap64(o->cg_time);
249
 
250
                if (n->cg_magic == CG_MAGIC) {
251
                        btotoff = n->cg_old_btotoff;
252
                        boff = n->cg_old_boff;
253
                        clustersumoff = n->cg_clustersumoff;
254
                } else {
255
                        btotoff = bswap32(n->cg_old_btotoff);
256
                        boff = bswap32(n->cg_old_boff);
257
                        clustersumoff = bswap32(n->cg_clustersumoff);
258
                }
259
 
260
                n32 = (u_int32_t *)((u_int8_t *)n + clustersumoff);
261
                o32 = (u_int32_t *)((u_int8_t *)o + clustersumoff);
262
                for (i = 1; i < fs->fs_contigsumsize + 1; i++)
263
                        n32[i] = bswap32(o32[i]);
264
 
265
                if (fs->fs_magic == FS_UFS2_MAGIC)
266
                        return;
267
 
268
                n32 = (u_int32_t *)((u_int8_t *)n + btotoff);
269
                o32 = (u_int32_t *)((u_int8_t *)o + btotoff);
270
                n16 = (u_int16_t *)((u_int8_t *)n + boff);
271
                o16 = (u_int16_t *)((u_int8_t *)o + boff);
272
 
273
                for (i = 0; i < fs->fs_old_cpg; i++)
274
                        n32[i] = bswap32(o32[i]);
275
 
276
                for (i = 0; i < fs->fs_old_cpg * fs->fs_old_nrpos; i++)
277
                        n16[i] = bswap16(o16[i]);
278
        }
279
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.