]>
git.saurik.com Git - apple/boot.git/blob - gen/libsaio/ufs_byteorder.c
2 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
7 * Reserved. This file contains Original Code and/or Modifications of
8 * Original Code as defined in and that are subject to the Apple Public
9 * Source License Version 1.1 (the "License"). You may not use this file
10 * except in compliance with the License. Please obtain a copy of the
11 * License at http://www.apple.com/publicsource and read it before using
14 * The Original Code and all software distributed under the License are
15 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
16 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
17 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE OR NON- INFRINGEMENT. Please see the
19 * License for the specific language governing rights and limitations
22 * @APPLE_LICENSE_HEADER_END@
25 * Copyright 1993 NeXT, Inc.
26 * All rights reserved.
29 #import <bsd/sys/types.h>
30 #import <bsd/sys/param.h>
31 #import <bsd/sys/vnode.h>
32 #import <bsd/ufs/fsdir.h>
33 #import <architecture/byte_order.h>
34 #import "ufs_byteorder.h"
37 #define swapBigLongToHost(thing) ((thing) = NXSwapBigLongToHost(thing))
38 #define swapBigShortToHost(thing) ((thing) = NXSwapBigShortToHost(thing))
41 swapBigIntsToHost(int *array
, int count
)
45 for (i
= 0; i
< count
; i
++)
46 swapBigLongToHost(array
[i
]);
51 swapBigShortToHosts(short *array
, int count
)
55 for (i
= 0; i
< count
; i
++)
56 swapBigShortToHost(array
[i
]);
61 byte_swap_superblock(struct fs
*sb
)
63 swapBigIntsToHost(((int *) sb
) + 2, 50);
65 swapBigLongToHost(sb
->fs_cgrotor
);
66 swapBigLongToHost(sb
->fs_cpc
);
68 swapBigShortToHosts((short *) sb
->fs_postbl
, MAXCPG
* NRPOS
);
70 swapBigLongToHost(sb
->fs_magic
);
75 byte_swap_disklabel_common(disk_label_t
*dl
)
77 swapBigLongToHost(dl
->dl_version
); /* ditto */
78 swapBigLongToHost(dl
->dl_label_blkno
);
79 swapBigLongToHost(dl
->dl_size
);
80 swapBigLongToHost(dl
->dl_flags
);
81 swapBigLongToHost(dl
->dl_tag
);
82 // swapBigShortToHost(dl->dl_checksum);
83 // if (dl->dl_version >= DL_V3)
84 // swapBigShortToHost(dl->dl_un.DL_v3_checksum);
86 // swapBigIntsToHost(dl->dl_un.DL_bad, NBAD);
91 byte_swap_disklabel_in(disk_label_t
*dl
)
93 byte_swap_disklabel_common(dl
);
94 byte_swap_disktab_in(&dl
->dl_dt
);
99 byte_swap_disktab_common(struct disktab
*dt
)
101 register unsigned int i
;
103 swapBigLongToHost(dt
->d_secsize
);
104 swapBigLongToHost(dt
->d_ntracks
);
105 swapBigLongToHost(dt
->d_nsectors
);
106 swapBigLongToHost(dt
->d_ncylinders
);
107 // swapBigLongToHost(dt->d_rpm);
108 swapBigShortToHost(dt
->d_front
);
109 swapBigShortToHost(dt
->d_back
);
110 // swapBigShortToHost(dt->d_ngroups);
111 // swapBigShortToHost(dt->d_ag_size);
112 // swapBigShortToHost(dt->d_ag_alts);
113 // swapBigShortToHost(dt->d_ag_off);
114 // swapBigIntsToHost(dt->d_boot0_blkno, NBOOTS);
116 for (i
=0; i
< NPART
; i
++)
117 byte_swap_partition(&dt
->d_partitions
[i
]);
121 * This is particularly grody. The beginning of the partition array is two
122 * bytes low on the 68 wrt natural alignment rules. Furthermore, each
123 * element of the partition table is two bytes smaller on 68k due to padding
124 * at the end of the struct.
127 byte_swap_disktab_in(struct disktab
*dt
)
129 struct partition
*pp
;
133 * Shift each struct partition up in memory by 2 + 2 * offset bytes.
134 * Do it backwards so we don't overwrite anything.
136 for (i
=NPART
- 1; i
>=0; i
--) {
137 struct partition temp
;
138 pp
= &dt
->d_partitions
[i
];
139 /* beware: compiler doesn't do overlapping struct assignment */
140 temp
= *(struct partition
*)(((char *) pp
) - 2 * (i
+ 1));
144 byte_swap_disktab_common(dt
);
149 byte_swap_partition(struct partition
*part
)
151 swapBigLongToHost(part
->p_base
);
152 swapBigLongToHost(part
->p_size
);
153 swapBigShortToHost(part
->p_bsize
);
154 swapBigShortToHost(part
->p_fsize
);
155 swapBigShortToHost(part
->p_cpg
);
156 swapBigShortToHost(part
->p_density
);
161 byte_swap_csum(struct csum
*cs
)
163 swapBigIntsToHost((int *) cs
, sizeof(struct csum
) / sizeof(int));
168 byte_swap_cylgroup(struct cg
*cg
)
170 swapBigLongToHost(cg
->cg_time
);
171 swapBigLongToHost(cg
->cg_cgx
);
172 swapBigShortToHost(cg
->cg_ncyl
);
173 swapBigShortToHost(cg
->cg_niblk
);
174 swapBigLongToHost(cg
->cg_ndblk
);
175 byte_swap_csum(&cg
->cg_cs
);
176 swapBigLongToHost(cg
->cg_rotor
);
177 swapBigLongToHost(cg
->cg_frotor
);
178 swapBigLongToHost(cg
->cg_irotor
);
179 swapBigIntsToHost(cg
->cg_frsum
, MAXFRAG
);
180 swapBigIntsToHost(cg
->cg_btot
, MAXCPG
);
181 swapBigShortToHosts((short *) cg
->cg_b
, MAXCPG
* NRPOS
);
182 swapBigLongToHost(cg
->cg_magic
);
188 byte_swap_inode_in(struct icommon
*dc
, struct icommon
*ic
)
192 ic
->ic_mode
= NXSwapBigShortToHost(dc
->ic_mode
);
193 ic
->ic_nlink
= NXSwapBigShortToHost(dc
->ic_nlink
);
194 // ic->ic_uid = NXSwapBigShortToHost(dc->ic_uid);
195 // ic->ic_gid = NXSwapBigShortToHost(dc->ic_gid);
197 ic
->ic_size
.val
[0] = NXSwapBigLongToHost(dc
->ic_size
.val
[1]);
198 ic
->ic_size
.val
[1] = NXSwapBigLongToHost(dc
->ic_size
.val
[0]);
200 // ic->ic_atime = NXSwapBigLongToHost(dc->ic_atime);
201 // ic->ic_mtime = NXSwapBigLongToHost(dc->ic_mtime);
202 // ic->ic_ctime = NXSwapBigLongToHost(dc->ic_ctime);
203 // ic->ic_atspare = NXSwapBigLongToHost(dc->ic_atspare);
204 // ic->ic_mtspare = NXSwapBigLongToHost(dc->ic_mtspare);
205 // ic->ic_ctspare = NXSwapBigLongToHost(dc->ic_ctspare);
207 ic
->ic_flags
= NXSwapBigLongToHost(dc
->ic_flags
);
209 if ((ic
->ic_flags
& IC_FASTLINK
) == 0) { /* not a fast symlink */
211 for (i
=0; i
< NDADDR
; i
++) /* direct blocks */
212 ic
->ic_db
[i
] = NXSwapBigLongToHost(dc
->ic_db
[i
]);
214 for (i
=0; i
< NIADDR
; i
++) /* indirect blocks */
215 ic
->ic_ib
[i
] = NXSwapBigLongToHost(dc
->ic_ib
[i
]);
218 bcopy(dc
->ic_symlink
, ic
->ic_symlink
, sizeof(dc
->ic_symlink
));
220 ic
->ic_blocks
= NXSwapBigLongToHost(dc
->ic_blocks
);
221 ic
->ic_gen
= NXSwapBigLongToHost(dc
->ic_gen
);
222 for (i
=0; i
< sizeof(ic
->ic_spare
) / sizeof(int); i
++)
223 ic
->ic_spare
[i
] = NXSwapBigLongToHost(dc
->ic_spare
[i
]);
228 byte_swap_dir_block_in(char *addr
, int count
)
230 register struct direct
*ep
= (struct direct
*) addr
;
231 register int entryoffsetinblk
= 0;
233 while (entryoffsetinblk
< count
) {
234 ep
= (struct direct
*) (entryoffsetinblk
+ addr
);
235 swapBigLongToHost(ep
->d_ino
);
236 swapBigShortToHost(ep
->d_reclen
);
237 swapBigShortToHost(ep
->d_namlen
);
238 entryoffsetinblk
+= ep
->d_reclen
;
239 if (ep
->d_reclen
< 12) /* handle garbage in dirs */