]> git.saurik.com Git - apple/xnu.git/blobdiff - bsd/hfs/hfscommon/BTree/BTreeTreeOps.c
xnu-1504.3.12.tar.gz
[apple/xnu.git] / bsd / hfs / hfscommon / BTree / BTreeTreeOps.c
index 777e6f0fcff9b65a438a69f93b038948c4c839bb..71d9e06c928b34b0c5670bf8baa62d61aa6972dc 100644 (file)
@@ -1,23 +1,29 @@
 /*
- * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 2000-2008 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@
  */
 /*
        File:           BTreeTreeOps.c
@@ -89,6 +95,7 @@
 */
 
 #include "../headers/BTreesPrivate.h"
+#include "../../hfs_btreeio.h"
 
 //
 /////////////////////// Routines Internal To BTree Module ///////////////////////
@@ -108,14 +115,14 @@ static OSStatus   CollapseTree            (BTreeControlBlockPtr            btreePtr,
 static OSStatus   RotateLeft           (BTreeControlBlockPtr            btreePtr,
                                                                         NodeDescPtr                             leftNode,
                                                                         NodeDescPtr                             rightNode,
-                                                                        UInt16                                          rightInsertIndex,
+                                                                        u_int16_t                                       rightInsertIndex,
                                                                         KeyPtr                                          keyPtr,
-                                                                        UInt8 *                                         recPtr,
-                                                                        UInt16                                          recSize,
-                                                                        UInt16                                         *insertIndex,
-                                                                        UInt32                                         *insertNodeNum,
+                                                                        u_int8_t *                                      recPtr,
+                                                                        u_int16_t                                       recSize,
+                                                                        u_int16_t                                      *insertIndex,
+                                                                        u_int32_t                                      *insertNodeNum,
                                                                         Boolean                                        *recordFit,
-                                                                        UInt16                                         *recsRotated );
+                                                                        u_int16_t                                      *recsRotated );
 
 static Boolean    RotateRecordLeft     (BTreeControlBlockPtr            btreePtr,
                                                                         NodeDescPtr                             leftNode,
@@ -124,14 +131,14 @@ static Boolean       RotateRecordLeft     (BTreeControlBlockPtr            btreePtr,
 static OSStatus           SplitLeft            (BTreeControlBlockPtr            btreePtr,
                                                                         BlockDescriptor                        *leftNode,
                                                                         BlockDescriptor                        *rightNode,
-                                                                        UInt32                                          rightNodeNum,
-                                                                        UInt16                                          index,
+                                                                        u_int32_t                                       rightNodeNum,
+                                                                        u_int16_t                                       index,
                                                                         KeyPtr                                          keyPtr,
-                                                                        UInt8 *                                         recPtr,
-                                                                        UInt16                                          recSize,
-                                                                        UInt16                                         *insertIndex,
-                                                                        UInt32                                         *insertNodeNum,
-                                                                        UInt16                                         *recsRotated );
+                                                                        u_int8_t *                                      recPtr,
+                                                                        u_int16_t                                       recSize,
+                                                                        u_int16_t                                      *insertIndex,
+                                                                        u_int32_t                                      *insertNodeNum,
+                                                                        u_int16_t                                      *recsRotated );
                                                                 
 
 
@@ -140,23 +147,23 @@ static    OSStatus        InsertLevel             (BTreeControlBlockPtr            btreePtr,
                                                                         InsertKey                                      *primaryKey,
                                                                         InsertKey                                      *secondaryKey,
                                                                         BlockDescriptor                        *targetNode,
-                                                                        UInt16                                          index,
-                                                                        UInt16                                          level,
-                                                                        UInt32                                         *insertNode );
+                                                                        u_int16_t                                       index,
+                                                                        u_int16_t                                       level,
+                                                                        u_int32_t                                      *insertNode );
                                                 
 static OSErr           InsertNode              (BTreeControlBlockPtr            btreePtr,
                                                                         InsertKey                                      *key,
                                                                         BlockDescriptor                        *rightNode,
-                                                                        UInt32                                          node,
-                                                                        UInt16                                          index,
-                                                                        UInt32                                         *newNode,       
-                                                                        UInt16                                         *newIndex,
+                                                                        u_int32_t                                       node,
+                                                                        u_int16_t                                       index,
+                                                                        u_int32_t                                      *newNode,       
+                                                                        u_int16_t                                      *newIndex,
                                                                         BlockDescriptor                        *leftNode,
                                                                         Boolean                                        *updateParent,
                                                                         Boolean                                        *insertParent,
                                                                         Boolean                                        *rootSplit );
                                                                         
-static UInt16          GetKeyLength    (const BTreeControlBlock *btreePtr,
+static u_int16_t               GetKeyLength    (const BTreeControlBlock *btreePtr,
                                                                         const BTreeKey *key,
                                                                         Boolean forLeafNode );
 
@@ -189,20 +196,20 @@ Result:           noErr                   - key found, index is record index
 OSStatus       SearchTree      (BTreeControlBlockPtr    btreePtr,
                                                 BTreeKeyPtr                     searchKey,
                                                 TreePathTable                   treePathTable,
-                                                UInt32                                 *nodeNum,
+                                                u_int32_t                              *nodeNum,
                                                 BlockDescriptor                *nodePtr,
-                                                UInt16                                 *returnIndex )
+                                                u_int16_t                              *returnIndex )
 {
        OSStatus        err;
-       SInt16          level;                                  //      Expected depth of current node
-       UInt32          curNodeNum;                             //      Current node we're searching
+       int16_t         level;                                  //      Expected depth of current node
+       u_int32_t       curNodeNum;                             //      Current node we're searching
        NodeRec         nodeRec;
-       UInt16          index;
+       u_int16_t       index;
        Boolean         keyFound;
-       SInt8           nodeKind;                               //      Kind of current node (index/leaf)
+       int8_t          nodeKind;                               //      Kind of current node (index/leaf)
        KeyPtr          keyPtr;
-       UInt8 *         dataPtr;
-       UInt16          dataSize;
+       u_int8_t *      dataPtr;
+       u_int16_t       dataSize;
        
        
        curNodeNum              = btreePtr->rootNode;
@@ -228,12 +235,12 @@ OSStatus  SearchTree      (BTreeControlBlockPtr    btreePtr,
         //
         if (curNodeNum == 0)
         {
-//          Panic("\pSearchTree: curNodeNum is zero!");
+//          Panic("SearchTree: curNodeNum is zero!");
             err = btBadNode;
             goto ErrorExit;
         }
         
-        err = GetNode (btreePtr, curNodeNum, &nodeRec);
+        err = GetNode (btreePtr, curNodeNum, 0, &nodeRec);
         if (err != noErr)
         {
                 goto ErrorExit;
@@ -247,7 +254,7 @@ OSStatus    SearchTree      (BTreeControlBlockPtr    btreePtr,
         //
         if (((BTNodeDescriptor*)nodeRec.buffer)->height != level)
         {
-//             Panic("\pIncorrect node height");
+//             Panic("Incorrect node height");
                 err = btBadNode;
                 goto ReleaseAndExit;
         }
@@ -257,7 +264,7 @@ OSStatus    SearchTree      (BTreeControlBlockPtr    btreePtr,
             // Nodes at level 1 must be leaves, by definition
             if (nodeKind != kBTLeafNode)
             {
- //            Panic("\pIncorrect node type: expected leaf");
+ //            Panic("Incorrect node type: expected leaf");
                 err = btBadNode;
                 goto ReleaseAndExit;           
             }
@@ -267,7 +274,7 @@ OSStatus    SearchTree      (BTreeControlBlockPtr    btreePtr,
             // A node at any other depth must be an index node
             if (nodeKind != kBTIndexNode)
             {
-//             Panic("\pIncorrect node type: expected index");
+//             Panic("Incorrect node type: expected index");
                 err = btBadNode;
                 goto ReleaseAndExit;
             }
@@ -302,7 +309,7 @@ OSStatus    SearchTree      (BTreeControlBlockPtr    btreePtr,
         
         //     Get the child pointer out of this index node.  We're now done with the current
         //     node and can continue the search with the child node.
-        curNodeNum = *(UInt32 *)dataPtr;
+        curNodeNum = *(u_int32_t *)dataPtr;
         err = ReleaseNode (btreePtr, &nodeRec);
         if (err != noErr)
         {
@@ -344,13 +351,13 @@ ErrorExit:
 OSStatus       InsertTree ( BTreeControlBlockPtr                btreePtr,
                                                 TreePathTable                           treePathTable,
                                                 KeyPtr                                          keyPtr,
-                                                UInt8 *                                         recPtr,
-                                                UInt16                                          recSize,
+                                                u_int8_t *                                      recPtr,
+                                                u_int16_t                                       recSize,
                                                 BlockDescriptor                        *targetNode,
-                                                UInt16                                          index,
-                                                UInt16                                          level,
+                                                u_int16_t                                       index,
+                                                u_int16_t                                       level,
                                                 Boolean                                         replacingKey,
-                                                UInt32                                         *insertNode )
+                                                u_int32_t                                      *insertNode )
 {
        InsertKey                       primaryKey;
        OSStatus                        err;
@@ -377,22 +384,22 @@ OSStatus  InsertLevel (BTreeControlBlockPtr                btreePtr,
                                                 InsertKey                                      *primaryKey,
                                                 InsertKey                                      *secondaryKey,
                                                 BlockDescriptor                        *targetNode,
-                                                UInt16                                          index,
-                                                UInt16                                          level,
-                                                UInt32                                         *insertNode )
+                                                u_int16_t                                       index,
+                                                u_int16_t                                       level,
+                                                u_int32_t                                      *insertNode )
 {
        OSStatus                         err;
        BlockDescriptor          leftNode;
-       UInt32                           targetNodeNum;
-       UInt32                           newNodeNum;
-       UInt16                           newIndex;
+       u_int32_t                        targetNodeNum;
+       u_int32_t                        newNodeNum;
+       u_int16_t                        newIndex;
        Boolean                          insertParent;
        Boolean                          updateParent;
        Boolean                          newRoot;
        InsertKey                       insertKey;
 
 #if defined(applec) && !defined(__SC__)
-       PanicIf ((level == 1) && (((NodeDescPtr)targetNode->buffer)->kind != kBTLeafNode), "\P InsertLevel: non-leaf at level 1! ");
+       PanicIf ((level == 1) && (((NodeDescPtr)targetNode->buffer)->kind != kBTLeafNode), " InsertLevel: non-leaf at level 1! ");
 #endif
        leftNode.buffer = nil;
        leftNode.blockHeader = nil;
@@ -437,7 +444,7 @@ OSStatus    InsertLevel (BTreeControlBlockPtr                btreePtr,
                M_ExitOnError (err);
                
                if ( DEBUG_BUILD && updateParent && newRoot )
-                       DebugStr("\p InsertLevel: New root from primary key, update from secondary key...");
+                       DebugStr(" InsertLevel: New root from primary key, update from secondary key...");
        }
 
        //////////////////////// Update Parent(s) ///////////////////////////////
@@ -445,17 +452,17 @@ OSStatus  InsertLevel (BTreeControlBlockPtr                btreePtr,
        if ( insertParent || updateParent )
        {
                BlockDescriptor         parentNode;
-               UInt32                          parentNodeNum;
+               u_int32_t                       parentNodeNum;
                KeyPtr                          keyPtr;
-               UInt8 *                         recPtr;
-               UInt16                          recSize;
+               u_int8_t *                      recPtr;
+               u_int16_t                       recSize;
                
                parentNode.buffer = nil;
                parentNode.blockHeader = nil;
 
                secondaryKey = nil;
                
-               PanicIf ( (level == btreePtr->treeDepth), "\p InsertLevel: unfinished insert!?");
+               PanicIf ( (level == btreePtr->treeDepth), " InsertLevel: unfinished insert!?");
 
                ++level;
 
@@ -463,13 +470,13 @@ OSStatus  InsertLevel (BTreeControlBlockPtr                btreePtr,
                index = treePathTable [level].index;
                parentNodeNum = treePathTable [level].node;
 
-               PanicIf ( parentNodeNum == 0, "\p InsertLevel: parent node is zero!?");
+               PanicIf ( parentNodeNum == 0, " InsertLevel: parent node is zero!?");
 
-               err = GetNode (btreePtr, parentNodeNum, &parentNode);   // released as target node in next level up
+               err = GetNode (btreePtr, parentNodeNum, 0, &parentNode);        // released as target node in next level up
                M_ExitOnError (err);
 #if defined(applec) && !defined(__SC__)
                if (DEBUG_BUILD && level > 1)
-                       PanicIf ( ((NodeDescPtr)parentNode.buffer)->kind != kBTIndexNode, "\P InsertLevel: parent node not an index node! ");
+                       PanicIf ( ((NodeDescPtr)parentNode.buffer)->kind != kBTIndexNode, " InsertLevel: parent node not an index node! ");
 #endif
                ////////////////////////// Update Parent Index //////////////////////////////
        
@@ -480,7 +487,7 @@ OSStatus    InsertLevel (BTreeControlBlockPtr                btreePtr,
 
                        //\80\80 debug: check if ptr == targetNodeNum
                        GetRecordByIndex (btreePtr, parentNode.buffer, index, &keyPtr, &recPtr, &recSize);
-                       PanicIf( (*(UInt32 *) recPtr) != targetNodeNum, "\p InsertLevel: parent ptr doesn't match target node!");
+                       PanicIf( (*(u_int32_t *) recPtr) != targetNodeNum, " InsertLevel: parent ptr doesn't match target node!");
                        
                        // need to delete and re-insert this parent key/ptr
                        // we delete it here and it gets re-inserted in the
@@ -489,7 +496,7 @@ OSStatus    InsertLevel (BTreeControlBlockPtr                btreePtr,
        
                        primaryKey->keyPtr               = (KeyPtr) GetRecordAddress( btreePtr, targetNode->buffer, 0 );
                        primaryKey->keyLength    = GetKeyLength(btreePtr, primaryKey->keyPtr, false);
-                       primaryKey->recPtr               = (UInt8 *) &targetNodeNum;
+                       primaryKey->recPtr               = (u_int8_t *) &targetNodeNum;
                        primaryKey->recSize              = sizeof(targetNodeNum);
                        primaryKey->replacingKey = kReplaceRecord;
                        primaryKey->skipRotate   = insertParent;                // don't rotate left if we have two inserts occuring
@@ -513,8 +520,8 @@ OSStatus    InsertLevel (BTreeControlBlockPtr                btreePtr,
                        
                        insertKeyPtr->keyPtr            = (KeyPtr) GetRecordAddress (btreePtr, leftNode.buffer, 0);
                        insertKeyPtr->keyLength         = GetKeyLength(btreePtr, insertKeyPtr->keyPtr, false);
-                       insertKeyPtr->recPtr            = (UInt8 *) &((NodeDescPtr)targetNode->buffer)->bLink;
-                       insertKeyPtr->recSize           = sizeof(UInt32);
+                       insertKeyPtr->recPtr            = (u_int8_t *) &((NodeDescPtr)targetNode->buffer)->bLink;
+                       insertKeyPtr->recSize           = sizeof(u_int32_t);
                        insertKeyPtr->replacingKey      = kInsertRecord;
                        insertKeyPtr->skipRotate        = false;                // a rotate is OK during second insert
                }       
@@ -537,7 +544,7 @@ ErrorExit:
        (void) ReleaseNode (btreePtr, targetNode);
        (void) ReleaseNode (btreePtr, &leftNode);
 
-       Panic ("\p InsertLevel: an error occurred!");
+       Panic (" InsertLevel: an error occurred!");
 
        return  err;
 
@@ -551,11 +558,11 @@ static OSErr      InsertNode      (BTreeControlBlockPtr    btreePtr,
                                                         InsertKey                              *key,
 
                                                         BlockDescriptor                *rightNode,
-                                                        UInt32                                  node,
-                                                        UInt16                                  index,
+                                                        u_int32_t                               node,
+                                                        u_int16_t                               index,
 
-                                                        UInt32                                 *newNode,       
-                                                        UInt16                                 *newIndex,
+                                                        u_int32_t                              *newNode,       
+                                                        u_int16_t                              *newIndex,
 
                                                         BlockDescriptor                *leftNode,
                                                         Boolean                                *updateParent,
@@ -563,25 +570,36 @@ static OSErr      InsertNode      (BTreeControlBlockPtr    btreePtr,
                                                         Boolean                                *rootSplit )
 {
        BlockDescriptor         *targetNode;
-       UInt32                           leftNodeNum;
-       UInt16                           recsRotated;
+       u_int32_t                        leftNodeNum;
+       u_int16_t                        recsRotated;
        OSErr                            err;
        Boolean                          recordFit;
 
        *rootSplit = false;
        
-       PanicIf ( rightNode->buffer == leftNode->buffer, "\p InsertNode: rightNode == leftNode, huh?");
+       PanicIf ( rightNode->buffer == leftNode->buffer, " InsertNode: rightNode == leftNode, huh?");
        
        leftNodeNum = ((NodeDescPtr) rightNode->buffer)->bLink;
 
 
        /////////////////////// Try Simple Insert ///////////////////////////////
 
-       if ( node == leftNodeNum )
-               targetNode = leftNode;
-       else
-               targetNode = rightNode;
-
+       /* sanity check our left and right nodes here. */
+       if (node == leftNodeNum) {
+               if (leftNode->buffer == NULL) {
+                       err = fsBTInvalidNodeErr;
+                       M_ExitOnError(err);     
+               }
+               else{
+                       targetNode = leftNode;
+               }
+       }
+       else {
+               // we can assume right node is initialized.
+               targetNode = rightNode; 
+       }
+       
+       
        recordFit = InsertKeyRecord (btreePtr, targetNode->buffer, index, key->keyPtr, key->keyLength, key->recPtr, key->recSize);
 
        if ( recordFit )
@@ -598,17 +616,17 @@ static OSErr      InsertNode      (BTreeControlBlockPtr    btreePtr,
        
        if ( !recordFit && leftNodeNum > 0 )
        {
-               PanicIf ( leftNode->buffer != nil, "\p InsertNode: leftNode already aquired!");
+               PanicIf ( leftNode->buffer != nil, " InsertNode: leftNode already acquired!");
 
                if ( leftNode->buffer == nil )
                {
-                       err = GetNode (btreePtr, leftNodeNum, leftNode);        // will be released by caller or a split below
+                       err = GetNode (btreePtr, leftNodeNum, 0, leftNode);     // will be released by caller or a split below
                        M_ExitOnError (err);
                        // XXXdbg
                        ModifyBlockStart(btreePtr->fileRefNum, leftNode);
                }
 
-               PanicIf ( ((NodeDescPtr) leftNode->buffer)->fLink != node, "\p InsertNode, RotateLeft: invalid sibling link!" );
+               PanicIf ( ((NodeDescPtr) leftNode->buffer)->fLink != node, " InsertNode, RotateLeft: invalid sibling link!" );
 
                if ( !key->skipRotate )         // are rotates allowed?
                {
@@ -679,13 +697,13 @@ Result:           noErr           - success
 OSStatus       DeleteTree                      (BTreeControlBlockPtr            btreePtr,
                                                                 TreePathTable                           treePathTable,
                                                                 BlockDescriptor                        *targetNode,
-                                                                UInt16                                          index,
-                                                                UInt16                                          level )
+                                                                u_int16_t                                       index,
+                                                                u_int16_t                                       level )
 {
        OSStatus                        err;
        BlockDescriptor         parentNode;
        BTNodeDescriptor        *targetNodePtr;
-       UInt32                          targetNodeNum;
+       u_int32_t                       targetNodeNum;
        Boolean                         deleteRequired;
        Boolean                         updateRequired;
 
@@ -699,7 +717,7 @@ OSStatus    DeleteTree                      (BTreeControlBlockPtr            btreePtr,
 
        targetNodeNum = treePathTable[level].node;
        targetNodePtr = targetNode->buffer;
-       PanicIf (targetNodePtr == nil, "\pDeleteTree: targetNode has nil buffer!");
+       PanicIf (targetNodePtr == nil, "DeleteTree: targetNode has nil buffer!");
 
        // XXXdbg
        ModifyBlockStart(btreePtr->fileRefNum, targetNode);
@@ -711,7 +729,7 @@ OSStatus    DeleteTree                      (BTreeControlBlockPtr            btreePtr,
        if ( targetNodePtr->numRecords == 0 )   // did we delete the last record?
        {
                BlockDescriptor         siblingNode;
-               UInt32                          siblingNodeNum;
+               u_int32_t                       siblingNodeNum;
 
                deleteRequired = true;
                
@@ -723,7 +741,7 @@ OSStatus    DeleteTree                      (BTreeControlBlockPtr            btreePtr,
                siblingNodeNum = targetNodePtr->bLink;                          // Left Sibling Node
                if ( siblingNodeNum != 0 )
                {
-                       err = GetNode (btreePtr, siblingNodeNum, &siblingNode);
+                       err = GetNode (btreePtr, siblingNodeNum, 0, &siblingNode);
                        M_ExitOnError (err);
 
                        // XXXdbg
@@ -741,7 +759,7 @@ OSStatus    DeleteTree                      (BTreeControlBlockPtr            btreePtr,
                siblingNodeNum = targetNodePtr->fLink;                          // Right Sibling Node
                if ( siblingNodeNum != 0 )
                {
-                       err = GetNode (btreePtr, siblingNodeNum, &siblingNode);
+                       err = GetNode (btreePtr, siblingNodeNum, 0, &siblingNode);
                        M_ExitOnError (err);
 
                        // XXXdbg
@@ -796,28 +814,28 @@ OSStatus  DeleteTree                      (BTreeControlBlockPtr            btreePtr,
 
                //// Get Parent Node and index
                index = treePathTable [level].index;
-               err = GetNode (btreePtr, treePathTable[level].node, &parentNode);
+               err = GetNode (btreePtr, treePathTable[level].node, 0, &parentNode);
                M_ExitOnError (err);
 
                if ( updateRequired )
                {
                         KeyPtr         keyPtr;
-                        UInt8 *        recPtr;
-                        UInt16         recSize;
-                        UInt32         insertNode;
+                        u_int8_t *     recPtr;
+                        u_int16_t      recSize;
+                        u_int32_t      insertNode;
                         
                         // XXXdbg
                         ModifyBlockStart(btreePtr->fileRefNum, &parentNode);
 
                        //\80\80 debug: check if ptr == targetNodeNum
                        GetRecordByIndex (btreePtr, parentNode.buffer, index, &keyPtr, &recPtr, &recSize);
-                       PanicIf( (*(UInt32 *) recPtr) != targetNodeNum, "\p DeleteTree: parent ptr doesn't match targetNodeNum!!");
+                       PanicIf( (*(u_int32_t *) recPtr) != targetNodeNum, " DeleteTree: parent ptr doesn't match targetNodeNum!!");
                        
                        // need to delete and re-insert this parent key/ptr
                        DeleteRecord (btreePtr, parentNode.buffer, index);
        
                        keyPtr = (KeyPtr) GetRecordAddress( btreePtr, targetNode->buffer, 0 );
-                       recPtr = (UInt8 *) &targetNodeNum;
+                       recPtr = (u_int8_t *) &targetNodeNum;
                        recSize = sizeof(targetNodeNum);
                        
                        err = InsertTree (btreePtr, treePathTable, keyPtr, recPtr, recSize,
@@ -854,8 +872,8 @@ static OSStatus     CollapseTree    (BTreeControlBlockPtr           btreePtr,
                                                                 BlockDescriptor                        *blockPtr )
 {
        OSStatus                err;
-       UInt32                  originalRoot;
-       UInt32                  nodeNum;
+       u_int32_t               originalRoot;
+       u_int32_t               nodeNum;
        
        originalRoot    = btreePtr->rootNode;
        
@@ -882,7 +900,7 @@ static OSStatus     CollapseTree    (BTreeControlBlockPtr           btreePtr,
                M_ExitOnError (err);
                
                //// Get New Root Node
-               err = GetNode (btreePtr, btreePtr->rootNode, blockPtr);
+               err = GetNode (btreePtr, btreePtr->rootNode, 0, blockPtr);
                M_ExitOnError (err);
 
                // XXXdbg
@@ -937,23 +955,23 @@ Result:           noErr           - success
 static OSStatus        RotateLeft              (BTreeControlBlockPtr            btreePtr,
                                                                 NodeDescPtr                             leftNode,
                                                                 NodeDescPtr                             rightNode,
-                                                                UInt16                                          rightInsertIndex,
+                                                                u_int16_t                                       rightInsertIndex,
                                                                 KeyPtr                                          keyPtr,
-                                                                UInt8 *                                         recPtr,
-                                                                UInt16                                          recSize,
-                                                                UInt16                                         *insertIndex,
-                                                                UInt32                                         *insertNodeNum,
+                                                                u_int8_t *                                      recPtr,
+                                                                u_int16_t                                       recSize,
+                                                                u_int16_t                                      *insertIndex,
+                                                                u_int32_t                                      *insertNodeNum,
                                                                 Boolean                                        *recordFit,
-                                                                UInt16                                         *recsRotated )
+                                                                u_int16_t                                      *recsRotated )
 {
        OSStatus                        err;
-       SInt32                          insertSize;
-       SInt32                          nodeSize;
-       SInt32                          leftSize, rightSize;
-       SInt32                          moveSize = 0;
-       UInt16                          keyLength;
-       UInt16                          lengthFieldSize;
-       UInt16                          index, moveIndex;
+       int32_t                         insertSize;
+       int32_t                         nodeSize;
+       int32_t                         leftSize, rightSize;
+       int32_t                         moveSize = 0;
+       u_int16_t                       keyLength;
+       u_int16_t                       lengthFieldSize;
+       u_int16_t                       index, moveIndex;
        Boolean                         didItFit;
 
        ///////////////////// Determine If Record Will Fit //////////////////////////
@@ -962,11 +980,11 @@ static OSStatus   RotateLeft              (BTreeControlBlockPtr            btreePtr,
 
        // the key's length field is 8-bits in HFS and 16-bits in HFS+
        if ( btreePtr->attributes & kBTBigKeysMask )
-               lengthFieldSize = sizeof(UInt16);
+               lengthFieldSize = sizeof(u_int16_t);
        else
-               lengthFieldSize = sizeof(UInt8);
+               lengthFieldSize = sizeof(u_int8_t);
 
-       insertSize = keyLength + lengthFieldSize + recSize + sizeof(UInt16);
+       insertSize = keyLength + lengthFieldSize + recSize + sizeof(u_int16_t);
 
        if ( M_IsOdd (insertSize) )
                ++insertSize;   // add pad byte;
@@ -1029,7 +1047,7 @@ static OSStatus   RotateLeft              (BTreeControlBlockPtr            btreePtr,
        {
                if ( index == rightInsertIndex )        // insert new record in left node
                {
-                       UInt16  leftInsertIndex;
+                       u_int16_t       leftInsertIndex;
                        
                        leftInsertIndex = leftNode->numRecords;
 
@@ -1037,7 +1055,7 @@ static OSStatus   RotateLeft              (BTreeControlBlockPtr            btreePtr,
                                                                                keyPtr, keyLength, recPtr, recSize);
                        if ( !didItFit )
                        {
-                               Panic ("\pRotateLeft: InsertKeyRecord (left) returned false!");
+                               Panic ("RotateLeft: InsertKeyRecord (left) returned false!");
                                err = fsBTBadRotateErr;
                                goto ErrorExit;
                        }
@@ -1050,7 +1068,7 @@ static OSStatus   RotateLeft              (BTreeControlBlockPtr            btreePtr,
                        didItFit = RotateRecordLeft (btreePtr, leftNode, rightNode);
                        if ( !didItFit )
                        {
-                               Panic ("\pRotateLeft: RotateRecordLeft returned false!");
+                               Panic ("RotateLeft: RotateRecordLeft returned false!");
                                err = fsBTBadRotateErr;
                                goto ErrorExit;
                        }
@@ -1067,7 +1085,7 @@ static OSStatus   RotateLeft              (BTreeControlBlockPtr            btreePtr,
                                                                        keyPtr, keyLength, recPtr, recSize);
                if ( !didItFit )
                {
-                       Panic ("\pRotateLeft: InsertKeyRecord (right) returned false!");
+                       Panic ("RotateLeft: InsertKeyRecord (right) returned false!");
                        err = fsBTBadRotateErr;
                        goto ErrorExit;
                }
@@ -1099,18 +1117,18 @@ ErrorExit:
 static OSStatus        SplitLeft               (BTreeControlBlockPtr            btreePtr,
                                                                 BlockDescriptor                        *leftNode,
                                                                 BlockDescriptor                        *rightNode,
-                                                                UInt32                                          rightNodeNum,
-                                                                UInt16                                          index,
+                                                                u_int32_t                                       rightNodeNum,
+                                                                u_int16_t                                       index,
                                                                 KeyPtr                                          keyPtr,
-                                                                UInt8 *                                         recPtr,
-                                                                UInt16                                          recSize,
-                                                                UInt16                                         *insertIndex,
-                                                                UInt32                                         *insertNodeNum,
-                                                                UInt16                                         *recsRotated )
+                                                                u_int8_t *                                      recPtr,
+                                                                u_int16_t                                       recSize,
+                                                                u_int16_t                                      *insertIndex,
+                                                                u_int32_t                                      *insertNodeNum,
+                                                                u_int16_t                                      *recsRotated )
 {
        OSStatus                        err;
        NodeDescPtr                     left, right;
-       UInt32                          newNodeNum;
+       u_int32_t                       newNodeNum;
        Boolean                         recordFit;
        
        
@@ -1119,7 +1137,7 @@ static OSStatus   SplitLeft               (BTreeControlBlockPtr            btreePtr,
        right = rightNode->buffer;
        left  = leftNode->buffer;
        
-       PanicIf ( right->bLink != 0 && left == 0, "\p SplitLeft: left sibling missing!?" );
+       PanicIf ( right->bLink != 0 && left == 0, " SplitLeft: left sibling missing!?" );
        
        /* type should be kBTLeafNode or kBTIndexNode */
        
@@ -1217,8 +1235,8 @@ static Boolean RotateRecordLeft (BTreeControlBlockPtr             btreePtr,
                                                                 NodeDescPtr                            leftNode,
                                                                 NodeDescPtr                            rightNode )
 {
-       UInt16          size;
-       UInt8 *         recPtr;
+       u_int16_t       size;
+       u_int8_t *      recPtr;
        Boolean         recordFit;
        
        size    = GetRecordSize (btreePtr, rightNode, 0);
@@ -1243,16 +1261,16 @@ static OSStatus AddNewRootNode  (BTreeControlBlockPtr    btreePtr,
 {
        OSStatus                        err;
        BlockDescriptor         rootNode;
-       UInt32                          rootNum;
+       u_int32_t                       rootNum;
        KeyPtr                          keyPtr;
        Boolean                         didItFit;
-       UInt16                          keyLength;      
+       u_int16_t                       keyLength;      
        
        rootNode.buffer = nil;
        rootNode.blockHeader = nil;
 
-       PanicIf (leftNode == nil, "\pAddNewRootNode: leftNode == nil");
-       PanicIf (rightNode == nil, "\pAddNewRootNode: rightNode == nil");
+       PanicIf (leftNode == nil, "AddNewRootNode: leftNode == nil");
+       PanicIf (rightNode == nil, "AddNewRootNode: rightNode == nil");
        
        
        /////////////////////// Initialize New Root Node ////////////////////////////
@@ -1276,9 +1294,9 @@ static OSStatus   AddNewRootNode  (BTreeControlBlockPtr    btreePtr,
        keyLength = GetKeyLength(btreePtr, keyPtr, false);
 
        didItFit = InsertKeyRecord ( btreePtr, rootNode.buffer, 0, keyPtr, keyLength,
-                                                                (UInt8 *) &rightNode->bLink, 4 );
+                                                                (u_int8_t *) &rightNode->bLink, 4 );
 
-       PanicIf ( !didItFit, "\pAddNewRootNode:InsertKeyRecord failed for left index record");
+       PanicIf ( !didItFit, "AddNewRootNode:InsertKeyRecord failed for left index record");
 
 
        //////////////////// Insert Right Node Index Record /////////////////////////
@@ -1287,9 +1305,9 @@ static OSStatus   AddNewRootNode  (BTreeControlBlockPtr    btreePtr,
        keyLength = GetKeyLength(btreePtr, keyPtr, false);
 
        didItFit = InsertKeyRecord ( btreePtr, rootNode.buffer, 1, keyPtr, keyLength,
-                                                                (UInt8 *) &leftNode->fLink, 4 );
+                                                                (u_int8_t *) &leftNode->fLink, 4 );
 
-       PanicIf ( !didItFit, "\pAddNewRootNode:InsertKeyRecord failed for right index record");
+       PanicIf ( !didItFit, "AddNewRootNode:InsertKeyRecord failed for right index record");
 
        
        /////////////////////////// Release Root Node ///////////////////////////////
@@ -1313,9 +1331,9 @@ ErrorExit:
 }
 
 
-static UInt16  GetKeyLength ( const BTreeControlBlock *btreePtr, const BTreeKey *key, Boolean forLeafNode )
+static u_int16_t       GetKeyLength ( const BTreeControlBlock *btreePtr, const BTreeKey *key, Boolean forLeafNode )
 {
-       UInt16 length;
+       u_int16_t length;
 
        if ( forLeafNode || btreePtr->attributes & kBTVariableIndexKeysMask )
                length = KeyLength (btreePtr, key);             // just use actual key length