]>
git.saurik.com Git - apple/bootx.git/blob - bootx.tproj/fs.subproj/ufs_byteorder.c
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
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.
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
20 * @APPLE_LICENSE_HEADER_END@
23 * Copyright 1993 NeXT, Inc.
24 * All rights reserved.
27 * ufs_byteorder.c - Functions for endian swapping UFS disk structures.
29 * Copyright (c) 1998-2000 Apple Computer, Inc.
34 #include <architecture/byte_order.h>
36 #include "ufs_byteorder.h"
38 #define swapBigLongToHost(thing) ((thing) = NXSwapBigLongToHost(thing))
39 #define swapBigShortToHost(thing) ((thing) = NXSwapBigShortToHost(thing))
42 swapBigIntsToHost(int *array
, int count
)
46 for (i
= 0; i
< count
; i
++)
47 swapBigLongToHost(array
[i
]);
52 swapBigShortToHosts(short *array
, int count
)
56 for (i
= 0; i
< count
; i
++)
57 swapBigShortToHost(array
[i
]);
62 byte_swap_superblock(struct fs
*sb
)
65 swapBigIntsToHost(((int *) sb
) + 2, 50);
67 swapBigLongToHost(sb
->fs_cgrotor
);
68 swapBigLongToHost(sb
->fs_cpc
);
70 swapBigShortToHosts((short *) sb
->fs_postbl
, MAXCPG
* NRPOS
);
72 swapBigLongToHost(sb
->fs_magic
);
78 byte_swap_inode_in(struct dinode
*dc
, struct dinode
*ic
)
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);
88 ic
->ic_size
.val
[0] = NXSwapBigLongToHost(dc
->ic_size
.val
[1]);
89 ic
->ic_size
.val
[1] = NXSwapBigLongToHost(dc
->ic_size
.val
[0]);
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);
98 ic
->ic_flags
= NXSwapBigLongToHost(dc
->ic_flags
);
100 if ((ic
->ic_flags
& IC_FASTLINK
) == 0) { /* not a fast symlink */
102 for (i
=0; i
< NDADDR
; i
++) /* direct blocks */
103 ic
->ic_db
[i
] = NXSwapBigLongToHost(dc
->ic_db
[i
]);
105 for (i
=0; i
< NIADDR
; i
++) /* indirect blocks */
106 ic
->ic_ib
[i
] = NXSwapBigLongToHost(dc
->ic_ib
[i
]);
109 bcopy(dc
->ic_symlink
, ic
->ic_symlink
, sizeof(dc
->ic_symlink
));
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
]);
122 byte_swap_dir_block_in(char *addr
, int count
)
125 register struct direct
*ep
= (struct direct
*) addr
;
126 register int entryoffsetinblk
= 0;
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 */