]> git.saurik.com Git - apple/bootx.git/blob - bootx.tproj/fs.subproj/ufs_byteorder.c
BootX-81.tar.gz
[apple/bootx.git] / bootx.tproj / fs.subproj / ufs_byteorder.c
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 void
78 byte_swap_inode_in(struct dinode *dc, struct dinode *ic)
79 {
80 #ifdef notyet
81 register int i;
82
83 ic->ic_mode = NXSwapBigShortToHost(dc->ic_mode);
84 ic->ic_nlink = NXSwapBigShortToHost(dc->ic_nlink);
85 // ic->ic_uid = NXSwapBigShortToHost(dc->ic_uid);
86 // ic->ic_gid = NXSwapBigShortToHost(dc->ic_gid);
87
88 ic->ic_size.val[0] = NXSwapBigLongToHost(dc->ic_size.val[1]);
89 ic->ic_size.val[1] = NXSwapBigLongToHost(dc->ic_size.val[0]);
90
91 // ic->ic_atime = NXSwapBigLongToHost(dc->ic_atime);
92 // ic->ic_mtime = NXSwapBigLongToHost(dc->ic_mtime);
93 // ic->ic_ctime = NXSwapBigLongToHost(dc->ic_ctime);
94 // ic->ic_atspare = NXSwapBigLongToHost(dc->ic_atspare);
95 // ic->ic_mtspare = NXSwapBigLongToHost(dc->ic_mtspare);
96 // ic->ic_ctspare = NXSwapBigLongToHost(dc->ic_ctspare);
97
98 ic->ic_flags = NXSwapBigLongToHost(dc->ic_flags);
99
100 if ((ic->ic_flags & IC_FASTLINK) == 0) { /* not a fast symlink */
101
102 for (i=0; i < NDADDR; i++) /* direct blocks */
103 ic->ic_db[i] = NXSwapBigLongToHost(dc->ic_db[i]);
104
105 for (i=0; i < NIADDR; i++) /* indirect blocks */
106 ic->ic_ib[i] = NXSwapBigLongToHost(dc->ic_ib[i]);
107 }
108 else
109 bcopy(dc->ic_symlink, ic->ic_symlink, sizeof(dc->ic_symlink));
110
111 ic->ic_blocks = NXSwapBigLongToHost(dc->ic_blocks);
112 ic->ic_gen = NXSwapBigLongToHost(dc->ic_gen);
113 for (i=0; i < sizeof(ic->ic_spare) / sizeof(int); i++)
114 ic->ic_spare[i] = NXSwapBigLongToHost(dc->ic_spare[i]);
115 #else
116 *ic = *dc;
117 #endif
118 }
119
120
121 void
122 byte_swap_dir_block_in(char *addr, int count)
123 {
124 #ifdef notyet
125 register struct direct *ep = (struct direct *) addr;
126 register int entryoffsetinblk = 0;
127
128 while (entryoffsetinblk < count) {
129 ep = (struct direct *) (entryoffsetinblk + addr);
130 swapBigLongToHost(ep->d_ino);
131 swapBigShortToHost(ep->d_reclen);
132 swapBigShortToHost(ep->d_namlen);
133 entryoffsetinblk += ep->d_reclen;
134 if (ep->d_reclen < 12) /* handle garbage in dirs */
135 break;
136 }
137 #endif
138 }