-
-//ÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑ
-// Routine: MapFileBlockFromFCB
-//
-// Function: Determine if the given file offset is within the set of extents
-// stored in the FCB. If so, return the file allocation
-// block number of the start of the extent, volume allocation block number
-// of the start of the extent, and file allocation block number immediately
-// following the extent.
-//
-// Input: vcb - the volume containing the extents
-// fcb - the file that owns the extents
-// offset - desired offset in bytes
-//
-// Output: firstFABN - file alloc block number of start of extent
-// firstBlock - volume alloc block number of start of extent
-// nextFABN - file alloc block number of next extent
-//
-// Result: noErr = ok
-// fxRangeErr = beyond FCB's extents
-//ÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑ
-static OSErr MapFileBlockFromFCB(
- const ExtendedVCB *vcb,
- const FCB *fcb,
- SInt64 offset, // Desired offset in bytes from start of file
- UInt32 *firstFABN, // FABN of first block of found extent
- UInt32 *firstBlock, // Corresponding allocation block number
- UInt32 *nextFABN) // FABN of block after end of extent
-{
- UInt32 index;
- UInt32 offsetBlocks;
- SInt64 temp64;
-
- temp64 = offset / (SInt64)vcb->blockSize;
- offsetBlocks = (UInt32)temp64;
-
- if (vcb->vcbSigWord == kHFSSigWord) {
- /* XXX SER Do we need to test for overflow values ??? */
- UInt16 blockCount;
- UInt16 currentFABN;
-
- currentFABN = 0;
-
- for (index=0; index<kHFSExtentDensity; index++) {
-
- blockCount = fcb->fcbExtents[index].blockCount;
-
- if (blockCount == 0)
- return fxRangeErr; // ran out of extents!
-
- // Is it in this extent?
- if (offsetBlocks < blockCount) {
- *firstFABN = currentFABN;
- *firstBlock = fcb->fcbExtents[index].startBlock;
- currentFABN += blockCount; // faster to add these as UInt16 first, then extend to UInt32
- *nextFABN = currentFABN;
- return noErr; // found the right extent
- }
-
- // Not in current extent, so adjust counters and loop again
- offsetBlocks -= blockCount;
- currentFABN += blockCount;
- }
- }
- else {
- UInt32 blockCount;
- UInt32 currentFABN;
-
- currentFABN = 0;
-
- for (index=0; index<kHFSPlusExtentDensity; index++) {
-
- blockCount = fcb->fcbExtents[index].blockCount;
-
- if (blockCount == 0)
- return fxRangeErr; // ran out of extents!
-
- // Is it in this extent?
- if (offsetBlocks < blockCount) {
- *firstFABN = currentFABN;
- *firstBlock = fcb->fcbExtents[index].startBlock;
- *nextFABN = currentFABN + blockCount;
- return noErr; // found the right extent
- }
-
- // Not in current extent, so adjust counters and loop again
- offsetBlocks -= blockCount;
- currentFABN += blockCount;
- }
- }
-
- // If we fall through here, the extent record was full, but the offset was
- // beyond those extents.
-
- return fxRangeErr;
-}
-
-