[CDFS_NEW] _SEH2_FINALLY implement SEH support for real instead of its current stub.
[reactos.git] / drivers / filesystems / cdfs_new / allocsup.c
1 /*++
2
3 Copyright (c) 1990-2000 Microsoft Corporation
4
5 Module Name:
6
7 AllocSup.c
8
9 Abstract:
10
11 This module implements the Allocation support routines for Cdfs.
12
13 The data structure used here is the CD_MCB. There is an entry in
14 the Mcb for each dirent for a file. The entry will map the offset
15 within some file to a starting disk offset and number of bytes.
16 The Mcb also contains the interleave information for an extent.
17 An interleave consists of a number of blocks with data and a
18 (possibly different) number of blocks to skip. Any number of
19 data/skip pairs may exist in an extent but the data and skip sizes
20 are the same throughout the extent.
21
22 We store the following information into an Mcb entry for an extent.
23
24 FileOffset Offset in file for start of extent
25 DiskOffset Offset on disk for start of extent
26 ByteCount Number of file bytes in extent, no skip bytes
27 DataBlockByteCount Number of bytes in each data block
28 TotalBlockByteCount Number of bytes is data block and skip block
29
30 The disk offset in the Mcb has already been biased by the size of
31 the Xar block if present. All of the byte count fields are aligned
32 on logical block boundaries. If this is a directory or path table
33 then the file offset has been biased to round the initial disk
34 offset down to a sector boundary. The biasing is done when loading
35 the values into an Mcb entry.
36
37 An XA file has a header prepended to the file and each sector is 2352
38 bytes. The allocation information ignores the header and only deals
39 with 2048 byte sectors. Callers into the allocation package have
40 adjusted the starting offset value to reflect 2048 sectors. On return
41 from this package the caller will have to convert from 2048 sector values
42 into raw XA sector values.
43
44
45 --*/
46
47 #include "cdprocs.h"
48
49 //
50 // The Bug check file id for this module
51 //
52
53 #define BugCheckFileId (CDFS_BUG_CHECK_ALLOCSUP)
54
55 //
56 // Local support routines
57 //
58
59 ULONG
60 CdFindMcbEntry (
61 IN PIRP_CONTEXT IrpContext,
62 IN PFCB Fcb,
63 IN LONGLONG FileOffset
64 );
65
66 VOID
67 CdDiskOffsetFromMcbEntry (
68 IN PIRP_CONTEXT IrpContext,
69 IN PCD_MCB_ENTRY McbEntry,
70 IN LONGLONG FileOffset,
71 IN PLONGLONG DiskOffset,
72 IN PULONG ByteCount
73 );
74
75 #ifdef ALLOC_PRAGMA
76 #pragma alloc_text(PAGE, CdAddInitialAllocation)
77 #pragma alloc_text(PAGE, CdAddAllocationFromDirent)
78 #pragma alloc_text(PAGE, CdDiskOffsetFromMcbEntry)
79 #pragma alloc_text(PAGE, CdFindMcbEntry)
80 #pragma alloc_text(PAGE, CdInitializeMcb)
81 #pragma alloc_text(PAGE, CdLookupAllocation)
82 #pragma alloc_text(PAGE, CdTruncateAllocation)
83 #pragma alloc_text(PAGE, CdUninitializeMcb)
84 #endif
85
86 \f
87 VOID
88 CdLookupAllocation (
89 IN PIRP_CONTEXT IrpContext,
90 IN PFCB Fcb,
91 IN LONGLONG FileOffset,
92 OUT PLONGLONG DiskOffset,
93 OUT PULONG ByteCount
94 )
95
96 /*++
97
98 Routine Description:
99
100 This routine looks through the mapping information for the file
101 to find the logical diskoffset and number of bytes at that offset.
102 We only deal with logical 2048 byte sectors here.
103
104 If the mapping isn't present we will look it up on disk now.
105 This routine assumes we are looking up a valid range in the file. This
106 routine raises if it can't find mapping for the file offset.
107
108 The Fcb may not be locked prior to calling this routine. We will always
109 acquire it here.
110
111 Arguments:
112
113 Fcb - Fcb representing this stream.
114
115 FileOffset - Lookup the allocation beginning at this point.
116
117 DiskOffset - Address to store the logical disk offset.
118
119 ByteCount - Address to store the number of contiguous bytes beginning
120 at DiskOffset above.
121
122 Return Value:
123
124 None.
125
126 --*/
127
128 {
129 BOOLEAN FirstPass = TRUE;
130 ULONG McbEntryOffset;
131 PFCB ParentFcb = NULL; /* ReactOS Change: GCC uninitialized variable bug */
132 BOOLEAN CleanupParent = FALSE;
133
134 BOOLEAN UnlockFcb = FALSE;
135
136 LONGLONG CurrentFileOffset;
137 ULONG CurrentMcbOffset;
138 PCD_MCB_ENTRY CurrentMcbEntry;
139
140 DIRENT_ENUM_CONTEXT DirContext;
141 DIRENT Dirent;
142
143 PAGED_CODE();
144
145 ASSERT_IRP_CONTEXT( IrpContext );
146 ASSERT_FCB( Fcb );
147
148 //
149 // Use a try finally to facilitate cleanup.
150 //
151
152 _SEH2_TRY {
153
154 //
155 // We use a loop to perform the lookup. If we don't find the mapping in the
156 // first pass then we look up all of the allocation and then look again.
157
158 while (TRUE) {
159
160 //
161 //
162 // Lookup the entry containing this file offset.
163 //
164
165 CdLockFcb( IrpContext, Fcb );
166 UnlockFcb = TRUE;
167
168 McbEntryOffset = CdFindMcbEntry( IrpContext, Fcb, FileOffset );
169
170 //
171 // If within the Mcb then we use the data out of this entry and are
172 // done.
173 //
174
175 if (McbEntryOffset < Fcb->Mcb.CurrentEntryCount) {
176
177 CdDiskOffsetFromMcbEntry( IrpContext,
178 Fcb->Mcb.McbArray + McbEntryOffset,
179 FileOffset,
180 DiskOffset,
181 ByteCount );
182
183 break;
184
185 //
186 // If this is not the first pass then the disk is corrupt.
187 //
188
189 } else if (!FirstPass) {
190
191 CdRaiseStatus( IrpContext, STATUS_DISK_CORRUPT_ERROR );
192 }
193
194 CdUnlockFcb( IrpContext, Fcb );
195 UnlockFcb = FALSE;
196
197 //
198 // Initialize the search dirent structures.
199 //
200
201 CdInitializeDirContext( IrpContext, &DirContext );
202 CdInitializeDirent( IrpContext, &Dirent );
203
204 //
205 // Otherwise we need to walk the dirents for this file until we find
206 // the one containing this entry. The parent Fcb should always be
207 // present.
208 //
209
210 ParentFcb = Fcb->ParentFcb;
211 CdAcquireFileShared( IrpContext, ParentFcb );
212 CleanupParent = TRUE;
213
214 //
215 // Do an unsafe test to see if we need to create a file object.
216 //
217
218 if (ParentFcb->FileObject == NULL) {
219
220 CdCreateInternalStream( IrpContext, ParentFcb->Vcb, ParentFcb );
221 }
222
223 //
224 // Initialize the local variables to indicate the first dirent
225 // and lookup the first dirent.
226 //
227
228 CurrentFileOffset = 0;
229 CurrentMcbOffset = 0;
230
231 CdLookupDirent( IrpContext,
232 ParentFcb,
233 CdQueryFidDirentOffset( Fcb->FileId ),
234 &DirContext );
235
236 //
237 // If we are adding allocation to the Mcb then add all of it.
238 //
239
240 while (TRUE ) {
241
242 //
243 // Update the dirent from the on-disk dirent.
244 //
245
246 CdUpdateDirentFromRawDirent( IrpContext, ParentFcb, &DirContext, &Dirent );
247
248 //
249 // Add this dirent to the Mcb if not already present.
250 //
251
252 CdLockFcb( IrpContext, Fcb );
253 UnlockFcb = TRUE;
254
255 if (CurrentMcbOffset >= Fcb->Mcb.CurrentEntryCount) {
256
257 CdAddAllocationFromDirent( IrpContext, Fcb, CurrentMcbOffset, CurrentFileOffset, &Dirent );
258 }
259
260 CdUnlockFcb( IrpContext, Fcb );
261 UnlockFcb = FALSE;
262
263 //
264 // If this is the last dirent for the file then exit.
265 //
266
267 if (!FlagOn( Dirent.DirentFlags, CD_ATTRIBUTE_MULTI )) {
268
269 break;
270 }
271
272 //
273 // If we couldn't find another entry then the directory is corrupt because
274 // the last dirent for a file doesn't exist.
275 //
276
277 if (!CdLookupNextDirent( IrpContext, ParentFcb, &DirContext, &DirContext )) {
278
279 CdRaiseStatus( IrpContext, STATUS_DISK_CORRUPT_ERROR );
280 }
281
282 //
283 // Update our loop variables.
284 //
285
286 CurrentMcbEntry = Fcb->Mcb.McbArray + CurrentMcbOffset;
287 CurrentFileOffset += CurrentMcbEntry->ByteCount;
288 CurrentMcbOffset += 1;
289 }
290
291 //
292 // All of the allocation is loaded. Go back and look up the mapping again.
293 // It better be there this time.
294 //
295
296 FirstPass = FALSE;
297 }
298
299 } _SEH2_FINALLY {
300
301 if (CleanupParent) {
302
303 //
304 // Release the parent and cleanup the dirent structures.
305 //
306
307 CdReleaseFile( IrpContext, ParentFcb );
308
309 CdCleanupDirContext( IrpContext, &DirContext );
310 CdCleanupDirent( IrpContext, &Dirent );
311 }
312
313 if (UnlockFcb) { CdUnlockFcb( IrpContext, Fcb ); }
314 } _SEH2_END;
315
316 return;
317 }
318
319 \f
320 VOID
321 CdAddAllocationFromDirent (
322 IN PIRP_CONTEXT IrpContext,
323 IN PFCB Fcb,
324 IN ULONG McbEntryOffset,
325 IN LONGLONG StartingFileOffset,
326 IN PDIRENT Dirent
327 )
328
329 /*++
330
331 Routine Description:
332
333 This routine is called to add an entry into the Cd Mcb. We grow the Mcb
334 as necessary and update the new entry.
335
336 NOTE - The Fcb has already been locked prior to makeing this call.
337
338 Arguments:
339
340 Fcb - Fcb containing the Mcb to update.
341
342 McbEntryOffset - Offset into the Mcb array to add this data.
343
344 StartingFileOffset - Offset in bytes from the start of the file.
345
346 Dirent - Dirent containing the on-disk data for this entry.
347
348 Return Value:
349
350 None
351
352 --*/
353
354 {
355 ULONG NewArraySize;
356 PVOID NewMcbArray;
357 PCD_MCB_ENTRY McbEntry;
358
359 PAGED_CODE();
360
361 ASSERT_IRP_CONTEXT( IrpContext );
362 ASSERT_FCB( Fcb );
363 ASSERT_LOCKED_FCB( Fcb );
364
365 //
366 // If we need to grow the Mcb then do it now.
367 //
368
369 if (McbEntryOffset >= Fcb->Mcb.MaximumEntryCount) {
370
371 //
372 // Allocate a new buffer and copy the old data over.
373 //
374
375 NewArraySize = Fcb->Mcb.MaximumEntryCount * 2 * sizeof( CD_MCB_ENTRY );
376
377 NewMcbArray = FsRtlAllocatePoolWithTag( CdPagedPool,
378 NewArraySize,
379 TAG_MCB_ARRAY );
380
381 RtlZeroMemory( NewMcbArray, NewArraySize );
382 RtlCopyMemory( NewMcbArray,
383 Fcb->Mcb.McbArray,
384 Fcb->Mcb.MaximumEntryCount * sizeof( CD_MCB_ENTRY ));
385
386 //
387 // Deallocate the current array unless it is embedded in the Fcb.
388 //
389
390 if (Fcb->Mcb.MaximumEntryCount != 1) {
391
392 CdFreePool( &Fcb->Mcb.McbArray );
393 }
394
395 //
396 // Now update the Mcb with the new array.
397 //
398
399 Fcb->Mcb.MaximumEntryCount *= 2;
400 Fcb->Mcb.McbArray = NewMcbArray;
401 }
402
403 //
404 // Update the new entry with the input data.
405 //
406
407 McbEntry = Fcb->Mcb.McbArray + McbEntryOffset;
408
409 //
410 // Start with the location and length on disk.
411 //
412
413 McbEntry->DiskOffset = LlBytesFromBlocks( Fcb->Vcb, Dirent->StartingOffset );
414 McbEntry->ByteCount = Dirent->DataLength;
415
416 //
417 // Round the byte count up to a logical block boundary if this is
418 // the last extent.
419 //
420
421 if (!FlagOn( Dirent->DirentFlags, CD_ATTRIBUTE_MULTI )) {
422
423 McbEntry->ByteCount = BlockAlign( Fcb->Vcb, McbEntry->ByteCount );
424 }
425
426 //
427 // The file offset is the logical position within this file.
428 // We know this is correct regardless of whether we bias the
429 // file size or disk offset.
430 //
431
432 McbEntry->FileOffset = StartingFileOffset;
433
434 //
435 // Convert the interleave information from logical blocks to
436 // bytes.
437 //
438
439 if (Dirent->FileUnitSize != 0) {
440
441 McbEntry->DataBlockByteCount = LlBytesFromBlocks( Fcb->Vcb, Dirent->FileUnitSize );
442 McbEntry->TotalBlockByteCount = McbEntry->DataBlockByteCount +
443 LlBytesFromBlocks( Fcb->Vcb, Dirent->InterleaveGapSize );
444
445 //
446 // If the file is not interleaved then the size of the data block
447 // and total block are the same as the byte count.
448 //
449
450 } else {
451
452 McbEntry->DataBlockByteCount =
453 McbEntry->TotalBlockByteCount = McbEntry->ByteCount;
454 }
455
456 //
457 // Update the number of entries in the Mcb. The Mcb is never sparse
458 // so whenever we add an entry it becomes the last entry in the Mcb.
459 //
460
461 Fcb->Mcb.CurrentEntryCount = McbEntryOffset + 1;
462
463 return;
464 }
465
466 \f
467 VOID
468 CdAddInitialAllocation (
469 IN PIRP_CONTEXT IrpContext,
470 IN PFCB Fcb,
471 IN ULONG StartingBlock,
472 IN LONGLONG DataLength
473 )
474
475 /*++
476
477 Routine Description:
478
479 This routine is called to set up the initial entry in an Mcb.
480
481 This routine handles the single initial entry for a directory file. We will
482 round the start block down to a sector boundary. Our caller has already
483 biased the DataLength with any adjustments. This is used for the case
484 where there is a single entry and we want to align the data on a sector
485 boundary.
486
487 Arguments:
488
489 Fcb - Fcb containing the Mcb to update.
490
491 StartingBlock - Starting logical block for this directory. This is
492 the start of the actual data. We will bias this by the sector
493 offset of the data.
494
495 DataLength - Length of the data.
496
497 Return Value:
498
499 None
500
501 --*/
502
503 {
504 PCD_MCB_ENTRY McbEntry;
505
506 PAGED_CODE();
507
508 ASSERT_IRP_CONTEXT( IrpContext );
509 ASSERT_FCB( Fcb );
510 ASSERT_LOCKED_FCB( Fcb );
511 ASSERT( 0 == Fcb->Mcb.CurrentEntryCount);
512 ASSERT( CDFS_NTC_FCB_DATA != Fcb->NodeTypeCode);
513
514 //
515 // Update the new entry with the input data.
516 //
517
518 McbEntry = Fcb->Mcb.McbArray;
519
520 //
521 // Start with the location and length on disk.
522 //
523
524 McbEntry->DiskOffset = LlBytesFromBlocks( Fcb->Vcb, StartingBlock );
525 McbEntry->DiskOffset -= Fcb->StreamOffset;
526
527 McbEntry->ByteCount = DataLength;
528
529 //
530 // The file offset is the logical position within this file.
531 // We know this is correct regardless of whether we bias the
532 // file size or disk offset.
533 //
534
535 McbEntry->FileOffset = 0;
536
537 //
538 // If the file is not interleaved then the size of the data block
539 // and total block are the same as the byte count.
540 //
541
542 McbEntry->DataBlockByteCount =
543 McbEntry->TotalBlockByteCount = McbEntry->ByteCount;
544
545 //
546 // Update the number of entries in the Mcb. The Mcb is never sparse
547 // so whenever we add an entry it becomes the last entry in the Mcb.
548 //
549
550 Fcb->Mcb.CurrentEntryCount = 1;
551
552 return;
553 }
554
555 \f
556 VOID
557 CdTruncateAllocation (
558 IN PIRP_CONTEXT IrpContext,
559 IN PFCB Fcb,
560 IN LONGLONG StartingFileOffset
561 )
562
563 /*++
564
565 Routine Description:
566
567 This routine truncates the Mcb for a file by eliminating all of the Mcb
568 entries from the entry which contains the given offset.
569
570 The Fcb should be locked when this routine is called.
571
572 Arguments:
573
574 Fcb - Fcb containing the Mcb to truncate.
575
576 StartingFileOffset - Offset in the file to truncate the Mcb from.
577
578 Return Value:
579
580 None
581
582 --*/
583
584 {
585 ULONG McbEntryOffset;
586
587 PAGED_CODE();
588
589 ASSERT_IRP_CONTEXT( IrpContext );
590 ASSERT_FCB( Fcb );
591 ASSERT_LOCKED_FCB( Fcb );
592
593 //
594 // Find the entry containing this starting offset.
595 //
596
597 McbEntryOffset = CdFindMcbEntry( IrpContext, Fcb, StartingFileOffset );
598
599 //
600 // Now set the current size of the mcb to this point.
601 //
602
603 Fcb->Mcb.CurrentEntryCount = McbEntryOffset;
604
605 return;
606 }
607
608 \f
609 VOID
610 CdInitializeMcb (
611 IN PIRP_CONTEXT IrpContext,
612 IN PFCB Fcb
613 )
614
615 /*++
616
617 Routine Description:
618
619 This routine is called to initialize the Mcb in an Fcb. We initialize
620 this with an entry count of one and point to the entry in the Fcb
621 itself.
622
623 Fcb should be acquired exclusively when this is called.
624
625 Arguments:
626
627 Fcb - Fcb containing the Mcb to initialize.
628
629 Return Value:
630
631 None
632
633 --*/
634
635 {
636 PAGED_CODE();
637
638 ASSERT_IRP_CONTEXT( IrpContext );
639 ASSERT_FCB( Fcb );
640
641 //
642 // Set the entry counts to show there is one entry in the array and
643 // it is unused.
644 //
645
646 Fcb->Mcb.MaximumEntryCount = 1;
647 Fcb->Mcb.CurrentEntryCount = 0;
648
649 Fcb->Mcb.McbArray = &Fcb->McbEntry;
650
651 return;
652 }
653
654 \f
655 VOID
656 CdUninitializeMcb (
657 IN PIRP_CONTEXT IrpContext,
658 IN PFCB Fcb
659 )
660
661 /*++
662
663 Routine Description:
664
665 This routine is called to cleanup an Mcb in an Fcb. We look at the
666 maximum run count in the Fcb and if greater than one we will deallocate
667 the buffer.
668
669 Fcb should be acquired exclusively when this is called.
670
671 Arguments:
672
673 Fcb - Fcb containing the Mcb to uninitialize.
674
675 Return Value:
676
677 None
678
679 --*/
680
681 {
682 PAGED_CODE();
683
684 ASSERT_IRP_CONTEXT( IrpContext );
685 ASSERT_FCB( Fcb );
686
687 //
688 // If the count is greater than one then this is an allocated buffer.
689 //
690
691 if (Fcb->Mcb.MaximumEntryCount > 1) {
692
693 CdFreePool( &Fcb->Mcb.McbArray );
694 }
695
696 return;
697 }
698
699 \f
700 //
701 // Local support routine
702 //
703
704 ULONG
705 CdFindMcbEntry (
706 IN PIRP_CONTEXT IrpContext,
707 IN PFCB Fcb,
708 IN LONGLONG FileOffset
709 )
710
711 /*++
712
713 Routine Description:
714
715 This routine is called to find the Mcb entry which contains the file
716 offset at the given point. If the file offset is not currently in the
717 Mcb then we return the offset of the entry to add.
718
719 Fcb should be locked when this is called.
720
721 Arguments:
722
723 Fcb - Fcb containing the Mcb to uninitialize.
724
725 FileOffset - Return the Mcb entry which contains this file offset.
726
727 Return Value:
728
729 ULONG - Offset in the Mcb of the entry for this offset.
730
731 --*/
732
733 {
734 ULONG CurrentMcbOffset;
735 PCD_MCB_ENTRY CurrentMcbEntry;
736
737 PAGED_CODE();
738
739 ASSERT_IRP_CONTEXT( IrpContext );
740 ASSERT_FCB( Fcb );
741 ASSERT_LOCKED_FCB( Fcb );
742
743 //
744 // We expect a linear search will be sufficient here.
745 //
746
747 CurrentMcbOffset = 0;
748 CurrentMcbEntry = Fcb->Mcb.McbArray;
749
750 while (CurrentMcbOffset < Fcb->Mcb.CurrentEntryCount) {
751
752 //
753 // Check if the offset lies within the current Mcb position.
754 //
755
756 if (FileOffset < CurrentMcbEntry->FileOffset + CurrentMcbEntry->ByteCount) {
757
758 break;
759 }
760
761 //
762 // Move to the next entry.
763 //
764
765 CurrentMcbOffset += 1;
766 CurrentMcbEntry += 1;
767 }
768
769 //
770 // This is the offset containing this file offset (or the point
771 // where an entry should be added).
772 //
773
774 return CurrentMcbOffset;
775 }
776
777 \f
778 //
779 // Local support routine
780 //
781
782 VOID
783 CdDiskOffsetFromMcbEntry (
784 IN PIRP_CONTEXT IrpContext,
785 IN PCD_MCB_ENTRY McbEntry,
786 IN LONGLONG FileOffset,
787 IN PLONGLONG DiskOffset,
788 IN PULONG ByteCount
789 )
790
791 /*++
792
793 Routine Description:
794
795 This routine is called to return the diskoffset and length of the file
796 data which begins at offset 'FileOffset'. We have the Mcb entry which
797 contains the mapping and interleave information.
798
799 NOTE - This routine deals with data in 2048 byte logical sectors. If
800 this is an XA file then our caller has already converted from
801 'raw' file bytes to 'cooked' file bytes.
802
803 Arguments:
804
805 McbEntry - Entry in the Mcb containing the allocation information.
806
807 FileOffset - Starting Offset in the file to find the matching disk
808 offsets.
809
810 DiskOffset - Address to store the starting disk offset for this operation.
811
812 ByteCount - Address to store number of contiguous bytes starting at this
813 disk offset.
814
815 Return Value:
816
817 None
818
819 --*/
820
821 {
822 LONGLONG ExtentOffset;
823
824 LONGLONG CurrentDiskOffset;
825 LONGLONG CurrentExtentOffset;
826
827 LONGLONG LocalByteCount;
828
829 PAGED_CODE();
830 ASSERT_IRP_CONTEXT( IrpContext );
831
832 //
833 // Extent offset is the difference between the file offset and the start
834 // of the extent.
835 //
836
837 ExtentOffset = FileOffset - McbEntry->FileOffset;
838
839 //
840 // Optimize the non-interleave case.
841 //
842
843 if (McbEntry->ByteCount == McbEntry->DataBlockByteCount) {
844
845 *DiskOffset = McbEntry->DiskOffset + ExtentOffset;
846
847 LocalByteCount = McbEntry->ByteCount - ExtentOffset;
848
849 } else {
850
851 //
852 // Walk though any interleave until we reach the current offset in
853 // this extent.
854 //
855
856 CurrentExtentOffset = McbEntry->DataBlockByteCount;
857 CurrentDiskOffset = McbEntry->DiskOffset;
858
859 while (CurrentExtentOffset <= ExtentOffset) {
860
861 CurrentDiskOffset += McbEntry->TotalBlockByteCount;
862 CurrentExtentOffset += McbEntry->DataBlockByteCount;
863 }
864
865 //
866 // We are now positioned at the data block containing the starting
867 // file offset we were given. The disk offset is the offset of
868 // the start of this block plus the extent offset into this block.
869 // The byte count is the data block byte count minus our offset into
870 // this block.
871 //
872
873 *DiskOffset = CurrentDiskOffset + (ExtentOffset + McbEntry->DataBlockByteCount - CurrentExtentOffset);
874
875 //
876 // Make sure we aren't past the end of the data length. This is possible
877 // if we only use part of the last data block on an interleaved file.
878 //
879
880 if (CurrentExtentOffset > McbEntry->ByteCount) {
881
882 CurrentExtentOffset = McbEntry->ByteCount;
883 }
884
885 LocalByteCount = CurrentExtentOffset - ExtentOffset;
886 }
887
888 //
889 // If the byte count exceeds our limit then cut it to fit in 32 bits.
890 //
891
892 if (LocalByteCount > MAXULONG) {
893
894 *ByteCount = MAXULONG;
895
896 } else {
897
898 *ByteCount = (ULONG) LocalByteCount;
899 }
900
901 return;
902 }
903