Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

911 lines
21 KiB

  1. /*++
  2. Copyright (c) 1990-2000 Microsoft Corporation
  3. Module Name:
  4. AllocSup.c
  5. Abstract:
  6. This module implements the Allocation support routines for Cdfs.
  7. The data structure used here is the CD_MCB. There is an entry in
  8. the Mcb for each dirent for a file. The entry will map the offset
  9. within some file to a starting disk offset and number of bytes.
  10. The Mcb also contains the interleave information for an extent.
  11. An interleave consists of a number of blocks with data and a
  12. (possibly different) number of blocks to skip. Any number of
  13. data/skip pairs may exist in an extent but the data and skip sizes
  14. are the same throughout the extent.
  15. We store the following information into an Mcb entry for an extent.
  16. FileOffset Offset in file for start of extent
  17. DiskOffset Offset on disk for start of extent
  18. ByteCount Number of file bytes in extent, no skip bytes
  19. DataBlockByteCount Number of bytes in each data block
  20. TotalBlockByteCount Number of bytes is data block and skip block
  21. The disk offset in the Mcb has already been biased by the size of
  22. the Xar block if present. All of the byte count fields are aligned
  23. on logical block boundaries. If this is a directory or path table
  24. then the file offset has been biased to round the initial disk
  25. offset down to a sector boundary. The biasing is done when loading
  26. the values into an Mcb entry.
  27. An XA file has a header prepended to the file and each sector is 2352
  28. bytes. The allocation information ignores the header and only deals
  29. with 2048 byte sectors. Callers into the allocation package have
  30. adjusted the starting offset value to reflect 2048 sectors. On return
  31. from this package the caller will have to convert from 2048 sector values
  32. into raw XA sector values.
  33. // @@BEGIN_DDKSPLIT
  34. Author:
  35. Brian Andrew [BrianAn] 01-July-1995
  36. Revision History:
  37. // @@END_DDKSPLIT
  38. --*/
  39. #include "CdProcs.h"
  40. //
  41. // The Bug check file id for this module
  42. //
  43. #define BugCheckFileId (CDFS_BUG_CHECK_ALLOCSUP)
  44. //
  45. // Local support routines
  46. //
  47. ULONG
  48. CdFindMcbEntry (
  49. IN PIRP_CONTEXT IrpContext,
  50. IN PFCB Fcb,
  51. IN LONGLONG FileOffset
  52. );
  53. VOID
  54. CdDiskOffsetFromMcbEntry (
  55. IN PIRP_CONTEXT IrpContext,
  56. IN PCD_MCB_ENTRY McbEntry,
  57. IN LONGLONG FileOffset,
  58. IN PLONGLONG DiskOffset,
  59. IN PULONG ByteCount
  60. );
  61. #ifdef ALLOC_PRAGMA
  62. #pragma alloc_text(PAGE, CdAddInitialAllocation)
  63. #pragma alloc_text(PAGE, CdAddAllocationFromDirent)
  64. #pragma alloc_text(PAGE, CdDiskOffsetFromMcbEntry)
  65. #pragma alloc_text(PAGE, CdFindMcbEntry)
  66. #pragma alloc_text(PAGE, CdInitializeMcb)
  67. #pragma alloc_text(PAGE, CdLookupAllocation)
  68. #pragma alloc_text(PAGE, CdTruncateAllocation)
  69. #pragma alloc_text(PAGE, CdUninitializeMcb)
  70. #endif
  71. VOID
  72. CdLookupAllocation (
  73. IN PIRP_CONTEXT IrpContext,
  74. IN PFCB Fcb,
  75. IN LONGLONG FileOffset,
  76. OUT PLONGLONG DiskOffset,
  77. OUT PULONG ByteCount
  78. )
  79. /*++
  80. Routine Description:
  81. This routine looks through the mapping information for the file
  82. to find the logical diskoffset and number of bytes at that offset.
  83. We only deal with logical 2048 byte sectors here.
  84. If the mapping isn't present we will look it up on disk now.
  85. This routine assumes we are looking up a valid range in the file. This
  86. routine raises if it can't find mapping for the file offset.
  87. The Fcb may not be locked prior to calling this routine. We will always
  88. acquire it here.
  89. Arguments:
  90. Fcb - Fcb representing this stream.
  91. FileOffset - Lookup the allocation beginning at this point.
  92. DiskOffset - Address to store the logical disk offset.
  93. ByteCount - Address to store the number of contiguous bytes beginning
  94. at DiskOffset above.
  95. Return Value:
  96. None.
  97. --*/
  98. {
  99. BOOLEAN FirstPass = TRUE;
  100. ULONG McbEntryOffset;
  101. PFCB ParentFcb;
  102. BOOLEAN CleanupParent = FALSE;
  103. BOOLEAN UnlockFcb = FALSE;
  104. LONGLONG CurrentFileOffset;
  105. ULONG CurrentMcbOffset;
  106. PCD_MCB_ENTRY CurrentMcbEntry;
  107. DIRENT_ENUM_CONTEXT DirContext;
  108. DIRENT Dirent;
  109. PAGED_CODE();
  110. ASSERT_IRP_CONTEXT( IrpContext );
  111. ASSERT_FCB( Fcb );
  112. //
  113. // Use a try finally to facilitate cleanup.
  114. //
  115. try {
  116. //
  117. // We use a loop to perform the lookup. If we don't find the mapping in the
  118. // first pass then we look up all of the allocation and then look again.
  119. while (TRUE) {
  120. //
  121. //
  122. // Lookup the entry containing this file offset.
  123. //
  124. CdLockFcb( IrpContext, Fcb );
  125. UnlockFcb = TRUE;
  126. McbEntryOffset = CdFindMcbEntry( IrpContext, Fcb, FileOffset );
  127. //
  128. // If within the Mcb then we use the data out of this entry and are
  129. // done.
  130. //
  131. if (McbEntryOffset < Fcb->Mcb.CurrentEntryCount) {
  132. CdDiskOffsetFromMcbEntry( IrpContext,
  133. Fcb->Mcb.McbArray + McbEntryOffset,
  134. FileOffset,
  135. DiskOffset,
  136. ByteCount );
  137. break;
  138. //
  139. // If this is not the first pass then the disk is corrupt.
  140. //
  141. } else if (!FirstPass) {
  142. CdRaiseStatus( IrpContext, STATUS_DISK_CORRUPT_ERROR );
  143. }
  144. CdUnlockFcb( IrpContext, Fcb );
  145. UnlockFcb = FALSE;
  146. //
  147. // Initialize the search dirent structures.
  148. //
  149. CdInitializeDirContext( IrpContext, &DirContext );
  150. CdInitializeDirent( IrpContext, &Dirent );
  151. //
  152. // Otherwise we need to walk the dirents for this file until we find
  153. // the one containing this entry. The parent Fcb should always be
  154. // present.
  155. //
  156. ParentFcb = Fcb->ParentFcb;
  157. CdAcquireFileShared( IrpContext, ParentFcb );
  158. CleanupParent = TRUE;
  159. //
  160. // Do an unsafe test to see if we need to create a file object.
  161. //
  162. if (ParentFcb->FileObject == NULL) {
  163. CdCreateInternalStream( IrpContext, ParentFcb->Vcb, ParentFcb );
  164. }
  165. //
  166. // Initialize the local variables to indicate the first dirent
  167. // and lookup the first dirent.
  168. //
  169. CurrentFileOffset = 0;
  170. CurrentMcbOffset = 0;
  171. CdLookupDirent( IrpContext,
  172. ParentFcb,
  173. CdQueryFidDirentOffset( Fcb->FileId ),
  174. &DirContext );
  175. //
  176. // If we are adding allocation to the Mcb then add all of it.
  177. //
  178. while (TRUE ) {
  179. //
  180. // Update the dirent from the on-disk dirent.
  181. //
  182. CdUpdateDirentFromRawDirent( IrpContext, ParentFcb, &DirContext, &Dirent );
  183. //
  184. // Add this dirent to the Mcb if not already present.
  185. //
  186. CdLockFcb( IrpContext, Fcb );
  187. UnlockFcb = TRUE;
  188. if (CurrentMcbOffset >= Fcb->Mcb.CurrentEntryCount) {
  189. CdAddAllocationFromDirent( IrpContext, Fcb, CurrentMcbOffset, CurrentFileOffset, &Dirent );
  190. }
  191. CdUnlockFcb( IrpContext, Fcb );
  192. UnlockFcb = FALSE;
  193. //
  194. // If this is the last dirent for the file then exit.
  195. //
  196. if (!FlagOn( Dirent.DirentFlags, CD_ATTRIBUTE_MULTI )) {
  197. break;
  198. }
  199. //
  200. // If we couldn't find another entry then the directory is corrupt because
  201. // the last dirent for a file doesn't exist.
  202. //
  203. if (!CdLookupNextDirent( IrpContext, ParentFcb, &DirContext, &DirContext )) {
  204. CdRaiseStatus( IrpContext, STATUS_DISK_CORRUPT_ERROR );
  205. }
  206. //
  207. // Update our loop variables.
  208. //
  209. CurrentMcbEntry = Fcb->Mcb.McbArray + CurrentMcbOffset;
  210. CurrentFileOffset += CurrentMcbEntry->ByteCount;
  211. CurrentMcbOffset += 1;
  212. }
  213. //
  214. // All of the allocation is loaded. Go back and look up the mapping again.
  215. // It better be there this time.
  216. //
  217. FirstPass = FALSE;
  218. }
  219. } finally {
  220. if (CleanupParent) {
  221. //
  222. // Release the parent and cleanup the dirent structures.
  223. //
  224. CdReleaseFile( IrpContext, ParentFcb );
  225. CdCleanupDirContext( IrpContext, &DirContext );
  226. CdCleanupDirent( IrpContext, &Dirent );
  227. }
  228. if (UnlockFcb) { CdUnlockFcb( IrpContext, Fcb ); }
  229. }
  230. return;
  231. }
  232. VOID
  233. CdAddAllocationFromDirent (
  234. IN PIRP_CONTEXT IrpContext,
  235. IN PFCB Fcb,
  236. IN ULONG McbEntryOffset,
  237. IN LONGLONG StartingFileOffset,
  238. IN PDIRENT Dirent
  239. )
  240. /*++
  241. Routine Description:
  242. This routine is called to add an entry into the Cd Mcb. We grow the Mcb
  243. as necessary and update the new entry.
  244. NOTE - The Fcb has already been locked prior to makeing this call.
  245. Arguments:
  246. Fcb - Fcb containing the Mcb to update.
  247. McbEntryOffset - Offset into the Mcb array to add this data.
  248. StartingFileOffset - Offset in bytes from the start of the file.
  249. Dirent - Dirent containing the on-disk data for this entry.
  250. Return Value:
  251. None
  252. --*/
  253. {
  254. ULONG NewArraySize;
  255. PVOID NewMcbArray;
  256. PCD_MCB_ENTRY McbEntry;
  257. PAGED_CODE();
  258. ASSERT_IRP_CONTEXT( IrpContext );
  259. ASSERT_FCB( Fcb );
  260. ASSERT_LOCKED_FCB( Fcb );
  261. //
  262. // If we need to grow the Mcb then do it now.
  263. //
  264. if (McbEntryOffset >= Fcb->Mcb.MaximumEntryCount) {
  265. //
  266. // Allocate a new buffer and copy the old data over.
  267. //
  268. NewArraySize = Fcb->Mcb.MaximumEntryCount * 2 * sizeof( CD_MCB_ENTRY );
  269. NewMcbArray = FsRtlAllocatePoolWithTag( CdPagedPool,
  270. NewArraySize,
  271. TAG_MCB_ARRAY );
  272. RtlZeroMemory( NewMcbArray, NewArraySize );
  273. RtlCopyMemory( NewMcbArray,
  274. Fcb->Mcb.McbArray,
  275. Fcb->Mcb.MaximumEntryCount * sizeof( CD_MCB_ENTRY ));
  276. //
  277. // Deallocate the current array unless it is embedded in the Fcb.
  278. //
  279. if (Fcb->Mcb.MaximumEntryCount != 1) {
  280. ExFreePool( Fcb->Mcb.McbArray );
  281. }
  282. //
  283. // Now update the Mcb with the new array.
  284. //
  285. Fcb->Mcb.MaximumEntryCount *= 2;
  286. Fcb->Mcb.McbArray = NewMcbArray;
  287. }
  288. //
  289. // Update the new entry with the input data.
  290. //
  291. McbEntry = Fcb->Mcb.McbArray + McbEntryOffset;
  292. //
  293. // Start with the location and length on disk.
  294. //
  295. McbEntry->DiskOffset = LlBytesFromBlocks( Fcb->Vcb, Dirent->StartingOffset );
  296. McbEntry->ByteCount = Dirent->DataLength;
  297. //
  298. // Round the byte count up to a logical block boundary if this is
  299. // the last extent.
  300. //
  301. if (!FlagOn( Dirent->DirentFlags, CD_ATTRIBUTE_MULTI )) {
  302. McbEntry->ByteCount = BlockAlign( Fcb->Vcb, McbEntry->ByteCount );
  303. }
  304. //
  305. // The file offset is the logical position within this file.
  306. // We know this is correct regardless of whether we bias the
  307. // file size or disk offset.
  308. //
  309. McbEntry->FileOffset = StartingFileOffset;
  310. //
  311. // Convert the interleave information from logical blocks to
  312. // bytes.
  313. //
  314. if (Dirent->FileUnitSize != 0) {
  315. McbEntry->DataBlockByteCount = BytesFromBlocks( Fcb->Vcb, Dirent->FileUnitSize );
  316. McbEntry->TotalBlockByteCount = McbEntry->DataBlockByteCount +
  317. BytesFromBlocks( Fcb->Vcb, Dirent->InterleaveGapSize );
  318. //
  319. // If the file is not interleaved then the size of the data block
  320. // and total block are the same as the byte count.
  321. //
  322. } else {
  323. McbEntry->DataBlockByteCount =
  324. McbEntry->TotalBlockByteCount = McbEntry->ByteCount;
  325. }
  326. //
  327. // Update the number of entries in the Mcb. The Mcb is never sparse
  328. // so whenever we add an entry it becomes the last entry in the Mcb.
  329. //
  330. Fcb->Mcb.CurrentEntryCount = McbEntryOffset + 1;
  331. return;
  332. }
  333. VOID
  334. CdAddInitialAllocation (
  335. IN PIRP_CONTEXT IrpContext,
  336. IN PFCB Fcb,
  337. IN ULONG StartingBlock,
  338. IN LONGLONG DataLength
  339. )
  340. /*++
  341. Routine Description:
  342. This routine is called to set up the initial entry in an Mcb.
  343. This routine handles the single initial entry for a directory file. We will
  344. round the start block down to a sector boundary. Our caller has already
  345. biased the DataLength with any adjustments. This is used for the case
  346. where there is a single entry and we want to align the data on a sector
  347. boundary.
  348. Arguments:
  349. Fcb - Fcb containing the Mcb to update.
  350. StartingBlock - Starting logical block for this directory. This is
  351. the start of the actual data. We will bias this by the sector
  352. offset of the data.
  353. DataLength - Length of the data.
  354. Return Value:
  355. None
  356. --*/
  357. {
  358. PCD_MCB_ENTRY McbEntry;
  359. PAGED_CODE();
  360. ASSERT_IRP_CONTEXT( IrpContext );
  361. ASSERT_FCB( Fcb );
  362. ASSERT_LOCKED_FCB( Fcb );
  363. ASSERT( 0 == Fcb->Mcb.CurrentEntryCount);
  364. ASSERT( CDFS_NTC_FCB_DATA != Fcb->NodeTypeCode);
  365. //
  366. // Update the new entry with the input data.
  367. //
  368. McbEntry = Fcb->Mcb.McbArray;
  369. //
  370. // Start with the location and length on disk.
  371. //
  372. McbEntry->DiskOffset = LlBytesFromBlocks( Fcb->Vcb, StartingBlock );
  373. McbEntry->DiskOffset -= Fcb->StreamOffset;
  374. McbEntry->ByteCount = DataLength;
  375. //
  376. // The file offset is the logical position within this file.
  377. // We know this is correct regardless of whether we bias the
  378. // file size or disk offset.
  379. //
  380. McbEntry->FileOffset = 0;
  381. //
  382. // If the file is not interleaved then the size of the data block
  383. // and total block are the same as the byte count.
  384. //
  385. McbEntry->DataBlockByteCount =
  386. McbEntry->TotalBlockByteCount = McbEntry->ByteCount;
  387. //
  388. // Update the number of entries in the Mcb. The Mcb is never sparse
  389. // so whenever we add an entry it becomes the last entry in the Mcb.
  390. //
  391. Fcb->Mcb.CurrentEntryCount = 1;
  392. return;
  393. }
  394. VOID
  395. CdTruncateAllocation (
  396. IN PIRP_CONTEXT IrpContext,
  397. IN PFCB Fcb,
  398. IN LONGLONG StartingFileOffset
  399. )
  400. /*++
  401. Routine Description:
  402. This routine truncates the Mcb for a file by eliminating all of the Mcb
  403. entries from the entry which contains the given offset.
  404. The Fcb should be locked when this routine is called.
  405. Arguments:
  406. Fcb - Fcb containing the Mcb to truncate.
  407. StartingFileOffset - Offset in the file to truncate the Mcb from.
  408. Return Value:
  409. None
  410. --*/
  411. {
  412. ULONG McbEntryOffset;
  413. PAGED_CODE();
  414. ASSERT_IRP_CONTEXT( IrpContext );
  415. ASSERT_FCB( Fcb );
  416. ASSERT_LOCKED_FCB( Fcb );
  417. //
  418. // Find the entry containg this starting offset.
  419. //
  420. McbEntryOffset = CdFindMcbEntry( IrpContext, Fcb, StartingFileOffset );
  421. //
  422. // Now set the current size of the mcb to this point.
  423. //
  424. Fcb->Mcb.CurrentEntryCount = McbEntryOffset;
  425. return;
  426. }
  427. VOID
  428. CdInitializeMcb (
  429. IN PIRP_CONTEXT IrpContext,
  430. IN PFCB Fcb
  431. )
  432. /*++
  433. Routine Description:
  434. This routine is called to initialize the Mcb in an Fcb. We initialize
  435. this with an entry count of one and point to the entry in the Fcb
  436. itself.
  437. Fcb should be acquired exclusively when this is called.
  438. Arguments:
  439. Fcb - Fcb containing the Mcb to initialize.
  440. Return Value:
  441. None
  442. --*/
  443. {
  444. PAGED_CODE();
  445. ASSERT_IRP_CONTEXT( IrpContext );
  446. ASSERT_FCB( Fcb );
  447. //
  448. // Set the entry counts to show there is one entry in the array and
  449. // it is unused.
  450. //
  451. Fcb->Mcb.MaximumEntryCount = 1;
  452. Fcb->Mcb.CurrentEntryCount = 0;
  453. Fcb->Mcb.McbArray = &Fcb->McbEntry;
  454. return;
  455. }
  456. VOID
  457. CdUninitializeMcb (
  458. IN PIRP_CONTEXT IrpContext,
  459. IN PFCB Fcb
  460. )
  461. /*++
  462. Routine Description:
  463. This routine is called to cleanup an Mcb in an Fcb. We look at the
  464. maximum run count in the Fcb and if greater than one we will deallocate
  465. the buffer.
  466. Fcb should be acquired exclusively when this is called.
  467. Arguments:
  468. Fcb - Fcb containing the Mcb to uninitialize.
  469. Return Value:
  470. None
  471. --*/
  472. {
  473. PAGED_CODE();
  474. ASSERT_IRP_CONTEXT( IrpContext );
  475. ASSERT_FCB( Fcb );
  476. //
  477. // If the count is greater than one then this is an allocated buffer.
  478. //
  479. if (Fcb->Mcb.MaximumEntryCount > 1) {
  480. ExFreePool( Fcb->Mcb.McbArray );
  481. }
  482. return;
  483. }
  484. //
  485. // Local suupport routine
  486. //
  487. ULONG
  488. CdFindMcbEntry (
  489. IN PIRP_CONTEXT IrpContext,
  490. IN PFCB Fcb,
  491. IN LONGLONG FileOffset
  492. )
  493. /*++
  494. Routine Description:
  495. This routine is called to find the Mcb entry which contains the file
  496. offset at the given point. If the file offset is not currently in the
  497. Mcb then we return the offset of the entry to add.
  498. Fcb should be locked when this is called.
  499. Arguments:
  500. Fcb - Fcb containing the Mcb to uninitialize.
  501. FileOffset - Return the Mcb entry which contains this file offset.
  502. Return Value:
  503. ULONG - Offset in the Mcb of the entry for this offset.
  504. --*/
  505. {
  506. ULONG CurrentMcbOffset;
  507. PCD_MCB_ENTRY CurrentMcbEntry;
  508. PAGED_CODE();
  509. ASSERT_IRP_CONTEXT( IrpContext );
  510. ASSERT_FCB( Fcb );
  511. ASSERT_LOCKED_FCB( Fcb );
  512. //
  513. // We expect a linear search will be sufficient here.
  514. //
  515. CurrentMcbOffset = 0;
  516. CurrentMcbEntry = Fcb->Mcb.McbArray;
  517. while (CurrentMcbOffset < Fcb->Mcb.CurrentEntryCount) {
  518. //
  519. // Check if the offset lies within the current Mcb position.
  520. //
  521. if (FileOffset < CurrentMcbEntry->FileOffset + CurrentMcbEntry->ByteCount) {
  522. break;
  523. }
  524. //
  525. // Move to the next entry.
  526. //
  527. CurrentMcbOffset += 1;
  528. CurrentMcbEntry += 1;
  529. }
  530. //
  531. // This is the offset containing this file offset (or the point
  532. // where an entry should be added).
  533. //
  534. return CurrentMcbOffset;
  535. }
  536. //
  537. // Local support routine
  538. //
  539. VOID
  540. CdDiskOffsetFromMcbEntry (
  541. IN PIRP_CONTEXT IrpContext,
  542. IN PCD_MCB_ENTRY McbEntry,
  543. IN LONGLONG FileOffset,
  544. IN PLONGLONG DiskOffset,
  545. IN PULONG ByteCount
  546. )
  547. /*++
  548. Routine Description:
  549. This routine is called to return the diskoffset and length of the file
  550. data which begins at offset 'FileOffset'. We have the Mcb entry which
  551. contains the mapping and interleave information.
  552. NOTE - This routine deals with data in 2048 byte logical sectors. If
  553. this is an XA file then our caller has already converted from
  554. 'raw' file bytes to 'cooked' file bytes.
  555. Arguments:
  556. McbEntry - Entry in the Mcb containing the allocation information.
  557. FileOffset - Starting Offset in the file to find the matching disk
  558. offsets.
  559. DiskOffset - Address to store the starting disk offset for this operation.
  560. ByteCount - Address to store number of contiguous bytes starting at this
  561. disk offset.
  562. Return Value:
  563. None
  564. --*/
  565. {
  566. LONGLONG ExtentOffset;
  567. LONGLONG CurrentDiskOffset;
  568. LONGLONG CurrentExtentOffset;
  569. LONGLONG LocalByteCount;
  570. PAGED_CODE();
  571. ASSERT_IRP_CONTEXT( IrpContext );
  572. //
  573. // Extent offset is the difference between the file offset and the start
  574. // of the extent.
  575. //
  576. ExtentOffset = FileOffset - McbEntry->FileOffset;
  577. //
  578. // Optimize the non-interleave case.
  579. //
  580. if (McbEntry->ByteCount == McbEntry->TotalBlockByteCount) {
  581. *DiskOffset = McbEntry->DiskOffset + ExtentOffset;
  582. LocalByteCount = McbEntry->ByteCount - ExtentOffset;
  583. } else {
  584. //
  585. // Walk though any interleave until we reach the current offset in
  586. // this extent.
  587. //
  588. CurrentExtentOffset = McbEntry->DataBlockByteCount;
  589. CurrentDiskOffset = McbEntry->DiskOffset;
  590. while (CurrentExtentOffset <= ExtentOffset) {
  591. CurrentDiskOffset += McbEntry->TotalBlockByteCount;
  592. CurrentExtentOffset += McbEntry->DataBlockByteCount;
  593. }
  594. //
  595. // We are now positioned at the data block containing the starting
  596. // file offset we were given. The disk offset is the offset of
  597. // the start of this block plus the extent offset into this block.
  598. // The byte count is the data block byte count minus our offset into
  599. // this block.
  600. //
  601. *DiskOffset = CurrentDiskOffset + (ExtentOffset + McbEntry->DataBlockByteCount - CurrentExtentOffset);
  602. //
  603. // Make sure we aren't past the end of the data length. This is possible
  604. // if we only use part of the last data block on an interleaved file.
  605. //
  606. if (CurrentExtentOffset > McbEntry->ByteCount) {
  607. CurrentExtentOffset = McbEntry->ByteCount;
  608. }
  609. LocalByteCount = CurrentExtentOffset - ExtentOffset;
  610. }
  611. //
  612. // If the byte count exceeds our limit then cut it to fit in 32 bits.
  613. //
  614. if (LocalByteCount > MAXULONG) {
  615. *ByteCount = MAXULONG;
  616. } else {
  617. *ByteCount = (ULONG) LocalByteCount;
  618. }
  619. return;
  620. }