/*
- * Copyright (c) 2000-2003 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 2000-2003, 2005 Apple Computer, 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@
*/
/*
File: BTreeAllocate.c
*/
+#include "../../hfs_btreeio.h"
#include "../../hfs_endian.h"
#include "../headers/BTreesPrivate.h"
///////////////////// Routines Internal To BTreeAllocate.c //////////////////////
-OSStatus GetMapNode (BTreeControlBlockPtr btreePtr,
+static OSStatus GetMapNode (BTreeControlBlockPtr btreePtr,
BlockDescriptor *nodePtr,
- UInt16 **mapPtr,
- UInt16 *mapSize );
+ u_int16_t **mapPtr,
+ u_int16_t *mapSize );
/////////////////////////////////////////////////////////////////////////////////
!= noErr - failure
-------------------------------------------------------------------------------*/
-OSStatus AllocateNode (BTreeControlBlockPtr btreePtr, UInt32 *nodeNum)
+OSStatus AllocateNode (BTreeControlBlockPtr btreePtr, u_int32_t *nodeNum)
{
OSStatus err;
BlockDescriptor node;
- UInt16 *mapPtr, *pos;
- UInt16 mapSize, size;
- UInt16 freeWord;
- UInt16 mask;
- UInt16 bitOffset;
- UInt32 nodeNumber;
+ u_int16_t *mapPtr, *pos;
+ u_int16_t mapSize, size;
+ u_int16_t freeWord;
+ u_int16_t mask;
+ u_int16_t bitOffset;
+ u_int32_t nodeNumber;
nodeNumber = 0; // first node number of header map record
!= noErr - GetNode or ReleaseNode encountered some difficulty
-------------------------------------------------------------------------------*/
-OSStatus FreeNode (BTreeControlBlockPtr btreePtr, UInt32 nodeNum)
+OSStatus FreeNode (BTreeControlBlockPtr btreePtr, u_int32_t nodeNum)
{
OSStatus err;
BlockDescriptor node;
- UInt32 nodeIndex;
- UInt16 mapSize;
- UInt16 *mapPos;
- UInt16 bitOffset;
+ u_int32_t nodeIndex;
+ u_int16_t mapSize;
+ u_int16_t *mapPos;
+ u_int16_t bitOffset;
//////////////////////////// Find Map Record ////////////////////////////////
-------------------------------------------------------------------------------*/
OSStatus ExtendBTree (BTreeControlBlockPtr btreePtr,
- UInt32 newTotalNodes )
+ u_int32_t newTotalNodes )
{
OSStatus err;
FCB *filePtr;
FSSize minEOF, maxEOF;
- UInt16 nodeSize;
- UInt32 oldTotalNodes;
- UInt32 newMapNodes;
- UInt32 mapBits, totalMapBits;
- UInt32 recStartBit;
- UInt32 nodeNum, nextNodeNum;
- UInt32 firstNewMapNodeNum, lastNewMapNodeNum;
+ u_int16_t nodeSize;
+ u_int32_t oldTotalNodes;
+ u_int32_t newMapNodes;
+ u_int32_t mapBits, totalMapBits;
+ u_int32_t recStartBit;
+ u_int32_t nodeNum, nextNodeNum;
+ u_int32_t firstNewMapNodeNum, lastNewMapNodeNum;
BlockDescriptor mapNode, newNode;
- UInt16 *mapPos;
- UInt16 *mapStart;
- UInt16 mapSize;
- UInt16 mapNodeRecSize;
- UInt32 bitInWord, bitInRecord;
- UInt16 mapIndex;
+ u_int16_t *mapPos;
+ u_int16_t *mapStart;
+ u_int16_t mapSize;
+ u_int16_t mapNodeRecSize;
+ u_int32_t bitInWord, bitInRecord;
+ u_int16_t mapIndex;
oldTotalNodes = btreePtr->totalNodes;
/////////////////////// Extend LEOF If Necessary ////////////////////////////
- minEOF = (UInt64)newTotalNodes * (UInt64)nodeSize;
- if ( filePtr->fcbEOF < minEOF )
+ minEOF = (u_int64_t)newTotalNodes * (u_int64_t)nodeSize;
+ if ( (u_int64_t)filePtr->fcbEOF < minEOF )
{
- maxEOF = (UInt64)0x7fffffffLL * (UInt64)nodeSize;
+ maxEOF = (u_int64_t)0x7fffffffLL * (u_int64_t)nodeSize;
err = btreePtr->setEndOfForkProc (btreePtr->fileRefNum, minEOF, maxEOF);
M_ExitOnError (err);
((NodeDescPtr)newNode.buffer)->kind = kBTMapNode;
// set free space offset
- *(UInt16 *)((Ptr)newNode.buffer + nodeSize - 4) = nodeSize - 6;
+ *(u_int16_t *)((Ptr)newNode.buffer + nodeSize - 4) = nodeSize - 6;
if (nodeNum++ == lastNewMapNodeNum)
break;
mapIndex = 0;
- mapStart = (UInt16 *) GetRecordAddress (btreePtr, mapNode.buffer, mapIndex);
+ mapStart = (u_int16_t *) GetRecordAddress (btreePtr, mapNode.buffer, mapIndex);
mapSize = GetRecordSize (btreePtr, mapNode.buffer, mapIndex);
if (DEBUG_BUILD && mapSize != M_MapRecordSize (btreePtr->nodeSize) )
!= noErr - failure
-------------------------------------------------------------------------------*/
+static
OSStatus GetMapNode (BTreeControlBlockPtr btreePtr,
BlockDescriptor *nodePtr,
- UInt16 **mapPtr,
- UInt16 *mapSize )
+ u_int16_t **mapPtr,
+ u_int16_t *mapSize )
{
OSStatus err;
- UInt16 mapIndex;
- UInt32 nextNodeNum;
+ u_int16_t mapIndex;
+ u_int32_t nextNodeNum;
if (nodePtr->buffer != nil) // if iterator is valid...
{
}
- *mapPtr = (UInt16 *) GetRecordAddress (btreePtr, nodePtr->buffer, mapIndex);
+ *mapPtr = (u_int16_t *) GetRecordAddress (btreePtr, nodePtr->buffer, mapIndex);
*mapSize = GetRecordSize (btreePtr, nodePtr->buffer, mapIndex);
return noErr;
////////////////////////////////// CalcMapBits //////////////////////////////////
-UInt32 CalcMapBits (BTreeControlBlockPtr btreePtr)
+u_int32_t CalcMapBits (BTreeControlBlockPtr btreePtr)
{
- UInt32 mapBits;
+ u_int32_t mapBits;
mapBits = M_HeaderMapRecordSize (btreePtr->nodeSize) << 3;