+/*-------------------------------------------------------------------------------
+Routine: BTCheckFreeSpace
+
+Function: Makes sure there is enough free space so that a tree operation
+ will succeed.
+
+Input: fcb - pointer file control block
+
+Output: none
+
+Result: noErr - success
+
+-------------------------------------------------------------------------------*/
+
+__private_extern__
+OSStatus BTCheckFreeSpace (FCB *filePtr)
+{
+ BTreeControlBlockPtr btreePtr;
+ int nodesNeeded, err = noErr;
+
+
+ M_ReturnErrorIf (filePtr == nil, paramErr);
+
+ btreePtr = (BTreeControlBlockPtr) filePtr->fcbBTCBPtr;
+
+ REQUIRE_FILE_LOCK(btreePtr->fileRefNum, true);
+
+ M_ReturnErrorIf (btreePtr == nil, fsBTInvalidFileErr);
+
+ // XXXdbg this is highly conservative but so much better than
+ // winding up with turds on your disk.
+ //
+ nodesNeeded = (btreePtr->treeDepth + 1) * 10;
+
+ if (btreePtr->freeNodes < nodesNeeded) {
+ err = ExtendBTree(btreePtr, nodesNeeded + btreePtr->totalNodes - btreePtr->freeNodes);
+ }
+
+ return err;
+}
+
+
+__private_extern__
+OSStatus BTHasContiguousNodes (FCB *filePtr)
+{
+ BTreeControlBlockPtr btreePtr;
+ int nodesNeeded, err = noErr;
+
+
+ M_ReturnErrorIf (filePtr == nil, paramErr);
+
+ btreePtr = (BTreeControlBlockPtr) filePtr->fcbBTCBPtr;
+
+ REQUIRE_FILE_LOCK(btreePtr->fileRefNum, true);
+
+ M_ReturnErrorIf (btreePtr == nil, fsBTInvalidFileErr);
+
+ return NodesAreContiguous(FCBTOVCB(filePtr), filePtr, btreePtr->nodeSize);
+}