]>
Commit | Line | Data |
---|---|---|
04fee52e A |
1 | /* |
2 | * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. | |
3 | * | |
4 | * @APPLE_LICENSE_HEADER_START@ | |
5 | * | |
6 | * The contents of this file constitute Original Code as defined in and | |
7 | * are subject to the Apple Public Source License Version 1.1 (the | |
8 | * "License"). You may not use this file except in compliance with the | |
9 | * License. Please obtain a copy of the License at | |
10 | * http://www.apple.com/publicsource and read it before using this file. | |
11 | * | |
12 | * This Original Code and all software distributed under the License are | |
13 | * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
14 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, | |
15 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
16 | * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the | |
17 | * License for the specific language governing rights and limitations | |
18 | * under the License. | |
19 | * | |
20 | * @APPLE_LICENSE_HEADER_END@ | |
21 | */ | |
22 | /* | |
23 | * Copyright 1993 NeXT, Inc. | |
24 | * All rights reserved. | |
25 | */ | |
26 | /* | |
27 | * ufs_byteorder.c - Functions for endian swapping UFS disk structures. | |
28 | * | |
29 | * Copyright (c) 1998-2000 Apple Computer, Inc. | |
30 | * | |
31 | * DRI: Josh de Cesare | |
32 | */ | |
33 | ||
34 | #include <architecture/byte_order.h> | |
35 | ||
36 | #include "ufs_byteorder.h" | |
37 | ||
38 | #define swapBigLongToHost(thing) ((thing) = NXSwapBigLongToHost(thing)) | |
39 | #define swapBigShortToHost(thing) ((thing) = NXSwapBigShortToHost(thing)) | |
40 | ||
41 | void | |
42 | swapBigIntsToHost(int *array, int count) | |
43 | { | |
44 | register int i; | |
45 | ||
46 | for (i = 0; i < count; i++) | |
47 | swapBigLongToHost(array[i]); | |
48 | } | |
49 | ||
50 | ||
51 | void | |
52 | swapBigShortToHosts(short *array, int count) | |
53 | { | |
54 | register int i; | |
55 | ||
56 | for (i = 0; i < count; i++) | |
57 | swapBigShortToHost(array[i]); | |
58 | } | |
59 | ||
60 | ||
61 | void | |
62 | byte_swap_superblock(struct fs *sb) | |
63 | { | |
64 | #ifdef notyet | |
65 | swapBigIntsToHost(((int *) sb) + 2, 50); | |
66 | ||
67 | swapBigLongToHost(sb->fs_cgrotor); | |
68 | swapBigLongToHost(sb->fs_cpc); | |
69 | ||
70 | swapBigShortToHosts((short *) sb->fs_postbl, MAXCPG * NRPOS); | |
71 | ||
72 | swapBigLongToHost(sb->fs_magic); | |
73 | #endif | |
74 | } | |
75 | ||
76 | ||
77 | static inline void | |
78 | byte_swap_disklabel_common(disk_label_t *dl) | |
79 | { | |
80 | ||
81 | swapBigLongToHost(dl->dl_version); /* ditto */ | |
82 | swapBigLongToHost(dl->dl_label_blkno); | |
83 | swapBigLongToHost(dl->dl_size); | |
84 | swapBigLongToHost(dl->dl_flags); | |
85 | swapBigLongToHost(dl->dl_tag); | |
86 | // swapBigShortToHost(dl->dl_checksum); | |
87 | // if (dl->dl_version >= DL_V3) | |
88 | // swapBigShortToHost(dl->dl_un.DL_v3_checksum); | |
89 | // else | |
90 | // swapBigIntsToHost(dl->dl_un.DL_bad, NBAD); | |
91 | ||
92 | } | |
93 | ||
94 | ||
95 | void | |
96 | byte_swap_disklabel_in(disk_label_t *dl) | |
97 | { | |
98 | ||
99 | byte_swap_disklabel_common(dl); | |
100 | byte_swap_disktab_in(&dl->dl_dt); | |
101 | ||
102 | } | |
103 | ||
104 | ||
105 | static inline void | |
106 | byte_swap_disktab_common(struct disktab *dt) | |
107 | { | |
108 | ||
109 | register unsigned int i; | |
110 | ||
111 | swapBigLongToHost(dt->d_secsize); | |
112 | swapBigLongToHost(dt->d_ntracks); | |
113 | swapBigLongToHost(dt->d_nsectors); | |
114 | swapBigLongToHost(dt->d_ncylinders); | |
115 | // swapBigLongToHost(dt->d_rpm); | |
116 | swapBigShortToHost(dt->d_front); | |
117 | swapBigShortToHost(dt->d_back); | |
118 | // swapBigShortToHost(dt->d_ngroups); | |
119 | // swapBigShortToHost(dt->d_ag_size); | |
120 | // swapBigShortToHost(dt->d_ag_alts); | |
121 | // swapBigShortToHost(dt->d_ag_off); | |
122 | // swapBigIntsToHost(dt->d_boot0_blkno, NBOOTS); | |
123 | ||
124 | for (i=0; i < NPART; i++) | |
125 | byte_swap_partition(&dt->d_partitions[i]); | |
126 | ||
127 | } | |
128 | ||
129 | /* | |
130 | * This is particularly grody. The beginning of the partition array is two | |
131 | * bytes low on the 68 wrt natural alignment rules. Furthermore, each | |
132 | * element of the partition table is two bytes smaller on 68k due to padding | |
133 | * at the end of the struct. | |
134 | */ | |
135 | void | |
136 | byte_swap_disktab_in(struct disktab *dt) | |
137 | { | |
138 | ||
139 | struct partition *pp; | |
140 | int i; | |
141 | ||
142 | /* | |
143 | * Shift each struct partition up in memory by 2 + 2 * offset bytes. | |
144 | * Do it backwards so we don't overwrite anything. | |
145 | */ | |
146 | for (i=NPART - 1; i >=0; i--) { | |
147 | struct partition temp; | |
148 | pp = &dt->d_partitions[i]; | |
149 | /* beware: compiler doesn't do overlapping struct assignment */ | |
150 | temp = *(struct partition *)(((char *) pp) - 2 * (i + 1)); | |
151 | *pp = temp; | |
152 | } | |
153 | ||
154 | byte_swap_disktab_common(dt); | |
155 | ||
156 | } | |
157 | ||
158 | ||
159 | void | |
160 | byte_swap_partition(struct partition *part) | |
161 | { | |
162 | ||
163 | swapBigLongToHost(part->p_base); | |
164 | swapBigLongToHost(part->p_size); | |
165 | swapBigShortToHost(part->p_bsize); | |
166 | swapBigShortToHost(part->p_fsize); | |
167 | swapBigShortToHost(part->p_cpg); | |
168 | swapBigShortToHost(part->p_density); | |
169 | ||
170 | } | |
171 | ||
172 | ||
173 | void | |
174 | byte_swap_inode_in(struct dinode *dc, struct dinode *ic) | |
175 | { | |
176 | #ifdef notyet | |
177 | register int i; | |
178 | ||
179 | ic->ic_mode = NXSwapBigShortToHost(dc->ic_mode); | |
180 | ic->ic_nlink = NXSwapBigShortToHost(dc->ic_nlink); | |
181 | // ic->ic_uid = NXSwapBigShortToHost(dc->ic_uid); | |
182 | // ic->ic_gid = NXSwapBigShortToHost(dc->ic_gid); | |
183 | ||
184 | ic->ic_size.val[0] = NXSwapBigLongToHost(dc->ic_size.val[1]); | |
185 | ic->ic_size.val[1] = NXSwapBigLongToHost(dc->ic_size.val[0]); | |
186 | ||
187 | // ic->ic_atime = NXSwapBigLongToHost(dc->ic_atime); | |
188 | // ic->ic_mtime = NXSwapBigLongToHost(dc->ic_mtime); | |
189 | // ic->ic_ctime = NXSwapBigLongToHost(dc->ic_ctime); | |
190 | // ic->ic_atspare = NXSwapBigLongToHost(dc->ic_atspare); | |
191 | // ic->ic_mtspare = NXSwapBigLongToHost(dc->ic_mtspare); | |
192 | // ic->ic_ctspare = NXSwapBigLongToHost(dc->ic_ctspare); | |
193 | ||
194 | ic->ic_flags = NXSwapBigLongToHost(dc->ic_flags); | |
195 | ||
196 | if ((ic->ic_flags & IC_FASTLINK) == 0) { /* not a fast symlink */ | |
197 | ||
198 | for (i=0; i < NDADDR; i++) /* direct blocks */ | |
199 | ic->ic_db[i] = NXSwapBigLongToHost(dc->ic_db[i]); | |
200 | ||
201 | for (i=0; i < NIADDR; i++) /* indirect blocks */ | |
202 | ic->ic_ib[i] = NXSwapBigLongToHost(dc->ic_ib[i]); | |
203 | } | |
204 | else | |
205 | bcopy(dc->ic_symlink, ic->ic_symlink, sizeof(dc->ic_symlink)); | |
206 | ||
207 | ic->ic_blocks = NXSwapBigLongToHost(dc->ic_blocks); | |
208 | ic->ic_gen = NXSwapBigLongToHost(dc->ic_gen); | |
209 | for (i=0; i < sizeof(ic->ic_spare) / sizeof(int); i++) | |
210 | ic->ic_spare[i] = NXSwapBigLongToHost(dc->ic_spare[i]); | |
211 | #else | |
212 | *ic = *dc; | |
213 | #endif | |
214 | } | |
215 | ||
216 | ||
217 | void | |
218 | byte_swap_dir_block_in(char *addr, int count) | |
219 | { | |
220 | #ifdef notyet | |
221 | register struct direct *ep = (struct direct *) addr; | |
222 | register int entryoffsetinblk = 0; | |
223 | ||
224 | while (entryoffsetinblk < count) { | |
225 | ep = (struct direct *) (entryoffsetinblk + addr); | |
226 | swapBigLongToHost(ep->d_ino); | |
227 | swapBigShortToHost(ep->d_reclen); | |
228 | swapBigShortToHost(ep->d_namlen); | |
229 | entryoffsetinblk += ep->d_reclen; | |
230 | if (ep->d_reclen < 12) /* handle garbage in dirs */ | |
231 | break; | |
232 | } | |
233 | #endif | |
234 | } |