]> git.saurik.com Git - apple/bootx.git/blob - bootx.tproj/fs.subproj/ext2fs_bswap.c
BootX-46.tar.gz
[apple/bootx.git] / bootx.tproj / fs.subproj / ext2fs_bswap.c
1 /*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
7 *
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * file.
14 *
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
22 *
23 * @APPLE_LICENSE_HEADER_END@
24 */
25 /* $NetBSD: ext2fs_bswap.c,v 1.4 2000/01/28 16:00:23 bouyer Exp $ */
26 /*
27 * Copyright (c) 1997 Manuel Bouyer.
28 *
29 * Redistribution and use in source and binary forms, with or without
30 * modification, are permitted provided that the following conditions
31 * are met:
32 * 1. Redistributions of source code must retain the above copyright
33 * notice, this list of conditions and the following disclaimer.
34 * 2. Redistributions in binary form must reproduce the above copyright
35 * notice, this list of conditions and the following disclaimer in the
36 * documentation and/or other materials provided with the distribution.
37 * 3. All advertising materials mentioning features or use of this software
38 * must display the following acknowledgement:
39 * This product includes software developed by the University of
40 * California, Berkeley and its contributors.
41 * 4. Neither the name of the University nor the names of its contributors
42 * may be used to endorse or promote products derived from this software
43 * without specific prior written permission.
44 *
45 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
46 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
47 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
48 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
49 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
50 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
51 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
52 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
53 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
54 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
55 * SUCH DAMAGE.
56 *
57 */
58 /*
59 * ext2fs_bswap.c - Functions for endian swapping Ext2 disk structures.
60 *
61 * Copyright (c) 2000 Apple Computer, Inc.
62 *
63 * DRI: Josh de Cesare
64 */
65
66 #include <sl.h>
67
68 #include "ext2fs.h"
69 #include "ext2fs_dinode.h"
70
71 /* These functions are only needed if native byte order is not big endian */
72 #if BYTE_ORDER == BIG_ENDIAN
73 void
74 e2fs_sb_bswap(old, new)
75 struct ext2fs *old, *new;
76 {
77 /* preserve unused fields */
78 memcpy(new, old, sizeof(struct ext2fs));
79 new->e2fs_icount = bswap32(old->e2fs_icount);
80 new->e2fs_bcount = bswap32(old->e2fs_bcount);
81 new->e2fs_rbcount = bswap32(old->e2fs_rbcount);
82 new->e2fs_fbcount = bswap32(old->e2fs_fbcount);
83 new->e2fs_ficount = bswap32(old->e2fs_ficount);
84 new->e2fs_first_dblock = bswap32(old->e2fs_first_dblock);
85 new->e2fs_log_bsize = bswap32(old->e2fs_log_bsize);
86 new->e2fs_fsize = bswap32(old->e2fs_fsize);
87 new->e2fs_bpg = bswap32(old->e2fs_bpg);
88 new->e2fs_fpg = bswap32(old->e2fs_fpg);
89 new->e2fs_ipg = bswap32(old->e2fs_ipg);
90 new->e2fs_mtime = bswap32(old->e2fs_mtime);
91 new->e2fs_wtime = bswap32(old->e2fs_wtime);
92 new->e2fs_mnt_count = bswap16(old->e2fs_mnt_count);
93 new->e2fs_max_mnt_count = bswap16(old->e2fs_max_mnt_count);
94 new->e2fs_magic = bswap16(old->e2fs_magic);
95 new->e2fs_state = bswap16(old->e2fs_state);
96 new->e2fs_beh = bswap16(old->e2fs_beh);
97 new->e2fs_minrev = bswap16(old->e2fs_minrev);
98 new->e2fs_lastfsck = bswap32(old->e2fs_lastfsck);
99 new->e2fs_fsckintv = bswap32(old->e2fs_fsckintv);
100 new->e2fs_creator = bswap32(old->e2fs_creator);
101 new->e2fs_rev = bswap32(old->e2fs_rev);
102 new->e2fs_ruid = bswap16(old->e2fs_ruid);
103 new->e2fs_rgid = bswap16(old->e2fs_rgid);
104 new->e2fs_first_ino = bswap32(old->e2fs_first_ino);
105 new->e2fs_inode_size = bswap16(old->e2fs_inode_size);
106 new->e2fs_block_group_nr = bswap16(old->e2fs_block_group_nr);
107 new->e2fs_features_compat = bswap32(old->e2fs_features_compat);
108 new->e2fs_features_incompat = bswap32(old->e2fs_features_incompat);
109 new->e2fs_features_rocompat = bswap32(old->e2fs_features_rocompat);
110 new->e2fs_algo = bswap32(old->e2fs_algo);
111 }
112
113 void e2fs_cg_bswap(old, new, size)
114 struct ext2_gd *old, *new;
115 int size;
116 {
117 int i;
118 for (i=0; i < (size / sizeof(struct ext2_gd)); i++) {
119 new[i].ext2bgd_b_bitmap = bswap32(old[i].ext2bgd_b_bitmap);
120 new[i].ext2bgd_i_bitmap = bswap32(old[i].ext2bgd_i_bitmap);
121 new[i].ext2bgd_i_tables = bswap32(old[i].ext2bgd_i_tables);
122 new[i].ext2bgd_nbfree = bswap16(old[i].ext2bgd_nbfree);
123 new[i].ext2bgd_nifree = bswap16(old[i].ext2bgd_nifree);
124 new[i].ext2bgd_ndirs = bswap16(old[i].ext2bgd_ndirs);
125 }
126 }
127
128 void e2fs_i_bswap(old, new)
129 struct ext2fs_dinode *old, *new;
130 {
131 new->e2di_mode = bswap16(old->e2di_mode);
132 new->e2di_uid = bswap16(old->e2di_uid);
133 new->e2di_gid = bswap16(old->e2di_gid);
134 new->e2di_nlink = bswap16(old->e2di_nlink);
135 new->e2di_size = bswap32(old->e2di_size);
136 new->e2di_atime = bswap32(old->e2di_atime);
137 new->e2di_ctime = bswap32(old->e2di_ctime);
138 new->e2di_mtime = bswap32(old->e2di_mtime);
139 new->e2di_dtime = bswap32(old->e2di_dtime);
140 new->e2di_nblock = bswap32(old->e2di_nblock);
141 new->e2di_flags = bswap32(old->e2di_flags);
142 new->e2di_gen = bswap32(old->e2di_gen);
143 new->e2di_facl = bswap32(old->e2di_facl);
144 new->e2di_dacl = bswap32(old->e2di_dacl);
145 new->e2di_faddr = bswap32(old->e2di_faddr);
146 memcpy(&new->e2di_blocks[0], &old->e2di_blocks[0],
147 (NDADDR+NIADDR) * sizeof(int));
148 }
149 #endif