Chameleon

Chameleon Svn Source Tree

Root/branches/cparm/i386/libsaio/ufs_byteorder.c

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

Archive Download this file

Revision: 1984