static int FindNextLeafNode( BTScanState *scanState, Boolean avoidIO ) { int err; BlockDescriptor block; FileReference fref; err = noErr; // Assume everything will be OK while ( 1 ) { if ( scanState->nodesLeftInBuffer == 0 ) { // Time to read some more nodes into the buffer if ( avoidIO ) { return fsBTTimeOutErr; } else { // read some more nodes into buffer err = ReadMultipleNodes( scanState ); if ( err != noErr ) break; } } else { // Adjust the node counters and point to the next node in the buffer ++scanState->nodeNum; --scanState->nodesLeftInBuffer; // If we've looked at all nodes in the tree, then we're done if ( scanState->nodeNum >= scanState->btcb->totalNodes ) return fsEndOfIterationErr; if ( scanState->nodesLeftInBuffer == 0 ) { scanState->recordNum = 0; continue; } scanState->currentNodePtr = (BTNodeDescriptor *)(((u_int8_t *)scanState->currentNodePtr) + scanState->btcb->nodeSize); } /* Fake a BlockDescriptor */ block.blockHeader = NULL; /* No buffer cache buffer */ block.buffer = scanState->currentNodePtr; block.blockNum = scanState->nodeNum; block.blockSize = scanState->btcb->nodeSize; block.blockReadFromDisk = 1; block.isModified = 0; fref = scanState->btcb->fileRefNum; /* This node was read from disk, so it must be swapped/checked. * Since we are reading multiple nodes, we might have read an * unused node. Therefore we allow swapping of unused nodes. */ err = hfs_swap_BTNode(&block, fref, kSwapBTNodeBigToHost, true); if ( err != noErr ) { printf("hfs: FindNextLeafNode: Error from hfs_swap_BTNode (node %u)\n", scanState->nodeNum); continue; } if ( scanState->currentNodePtr->kind == kBTLeafNode ) break; } return err; } /* FindNextLeafNode */
static int FindNextLeafNode( BTScanState *scanState, Boolean avoidIO ) { int err; err = noErr; // Assume everything will be OK while ( 1 ) { if ( scanState->nodesLeftInBuffer == 0 ) { // Time to read some more nodes into the buffer if ( avoidIO ) { return fsBTTimeOutErr; } else { // read some more nodes into buffer err = ReadMultipleNodes( scanState ); if ( err != noErr ) break; } } else { // Adjust the node counters and point to the next node in the buffer ++scanState->nodeNum; --scanState->nodesLeftInBuffer; // If we've looked at all nodes in the tree, then we're done if ( scanState->nodeNum >= scanState->btcb->totalNodes ) return fsEndOfIterationErr; if ( scanState->nodesLeftInBuffer == 0 ) { scanState->recordNum = 0; continue; } (u_int8_t *) scanState->currentNodePtr += scanState->btcb->nodeSize; } #if BYTE_ORDER == LITTLE_ENDIAN { BlockDescriptor block; FileReference fref; /* Fake a BlockDescriptor */ block.buffer = scanState->currentNodePtr; block.blockSize = scanState->btcb->nodeSize; block.blockReadFromDisk = 1; block.isModified = 0; fref = scanState->btcb->fileRefNum; SWAP_BT_NODE(&block, ISHFSPLUS(VTOVCB(fref)), VTOC(fref)->c_fileid, 0); } #endif // Make sure this is a valid node if ( CheckNode( scanState->btcb, scanState->currentNodePtr ) != noErr ) { continue; } if ( scanState->currentNodePtr->kind == kBTLeafNode ) break; } return err; } /* FindNextLeafNode */