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