]>
Commit | Line | Data |
---|---|---|
14c7c974 | 1 | /* |
57c72a9a | 2 | * Copyright (c) 1999-2003 Apple Computer, Inc. All rights reserved. |
14c7c974 A |
3 | * |
4 | * @APPLE_LICENSE_HEADER_START@ | |
5 | * | |
57c72a9a | 6 | * Portions Copyright (c) 1999-2003 Apple Computer, Inc. All Rights |
4f6e3300 A |
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 | |
57c72a9a | 9 | * Source License Version 2.0 (the "License"). You may not use this file |
4f6e3300 A |
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 | |
12 | * this file. | |
14c7c974 A |
13 | * |
14 | * The Original Code and all software distributed under the License are | |
4f6e3300 | 15 | * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER |
14c7c974 A |
16 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
17 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
4f6e3300 A |
18 | * FITNESS FOR A PARTICULAR PURPOSE OR NON- INFRINGEMENT. Please see the |
19 | * License for the specific language governing rights and limitations | |
20 | * under the License. | |
14c7c974 A |
21 | * |
22 | * @APPLE_LICENSE_HEADER_END@ | |
23 | */ | |
24 | /* | |
25 | * Copyright 1993 NeXT, Inc. | |
26 | * All rights reserved. | |
27 | */ | |
28 | ||
75b89a82 A |
29 | #include <sys/types.h> |
30 | #include <sys/param.h> | |
31 | #include <sys/vnode.h> | |
14c7c974 | 32 | #include <ufs/ufs/dir.h> |
f083c6c3 | 33 | #include <libkern/OSByteOrder.h> |
14c7c974 A |
34 | #include "ufs_byteorder.h" |
35 | #include "libsaio.h" | |
36 | ||
f083c6c3 A |
37 | #define swapBigLongToHost(thing) ((thing) = OSSwapBigToHostInt32(thing)) |
38 | #define swapBigShortToHost(thing) ((thing) = OSSwapBigToHostInt16(thing)) | |
39 | #define byte_swap_longlong(thing) ((thing) = OSSwapBigToHostInt64(thing)) | |
40 | #define byte_swap_int(thing) ((thing) = OSSwapBigToHostInt32(thing)) | |
41 | #define byte_swap_short(thing) ((thing) = OSSwapBigToHostInt16(thing)) | |
14c7c974 | 42 | |
57c72a9a | 43 | #if UNUSED |
14c7c974 A |
44 | void |
45 | byte_swap_longlongs(unsigned long long *array, int count) | |
46 | { | |
47 | register unsigned long long i; | |
48 | ||
f083c6c3 | 49 | for (i = 0; i < (unsigned long long)count; i++) |
14c7c974 A |
50 | byte_swap_longlong(array[i]); |
51 | } | |
57c72a9a | 52 | #endif |
14c7c974 A |
53 | |
54 | void | |
bba600dd | 55 | byte_swap_ints(unsigned int *array, int count) |
14c7c974 A |
56 | { |
57 | register int i; | |
58 | ||
59 | for (i = 0; i < count; i++) | |
60 | byte_swap_int(array[i]); | |
61 | } | |
62 | ||
63 | void | |
bba600dd | 64 | byte_swap_shorts(unsigned short *array, int count) |
14c7c974 A |
65 | { |
66 | register int i; | |
67 | ||
68 | for (i = 0; i < count; i++) | |
69 | byte_swap_short(array[i]); | |
70 | } | |
71 | ||
57c72a9a A |
72 | #if UNUSED |
73 | static void | |
bba600dd | 74 | swapBigIntsToHost(unsigned int *array, int count) |
14c7c974 A |
75 | { |
76 | register int i; | |
77 | ||
78 | for (i = 0; i < count; i++) | |
79 | swapBigLongToHost(array[i]); | |
80 | } | |
81 | ||
57c72a9a | 82 | static void |
bba600dd | 83 | swapBigShortToHosts(unsigned short *array, int count) |
14c7c974 A |
84 | { |
85 | register int i; | |
86 | ||
87 | for (i = 0; i < count; i++) | |
88 | swapBigShortToHost(array[i]); | |
89 | } | |
57c72a9a | 90 | #endif |
14c7c974 A |
91 | |
92 | void | |
93 | byte_swap_superblock(struct fs *sb) | |
94 | { | |
95 | u_int16_t * usptr; | |
96 | unsigned long size; | |
97 | ||
bba600dd | 98 | byte_swap_ints(((u_int32_t *)&sb->fs_firstfield), 52); |
14c7c974 A |
99 | byte_swap_int(sb->fs_cgrotor); |
100 | byte_swap_int(sb->fs_cpc); | |
bba600dd A |
101 | byte_swap_shorts((u_int16_t *)sb->fs_opostbl, 16 * 8); |
102 | byte_swap_ints((u_int32_t *)sb->fs_sparecon, 50); | |
103 | byte_swap_ints((u_int32_t *)&sb->fs_contigsumsize, 3); | |
57c72a9a | 104 | #if UNUSED |
14c7c974 | 105 | byte_swap_longlongs((u_int64_t *)&sb->fs_maxfilesize,3); |
57c72a9a | 106 | #endif |
bba600dd | 107 | byte_swap_ints((u_int32_t *)&sb->fs_state, 6); |
14c7c974 A |
108 | |
109 | /* Got these magic numbers from mkfs.c in newfs */ | |
110 | if (sb->fs_nrpos != 8 || sb->fs_cpc > 16) { | |
111 | usptr = (u_int16_t *)((u_int8_t *)(sb) + (sb)->fs_postbloff); | |
112 | size = sb->fs_cpc * sb->fs_nrpos; | |
113 | byte_swap_shorts(usptr,size); /* fs_postbloff */ | |
114 | } | |
115 | } | |
116 | ||
14c7c974 A |
117 | |
118 | /* This value should correspond to the value set in the ffs_mounts */ | |
119 | ||
120 | #define RESYMLNKLEN 60 | |
121 | ||
122 | void | |
123 | byte_swap_dinode_in(struct dinode *di) | |
124 | { | |
125 | int i; | |
126 | ||
57c72a9a A |
127 | di->di_mode = OSSwapInt16(di->di_mode); |
128 | di->di_nlink = OSSwapInt16(di->di_nlink); | |
14c7c974 | 129 | #ifdef LFS |
57c72a9a | 130 | di->di_u.inumber = OSSwapInt32(di->di_u.inumber); |
14c7c974 | 131 | #else |
57c72a9a A |
132 | di->di_u.oldids[0] = OSSwapInt16(di->di_u.oldids[0]); |
133 | di->di_u.oldids[1] = OSSwapInt16(di->di_u.oldids[1]); | |
14c7c974 | 134 | #endif |
57c72a9a A |
135 | di->di_size = OSSwapInt64(di->di_size); |
136 | di->di_atime = OSSwapInt32(di->di_atime); | |
137 | di->di_atimensec = OSSwapInt32(di->di_atimensec); | |
138 | di->di_mtime = OSSwapInt32(di->di_mtime); | |
139 | di->di_mtimensec = OSSwapInt32(di->di_mtimensec); | |
140 | di->di_ctime = OSSwapInt32(di->di_ctime); | |
141 | di->di_ctimensec = OSSwapInt32(di->di_ctimensec); | |
14c7c974 A |
142 | if (((di->di_mode & IFMT) != IFLNK ) || (di->di_size > RESYMLNKLEN)) { |
143 | for (i=0; i < NDADDR; i++) /* direct blocks */ | |
57c72a9a | 144 | di->di_db[i] = OSSwapInt32(di->di_db[i]); |
14c7c974 | 145 | for (i=0; i < NIADDR; i++) /* indirect blocks */ |
57c72a9a | 146 | di->di_ib[i] = OSSwapInt32(di->di_ib[i]); |
14c7c974 | 147 | } |
57c72a9a A |
148 | di->di_flags = OSSwapInt32(di->di_flags); |
149 | di->di_blocks = OSSwapInt32(di->di_blocks); | |
150 | di->di_gen = OSSwapInt32(di->di_gen); | |
151 | di->di_uid = OSSwapInt32(di->di_uid); | |
152 | di->di_gid = OSSwapInt32(di->di_gid); | |
153 | di->di_spare[0] = OSSwapInt32(di->di_spare[0]); | |
154 | di->di_spare[1] = OSSwapInt32(di->di_spare[1]); | |
14c7c974 A |
155 | } |
156 | ||
157 | void | |
158 | byte_swap_dir_block_in(char *addr, int count) | |
159 | { | |
160 | register struct direct * ep = (struct direct *) addr; | |
161 | register int entryoffsetinblk = 0; | |
162 | ||
163 | while (entryoffsetinblk < count) { | |
164 | ep = (struct direct *) (entryoffsetinblk + addr); | |
165 | swapBigLongToHost(ep->d_ino); | |
166 | swapBigShortToHost(ep->d_reclen); | |
167 | entryoffsetinblk += ep->d_reclen; | |
168 | if (ep->d_reclen < 12) /* handle garbage in dirs */ | |
169 | break; | |
170 | } | |
171 | } |