Lines Matching defs:btreePtr
189 BTreeControlBlockPtr btreePtr;
204 btreePtr = (BTreeControlBlockPtr) filePtr->fcbBTCBPtr;
205 btreePtr->keyCompareProc = keyCompareProc;
215 btreePtr = (BTreeControlBlock*) NewPtrSysClear( sizeof( BTreeControlBlock ) );
216 if (btreePtr == nil)
218 Panic ("\pBTOpen: no memory for btreePtr.");
222 btreePtr->getBlockProc = GetBTreeBlock;
223 btreePtr->releaseBlockProc = ReleaseBTreeBlock;
224 btreePtr->setEndOfForkProc = ExtendBTreeFile;
225 btreePtr->keyCompareProc = keyCompareProc;
230 btreePtr->fileRefNum = GetFileRefNumFromFCB(filePtr);
231 filePtr->fcbBTCBPtr = (Ptr) btreePtr; // attach btree cb to file
234 nodeRec.blockSize = VTOHFS(btreePtr->fileRefNum)->hfs_physical_block_size;
241 REQUIRE_FILE_LOCK(btreePtr->fileRefNum, false);
245 err = SetBTreeBlockSize (btreePtr->fileRefNum, nodeRec.blockSize, 1);
249 err = GetBTreeBlock(btreePtr->fileRefNum,
260 ++btreePtr->numGetNodes;
274 btreePtr->treeDepth = header->treeDepth;
275 btreePtr->rootNode = header->rootNode;
276 btreePtr->leafRecords = header->leafRecords;
277 btreePtr->firstLeafNode = header->firstLeafNode;
278 btreePtr->lastLeafNode = header->lastLeafNode;
279 btreePtr->nodeSize = header->nodeSize;
280 btreePtr->maxKeyLength = header->maxKeyLength;
281 btreePtr->totalNodes = header->totalNodes;
282 btreePtr->freeNodes = header->freeNodes;
285 btreePtr->btreeType = header->btreeType;
287 btreePtr->keyCompareType = header->keyCompareType;
289 btreePtr->attributes = header->attributes;
291 if ( btreePtr->maxKeyLength > 40 )
292 btreePtr->attributes |= (kBTBigKeysMask + kBTVariableIndexKeysMask); //�� we need a way to save these attributes
296 btreePtr->version = kBTreeVersion;
297 btreePtr->flags = 0;
298 btreePtr->writeCount = 1;
305 if (btreePtr->nodeSize < VTOHFS(btreePtr->fileRefNum)->hfs_logical_block_size)
311 if (btreePtr->leafRecords > 0 ||
312 VTOHFS(btreePtr->fileRefNum)->hfs_flags & HFS_WRITEABLE_MEDIA)
324 if ( btreePtr->nodeSize != nodeRec.blockSize )
326 err = SetBTreeBlockSize (btreePtr->fileRefNum, btreePtr->nodeSize, 32);
333 err = ReleaseBTreeBlock(btreePtr->fileRefNum, &nodeRec, kTrashBlock);
334 ++btreePtr->numReleaseNodes;
337 err = GetNode (btreePtr, kHeaderNodeNum, 0, &nodeRec );
344 err = ReleaseNode (btreePtr, &nodeRec);
357 if ( FCBTOHFS(filePtr)->jnl && !NodesAreContiguous(FCBTOVCB(filePtr), filePtr, btreePtr->nodeSize) ) {
373 (void) ReleaseNode (btreePtr, &nodeRec);
374 DisposePtr( (Ptr) btreePtr );
399 BTreeControlBlockPtr btreePtr;
401 btreePtr = (BTreeControlBlockPtr) filePtr->fcbBTCBPtr;
403 if (btreePtr == nil)
406 REQUIRE_FILE_LOCK(btreePtr->fileRefNum, false);
410 btreePtr->attributes &= ~kBTBadCloseMask; // clear "bad close" attribute bit
411 err = UpdateHeader (btreePtr, true);
414 DisposePtr( (Ptr) btreePtr );
464 BTreeControlBlockPtr btreePtr;
488 btreePtr = (BTreeControlBlockPtr) filePtr->fcbBTCBPtr;
489 if (btreePtr == nil)
494 REQUIRE_FILE_LOCK(btreePtr->fileRefNum, true);
500 err = IsItAHint (btreePtr, searchIterator, &validHint);
507 err = GetNode (btreePtr, nodeNum, kGetNodeHint, &node);
513 foundRecord = SearchNode (btreePtr, node.buffer, &searchIterator->key, &index);
520 err = ReleaseNode (btreePtr, &node);
525 ++btreePtr->numValidHints;
538 err = SearchTree ( btreePtr, &searchIterator->key, treePathTable, &nodeNum, &node, &index);
557 GetRecordByIndex (btreePtr, node.buffer, index, &keyPtr, &recordPtr, &len);
579 resultIterator->hint.writeCount = btreePtr->writeCount;
591 BlockMoveData ((Ptr)keyPtr, (Ptr)&resultIterator->key, CalcKeySize(btreePtr, keyPtr));
593 BlockMoveData ((Ptr)&searchIterator->key, (Ptr)&resultIterator->key, CalcKeySize(btreePtr, &searchIterator->key));
596 err = ReleaseNode (btreePtr, &node);
656 BTreeControlBlockPtr btreePtr;
683 btreePtr = (BTreeControlBlockPtr) filePtr->fcbBTCBPtr;
684 if (btreePtr == nil)
689 REQUIRE_FILE_LOCK(btreePtr->fileRefNum, true);
705 if (operation == kBTreeFirstRecord) nodeNum = btreePtr->firstLeafNode;
706 else nodeNum = btreePtr->lastLeafNode;
714 err = GetNode (btreePtr, nodeNum, 0, &node);
720 err = ReleaseNode (btreePtr, &node);
739 err = FindIteratorPosition (btreePtr, iterator,
762 err = ReleaseNode(btreePtr, &node);
766 err = GetNode (btreePtr, nodeNum, 0, &left);
770 err = GetRightSiblingNode (btreePtr, left.buffer, &node);
779 err = ReleaseNode(btreePtr, &right);
814 err = GetNode (btreePtr, nodeNum, 0, &right);
823 err = ReleaseNode(btreePtr, &left);
848 err = GetRecordByIndex (btreePtr, node.buffer, index, &keyPtr, &recordPtr, &len);
867 iterator->hint.writeCount = btreePtr->writeCount;
886 iterator->maxLeafRecs = max(btreePtr->leafRecords, iterator->maxLeafRecs);
898 BlockMoveData ((Ptr)keyPtr, (Ptr)&iterator->key, CalcKeySize(btreePtr, keyPtr));
904 err = ReleaseNode (btreePtr, &node);
909 err = ReleaseNode (btreePtr, &left);
915 err = ReleaseNode (btreePtr, &right);
925 (void) ReleaseNode (btreePtr, &left);
926 (void) ReleaseNode (btreePtr, &node);
927 (void) ReleaseNode (btreePtr, &right);
974 BTreeControlBlockPtr btreePtr;
993 btreePtr = (BTreeControlBlockPtr) filePtr->fcbBTCBPtr;
995 REQUIRE_FILE_LOCK(btreePtr->fileRefNum, true);
1012 nodeNum = btreePtr->firstLeafNode;
1014 nodeNum = btreePtr->lastLeafNode;
1022 err = GetNode(btreePtr, nodeNum, 0, &node);
1028 err = ReleaseNode(btreePtr, &node);
1048 err = FindIteratorPosition(btreePtr, iterator, &left, &node, &right,
1073 err = ReleaseNode(btreePtr, &node);
1077 err = GetNode (btreePtr, nodeNum, 0, &left);
1081 err = GetRightSiblingNode (btreePtr, left.buffer, &node);
1090 err = ReleaseNode(btreePtr, &right);
1125 err = GetNode(btreePtr, nodeNum, 0, &right);
1134 err = ReleaseNode(btreePtr, &left);
1157 err = GetRecordByIndex(btreePtr, node.buffer, index, &keyPtr, &recordPtr, &len);
1175 err = GetNode(btreePtr, nodeNum, 0, &right);
1184 err = ReleaseNode(btreePtr, &left);
1192 err = GetRecordByIndex(btreePtr, node.buffer, index,
1206 iterator->hint.writeCount = btreePtr->writeCount;
1211 BlockMoveData((Ptr)keyPtr, (Ptr)&iterator->key, CalcKeySize(btreePtr, keyPtr));
1218 err = ReleaseNode(btreePtr, &node);
1223 err = ReleaseNode(btreePtr, &left);
1229 err = ReleaseNode(btreePtr, &right);
1239 (void) ReleaseNode(btreePtr, &left);
1240 (void) ReleaseNode(btreePtr, &node);
1241 (void) ReleaseNode(btreePtr, &right);
1267 BTreeControlBlockPtr btreePtr;
1284 btreePtr = (BTreeControlBlockPtr) filePtr->fcbBTCBPtr;
1286 REQUIRE_FILE_LOCK(btreePtr->fileRefNum, false);
1292 err = SearchTree (btreePtr, &iterator->key, treePathTable, &insertNodeNum, &nodeRec, &index);
1303 if (btreePtr->freeNodes == 0)
1305 err = ExtendBTree (btreePtr, btreePtr->totalNodes + 1);
1309 err = AllocateNode (btreePtr, &insertNodeNum);
1312 err = GetNewNode (btreePtr, insertNodeNum, &nodeRec);
1316 ModifyBlockStart(btreePtr->fileRefNum, &nodeRec);
1321 recordFit = InsertKeyRecord (btreePtr, nodeRec.buffer, 0,
1322 &iterator->key, KeyLength(btreePtr, &iterator->key),
1335 btreePtr->treeDepth = 1;
1336 btreePtr->rootNode = insertNodeNum;
1337 btreePtr->firstLeafNode = insertNodeNum;
1338 btreePtr->lastLeafNode = insertNodeNum;
1340 err = UpdateNode (btreePtr, &nodeRec, 0, kLockTransaction);
1343 M_BTreeHeaderDirty (btreePtr);
1353 ModifyBlockStart(btreePtr->fileRefNum, &nodeRec);
1355 recordFit = InsertKeyRecord (btreePtr, nodeRec.buffer, index,
1356 &iterator->key, KeyLength(btreePtr, &iterator->key),
1360 err = UpdateNode (btreePtr, &nodeRec, 0, kLockTransaction);
1369 if ((btreePtr->treeDepth + 1UL) > btreePtr->freeNodes)
1371 nodesNeeded = btreePtr->treeDepth + 1 + btreePtr->totalNodes - btreePtr->freeNodes;
1372 if (nodesNeeded > CalcMapBits (btreePtr)) // we'll need to add a map node too!
1375 err = ExtendBTree (btreePtr, nodesNeeded);
1381 err = InsertTree (btreePtr, treePathTable, &iterator->key, record->bufferAddress,
1389 ++btreePtr->writeCount;
1390 ++btreePtr->leafRecords;
1391 M_BTreeHeaderDirty (btreePtr);
1394 iterator->hint.writeCount = btreePtr->writeCount;
1407 (void) ReleaseNode (btreePtr, &nodeRec);
1430 BTreeControlBlockPtr btreePtr;
1449 btreePtr = (BTreeControlBlockPtr) filePtr->fcbBTCBPtr;
1451 REQUIRE_FILE_LOCK(btreePtr->fileRefNum, false);
1455 err = IsItAHint (btreePtr, iterator, &validHint);
1462 err = GetNode (btreePtr, insertNodeNum, kGetNodeHint, &nodeRec);
1466 ModifyBlockStart(btreePtr->fileRefNum, &nodeRec);
1468 err = TrySimpleReplace (btreePtr, nodeRec.buffer, iterator, record, recordLen, &recordFit);
1473 err = UpdateNode (btreePtr, &nodeRec, 0, 0);
1476 ++btreePtr->numValidHints;
1485 err = ReleaseNode (btreePtr, &nodeRec);
1497 err = SearchTree (btreePtr, &iterator->key, treePathTable, &insertNodeNum, &nodeRec, &index);
1504 ModifyBlockStart(btreePtr->fileRefNum, &nodeRec);
1506 err = TrySimpleReplace (btreePtr, nodeRec.buffer, iterator, record, recordLen, &recordFit);
1511 err = UpdateNode (btreePtr, &nodeRec, 0, 0);
1520 if ((btreePtr->treeDepth + 1UL) > btreePtr->freeNodes)
1522 nodesNeeded = btreePtr->treeDepth + 1 + btreePtr->totalNodes - btreePtr->freeNodes;
1523 if (nodesNeeded > CalcMapBits (btreePtr)) // we'll need to add a map node too!
1526 err = ExtendBTree (btreePtr, nodesNeeded);
1531 ModifyBlockStart(btreePtr->fileRefNum, &nodeRec);
1533 DeleteRecord (btreePtr, nodeRec.buffer, index); // delete existing key/record
1535 err = InsertTree (btreePtr, treePathTable, &iterator->key, record->bufferAddress,
1539 ++btreePtr->writeCount; /* writeCount changes only if the tree structure changed */
1543 iterator->hint.writeCount = btreePtr->writeCount;
1556 (void) ReleaseNode (btreePtr, &nodeRec);
1576 BTreeControlBlockPtr btreePtr;
1592 btreePtr = (BTreeControlBlockPtr) filePtr->fcbBTCBPtr;
1594 REQUIRE_FILE_LOCK(btreePtr->fileRefNum, true);
1598 err = IsItAHint (btreePtr, iterator, &validHint);
1605 err = GetNode (btreePtr, insertNodeNum, kGetNodeHint, &nodeRec);
1609 SearchNode (btreePtr, nodeRec.buffer, &iterator->key, &index))
1611 err = GetRecordByIndex(btreePtr, nodeRec.buffer, index, &keyPtr, &recordPtr, &recordLen);
1615 ModifyBlockStart(btreePtr->fileRefNum, &nodeRec);
1620 err = UpdateNode (btreePtr, &nodeRec, 0, 0);
1623 ++btreePtr->numValidHints;
1632 err = ReleaseNode (btreePtr, &nodeRec);
1643 err = SearchTree (btreePtr, &iterator->key, treePathTable, &insertNodeNum, &nodeRec, &index);
1646 err = GetRecordByIndex(btreePtr, nodeRec.buffer, index, &keyPtr, &recordPtr, &recordLen);
1650 ModifyBlockStart(btreePtr->fileRefNum, &nodeRec);
1655 err = UpdateNode (btreePtr, &nodeRec, 0, 0);
1660 iterator->hint.writeCount = btreePtr->writeCount;
1671 (void) ReleaseNode (btreePtr, &nodeRec);
1689 BTreeControlBlockPtr btreePtr;
1705 btreePtr = (BTreeControlBlockPtr) filePtr->fcbBTCBPtr;
1706 if (btreePtr == nil)
1712 REQUIRE_FILE_LOCK(btreePtr->fileRefNum, false);
1719 err = SearchTree (btreePtr, &iterator->key, treePathTable, &nodeNum, &nodeRec, &index);
1725 if ((btreePtr->treeDepth + 1UL) > btreePtr->totalNodes)
1727 nodesNeeded = btreePtr->treeDepth + 1 + btreePtr->totalNodes;
1728 if (nodesNeeded > CalcMapBits (btreePtr))
1731 err = ExtendBTree (btreePtr, nodesNeeded);
1737 err = DeleteTree (btreePtr, treePathTable, &nodeRec, index, 1);
1740 ++btreePtr->writeCount;
1741 --btreePtr->leafRecords;
1742 M_BTreeHeaderDirty (btreePtr);
1751 (void) ReleaseNode (btreePtr, &nodeRec);
1764 BTreeControlBlockPtr btreePtr;
1769 btreePtr = (BTreeControlBlockPtr) filePtr->fcbBTCBPtr;
1775 * REQUIRE_FILE_LOCK(btreePtr->fileRefNum, true);
1778 M_ReturnErrorIf (btreePtr == nil, fsBTInvalidFileErr);
1783 info->nodeSize = btreePtr->nodeSize;
1784 info->maxKeyLength = btreePtr->maxKeyLength;
1785 info->treeDepth = btreePtr->treeDepth;
1786 info->numRecords = btreePtr->leafRecords;
1787 info->numNodes = btreePtr->totalNodes;
1788 info->numFreeNodes = btreePtr->freeNodes;
1789 info->lastfsync = btreePtr->lastfsync;
1790 info->keyCompareType = btreePtr->keyCompareType;
1799 BTreeControlBlockPtr btreePtr;
1801 btreePtr = (BTreeControlBlockPtr) filePtr->fcbBTCBPtr;
1802 return TreeIsDirty(btreePtr);
1822 BTreeControlBlockPtr btreePtr;
1827 btreePtr = (BTreeControlBlockPtr) filePtr->fcbBTCBPtr;
1829 M_ReturnErrorIf (btreePtr == nil, fsBTInvalidFileErr);
1831 REQUIRE_FILE_LOCK(btreePtr->fileRefNum, true);
1833 err = UpdateHeader (btreePtr, false);
1859 BTreeControlBlockPtr btreePtr;
1867 btreePtr = (BTreeControlBlockPtr) filePtr->fcbBTCBPtr;
1868 if (btreePtr == nil)
1871 REQUIRE_FILE_LOCK(btreePtr->fileRefNum, false);
1873 err = GetNode(btreePtr, kHeaderNodeNum, 0, &node);
1879 btreePtr->treeDepth = header->treeDepth;
1880 btreePtr->rootNode = header->rootNode;
1881 btreePtr->leafRecords = header->leafRecords;
1882 btreePtr->firstLeafNode = header->firstLeafNode;
1883 btreePtr->lastLeafNode = header->lastLeafNode;
1884 btreePtr->maxKeyLength = header->maxKeyLength;
1885 btreePtr->totalNodes = header->totalNodes;
1886 btreePtr->freeNodes = header->freeNodes;
1887 btreePtr->btreeType = header->btreeType;
1889 btreePtr->flags &= (~kBTHeaderDirty);
1892 (void) ReleaseNode(btreePtr, &node);
1943 BTreeControlBlockPtr btreePtr;
1948 btreePtr = (BTreeControlBlockPtr) filePtr->fcbBTCBPtr;
1951 REQUIRE_FILE_LOCK(btreePtr->fileRefNum, true);
1953 M_ReturnErrorIf (btreePtr == nil, fsBTInvalidFileErr);
1956 *lastsync = btreePtr->lastfsync;
1982 BTreeControlBlockPtr btreePtr;
1987 btreePtr = (BTreeControlBlockPtr) filePtr->fcbBTCBPtr;
1990 REQUIRE_FILE_LOCK(btreePtr->fileRefNum, true);
1992 M_ReturnErrorIf (btreePtr == nil, fsBTInvalidFileErr);
1995 btreePtr->lastfsync = lastsync;
2004 BTreeControlBlockPtr btreePtr;
2009 btreePtr = (BTreeControlBlockPtr) filePtr->fcbBTCBPtr;
2011 REQUIRE_FILE_LOCK(btreePtr->fileRefNum, true);
2013 M_ReturnErrorIf (btreePtr == nil, fsBTInvalidFileErr);
2015 return NodesAreContiguous(FCBTOVCB(filePtr), filePtr, btreePtr->nodeSize);
2029 BTreeControlBlockPtr btreePtr;
2039 btreePtr = (BTreeControlBlockPtr) filePtr->fcbBTCBPtr;
2040 if (btreePtr == nil)
2043 REQUIRE_FILE_LOCK(btreePtr->fileRefNum, false);
2045 err = GetNode(btreePtr, kHeaderNodeNum, 0, &node);
2052 (void) ReleaseNode(btreePtr, &node);
2067 BTreeControlBlockPtr btreePtr;
2077 btreePtr = (BTreeControlBlockPtr) filePtr->fcbBTCBPtr;
2078 if (btreePtr == nil)
2081 REQUIRE_FILE_LOCK(btreePtr->fileRefNum, false);
2083 err = GetNode(btreePtr, kHeaderNodeNum, 0, &node);
2087 ModifyBlockStart(btreePtr->fileRefNum, &node);
2092 err = UpdateNode (btreePtr, &node, 0, 0);