+ return err;
+}
+
+
+
+//////////////////////////////// BTUpdateRecord ////////////////////////////////
+
+OSStatus
+BTUpdateRecord(FCB *filePtr, BTreeIterator *iterator,
+ IterateCallBackProcPtr callBackProc, void * callBackState)
+{
+ OSStatus err;
+ BTreeControlBlockPtr btreePtr;
+ TreePathTable treePathTable;
+ BlockDescriptor nodeRec;
+ RecordPtr recordPtr;
+ BTreeKeyPtr keyPtr;
+ UInt32 insertNodeNum;
+ UInt16 recordLen;
+ UInt16 index;
+ Boolean validHint;
+
+
+ ////////////////////////// Priliminary Checks ///////////////////////////////
+
+ nodeRec.buffer = nil; // so we can call ReleaseNode
+ nodeRec.blockHeader = nil;
+
+ btreePtr = (BTreeControlBlockPtr) filePtr->fcbBTCBPtr;
+
+ REQUIRE_FILE_LOCK(btreePtr->fileRefNum, true);
+
+ ////////////////////////////// Take A Hint //////////////////////////////////
+
+ err = IsItAHint (btreePtr, iterator, &validHint);
+ M_ExitOnError (err);
+
+ if (validHint)
+ {
+ insertNodeNum = iterator->hint.nodeNum;
+
+ err = GetNode (btreePtr, insertNodeNum, &nodeRec);
+ if (err == noErr)
+ {
+ if (((NodeDescPtr)nodeRec.buffer)->kind == kBTLeafNode &&
+ SearchNode (btreePtr, nodeRec.buffer, &iterator->key, &index))
+ {
+ err = GetRecordByIndex(btreePtr, nodeRec.buffer, index, &keyPtr, &recordPtr, &recordLen);
+ M_ExitOnError (err);
+
+ // XXXdbg
+ ModifyBlockStart(btreePtr->fileRefNum, &nodeRec);
+
+ err = callBackProc(keyPtr, recordPtr, callBackState);
+ M_ExitOnError (err);
+
+ err = UpdateNode (btreePtr, &nodeRec, 0, 0);
+ M_ExitOnError (err);
+
+ ++btreePtr->numValidHints;
+
+ goto Success;
+ }
+ else
+ {
+ (void) BTInvalidateHint( iterator );
+ }
+
+ err = ReleaseNode (btreePtr, &nodeRec);
+ M_ExitOnError (err);
+ }
+ else
+ {
+ (void) BTInvalidateHint( iterator );
+ }
+ }
+
+ ////////////////////////////// Get A Clue ///////////////////////////////////
+
+ err = SearchTree (btreePtr, &iterator->key, treePathTable, &insertNodeNum, &nodeRec, &index);
+ M_ExitOnError (err);
+
+ err = GetRecordByIndex(btreePtr, nodeRec.buffer, index, &keyPtr, &recordPtr, &recordLen);
+ M_ExitOnError (err);
+
+ // XXXdbg
+ ModifyBlockStart(btreePtr->fileRefNum, &nodeRec);
+
+ err = callBackProc(keyPtr, recordPtr, callBackState);
+ M_ExitOnError (err);
+
+ err = UpdateNode (btreePtr, &nodeRec, 0, 0);
+ M_ExitOnError (err);
+
+Success:
+ // create hint
+ iterator->hint.writeCount = btreePtr->writeCount;
+ iterator->hint.nodeNum = insertNodeNum;
+ iterator->hint.index = 0;
+ iterator->hint.reserved1 = 0;
+ iterator->hint.reserved2 = 0;
+ return noErr;
+
+ ////////////////////////////// Error Exit ///////////////////////////////////