/*
- * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 2000-2007 Apple Inc. All rights reserved.
*
- * @APPLE_LICENSE_HEADER_START@
+ * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
*
- * The contents of this file constitute Original Code as defined in and
- * are subject to the Apple Public Source License Version 1.1 (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 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. The rights granted to you under the License
+ * may not be used to create, or enable the creation or redistribution of,
+ * unlawful or unlicensed copies of an Apple operating system, or to
+ * circumvent, violate, or enable the circumvention or violation of, any
+ * terms of an Apple operating system software license agreement.
*
- * This Original Code and all software distributed under the License are
- * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ 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.
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
*
- * @APPLE_LICENSE_HEADER_END@
+ * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
*/
+
/*
* hfs.c - File System Module for HFS and HFS+.
*
static long long gAllocationOffset;
static long gIsHFSPlus;
static long gCaseSensitive;
-static long gBlockSize;
+static unsigned long gBlockSize;
static char gBTreeHeaderBuffer[512];
static BTHeaderRec *gBTHeaders[2];
static char gHFSMdbVib[kBlockSize];
static long ReadFile(void *file, long *length, void *base, long offset);
static long GetCatalogEntryInfo(void *entry, long *flags, long *time);
-static long ResolvePathToCatalogEntry(char *filePath, long *flags,
- void *entry, long dirID, long *dirIndex);
+static long ResolvePathToCatalogEntry(char *filePath, long *flags, void *entry,
+ unsigned long dirID, unsigned long *dirIndex);
-static long GetCatalogEntry(long *dirIndex, char **name,
+static long GetCatalogEntry(unsigned long *dirIndex, char **name,
long *flags, long *time);
-static long ReadCatalogEntry(char *fileName, long dirID, void *entry,
- long *dirIndex);
-static long ReadExtentsEntry(long fileID, long startBlock, void *entry);
+static long ReadCatalogEntry(char *fileName, unsigned long dirID, void *entry,
+ unsigned long *dirIndex);
+static long ReadExtentsEntry(unsigned long fileID, unsigned long startBlock, void *entry);
-static long ReadBTreeEntry(long btree, void *key, char *entry, long *dirIndex);
+static long ReadBTreeEntry(long btree, void *key, char *entry,
+ unsigned long *dirIndex);
static void GetBTreeRecord(long index, char *nodeBuffer, long nodeSize,
char **key, char **data);
-static long ReadExtent(char *extent, long extentSize, long extentFile,
- long offset, long size, void *buffer, long cache);
+static long ReadExtent(void *extent, u_int64_t extentSize, unsigned long extentFile,
+ u_int64_t offset, long size, void *buffer, long cache);
-static long GetExtentStart(void *extents, long index);
-static long GetExtentSize(void *extents, long index);
+static unsigned long GetExtentStart(void *extents, long index);
+static unsigned long GetExtentSize(void *extents, long index);
static long CompareHFSCatalogKeys(void *key, void *testKey);
static long CompareHFSPlusCatalogKeys(void *key, void *testKey);
long HFSInitPartition(CICell ih)
{
- long extentSize, extentFile, nodeSize;
+ unsigned long extentFile;
+ long nodeSize;
+ u_int64_t extentSize;
void *extent;
if (ih == gCurrentIH) return 0;
gBTHeaders[1] = 0;
// Look for the HFS MDB
- Seek(ih, kMDBBaseOffset);
+ Seek(ih, (long long)kMDBBaseOffset);
Read(ih, (long)gHFSMdbVib, kBlockSize);
if (gHFSMDB->drSigWord == kHFSSigWord) {
unsigned long offset, unsigned long length)
{
char entry[512];
- long dirID, result, flags;
+ unsigned long dirID;
+ long result, flags;
if (HFSInitPartition(ih) == -1) return -1;
return length;
}
-long HFSGetDirEntry(CICell ih, char *dirPath, long *dirIndex, char **name,
- long *flags, long *time)
+long HFSGetDirEntry(CICell ih, char *dirPath, unsigned long *dirIndex,
+ char **name, long *flags, long *time)
{
char entry[512];
- long dirID, dirFlags;
+ unsigned long dirID, dirFlags;
if (HFSInitPartition(ih) == -1) return -1;
static long ReadFile(void *file, long *length, void *base, long offset)
{
void *extents;
- long fileID, fileLength;
+ unsigned long fileID;
+ u_int64_t fileLength;
HFSCatalogFile *hfsFile = file;
HFSPlusCatalogFile *hfsPlusFile = file;
}
if ((*length == 0) || ((offset + *length) > fileLength)) {
- *length = fileLength - offset;
+ *length = (long)(fileLength - offset);
}
if (*length > kLoadSize) {
return -1;
}
- *length = ReadExtent((char *)extents, fileLength, fileID,
+ *length = ReadExtent(extents, fileLength, fileID,
offset, *length, base, 0);
return 0;
return 0;
}
-static long ResolvePathToCatalogEntry(char *filePath, long *flags,
- void *entry, long dirID, long *dirIndex)
+static long ResolvePathToCatalogEntry(char *filePath, long *flags, void *entry,
+ unsigned long dirID, unsigned long *dirIndex)
{
char *restPath;
- long result, cnt, subFolderID = 0, tmpDirIndex;
+ long result, cnt;
+ unsigned long subFolderID = 0, tmpDirIndex;
HFSPlusCatalogFile *hfsPlusFile;
// Copy the file name to gTempStr
return result;
}
-static long GetCatalogEntry(long *dirIndex, char **name,
+static long GetCatalogEntry(unsigned long *dirIndex, char **name,
long *flags, long *time)
{
- long extentSize, nodeSize, curNode, index;
+ long nodeSize, index;
+ u_int32_t curNode;
+ u_int64_t extentSize;
void *extent;
char *nodeBuf, *testKey, *entry;
BTNodeDescriptor *node;
// Read the BTree node and get the record for index.
ReadExtent(extent, extentSize, kHFSCatalogFileID,
- curNode * nodeSize, nodeSize, nodeBuf, 1);
+ curNode * (u_int32_t)nodeSize, nodeSize, nodeBuf, 1);
GetBTreeRecord(index, nodeBuf, nodeSize, &testKey, &entry);
GetCatalogEntryInfo(entry, flags, time);
return 0;
}
-static long ReadCatalogEntry(char *fileName, long dirID,
- void *entry, long *dirIndex)
+static long ReadCatalogEntry(char *fileName, unsigned long dirID,
+ void *entry, unsigned long *dirIndex)
{
long length;
char key[sizeof(HFSPlusCatalogKey)];
return ReadBTreeEntry(kBTreeCatalog, &key, entry, dirIndex);
}
-static long ReadExtentsEntry(long fileID, long startBlock, void *entry)
+static long ReadExtentsEntry(unsigned long fileID, unsigned long startBlock, void *entry)
{
char key[sizeof(HFSPlusExtentKey)];
HFSExtentKey *hfsKey = (HFSExtentKey *)key;
return ReadBTreeEntry(kBTreeExtents, &key, entry, 0);
}
-static long ReadBTreeEntry(long btree, void *key, char *entry, long *dirIndex)
+static long ReadBTreeEntry(long btree, void *key, char *entry, unsigned long *dirIndex)
{
- long extentSize;
+ u_int64_t extentSize;
void *extent;
- short extentFile;
+ unsigned long extentFile;
char *nodeBuf;
BTNodeDescriptor *node;
long nodeSize, result = 0, entrySize = 0;
long curNode, index = 0, lowerBound, upperBound;
- char *testKey, *recordData;
+ char *testKey, *recordData = NULL;
// Figure out which tree is being looked at.
if (btree == kBTreeCatalog) {
while (1) {
// Read the current node.
ReadExtent(extent, extentSize, extentFile,
- curNode * nodeSize, nodeSize, nodeBuf, 1);
+ (u_int64_t)curNode * (u_int64_t)nodeSize, nodeSize, nodeBuf, 1);
// Find the matching key.
lowerBound = 0;
}
}
-static long ReadExtent(char *extent, long extentSize,
- long extentFile, long offset, long size,
- void *buffer, long cache)
+static long ReadExtent(void *extent, u_int64_t extentSize, unsigned long extentFile,
+ u_int64_t offset, long size, void *buffer, long cache)
{
- long lastOffset, blockNumber, countedBlocks = 0;
- long nextExtent = 0, sizeRead = 0, readSize;
- long nextExtentBlock, currentExtentBlock = 0;
- long long readOffset;
- long extentDensity, sizeofExtent, currentExtentSize;
- char *currentExtent, *extentBuffer = 0, *bufferPos = buffer;
+ u_int64_t lastOffset;
+ unsigned long blockNumber, countedBlocks = 0, nextExtent = 0, sizeRead = 0;
+ u_int64_t readSize;
+ unsigned long nextExtentBlock, currentExtentBlock = 0;
+ u_int64_t readOffset;
+ long extentDensity, sizeofExtent, currentExtentSize;
+ char *currentExtent, *extentBuffer = 0, *bufferPos = buffer;
if (offset >= extentSize) return 0;
countedBlocks += currentExtentSize;
}
- readOffset = ((blockNumber - countedBlocks) * gBlockSize) +
- (offset % gBlockSize);
+ readOffset = ((u_int64_t)(blockNumber - countedBlocks) * (u_int64_t)gBlockSize) +
+ (offset % gBlockSize);
- readSize = GetExtentSize(currentExtent, 0) * gBlockSize - readOffset;
+ readSize = ((u_int64_t)GetExtentSize(currentExtent, 0) * (u_int64_t)gBlockSize) - readOffset;
if (readSize > (size - sizeRead)) readSize = size - sizeRead;
- readOffset += (long long)GetExtentStart(currentExtent, 0) * gBlockSize;
+ readOffset += (u_int64_t)GetExtentStart(currentExtent, 0) * gBlockSize;
CacheRead(gCurrentIH, bufferPos, gAllocationOffset + readOffset,
- readSize, cache);
+ (long)readSize, cache);
+ // truncation: readSize capped pre-CacheRead
sizeRead += readSize;
offset += readSize;
bufferPos += readSize;
return sizeRead;
}
-static long GetExtentStart(void *extents, long index)
+static unsigned long GetExtentStart(void *extents, long index)
{
- long start;
+ unsigned long start;
HFSExtentDescriptor *hfsExtents = extents;
HFSPlusExtentDescriptor *hfsPlusExtents = extents;
return start;
}
-static long GetExtentSize(void *extents, long index)
+static unsigned long GetExtentSize(void *extents, long index)
{
- long size;
+ unsigned long size;
HFSExtentDescriptor *hfsExtents = extents;
HFSPlusExtentDescriptor *hfsPlusExtents = extents;
static long CompareHFSCatalogKeys(void *key, void *testKey)
{
HFSCatalogKey *searchKey, *trialKey;
- long result, searchParentID, trialParentID;
+ long result;
+ unsigned long searchParentID, trialParentID;
searchKey = key;
trialKey = testKey;
static long CompareHFSPlusCatalogKeys(void *key, void *testKey)
{
HFSPlusCatalogKey *searchKey, *trialKey;
- long result, searchParentID, trialParentID;
+ long result;
+ unsigned long searchParentID, trialParentID;
searchKey = key;
trialKey = testKey;