Chameleon

Chameleon Commit Details

Date:2011-07-02 11:21:36 (8 years 4 months ago)
Author:Azimutz
Commit:1096
Parents: 1095
Message:Sync these two with trunk (r1095).
Changes:
D/branches/azimutz/trunkAutoResolution/i386/libsaio/ufs_byteorder.c
D/branches/azimutz/trunkAutoResolution/i386/libsaio/ufs.c
D/branches/azimutz/trunkGraphicsEnablerModules/i386/libsaio/ufs_byteorder.c
D/branches/azimutz/trunkGraphicsEnablerModules/i386/libsaio/ufs.c
M/branches/azimutz/trunkAutoResolution/i386/libsaio/Makefile
M/branches/azimutz/trunkGraphicsEnablerModules/i386/boot2/boot.c
M/branches/azimutz/trunkGraphicsEnablerModules/i386/libsaio/Makefile
M/branches/azimutz/trunkAutoResolution
M/branches/azimutz/trunkAutoResolution/i386/boot2/boot.c
M/branches/azimutz/trunkGraphicsEnablerModules

File differences

branches/azimutz/trunkAutoResolution/i386/libsaio/ufs.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
/*
* Copyright (c) 2000-2003 Apple Computer, Inc. All rights reserved.
*
* @APPLE_LICENSE_HEADER_START@
*
* The contents of this file constitute Original Code as defined in and
* are subject to the Apple Public Source License Version 2.0 (the
* "License"). You may not use this file except in compliance with the
* License. Please obtain a copy of the License at
* http://www.apple.com/publicsource and read it before using this file.
*
* This Original Code and all software distributed under the License are
* distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
* License for the specific language governing rights and limitations
* under the License.
*
* @APPLE_LICENSE_HEADER_END@
*/
/*
* ufs.c - File System Module for UFS.
*
* Copyright (c) 1998-2002 Apple Computer, Inc.
*
* DRI: Josh de Cesare
*/
#if 0
#include <sl.h>
#include "ufs.h"
#include "ufs_byteorder.h"
#if !defined(MAXNAMLEN) && defined(UFSMAXNAMLEN)
#define MAXNAMLEN UFSMAXNAMLEN
#endif
typedef struct dinode Inode, *InodePtr;
// Private function prototypes
static char *ReadBlock(long fragNum, long fragOffset, long length,
char *buffer, long cache);
static long ReadInode(long inodeNum, InodePtr inode, long *flags, long *time);
static long ResolvePathToInode(char *filePath, long *flags,
InodePtr fileInode, InodePtr dirInode);
static long ReadDirEntry(InodePtr dirInode, long *fileInodeNum,
long long *dirIndex, char **name);
static long FindFileInDir(char *fileName, long *flags,
InodePtr fileInode, InodePtr dirInode);
static char *ReadFileBlock(InodePtr fileInode, long fragNum, long blockOffset,
long length, char *buffer, long cache);
static long ReadFile(InodePtr fileInode, uint64_t *length, void *base, uint64_t offset);
#define kDevBlockSize (0x200) // Size of each disk block.
#define kDiskLabelBlock (15) // Block the DL is in.
#ifdef __i386__
static CICell gCurrentIH;
static long long gPartitionBase;
static char *gULBuf;
static char *gFSBuf;
static struct fs *gFS;
#if !BOOT1
static struct ufslabel gUFSLabel; // for UUID
#endif
static long gBlockSize;
static long gFragSize;
static long gFragsPerBlock;
static char *gTempBlock;
static char *gTempName;
static char *gTempName2;
static InodePtr gRootInodePtr;
static InodePtr gFileInodePtr;
#else /* !__i386__ */
static CICell gCurrentIH;
static long long gPartitionBase;
static char gDLBuf[8192];
static char gFSBuf[SBSIZE];
static struct fs *gFS;
#if !BOOT1
static struct ufslabel gUFSLabel; // for UUID
#endif
static long gBlockSize;
static long gFragSize;
static long gFragsPerBlock;
static char *gTempBlock;
static char gTempName[MAXNAMLEN + 1];
static char gTempName2[MAXNAMLEN + 1];
static Inode _gRootInode;
static Inode _gFileInode;
static InodePtr gRootInodePtr = &_gRootInode;
static InodePtr gFileInodePtr = &_gFileInode;
#endif /* !__i386__ */
// Public functions
void UFSFree(CICell ih)
{
if(gCurrentIH == ih)
gCurrentIH = 0;
free(ih);
}
long UFSInitPartition( CICell ih )
{
#if !BOOT1
long ret;
#endif
if (ih == gCurrentIH) {
#ifdef __i386__
CacheInit(ih, gBlockSize);
#endif
return 0;
}
#if !BOOT1
verbose("UFSInitPartition: %x\n", ih);
#endif
gCurrentIH = 0;
#ifdef __i386__
if (!gULBuf) gULBuf = (char *) malloc(UFS_LABEL_SIZE);
if (!gFSBuf) gFSBuf = (char *) malloc(SBSIZE);
if (!gTempName) gTempName = (char *) malloc(MAXNAMLEN + 1);
if (!gTempName2) gTempName2 = (char *) malloc(MAXNAMLEN + 1);
if (!gRootInodePtr) gRootInodePtr = (InodePtr) malloc(sizeof(Inode));
if (!gFileInodePtr) gFileInodePtr = (InodePtr) malloc(sizeof(Inode));
if (!gULBuf || !gFSBuf || !gTempName || !gTempName2 ||
!gRootInodePtr || !gFileInodePtr) return -1;
#endif
// Assume there is no Disk Label
gPartitionBase = 0;
#if !BOOT1
// read the disk label to get the UUID
// (rumor has it that UFS headers can be either-endian on disk; hopefully
// that isn't true for this UUID field).
Seek(ih, gPartitionBase + UFS_LABEL_OFFSET);
ret = Read(ih, (long)&gUFSLabel, UFS_LABEL_SIZE);
if(ret != 0)
bzero(&gUFSLabel, UFS_LABEL_SIZE);
#endif /* !BOOT1 */
// Look for the Super Block
Seek(ih, gPartitionBase + SBOFF);
Read(ih, (long)gFSBuf, SBSIZE);
gFS = (struct fs *)gFSBuf;
byte_swap_superblock(gFS);
if (gFS->fs_magic != FS_MAGIC) {
return -1;
}
ih->modTime = gFS->fs_time;
// Calculate the block size and set up the block cache.
gBlockSize = gFS->fs_bsize;
gFragSize = gFS->fs_fsize;
gFragsPerBlock = gBlockSize / gFragSize;
if (gTempBlock != 0) free(gTempBlock);
gTempBlock = malloc(gBlockSize);
CacheInit(ih, gBlockSize);
gCurrentIH = ih;
// Read the Root Inode
ReadInode(ROOTINO, gRootInodePtr, 0, 0);
return 0;
}
#if !BOOT1
long UFSGetUUID(CICell ih, char *uuidStr)
{
long long uuid = gUFSLabel.ul_uuid;
if (UFSInitPartition(ih) == -1) return -1;
if (uuid == 0LL) return -1;
return CreateUUIDString((uint8_t*)(&uuid), sizeof(uuid), uuidStr);
}
#endif /* !BOOT1 */
long UFSLoadFile( CICell ih, char * filePath )
{
return UFSReadFile(ih, filePath, (void *)gFSLoadAddress, 0, 0);
}
long UFSReadFile( CICell ih, char * filePath, void * base, uint64_t offset, uint64_t length )
{
long ret, flags;
#if !BOOT1
verbose("Loading UFS file: [%s] from %x.\n", filePath, (unsigned)ih);
#endif
if (UFSInitPartition(ih) == -1) return -1;
// Skip one or two leading '/'.
if (*filePath == '/') filePath++;
if (*filePath == '/') filePath++;
ret = ResolvePathToInode(filePath, &flags, gFileInodePtr, gRootInodePtr);
if ((ret == -1) || ((flags & kFileTypeMask) != kFileTypeFlat)) return -1;
ret = ReadFile(gFileInodePtr, &length, base, offset);
if (ret == -1) return -1;
return length;
}
#ifndef BOOT1
long UFSGetDirEntry( CICell ih, char * dirPath, long long * dirIndex,
char ** name, long * flags, long * time,
FinderInfo * finderInfo, long * infoValid)
{
long ret, fileInodeNum, dirFlags;
Inode tmpInode;
if (UFSInitPartition(ih) == -1) return -1;
if (infoValid) *infoValid = 0;
// Skip a leading '/' if present
if (*dirPath == '/') dirPath++;
if (*dirPath == '/') dirPath++;
ret = ResolvePathToInode(dirPath, &dirFlags, gFileInodePtr, gRootInodePtr);
if ((ret == -1) || ((dirFlags & kFileTypeMask) != kFileTypeDirectory))
return -1;
ret = ReadDirEntry(gFileInodePtr, &fileInodeNum, dirIndex, name);
if (ret != 0) return ret;
ReadInode(fileInodeNum, &tmpInode, flags, time);
return 0;
}
void
UFSGetDescription(CICell ih, char *str, long strMaxLen)
{
if (UFSInitPartition(ih) == -1) { return; }
struct ufslabel *ul;
// Look for the Disk Label
Seek(ih, 1ULL * UFS_LABEL_OFFSET);
Read(ih, (long)gULBuf, UFS_LABEL_SIZE);
ul = (struct ufslabel *)gULBuf;
unsigned char magic_bytes[] = UFS_LABEL_MAGIC;
int i;
unsigned char *p = (unsigned char *)&ul->ul_magic;
for (i=0; i<sizeof(magic_bytes); i++, p++) {
if (*p != magic_bytes[i])
return;
}
strncpy(str, (const char *)ul->ul_name, strMaxLen);
}
long
UFSGetFileBlock(CICell ih, char *filePath, unsigned long long *firstBlock)
{
long ret, flags;
if (UFSInitPartition(ih) == -1) return -1;
// Skip one or two leading '/'.
if (*filePath == '/') filePath++;
if (*filePath == '/') filePath++;
ret = ResolvePathToInode(filePath, &flags, gFileInodePtr, gRootInodePtr);
if ((ret == -1) || ((flags & kFileTypeMask) != kFileTypeFlat)) return -1;
*firstBlock = (gPartitionBase + 1ULL * gFileInodePtr->di_db[0] * gBlockSize) / 512ULL;
return 0;
}
#endif /* !BOOT1 */
// Private functions
static char * ReadBlock( long fragNum, long blockOffset, long length,
char * buffer, long cache )
{
long long offset;
long blockNum;
blockNum = fragNum / gFragsPerBlock;
fragNum -= blockNum * gFragsPerBlock;
blockOffset += fragNum * gFragSize;
offset = gPartitionBase + 1ULL * blockNum * gBlockSize;
if (cache && ((blockOffset + length) <= gBlockSize)) {
CacheRead(gCurrentIH, gTempBlock, offset, gBlockSize, 1);
if (buffer != 0) bcopy(gTempBlock + blockOffset, buffer, length);
else buffer = gTempBlock + blockOffset;
} else {
offset += blockOffset;
CacheRead(gCurrentIH, buffer, offset, length, 0);
}
return buffer;
}
static long ReadInode( long inodeNum, InodePtr inode, long * flags, long * time )
{
long fragNum = ino_to_fsba(gFS, inodeNum);
long blockOffset = ino_to_fsbo(gFS, inodeNum) * sizeof(Inode);
ReadBlock(fragNum, blockOffset, sizeof(Inode), (char *)inode, 1);
byte_swap_dinode_in(inode);
if (time != 0) *time = inode->di_mtime;
if (flags != 0) {
switch (inode->di_mode & IFMT) {
case IFREG: *flags = kFileTypeFlat; break;
case IFDIR: *flags = kFileTypeDirectory; break;
case IFLNK: *flags = kFileTypeLink; break;
default : *flags = kFileTypeUnknown; break;
}
*flags |= inode->di_mode & kPermMask;
if (inode->di_uid != 0) *flags |= kOwnerNotRoot;
}
return 0;
}
static long ResolvePathToInode( char * filePath, long * flags,
InodePtr fileInode, InodePtr dirInode )
{
char * restPath;
long ret, cnt;
// if filePath is empty the we want this directory.
if (*filePath == '\0') {
bcopy((char *)dirInode, (char *)fileInode, sizeof(Inode));
return 0;
}
// Copy the file name to gTempName
cnt = 0;
while ((filePath[cnt] != '/') && (filePath[cnt] != '\0')) cnt++;
strlcpy(gTempName, filePath, cnt+1);
// Move restPath to the right place.
if (filePath[cnt] != '\0') cnt++;
restPath = filePath + cnt;
// gTempName is a name in the current Dir.
// restPath is the rest of the path if any.
ret = FindFileInDir(gTempName, flags, fileInode, dirInode);
if (ret == -1) return -1;
if ((*restPath != '\0') && ((*flags & kFileTypeMask) == kFileTypeDirectory))
ret = ResolvePathToInode(restPath, flags, fileInode, fileInode);
return ret;
}
static long ReadDirEntry( InodePtr dirInode, long * fileInodeNum,
long long * dirIndex, char ** name )
{
struct direct *dir;
char *buffer;
long long index;
long dirBlockNum, dirBlockOffset;
while (1) {
index = *dirIndex;
dirBlockOffset = (long) (index % DIRBLKSIZ);
dirBlockNum = (long) (index / DIRBLKSIZ);
buffer = ReadFileBlock(dirInode, dirBlockNum, 0, DIRBLKSIZ, 0, 1);
if (buffer == 0) return -1;
dir = (struct direct *)(buffer + dirBlockOffset);
byte_swap_dir_block_in((char *)dir, 1);
*dirIndex += dir->d_reclen;
if (dir->d_ino != 0) break;
if (dirBlockOffset != 0) return -1;
}
*fileInodeNum = dir->d_ino;
*name = strlcpy(gTempName2, dir->d_name, dir->d_namlen+1);
return 0;
}
static long FindFileInDir( char * fileName, long * flags,
InodePtr fileInode, InodePtr dirInode )
{
long ret, inodeNum;
long long index = 0;
char *name;
while (1) {
ret = ReadDirEntry(dirInode, &inodeNum, &index, &name);
if (ret == -1) return -1;
if (strcmp(fileName, name) == 0) break;
}
ReadInode(inodeNum, fileInode, flags, 0);
return 0;
}
static char * ReadFileBlock( InodePtr fileInode, long fragNum, long blockOffset,
long length, char * buffer, long cache )
{
long fragCount, blockNum;
long diskFragNum, indFragNum, indBlockOff, refsPerBlock;
char *indBlock;
fragCount = (fileInode->di_size + gFragSize - 1) / gFragSize;
if (fragNum >= fragCount) return 0;
refsPerBlock = gBlockSize / sizeof(ufs_daddr_t);
blockNum = fragNum / gFragsPerBlock;
fragNum -= blockNum * gFragsPerBlock;
// Get Direct Block Number.
if (blockNum < NDADDR) {
diskFragNum = fileInode->di_db[blockNum];
} else {
blockNum -= NDADDR;
// Get Single Indirect Fragment Number.
if (blockNum < refsPerBlock) {
indFragNum = fileInode->di_ib[0];
} else {
blockNum -= refsPerBlock;
// Get Double Indirect Fragment Number.
if (blockNum < (refsPerBlock * refsPerBlock)) {
indFragNum = fileInode->di_ib[1];
} else {
blockNum -= refsPerBlock * refsPerBlock;
// Get Triple Indirect Fragment Number.
indFragNum = fileInode->di_ib[2];
indBlock = ReadBlock(indFragNum, 0, gBlockSize, 0, 1);
indBlockOff = blockNum / (refsPerBlock * refsPerBlock);
blockNum %= (refsPerBlock * refsPerBlock);
indFragNum = SWAP_BE32(((ufs_daddr_t *)indBlock)[indBlockOff]);
}
indBlock = ReadBlock(indFragNum, 0, gBlockSize, 0, 1);
indBlockOff = blockNum / refsPerBlock;
blockNum %= refsPerBlock;
indFragNum = SWAP_BE32(((ufs_daddr_t *)indBlock)[indBlockOff]);
}
indBlock = ReadBlock(indFragNum, 0, gBlockSize, 0, 1);
diskFragNum = SWAP_BE32(((ufs_daddr_t *)indBlock)[blockNum]);
}
buffer = ReadBlock(diskFragNum+fragNum, blockOffset, length, buffer, cache);
return buffer;
}
static long ReadFile( InodePtr fileInode, uint64_t * length, void * base, uint64_t offset )
{
long bytesLeft, curSize, curFrag;
char *buffer, *curAddr = (char *)base;
bytesLeft = fileInode->di_size;
if (offset > bytesLeft) {
printf("Offset is too large.\n");
return -1;
}
if ((*length == 0) || ((offset + *length) > bytesLeft)) {
*length = bytesLeft - offset;
}
/*
if (bytesLeft > kLoadSize) {
printf("File is too large.\n");
return -1;
}
*/
bytesLeft = *length;
curFrag = (offset / gBlockSize) * gFragsPerBlock;
offset %= gBlockSize;
while (bytesLeft) {
curSize = gBlockSize;
if (curSize > bytesLeft) curSize = bytesLeft;
if ((offset + curSize) > gBlockSize) curSize = (gBlockSize - offset);
buffer = ReadFileBlock(fileInode, curFrag, offset, curSize, curAddr, 0);
if (buffer == 0) break;
if (offset != 0) offset = 0;
curFrag += gFragsPerBlock;
curAddr += curSize;
bytesLeft -= curSize;
}
return bytesLeft;
}
#endif
branches/azimutz/trunkAutoResolution/i386/libsaio/ufs_byteorder.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
/*
* Copyright (c) 1999-2003 Apple Computer, Inc. All rights reserved.
*
* @APPLE_LICENSE_HEADER_START@
*
* Portions Copyright (c) 1999-2003 Apple Computer, Inc. All Rights
* Reserved. This file contains Original Code and/or Modifications of
* Original Code as defined in and that are subject to the Apple Public
* Source License Version 2.0 (the "License"). You may not use this file
* except in compliance with the License. Please obtain a copy of the
* License at http://www.apple.com/publicsource and read it before using
* this file.
*
* The Original Code and all software distributed under the License are
* distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE OR NON- INFRINGEMENT. Please see the
* License for the specific language governing rights and limitations
* under the License.
*
* @APPLE_LICENSE_HEADER_END@
*/
/*
* Copyright 1993 NeXT, Inc.
* All rights reserved.
*/
#if 0
#include <sys/types.h>
#include <sys/param.h>
//#include <sys/vnode.h>
#include <ufs/ufs/dir.h>
#include <libkern/OSByteOrder.h>
#include "ufs_byteorder.h"
#include "libsaio.h"
#defineswapBigLongToHost(thing) ((thing) = OSSwapBigToHostInt32(thing))
#defineswapBigShortToHost(thing) ((thing) = OSSwapBigToHostInt16(thing))
#definebyte_swap_longlong(thing) ((thing) = OSSwapBigToHostInt64(thing))
#definebyte_swap_int(thing) ((thing) = OSSwapBigToHostInt32(thing))
#definebyte_swap_short(thing) ((thing) = OSSwapBigToHostInt16(thing))
#if UNUSED
void
byte_swap_longlongs(unsigned long long *array, int count)
{
register unsigned long longi;
for (i = 0; i < (unsigned long long)count; i++)
byte_swap_longlong(array[i]);
}
#endif
void
byte_swap_ints(unsigned int *array, int count)
{
register inti;
for (i = 0; i < count; i++)
byte_swap_int(array[i]);
}
void
byte_swap_shorts(unsigned short *array, int count)
{
register inti;
for (i = 0; i < count; i++)
byte_swap_short(array[i]);
}
#if UNUSED
static void
swapBigIntsToHost(unsigned int *array, int count)
{
register inti;
for (i = 0; i < count; i++)
swapBigLongToHost(array[i]);
}
static void
swapBigShortToHosts(unsigned short *array, int count)
{
register inti;
for (i = 0; i < count; i++)
swapBigShortToHost(array[i]);
}
#endif
void
byte_swap_superblock(struct fs *sb)
{
u_int16_t * usptr;
unsigned long size;
byte_swap_ints(((u_int32_t *)&sb->fs_firstfield), 52);
byte_swap_int(sb->fs_cgrotor);
byte_swap_int(sb->fs_cpc);
byte_swap_shorts((u_int16_t *)sb->fs_opostbl, 16 * 8);
byte_swap_ints((u_int32_t *)sb->fs_sparecon, 50);
byte_swap_ints((u_int32_t *)&sb->fs_contigsumsize, 3);
#if UNUSED
byte_swap_longlongs((u_int64_t *)&sb->fs_maxfilesize,3);
#endif
byte_swap_ints((u_int32_t *)&sb->fs_state, 6);
/* Got these magic numbers from mkfs.c in newfs */
if (sb->fs_nrpos != 8 || sb->fs_cpc > 16) {
usptr = (u_int16_t *)((u_int8_t *)(sb) + (sb)->fs_postbloff);
size = sb->fs_cpc * sb->fs_nrpos;
byte_swap_shorts(usptr,size);/* fs_postbloff */
}
}
/* This value should correspond to the value set in the ffs_mounts */
#define RESYMLNKLEN 60
void
byte_swap_dinode_in(struct dinode *di)
{
int i;
di->di_mode = OSSwapInt16(di->di_mode);
di->di_nlink = OSSwapInt16(di->di_nlink);
#ifdef LFS
di->di_u.inumber = OSSwapInt32(di->di_u.inumber);
#else
di->di_u.oldids[0] = OSSwapInt16(di->di_u.oldids[0]);
di->di_u.oldids[1] = OSSwapInt16(di->di_u.oldids[1]);
#endif
di->di_size = OSSwapInt64(di->di_size);
di->di_atime = OSSwapInt32(di->di_atime);
di->di_atimensec = OSSwapInt32(di->di_atimensec);
di->di_mtime = OSSwapInt32(di->di_mtime);
di->di_mtimensec = OSSwapInt32(di->di_mtimensec);
di->di_ctime = OSSwapInt32(di->di_ctime);
di->di_ctimensec = OSSwapInt32(di->di_ctimensec);
if (((di->di_mode & IFMT) != IFLNK ) || (di->di_size > RESYMLNKLEN)) {
for (i=0; i < NDADDR; i++)/* direct blocks */
di->di_db[i] = OSSwapInt32(di->di_db[i]);
for (i=0; i < NIADDR; i++)/* indirect blocks */
di->di_ib[i] = OSSwapInt32(di->di_ib[i]);
}
di->di_flags = OSSwapInt32(di->di_flags);
di->di_blocks = OSSwapInt32(di->di_blocks);
di->di_gen = OSSwapInt32(di->di_gen);
di->di_uid = OSSwapInt32(di->di_uid);
di->di_gid = OSSwapInt32(di->di_gid);
di->di_spare[0] = OSSwapInt32(di->di_spare[0]);
di->di_spare[1] = OSSwapInt32(di->di_spare[1]);
}
void
byte_swap_dir_block_in(char *addr, int count)
{
register struct direct * ep = (struct direct *) addr;
register int entryoffsetinblk = 0;
while (entryoffsetinblk < count) {
ep = (struct direct *) (entryoffsetinblk + addr);
swapBigLongToHost(ep->d_ino);
swapBigShortToHost(ep->d_reclen);
entryoffsetinblk += ep->d_reclen;
if (ep->d_reclen < 12)/* handle garbage in dirs */
break;
}
}
#endif
branches/azimutz/trunkAutoResolution/i386/libsaio/Makefile
3131
3232
3333
34
3534
3635
3736
SAIO_OBJS = table.o asm.o bios.o biosfn.o \
disk.o sys.o cache.o bootstruct.o \
stringTable.o load.o pci.o allocate.o misc.o \
ufs.o ufs_byteorder.o \
vbe.o nbp.o hfs.o hfs_compare.o \
xml.o ntfs.o msdos.o md5c.o device_tree.o \
cpu.o platform.o acpi_patcher.o \
branches/azimutz/trunkAutoResolution/i386/boot2/boot.c
578578
579579
580580
581
581
582582
583583
584584
break;
}
if(getBoolForKey(kUseKernelCache, &usecache, &bootInfo->bootConfig)) {
if(getBoolForKey(kUseKernelCache, &usecache, &bootInfo->bootConfig) && usecache) {
if (getValueForKey(kKernelCacheKey, &val, &len, &bootInfo->bootConfig)) {
strlcpy(gBootKernelCacheFile, val, len+1);
}
branches/azimutz/trunkGraphicsEnablerModules/i386/libsaio/ufs.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
/*
* Copyright (c) 2000-2003 Apple Computer, Inc. All rights reserved.
*
* @APPLE_LICENSE_HEADER_START@
*
* The contents of this file constitute Original Code as defined in and
* are subject to the Apple Public Source License Version 2.0 (the
* "License"). You may not use this file except in compliance with the
* License. Please obtain a copy of the License at
* http://www.apple.com/publicsource and read it before using this file.
*
* This Original Code and all software distributed under the License are
* distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
* License for the specific language governing rights and limitations
* under the License.
*
* @APPLE_LICENSE_HEADER_END@
*/
/*
* ufs.c - File System Module for UFS.
*
* Copyright (c) 1998-2002 Apple Computer, Inc.
*
* DRI: Josh de Cesare
*/
#if 0
#include <sl.h>
#include "ufs.h"
#include "ufs_byteorder.h"
#if !defined(MAXNAMLEN) && defined(UFSMAXNAMLEN)
#define MAXNAMLEN UFSMAXNAMLEN
#endif
typedef struct dinode Inode, *InodePtr;
// Private function prototypes
static char *ReadBlock(long fragNum, long fragOffset, long length,
char *buffer, long cache);
static long ReadInode(long inodeNum, InodePtr inode, long *flags, long *time);
static long ResolvePathToInode(char *filePath, long *flags,
InodePtr fileInode, InodePtr dirInode);
static long ReadDirEntry(InodePtr dirInode, long *fileInodeNum,
long long *dirIndex, char **name);
static long FindFileInDir(char *fileName, long *flags,
InodePtr fileInode, InodePtr dirInode);
static char *ReadFileBlock(InodePtr fileInode, long fragNum, long blockOffset,
long length, char *buffer, long cache);
static long ReadFile(InodePtr fileInode, uint64_t *length, void *base, uint64_t offset);
#define kDevBlockSize (0x200) // Size of each disk block.
#define kDiskLabelBlock (15) // Block the DL is in.
#ifdef __i386__
static CICell gCurrentIH;
static long long gPartitionBase;
static char *gULBuf;
static char *gFSBuf;
static struct fs *gFS;
#if !BOOT1
static struct ufslabel gUFSLabel; // for UUID
#endif
static long gBlockSize;
static long gFragSize;
static long gFragsPerBlock;
static char *gTempBlock;
static char *gTempName;
static char *gTempName2;
static InodePtr gRootInodePtr;
static InodePtr gFileInodePtr;
#else /* !__i386__ */
static CICell gCurrentIH;
static long long gPartitionBase;
static char gDLBuf[8192];
static char gFSBuf[SBSIZE];
static struct fs *gFS;
#if !BOOT1
static struct ufslabel gUFSLabel; // for UUID
#endif
static long gBlockSize;
static long gFragSize;
static long gFragsPerBlock;
static char *gTempBlock;
static char gTempName[MAXNAMLEN + 1];
static char gTempName2[MAXNAMLEN + 1];
static Inode _gRootInode;
static Inode _gFileInode;
static InodePtr gRootInodePtr = &_gRootInode;
static InodePtr gFileInodePtr = &_gFileInode;
#endif /* !__i386__ */
// Public functions
void UFSFree(CICell ih)
{
if(gCurrentIH == ih)
gCurrentIH = 0;
free(ih);
}
long UFSInitPartition( CICell ih )
{
#if !BOOT1
long ret;
#endif
if (ih == gCurrentIH) {
#ifdef __i386__
CacheInit(ih, gBlockSize);
#endif
return 0;
}
#if !BOOT1
verbose("UFSInitPartition: %x\n", ih);
#endif
gCurrentIH = 0;
#ifdef __i386__
if (!gULBuf) gULBuf = (char *) malloc(UFS_LABEL_SIZE);
if (!gFSBuf) gFSBuf = (char *) malloc(SBSIZE);
if (!gTempName) gTempName = (char *) malloc(MAXNAMLEN + 1);
if (!gTempName2) gTempName2 = (char *) malloc(MAXNAMLEN + 1);
if (!gRootInodePtr) gRootInodePtr = (InodePtr) malloc(sizeof(Inode));
if (!gFileInodePtr) gFileInodePtr = (InodePtr) malloc(sizeof(Inode));
if (!gULBuf || !gFSBuf || !gTempName || !gTempName2 ||
!gRootInodePtr || !gFileInodePtr) return -1;
#endif
// Assume there is no Disk Label
gPartitionBase = 0;
#if !BOOT1
// read the disk label to get the UUID
// (rumor has it that UFS headers can be either-endian on disk; hopefully
// that isn't true for this UUID field).
Seek(ih, gPartitionBase + UFS_LABEL_OFFSET);
ret = Read(ih, (long)&gUFSLabel, UFS_LABEL_SIZE);
if(ret != 0)
bzero(&gUFSLabel, UFS_LABEL_SIZE);
#endif /* !BOOT1 */
// Look for the Super Block
Seek(ih, gPartitionBase + SBOFF);
Read(ih, (long)gFSBuf, SBSIZE);
gFS = (struct fs *)gFSBuf;
byte_swap_superblock(gFS);
if (gFS->fs_magic != FS_MAGIC) {
return -1;
}
ih->modTime = gFS->fs_time;
// Calculate the block size and set up the block cache.
gBlockSize = gFS->fs_bsize;
gFragSize = gFS->fs_fsize;
gFragsPerBlock = gBlockSize / gFragSize;
if (gTempBlock != 0) free(gTempBlock);
gTempBlock = malloc(gBlockSize);
CacheInit(ih, gBlockSize);
gCurrentIH = ih;
// Read the Root Inode
ReadInode(ROOTINO, gRootInodePtr, 0, 0);
return 0;
}
#if !BOOT1
long UFSGetUUID(CICell ih, char *uuidStr)
{
long long uuid = gUFSLabel.ul_uuid;
if (UFSInitPartition(ih) == -1) return -1;
if (uuid == 0LL) return -1;
return CreateUUIDString((uint8_t*)(&uuid), sizeof(uuid), uuidStr);
}
#endif /* !BOOT1 */
long UFSLoadFile( CICell ih, char * filePath )
{
return UFSReadFile(ih, filePath, (void *)gFSLoadAddress, 0, 0);
}
long UFSReadFile( CICell ih, char * filePath, void * base, uint64_t offset, uint64_t length )
{
long ret, flags;
#if !BOOT1
verbose("Loading UFS file: [%s] from %x.\n", filePath, (unsigned)ih);
#endif
if (UFSInitPartition(ih) == -1) return -1;
// Skip one or two leading '/'.
if (*filePath == '/') filePath++;
if (*filePath == '/') filePath++;
ret = ResolvePathToInode(filePath, &flags, gFileInodePtr, gRootInodePtr);
if ((ret == -1) || ((flags & kFileTypeMask) != kFileTypeFlat)) return -1;
ret = ReadFile(gFileInodePtr, &length, base, offset);
if (ret == -1) return -1;
return length;
}
#ifndef BOOT1
long UFSGetDirEntry( CICell ih, char * dirPath, long long * dirIndex,
char ** name, long * flags, long * time,
FinderInfo * finderInfo, long * infoValid)
{
long ret, fileInodeNum, dirFlags;
Inode tmpInode;
if (UFSInitPartition(ih) == -1) return -1;
if (infoValid) *infoValid = 0;
// Skip a leading '/' if present
if (*dirPath == '/') dirPath++;
if (*dirPath == '/') dirPath++;
ret = ResolvePathToInode(dirPath, &dirFlags, gFileInodePtr, gRootInodePtr);
if ((ret == -1) || ((dirFlags & kFileTypeMask) != kFileTypeDirectory))
return -1;
ret = ReadDirEntry(gFileInodePtr, &fileInodeNum, dirIndex, name);
if (ret != 0) return ret;
ReadInode(fileInodeNum, &tmpInode, flags, time);
return 0;
}
void
UFSGetDescription(CICell ih, char *str, long strMaxLen)
{
if (UFSInitPartition(ih) == -1) { return; }
struct ufslabel *ul;
// Look for the Disk Label
Seek(ih, 1ULL * UFS_LABEL_OFFSET);
Read(ih, (long)gULBuf, UFS_LABEL_SIZE);
ul = (struct ufslabel *)gULBuf;
unsigned char magic_bytes[] = UFS_LABEL_MAGIC;
int i;
unsigned char *p = (unsigned char *)&ul->ul_magic;
for (i=0; i<sizeof(magic_bytes); i++, p++) {
if (*p != magic_bytes[i])
return;
}
strncpy(str, (const char *)ul->ul_name, strMaxLen);
}
long
UFSGetFileBlock(CICell ih, char *filePath, unsigned long long *firstBlock)
{
long ret, flags;
if (UFSInitPartition(ih) == -1) return -1;
// Skip one or two leading '/'.
if (*filePath == '/') filePath++;
if (*filePath == '/') filePath++;
ret = ResolvePathToInode(filePath, &flags, gFileInodePtr, gRootInodePtr);
if ((ret == -1) || ((flags & kFileTypeMask) != kFileTypeFlat)) return -1;
*firstBlock = (gPartitionBase + 1ULL * gFileInodePtr->di_db[0] * gBlockSize) / 512ULL;
return 0;
}
#endif /* !BOOT1 */
// Private functions
static char * ReadBlock( long fragNum, long blockOffset, long length,
char * buffer, long cache )
{
long long offset;
long blockNum;
blockNum = fragNum / gFragsPerBlock;
fragNum -= blockNum * gFragsPerBlock;
blockOffset += fragNum * gFragSize;
offset = gPartitionBase + 1ULL * blockNum * gBlockSize;
if (cache && ((blockOffset + length) <= gBlockSize)) {
CacheRead(gCurrentIH, gTempBlock, offset, gBlockSize, 1);
if (buffer != 0) bcopy(gTempBlock + blockOffset, buffer, length);
else buffer = gTempBlock + blockOffset;
} else {
offset += blockOffset;
CacheRead(gCurrentIH, buffer, offset, length, 0);
}
return buffer;
}
static long ReadInode( long inodeNum, InodePtr inode, long * flags, long * time )
{
long fragNum = ino_to_fsba(gFS, inodeNum);
long blockOffset = ino_to_fsbo(gFS, inodeNum) * sizeof(Inode);
ReadBlock(fragNum, blockOffset, sizeof(Inode), (char *)inode, 1);
byte_swap_dinode_in(inode);
if (time != 0) *time = inode->di_mtime;
if (flags != 0) {
switch (inode->di_mode & IFMT) {
case IFREG: *flags = kFileTypeFlat; break;
case IFDIR: *flags = kFileTypeDirectory; break;
case IFLNK: *flags = kFileTypeLink; break;
default : *flags = kFileTypeUnknown; break;
}
*flags |= inode->di_mode & kPermMask;
if (inode->di_uid != 0) *flags |= kOwnerNotRoot;
}
return 0;
}
static long ResolvePathToInode( char * filePath, long * flags,
InodePtr fileInode, InodePtr dirInode )
{
char * restPath;
long ret, cnt;
// if filePath is empty the we want this directory.
if (*filePath == '\0') {
bcopy((char *)dirInode, (char *)fileInode, sizeof(Inode));
return 0;
}
// Copy the file name to gTempName
cnt = 0;
while ((filePath[cnt] != '/') && (filePath[cnt] != '\0')) cnt++;
strlcpy(gTempName, filePath, cnt+1);
// Move restPath to the right place.
if (filePath[cnt] != '\0') cnt++;
restPath = filePath + cnt;
// gTempName is a name in the current Dir.
// restPath is the rest of the path if any.
ret = FindFileInDir(gTempName, flags, fileInode, dirInode);
if (ret == -1) return -1;
if ((*restPath != '\0') && ((*flags & kFileTypeMask) == kFileTypeDirectory))
ret = ResolvePathToInode(restPath, flags, fileInode, fileInode);
return ret;
}
static long ReadDirEntry( InodePtr dirInode, long * fileInodeNum,
long long * dirIndex, char ** name )
{
struct direct *dir;
char *buffer;
long long index;
long dirBlockNum, dirBlockOffset;
while (1) {
index = *dirIndex;
dirBlockOffset = (long) (index % DIRBLKSIZ);
dirBlockNum = (long) (index / DIRBLKSIZ);
buffer = ReadFileBlock(dirInode, dirBlockNum, 0, DIRBLKSIZ, 0, 1);
if (buffer == 0) return -1;
dir = (struct direct *)(buffer + dirBlockOffset);
byte_swap_dir_block_in((char *)dir, 1);
*dirIndex += dir->d_reclen;
if (dir->d_ino != 0) break;
if (dirBlockOffset != 0) return -1;
}
*fileInodeNum = dir->d_ino;
*name = strlcpy(gTempName2, dir->d_name, dir->d_namlen+1);
return 0;
}
static long FindFileInDir( char * fileName, long * flags,
InodePtr fileInode, InodePtr dirInode )
{
long ret, inodeNum;
long long index = 0;
char *name;
while (1) {
ret = ReadDirEntry(dirInode, &inodeNum, &index, &name);
if (ret == -1) return -1;
if (strcmp(fileName, name) == 0) break;
}
ReadInode(inodeNum, fileInode, flags, 0);
return 0;
}
static char * ReadFileBlock( InodePtr fileInode, long fragNum, long blockOffset,
long length, char * buffer, long cache )
{
long fragCount, blockNum;
long diskFragNum, indFragNum, indBlockOff, refsPerBlock;
char *indBlock;
fragCount = (fileInode->di_size + gFragSize - 1) / gFragSize;
if (fragNum >= fragCount) return 0;
refsPerBlock = gBlockSize / sizeof(ufs_daddr_t);
blockNum = fragNum / gFragsPerBlock;
fragNum -= blockNum * gFragsPerBlock;
// Get Direct Block Number.
if (blockNum < NDADDR) {
diskFragNum = fileInode->di_db[blockNum];
} else {
blockNum -= NDADDR;
// Get Single Indirect Fragment Number.
if (blockNum < refsPerBlock) {
indFragNum = fileInode->di_ib[0];
} else {
blockNum -= refsPerBlock;
// Get Double Indirect Fragment Number.
if (blockNum < (refsPerBlock * refsPerBlock)) {
indFragNum = fileInode->di_ib[1];
} else {
blockNum -= refsPerBlock * refsPerBlock;
// Get Triple Indirect Fragment Number.
indFragNum = fileInode->di_ib[2];
indBlock = ReadBlock(indFragNum, 0, gBlockSize, 0, 1);
indBlockOff = blockNum / (refsPerBlock * refsPerBlock);
blockNum %= (refsPerBlock * refsPerBlock);
indFragNum = SWAP_BE32(((ufs_daddr_t *)indBlock)[indBlockOff]);
}
indBlock = ReadBlock(indFragNum, 0, gBlockSize, 0, 1);
indBlockOff = blockNum / refsPerBlock;
blockNum %= refsPerBlock;
indFragNum = SWAP_BE32(((ufs_daddr_t *)indBlock)[indBlockOff]);
}
indBlock = ReadBlock(indFragNum, 0, gBlockSize, 0, 1);
diskFragNum = SWAP_BE32(((ufs_daddr_t *)indBlock)[blockNum]);
}
buffer = ReadBlock(diskFragNum+fragNum, blockOffset, length, buffer, cache);
return buffer;
}
static long ReadFile( InodePtr fileInode, uint64_t * length, void * base, uint64_t offset )
{
long bytesLeft, curSize, curFrag;
char *buffer, *curAddr = (char *)base;
bytesLeft = fileInode->di_size;
if (offset > bytesLeft) {
printf("Offset is too large.\n");
return -1;
}
if ((*length == 0) || ((offset + *length) > bytesLeft)) {
*length = bytesLeft - offset;
}
/*
if (bytesLeft > kLoadSize) {
printf("File is too large.\n");
return -1;
}
*/
bytesLeft = *length;
curFrag = (offset / gBlockSize) * gFragsPerBlock;
offset %= gBlockSize;
while (bytesLeft) {
curSize = gBlockSize;
if (curSize > bytesLeft) curSize = bytesLeft;
if ((offset + curSize) > gBlockSize) curSize = (gBlockSize - offset);
buffer = ReadFileBlock(fileInode, curFrag, offset, curSize, curAddr, 0);
if (buffer == 0) break;
if (offset != 0) offset = 0;
curFrag += gFragsPerBlock;
curAddr += curSize;
bytesLeft -= curSize;
}
return bytesLeft;
}
#endif
branches/azimutz/trunkGraphicsEnablerModules/i386/libsaio/ufs_byteorder.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
/*
* Copyright (c) 1999-2003 Apple Computer, Inc. All rights reserved.
*
* @APPLE_LICENSE_HEADER_START@
*
* Portions Copyright (c) 1999-2003 Apple Computer, Inc. All Rights
* Reserved. This file contains Original Code and/or Modifications of
* Original Code as defined in and that are subject to the Apple Public
* Source License Version 2.0 (the "License"). You may not use this file
* except in compliance with the License. Please obtain a copy of the
* License at http://www.apple.com/publicsource and read it before using
* this file.
*
* The Original Code and all software distributed under the License are
* distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE OR NON- INFRINGEMENT. Please see the
* License for the specific language governing rights and limitations
* under the License.
*
* @APPLE_LICENSE_HEADER_END@
*/
/*
* Copyright 1993 NeXT, Inc.
* All rights reserved.
*/
#if 0
#include <sys/types.h>
#include <sys/param.h>
//#include <sys/vnode.h>
#include <ufs/ufs/dir.h>
#include <libkern/OSByteOrder.h>
#include "ufs_byteorder.h"
#include "libsaio.h"
#defineswapBigLongToHost(thing) ((thing) = OSSwapBigToHostInt32(thing))
#defineswapBigShortToHost(thing) ((thing) = OSSwapBigToHostInt16(thing))
#definebyte_swap_longlong(thing) ((thing) = OSSwapBigToHostInt64(thing))
#definebyte_swap_int(thing) ((thing) = OSSwapBigToHostInt32(thing))
#definebyte_swap_short(thing) ((thing) = OSSwapBigToHostInt16(thing))
#if UNUSED
void
byte_swap_longlongs(unsigned long long *array, int count)
{
register unsigned long longi;
for (i = 0; i < (unsigned long long)count; i++)
byte_swap_longlong(array[i]);
}
#endif
void
byte_swap_ints(unsigned int *array, int count)
{
register inti;
for (i = 0; i < count; i++)
byte_swap_int(array[i]);
}
void
byte_swap_shorts(unsigned short *array, int count)
{
register inti;
for (i = 0; i < count; i++)
byte_swap_short(array[i]);
}
#if UNUSED
static void
swapBigIntsToHost(unsigned int *array, int count)
{
register inti;
for (i = 0; i < count; i++)
swapBigLongToHost(array[i]);
}
static void
swapBigShortToHosts(unsigned short *array, int count)
{
register inti;
for (i = 0; i < count; i++)
swapBigShortToHost(array[i]);
}
#endif
void
byte_swap_superblock(struct fs *sb)
{
u_int16_t * usptr;
unsigned long size;
byte_swap_ints(((u_int32_t *)&sb->fs_firstfield), 52);
byte_swap_int(sb->fs_cgrotor);
byte_swap_int(sb->fs_cpc);
byte_swap_shorts((u_int16_t *)sb->fs_opostbl, 16 * 8);
byte_swap_ints((u_int32_t *)sb->fs_sparecon, 50);
byte_swap_ints((u_int32_t *)&sb->fs_contigsumsize, 3);
#if UNUSED
byte_swap_longlongs((u_int64_t *)&sb->fs_maxfilesize,3);
#endif
byte_swap_ints((u_int32_t *)&sb->fs_state, 6);
/* Got these magic numbers from mkfs.c in newfs */
if (sb->fs_nrpos != 8 || sb->fs_cpc > 16) {
usptr = (u_int16_t *)((u_int8_t *)(sb) + (sb)->fs_postbloff);
size = sb->fs_cpc * sb->fs_nrpos;
byte_swap_shorts(usptr,size);/* fs_postbloff */
}
}
/* This value should correspond to the value set in the ffs_mounts */
#define RESYMLNKLEN 60
void
byte_swap_dinode_in(struct dinode *di)
{
int i;
di->di_mode = OSSwapInt16(di->di_mode);
di->di_nlink = OSSwapInt16(di->di_nlink);
#ifdef LFS
di->di_u.inumber = OSSwapInt32(di->di_u.inumber);
#else
di->di_u.oldids[0] = OSSwapInt16(di->di_u.oldids[0]);
di->di_u.oldids[1] = OSSwapInt16(di->di_u.oldids[1]);
#endif
di->di_size = OSSwapInt64(di->di_size);
di->di_atime = OSSwapInt32(di->di_atime);
di->di_atimensec = OSSwapInt32(di->di_atimensec);
di->di_mtime = OSSwapInt32(di->di_mtime);
di->di_mtimensec = OSSwapInt32(di->di_mtimensec);
di->di_ctime = OSSwapInt32(di->di_ctime);
di->di_ctimensec = OSSwapInt32(di->di_ctimensec);
if (((di->di_mode & IFMT) != IFLNK ) || (di->di_size > RESYMLNKLEN)) {
for (i=0; i < NDADDR; i++)/* direct blocks */
di->di_db[i] = OSSwapInt32(di->di_db[i]);
for (i=0; i < NIADDR; i++)/* indirect blocks */
di->di_ib[i] = OSSwapInt32(di->di_ib[i]);
}
di->di_flags = OSSwapInt32(di->di_flags);
di->di_blocks = OSSwapInt32(di->di_blocks);
di->di_gen = OSSwapInt32(di->di_gen);
di->di_uid = OSSwapInt32(di->di_uid);
di->di_gid = OSSwapInt32(di->di_gid);
di->di_spare[0] = OSSwapInt32(di->di_spare[0]);
di->di_spare[1] = OSSwapInt32(di->di_spare[1]);
}
void
byte_swap_dir_block_in(char *addr, int count)
{
register struct direct * ep = (struct direct *) addr;
register int entryoffsetinblk = 0;
while (entryoffsetinblk < count) {
ep = (struct direct *) (entryoffsetinblk + addr);
swapBigLongToHost(ep->d_ino);
swapBigShortToHost(ep->d_reclen);
entryoffsetinblk += ep->d_reclen;
if (ep->d_reclen < 12)/* handle garbage in dirs */
break;
}
}
#endif
branches/azimutz/trunkGraphicsEnablerModules/i386/libsaio/Makefile
3131
3232
3333
34
3534
3635
3736
SAIO_OBJS = table.o asm.o bios.o biosfn.o \
disk.o sys.o cache.o bootstruct.o \
stringTable.o load.o pci.o allocate.o misc.o \
ufs.o ufs_byteorder.o \
vbe.o nbp.o hfs.o hfs_compare.o \
xml.o ntfs.o msdos.o md5c.o device_tree.o \
cpu.o platform.o acpi_patcher.o \
branches/azimutz/trunkGraphicsEnablerModules/i386/boot2/boot.c
486486
487487
488488
489
489
490490
491491
492492
break;
}
if(getBoolForKey(kUseKernelCache, &usecache, &bootInfo->bootConfig)) {
if(getBoolForKey(kUseKernelCache, &usecache, &bootInfo->bootConfig) && usecache) {
if (getValueForKey(kKernelCacheKey, &val, &len, &bootInfo->bootConfig)) {
strlcpy(gBootKernelCacheFile, val, len+1);
}

Archive Download the corresponding diff file

Revision: 1096