ReactOS 0.4.15-dev-8145-ga541a46
read.c File Reference
#include "ext2fs.h"
Include dependency graph for read.c:

Go to the source code of this file.

Macros

#define SafeZeroMemory(AT, BYTE_COUNT)
 

Functions

NTSTATUS Ext2ReadComplete (IN PEXT2_IRP_CONTEXT IrpContext)
 
NTSTATUS Ext2ReadFile (IN PEXT2_IRP_CONTEXT IrpContext)
 
NTSTATUS Ext2ReadVolume (IN PEXT2_IRP_CONTEXT IrpContext)
 
NTSTATUS Ext2CompleteIrpContext (IN PEXT2_IRP_CONTEXT IrpContext, IN NTSTATUS Status)
 
NTSTATUS Ext2ReadInode (IN PEXT2_IRP_CONTEXT IrpContext, IN PEXT2_VCB Vcb, IN PEXT2_MCB Mcb, IN ULONGLONG Offset, IN PVOID Buffer, IN ULONG Size, IN BOOLEAN bDirectIo, OUT PULONG BytesRead)
 
NTSTATUS Ext2Read (IN PEXT2_IRP_CONTEXT IrpContext)
 

Variables

PEXT2_GLOBAL Ext2Global
 

Macro Definition Documentation

◆ SafeZeroMemory

#define SafeZeroMemory (   AT,
  BYTE_COUNT 
)
Value:
{ \
if (AT) \
RtlZeroMemory((AT), (BYTE_COUNT)); \
Ext2RaiseStatus( IrpContext, STATUS_INVALID_USER_BUFFER ); \
} _SEH2_END; \
}
#define _SEH2_END
Definition: filesup.c:22
#define _SEH2_TRY
Definition: filesup.c:19
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
#define AT
Definition: mbstring.h:34
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:66
#define STATUS_INVALID_USER_BUFFER
Definition: udferr_usr.h:166

Definition at line 301 of file read.c.

Function Documentation

◆ Ext2CompleteIrpContext()

NTSTATUS Ext2CompleteIrpContext ( IN PEXT2_IRP_CONTEXT  IrpContext,
IN NTSTATUS  Status 
)

Definition at line 32 of file read.c.

35{
36 PIRP Irp = NULL;
37 BOOLEAN bPrint;
38
39 Irp = IrpContext->Irp;
40
41 if (Irp != NULL) {
42
43 if (NT_ERROR(Status)) {
44 Irp->IoStatus.Information = 0;
45 }
46
47 Irp->IoStatus.Status = Status;
48 bPrint = !IsFlagOn(IrpContext->Flags, IRP_CONTEXT_FLAG_REQUEUED);
49
51 Irp, bPrint, (CCHAR)(NT_SUCCESS(Status)?
53
54 IrpContext->Irp = NULL;
55 }
56
57 Ext2FreeIrpContext(IrpContext);
58
59 return Status;
60}
unsigned char BOOLEAN
_In_ PIRP Irp
Definition: csq.h:116
#define NULL
Definition: types.h:112
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
VOID Ext2FreeIrpContext(IN PEXT2_IRP_CONTEXT IrpContext)
Definition: memory.c:114
#define Ext2CompleteRequest(Irp, bPrint, PriorityBoost)
Definition: ext2fs.h:1475
#define IRP_CONTEXT_FLAG_REQUEUED
Definition: ext2fs.h:1094
#define IsFlagOn(a, b)
Definition: ext2fs.h:177
Status
Definition: gdiplustypes.h:25
char CCHAR
Definition: typedefs.h:51
#define NT_ERROR(Status)
Definition: umtypes.h:106
#define IO_NO_INCREMENT
Definition: iotypes.h:598
#define IO_DISK_INCREMENT
Definition: iotypes.h:600

Referenced by Ex2ProcessMountPoint(), Ex2ProcessUserPerfStat(), Ext2AllowExtendedDasdIo(), Ext2Cleanup(), Ext2Close(), Ext2Create(), Ext2DeleteReparsePoint(), Ext2DeviceControlNormal(), Ext2DirectoryControl(), Ext2DismountVolume(), Ext2DispatchRequest(), Ext2ExceptionHandler(), Ext2FileSystemControl(), Ext2Flush(), Ext2GetReparsePoint(), Ext2GetRetrievalPointerBase(), Ext2GetRetrievalPointers(), Ext2InvalidateVolumes(), Ext2IsVolumeDirty(), Ext2IsVolumeMounted(), Ext2LockControl(), Ext2LockVolume(), Ext2MountVolume(), Ext2NotifyChangeDirectory(), Ext2OplockComplete(), Ext2OplockRequest(), Ext2ProcessUserProperty(), Ext2QueryDirectory(), Ext2QueryEa(), Ext2QueryFileInformation(), Ext2QueryRetrievalPointers(), Ext2QueryVolumeInformation(), Ext2Read(), Ext2ReadComplete(), Ext2ReadFile(), Ext2ReadVolume(), Ext2SetEa(), Ext2SetFileInformation(), Ext2SetReparsePoint(), Ext2SetVolumeInformation(), Ext2ShutDown(), Ext2UnlockVolume(), Ext2UserFsRequest(), Ext2VerifyVolume(), Ext2Write(), Ext2WriteComplete(), Ext2WriteFile(), and Ext2WriteVolume().

◆ Ext2Read()

NTSTATUS Ext2Read ( IN PEXT2_IRP_CONTEXT  IrpContext)

Definition at line 863 of file read.c.

864{
867 PEXT2_FCBVCB FcbOrVcb;
870 BOOLEAN bCompleteRequest;
871
872 ASSERT(IrpContext);
873
874 ASSERT((IrpContext->Identifier.Type == EXT2ICX) &&
875 (IrpContext->Identifier.Size == sizeof(EXT2_IRP_CONTEXT)));
876
877 _SEH2_TRY {
878
879 if (FlagOn(IrpContext->MinorFunction, IRP_MN_COMPLETE)) {
880
881 Status = Ext2ReadComplete(IrpContext);
882 bCompleteRequest = FALSE;
883
884 } else {
885
886 DeviceObject = IrpContext->DeviceObject;
887
890 bCompleteRequest = TRUE;
892 }
893
894 Vcb = (PEXT2_VCB) DeviceObject->DeviceExtension;
895 if (Vcb->Identifier.Type != EXT2VCB ||
896 Vcb->Identifier.Size != sizeof(EXT2_VCB) ) {
898 bCompleteRequest = TRUE;
899
901 }
902
903 FileObject = IrpContext->FileObject;
904
905 if (FlagOn(Vcb->Flags, VCB_VOLUME_LOCKED) &&
906 Vcb->LockFile != FileObject ) {
908#ifdef __REACTOS__
909 bCompleteRequest = TRUE;
910#endif
912 }
913
914 FcbOrVcb = (PEXT2_FCBVCB) FileObject->FsContext;
915
916 if (FcbOrVcb->Identifier.Type == EXT2VCB) {
917
918 Status = Ext2ReadVolume(IrpContext);
919 bCompleteRequest = FALSE;
920
921 } else if (FcbOrVcb->Identifier.Type == EXT2FCB) {
922
923 if (IsFlagOn(Vcb->Flags, VCB_DISMOUNT_PENDING)) {
925 bCompleteRequest = TRUE;
927 }
928
929 Status = Ext2ReadFile(IrpContext);
930 bCompleteRequest = FALSE;
931 } else {
932 DEBUG(DL_ERR, ( "Ext2Read: Inavlid FileObject (Vcb or Fcb corrupted)\n"));
933 DbgBreak();
934
936 bCompleteRequest = TRUE;
937 }
938 }
939
940 } _SEH2_FINALLY {
941 if (bCompleteRequest) {
942 Ext2CompleteIrpContext(IrpContext, Status);
943 }
944 } _SEH2_END;
945
946 return Status;
947}
LONG NTSTATUS
Definition: precomp.h:26
#define DEBUG(args)
Definition: rdesktop.h:129
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define VCB_VOLUME_LOCKED
Definition: ext2fs.h:789
#define FlagOn(_F, _SF)
Definition: ext2fs.h:179
@ EXT2FCB
Definition: ext2fs.h:463
@ EXT2ICX
Definition: ext2fs.h:465
@ EXT2VCB
Definition: ext2fs.h:462
#define IsExt2FsDevice(DO)
Definition: ext2fs.h:616
#define VCB_DISMOUNT_PENDING
Definition: ext2fs.h:791
struct _EXT2_FCBVCB * PEXT2_FCBVCB
#define DbgBreak()
Definition: ext2fs.h:46
struct _EXT2_VCB * PEXT2_VCB
#define DL_ERR
Definition: ext2fs.h:1434
#define _SEH2_FINALLY
Definition: filesup.c:21
#define _SEH2_LEAVE
Definition: filesup.c:20
NTSTATUS Ext2ReadComplete(IN PEXT2_IRP_CONTEXT IrpContext)
Definition: read.c:832
NTSTATUS Ext2ReadFile(IN PEXT2_IRP_CONTEXT IrpContext)
Definition: read.c:471
NTSTATUS Ext2CompleteIrpContext(IN PEXT2_IRP_CONTEXT IrpContext, IN NTSTATUS Status)
Definition: read.c:32
NTSTATUS Ext2ReadVolume(IN PEXT2_IRP_CONTEXT IrpContext)
Definition: read.c:64
if(dx< 0)
Definition: linetemp.h:194
#define ASSERT(a)
Definition: mode.c:44
#define STATUS_TOO_LATE
Definition: ntstatus.h:626
#define Vcb
Definition: cdprocs.h:1415
EXT2_IDENTIFIER Identifier
Definition: ext2fs.h:633
EXT2_IDENTIFIER_TYPE Type
Definition: ext2fs.h:477
#define STATUS_INVALID_DEVICE_REQUEST
Definition: udferr_usr.h:138
#define STATUS_ACCESS_DENIED
Definition: udferr_usr.h:145
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
_In_ WDFREQUEST _In_ WDFFILEOBJECT FileObject
Definition: wdfdevice.h:550
#define IRP_MN_COMPLETE
Definition: iotypes.h:4420
* PFILE_OBJECT
Definition: iotypes.h:1998

◆ Ext2ReadComplete()

NTSTATUS Ext2ReadComplete ( IN PEXT2_IRP_CONTEXT  IrpContext)

Definition at line 832 of file read.c.

833{
836 PIRP Irp;
837
838 _SEH2_TRY {
839
840 ASSERT(IrpContext);
841 ASSERT((IrpContext->Identifier.Type == EXT2ICX) &&
842 (IrpContext->Identifier.Size == sizeof(EXT2_IRP_CONTEXT)));
843
844 FileObject = IrpContext->FileObject;
845 Irp = IrpContext->Irp;
846
847 CcMdlReadComplete(FileObject, Irp->MdlAddress);
848 Irp->MdlAddress = NULL;
850
851 } _SEH2_FINALLY {
852
853 if (!IrpContext->ExceptionInProgress) {
854 Ext2CompleteIrpContext(IrpContext, Status);
855 }
856 } _SEH2_END;
857
858 return Status;
859}
VOID NTAPI CcMdlReadComplete(IN PFILE_OBJECT FileObject, IN PMDL MdlChain)
Definition: mdlsup.c:75
#define STATUS_SUCCESS
Definition: shellext.h:65
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132

Referenced by Ext2Read().

◆ Ext2ReadFile()

NTSTATUS Ext2ReadFile ( IN PEXT2_IRP_CONTEXT  IrpContext)

Definition at line 471 of file read.c.

472{
474
479
481
482 PIRP Irp = NULL;
483 PIO_STACK_LOCATION IoStackLocation = NULL;
484
488
489 BOOLEAN OpPostIrp = FALSE;
490 BOOLEAN PagingIo;
491 BOOLEAN Nocache;
492 BOOLEAN SynchronousIo;
493 BOOLEAN MainResourceAcquired = FALSE;
494 BOOLEAN PagingIoResourceAcquired = FALSE;
495
497
498 _SEH2_TRY {
499
500 ASSERT(IrpContext);
501 ASSERT((IrpContext->Identifier.Type == EXT2ICX) &&
502 (IrpContext->Identifier.Size == sizeof(EXT2_IRP_CONTEXT)));
503
504 DeviceObject = IrpContext->DeviceObject;
505 Vcb = (PEXT2_VCB) DeviceObject->DeviceExtension;
506 ASSERT(Vcb != NULL);
507 ASSERT((Vcb->Identifier.Type == EXT2VCB) &&
508 (Vcb->Identifier.Size == sizeof(EXT2_VCB)));
509
510 FileObject = IrpContext->FileObject;
511 Fcb = (PEXT2_FCB) FileObject->FsContext;
512 ASSERT(Fcb);
514 (Fcb->Identifier.Size == sizeof(EXT2_FCB)));
515
516 Ccb = (PEXT2_CCB) FileObject->FsContext2;
517
518 Irp = IrpContext->Irp;
519 IoStackLocation = IoGetCurrentIrpStackLocation(Irp);
520
521 Length = IoStackLocation->Parameters.Read.Length;
522 ByteOffset = IoStackLocation->Parameters.Read.ByteOffset;
523
524 PagingIo = IsFlagOn(Irp->Flags, IRP_PAGING_IO);
525 Nocache = IsFlagOn(Irp->Flags, IRP_NOCACHE);
526 SynchronousIo = IsFlagOn(FileObject->Flags, FO_SYNCHRONOUS_IO);
527
528 if (PagingIo) {
529 ASSERT(Nocache);
530 }
531
532 DEBUG(DL_INF, ("Ext2ReadFile: reading %wZ Off=%I64xh Len=%xh Paging=%xh Nocache=%xh\n",
533 &Fcb->Mcb->ShortName, ByteOffset.QuadPart, Length, PagingIo, Nocache));
534
535 if (IsSpecialFile(Fcb) || IsInodeSymLink(Fcb->Inode) ) {
538 }
539
540 if ((IsSymLink(Fcb) && IsFileDeleted(Fcb->Mcb->Target)) ||
544 }
545
546 if (Length == 0) {
547 Irp->IoStatus.Information = 0;
550 }
551
553 ByteOffset.HighPart == -1) {
554 ByteOffset = FileObject->CurrentByteOffset;
555 }
556
557 if (Nocache && (ByteOffset.LowPart & (SECTOR_SIZE - 1) ||
558 Length & (SECTOR_SIZE - 1))) {
560 DbgBreak();
562 }
563
564 if (FlagOn(IrpContext->MinorFunction, IRP_MN_DPC)) {
565 ClearFlag(IrpContext->MinorFunction, IRP_MN_DPC);
567 DbgBreak();
569 }
570
572
573 if (PagingIo) {
574
577 IsFlagOn(IrpContext->Flags, IRP_CONTEXT_FLAG_WAIT) )) {
580 }
581 PagingIoResourceAcquired = TRUE;
582
583 } else {
584
585 if (Nocache && Ccb != NULL && Fcb->SectionObject.DataSectionObject) {
586
589 IsFlagOn(IrpContext->Flags, IRP_CONTEXT_FLAG_WAIT) )) {
592 }
593 MainResourceAcquired = TRUE;
594
595 CcFlushCache(&Fcb->SectionObject,
596 &ByteOffset,
597 Length,
598 &Irp->IoStatus );
599 if (!NT_SUCCESS(Irp->IoStatus.Status))
602
605 }
606 CcPurgeCacheSection( &Fcb->SectionObject,
607 NULL,
608 0,
609 FALSE );
610
612
613 } else {
614
617 IsFlagOn(IrpContext->Flags, IRP_CONTEXT_FLAG_WAIT) )) {
620 }
621 MainResourceAcquired = TRUE;
622 }
623
625 &Fcb->FileLockAnchor,
626 Irp )) {
629 }
630 }
631
632 if ((ByteOffset.QuadPart + (LONGLONG)Length) > Fcb->Header.FileSize.QuadPart) {
633 if (ByteOffset.QuadPart >= Fcb->Header.FileSize.QuadPart) {
634 Irp->IoStatus.Information = 0;
637 }
638 ReturnedLength = (ULONG)(Fcb->Header.FileSize.QuadPart - ByteOffset.QuadPart);
639 }
640
641
642 if (!IsDirectory(Fcb) && Ccb != NULL) {
643 Status = FsRtlCheckOplock( &Fcb->Oplock,
644 Irp,
645 IrpContext,
647 Ext2LockIrp );
648
649 if (Status != STATUS_SUCCESS) {
650 OpPostIrp = TRUE;
652 }
653
654 //
655 // Set the flag indicating if Fast I/O is possible
656 //
657
658 Fcb->Header.IsFastIoPossible = Ext2IsFastIoPossible(Fcb);
659 }
660
661 if (!Nocache) {
662
663 if (IsDirectory(Fcb)) {
665 }
666
667 if (FileObject->PrivateCacheMap == NULL) {
670 (PCC_FILE_SIZES)(&Fcb->Header.AllocationSize),
671 FALSE,
673 Fcb );
677 }
678
679 if (FlagOn(IrpContext->MinorFunction, IRP_MN_MDL)) {
680 CcMdlRead(
682 (&ByteOffset),
684 &Irp->MdlAddress,
685 &Irp->IoStatus );
686
687 Status = Irp->IoStatus.Status;
688
689 } else {
690
692 if (Buffer == NULL) {
694 DbgBreak();
696 }
697
699 Ext2CanIWait(), Buffer, &Irp->IoStatus)) {
700
703 Buffer, &Irp->IoStatus)) {
705 DbgBreak();
707 }
708 }
709 Status = Irp->IoStatus.Status;
710 }
711
712 } else {
713
715 PUCHAR SystemVA = Ext2GetUserBuffer(IrpContext->Irp);
716
717 if (ByteOffset.QuadPart + BytesRead > Fcb->Header.ValidDataLength.QuadPart) {
718
719 if (ByteOffset.QuadPart >= Fcb->Header.ValidDataLength.QuadPart) {
720 if (SystemVA) {
721 SafeZeroMemory(SystemVA, Length);
722 }
723 Irp->IoStatus.Information = ReturnedLength;
726 } else {
727 BytesRead = (ULONG)(Fcb->Header.ValidDataLength.QuadPart - ByteOffset.QuadPart);
728 if (SystemVA) {
730 }
731 }
732 }
733
735 IrpContext->Irp,
736 BytesRead,
737 IoReadAccess );
738
739 if (!NT_SUCCESS(Status)) {
741 }
742
744 IrpContext,
745 Vcb,
746 Fcb->Mcb,
747 ByteOffset.QuadPart,
748 NULL,
749 BytesRead,
750 TRUE,
751 NULL );
752
753 /* we need re-queue this request in case STATUS_CANT_WAIT
754 and fail it in other failure cases */
755 if (!NT_SUCCESS(Status)) {
757 }
758
759 /* pended by low level device */
760 if (Status == STATUS_PENDING) {
761 IrpContext->Irp = Irp = NULL;
763 }
764
765 Irp = IrpContext->Irp;
766 ASSERT(Irp);
767 Status = Irp->IoStatus.Status;
768
769 if (!NT_SUCCESS(Status)) {
771 }
772 }
773
774 Irp->IoStatus.Information = ReturnedLength;
775
776 } _SEH2_FINALLY {
777
778 if (Irp) {
779 if (PagingIoResourceAcquired) {
781 }
782
783 if (MainResourceAcquired) {
785 }
786 }
787
788 if (!OpPostIrp && !IrpContext->ExceptionInProgress) {
789
790 if (Irp) {
791 if ( Status == STATUS_PENDING ||
793
795 IrpContext->Irp,
796 Length,
798
799 if (NT_SUCCESS(Status)) {
800 Status = Ext2QueueRequest(IrpContext);
801 } else {
802 Ext2CompleteIrpContext(IrpContext, Status);
803 }
804 } else {
805 if (NT_SUCCESS(Status)) {
806 if (!PagingIo) {
807 if (SynchronousIo) {
808 FileObject->CurrentByteOffset.QuadPart =
809 ByteOffset.QuadPart + Irp->IoStatus.Information;
810 }
812 }
813 }
814
815 Ext2CompleteIrpContext(IrpContext, Status);
816 }
817
818 } else {
819
820 Ext2FreeIrpContext(IrpContext);
821 }
822 }
823 } _SEH2_END;
824
825 DEBUG(DL_IO, ("Ext2ReadFile: %wZ fetch at Off=%I64xh Len=%xh Paging=%xh Nocache=%xh Returned=%xh Status=%xh\n",
826 &Fcb->Mcb->ShortName, ByteOffset.QuadPart, Length, PagingIo, Nocache, ReturnedLength, Status));
827 return Status;
828
829}
static PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(PIRP Irp)
_In_ ULONG _In_ BATTERY_QUERY_INFORMATION_LEVEL _In_ LONG _In_ ULONG _Out_ PULONG ReturnedLength
Definition: batclass.h:188
#define SECTOR_SIZE
Definition: fs.h:22
VOID NTAPI CcMdlRead(IN PFILE_OBJECT FileObject, IN PLARGE_INTEGER FileOffset, IN ULONG Length, OUT PMDL *MdlChain, OUT PIO_STATUS_BLOCK IoStatus)
Definition: mdlsup.c:64
VOID NTAPI CcSetReadAheadGranularity(IN PFILE_OBJECT FileObject, IN ULONG Granularity)
Definition: cachesub.c:36
VOID NTAPI CcFlushCache(IN PSECTION_OBJECT_POINTERS SectionObjectPointer, IN OPTIONAL PLARGE_INTEGER FileOffset, IN ULONG Length, OUT OPTIONAL PIO_STATUS_BLOCK IoStatus)
Definition: cachesub.c:222
_In_ PFCB Fcb
Definition: cdprocs.h:159
_Inout_ PFILE_OBJECT _In_ TYPE_OF_OPEN PFCB _In_opt_ PCCB Ccb
Definition: cdprocs.h:592
#define IRP_CONTEXT_FLAG_WAIT
Definition: cdstruc.h:1215
Definition: bufpool.h:45
#define ExAcquireResourceExclusiveLite(res, wait)
Definition: env_spec_w32.h:615
#define ExAcquireResourceSharedLite(res, wait)
Definition: env_spec_w32.h:621
#define ClearFlag(_F, _SF)
Definition: ext2fs.h:191
#define IsSpecialFile(Fcb)
Definition: ext2fs.h:284
VOID Ext2OplockComplete(IN PVOID Context, IN PIRP Irp)
Definition: dispatch.c:45
#define IsDirectory(Fcb)
Definition: ext2fs.h:283
#define IsFileDeleted(Mcb)
Definition: ext2fs.h:968
NTSTATUS Ext2QueueRequest(IN PEXT2_IRP_CONTEXT IrpContext)
Definition: dispatch.c:158
#define DL_INF
Definition: ext2fs.h:1436
#define Ext2NormalizeAndRaiseStatus(IRPCONTEXT, STATUS)
Definition: ext2fs.h:268
#define FCB_FILE_MODIFIED
Definition: ext2fs.h:882
NTSTATUS Ext2LockUserBuffer(IN PIRP Irp, IN ULONG Length, IN LOCK_OPERATION Operation)
Definition: block.c:113
#define ClearLongFlag(_F, _SF)
Definition: ext2fs.h:259
#define IsSymLink(Fcb)
Definition: ext2fs.h:285
PVOID Ext2GetUserBuffer(IN PIRP Irp)
Definition: block.c:146
#define IsInodeSymLink(I)
Definition: ext2fs.h:286
#define Ext2CanIWait()
Definition: ext2fs.h:1100
VOID Ext2LockIrp(IN PVOID Context, IN PIRP Irp)
Definition: dispatch.c:94
struct _EXT2_CCB * PEXT2_CCB
struct _EXT2_FCB * PEXT2_FCB
#define DL_IO
Definition: ext2fs.h:1450
FAST_IO_POSSIBLE Ext2IsFastIoPossible(IN PEXT2_FCB Fcb)
Definition: fastio.c:38
IN PDCB IN PCCB IN VBO IN OUT PULONG OUT PDIRENT OUT PBCB OUT PVBO ByteOffset
Definition: fatprocs.h:731
BOOLEAN NTAPI FsRtlCheckLockForReadAccess(IN PFILE_LOCK FileLock, IN PIRP Irp)
Definition: filelock.c:672
#define READ_AHEAD_GRANULARITY
Definition: read.c:60
#define SafeZeroMemory(AT, BYTE_COUNT)
Definition: read.c:301
PEXT2_GLOBAL Ext2Global
Definition: init.c:16
NTSTATUS Ext2ReadInode(IN PEXT2_IRP_CONTEXT IrpContext, IN PEXT2_VCB Vcb, IN PEXT2_MCB Mcb, IN ULONGLONG Offset, IN PVOID Buffer, IN ULONG Size, IN BOOLEAN bDirectIo, OUT PULONG BytesRead)
Definition: read.c:311
VOID NTAPI CcInitializeCacheMap(IN PFILE_OBJECT FileObject, IN PCC_FILE_SIZES FileSizes, IN BOOLEAN PinAccess, IN PCACHE_MANAGER_CALLBACKS Callbacks, IN PVOID LazyWriteContext)
Definition: fssup.c:195
BOOLEAN NTAPI CcPurgeCacheSection(IN PSECTION_OBJECT_POINTERS SectionObjectPointer, IN OPTIONAL PLARGE_INTEGER FileOffset, IN ULONG Length, IN BOOLEAN UninitializeCacheMaps)
Definition: fssup.c:386
#define FILE_USE_FILE_POINTER_POSITION
Definition: nt_native.h:780
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
BOOLEAN NTAPI CcCopyRead(IN PFILE_OBJECT FileObject, IN PLARGE_INTEGER FileOffset, IN ULONG Length, IN BOOLEAN Wait, OUT PVOID Buffer, OUT PIO_STATUS_BLOCK IoStatus)
Definition: copysup.c:43
VOID FASTCALL ExReleaseResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1822
#define STATUS_CANT_WAIT
Definition: ntstatus.h:452
#define STATUS_FILE_LOCK_CONFLICT
Definition: ntstatus.h:320
#define STATUS_PENDING
Definition: ntstatus.h:82
NTSTATUS NTAPI FsRtlCheckOplock(IN POPLOCK Oplock, IN PIRP Irp, IN PVOID Context, IN POPLOCK_WAIT_COMPLETE_ROUTINE CompletionRoutine OPTIONAL, IN POPLOCK_FS_PREPOST_IRP PostIrpRoutine OPTIONAL)
Definition: oplock.c:1170
#define STATUS_END_OF_FILE
Definition: shellext.h:67
ULONG Type
Definition: ntfs.h:95
ULONG Size
Definition: ntfs.h:96
CACHE_MANAGER_CALLBACKS CacheManagerCallbacks
Definition: ext2fs.h:532
ULONG Flags
Definition: ntfs.h:536
CD_MCB Mcb
Definition: cdstruc.h:1016
ERESOURCE PagingIoResource
Definition: ntfs.h:527
NTFSIDENTIFIER Identifier
Definition: ntfs.h:515
FSRTL_ADVANCED_FCB_HEADER Header
Definition: cdstruc.h:925
ERESOURCE MainResource
Definition: ntfs.h:528
union _IO_STACK_LOCATION::@1569 Parameters
struct _IO_STACK_LOCATION::@3984::@3988 Read
int64_t LONGLONG
Definition: typedefs.h:68
unsigned char * PUCHAR
Definition: typedefs.h:53
uint32_t ULONG
Definition: typedefs.h:59
#define STATUS_FILE_DELETED
Definition: udferr_usr.h:172
_Must_inspect_result_ _In_ WDFIOTARGET _In_opt_ WDFREQUEST _In_opt_ PWDF_MEMORY_DESCRIPTOR _In_opt_ PLONGLONG _In_opt_ PWDF_REQUEST_SEND_OPTIONS _Out_opt_ PULONG_PTR BytesRead
Definition: wdfiotarget.h:870
#define ExConvertExclusiveToShared
Definition: exfuncs.h:344
#define IRP_PAGING_IO
#define FO_FILE_FAST_IO_READ
Definition: iotypes.h:1795
#define IRP_MN_MDL
Definition: iotypes.h:4419
#define IRP_MN_DPC
Definition: iotypes.h:4418
#define FO_SYNCHRONOUS_IO
Definition: iotypes.h:1776
#define IRP_NOCACHE
@ IoReadAccess
Definition: ketypes.h:863
@ IoWriteAccess
Definition: ketypes.h:864

Referenced by Ext2Read().

◆ Ext2ReadInode()

NTSTATUS Ext2ReadInode ( IN PEXT2_IRP_CONTEXT  IrpContext,
IN PEXT2_VCB  Vcb,
IN PEXT2_MCB  Mcb,
IN ULONGLONG  Offset,
IN PVOID  Buffer,
IN ULONG  Size,
IN BOOLEAN  bDirectIo,
OUT PULONG  BytesRead 
)

Definition at line 311 of file read.c.

321{
322 PEXT2_EXTENT Chain = NULL;
323 PEXT2_EXTENT Extent = NULL, Prev = NULL;
324
327 ULONG RealSize ;
328
329 if (BytesRead) {
330 *BytesRead = 0;
331 }
332
333 _SEH2_TRY {
334
336
337 ASSERT((Mcb->Identifier.Type == EXT2MCB) &&
338 (Mcb->Identifier.Size == sizeof(EXT2_MCB)));
339
340 if ((Mcb->Identifier.Type != EXT2MCB) ||
341 (Mcb->Identifier.Size != sizeof(EXT2_MCB))) {
343 }
344
345 if (Buffer == NULL && IrpContext != NULL)
346 Buffer = Ext2GetUserBuffer(IrpContext->Irp);
347
348
349 /* handle fast symlinks */
350 if (S_ISLNK(Mcb->Inode.i_mode) && 0 == Mcb->Inode.i_blocks) {
351
352 PUCHAR Data = (PUCHAR) (&Mcb->Inode.i_block[0]);
353 if (!Buffer) {
356 }
357
363 } else {
365 }
367 }
368
369 //
370 // Build the scatterred block ranges to be read
371 //
372
373 if (bDirectIo) {
374 RealSize = CEILING_ALIGNED(ULONG, Size, SECTOR_SIZE - 1);
375 } else {
376 RealSize = Size;
377 }
378
380 IrpContext,
381 Vcb,
382 Mcb,
383 Offset,
384 RealSize,
385 FALSE,
386 &Chain
387 );
388
389 if (!NT_SUCCESS(Status)) {
391 }
392
393 if (Chain == NULL) {
397 }
398
399 /* for sparse file, we need zero the gaps */
400 for (Extent = Chain; Buffer != NULL && Extent != NULL; Extent = Extent->Next) {
401 if (NULL == Prev) {
402 ASSERT(Extent == Chain);
403 if (Extent->Offset) {
405 }
406 } else if (Extent->Offset > (Prev->Offset + Prev->Length)) {
407 SafeZeroMemory((PCHAR)Buffer + Prev->Offset + Prev->Length,
408 Extent->Offset - Prev->Offset - Prev->Length);
409 }
410 if (NULL == Extent->Next) {
411 if (Extent->Offset + Extent->Length < Size) {
413 Size - Extent->Offset - Extent->Length);
414 }
415 }
416 Prev = Extent;
417 }
418
419 if (bDirectIo) {
420
421 ASSERT(IrpContext != NULL);
422
423 // Offset should be SECTOR_SIZE aligned ...
425 IrpContext,
426 Vcb,
427 Chain,
428 Size
429 );
430 } else {
431
432 for (Extent = Chain; Extent != NULL; Extent = Extent->Next) {
433
434 if (!CcCopyRead(
435 Vcb->Volume,
436 (PLARGE_INTEGER)(&(Extent->Lba)),
437 Extent->Length,
438 PIN_WAIT,
439 (PVOID)((PUCHAR)Buffer + Extent->Offset),
440 &IoStatus
441 )) {
443 } else {
444 Status = IoStatus.Status;
445 }
446
447 if (!NT_SUCCESS(Status)) {
448 break;
449 }
450 }
451 }
452
453 } _SEH2_FINALLY {
454
455 if (Chain) {
457 }
458
460 } _SEH2_END;
461
462 if (NT_SUCCESS(Status)) {
463 if (BytesRead)
464 *BytesRead = Size;
465 }
466
467 return Status;
468}
@ EXT2MCB
Definition: ext2fs.h:467
VOID Ext2DestroyExtentChain(IN PEXT2_EXTENT Chain)
Definition: memory.c:546
#define EXT2_LINKLEN_IN_INODE
Definition: ext2fs.h:76
NTSTATUS Ext2BuildExtents(IN PEXT2_IRP_CONTEXT IrpContext, IN PEXT2_VCB Vcb, IN PEXT2_MCB Mcb, IN ULONGLONG Offset, IN ULONG Size, IN BOOLEAN bAlloc, OUT PEXT2_EXTENT *Chain)
Definition: memory.c:1207
#define S_ISLNK(m)
Definition: ext2fs.h:373
#define Ext2DerefMcb(Mcb)
Definition: ext2fs.h:996
NTSTATUS Ext2ReadWriteBlocks(IN PEXT2_IRP_CONTEXT IrpContext, IN PEXT2_VCB Vcb, IN PEXT2_EXTENT Extent, IN ULONG Length)
Definition: block.c:260
#define CEILING_ALIGNED(T, A, B)
Definition: ext2fs.h:111
#define Ext2ReferMcb(Mcb)
Definition: ext2fs.h:995
IN PVCB IN ULONG IN OUT PULONG IN BOOLEAN OUT PLARGE_MCB Mcb
Definition: fatprocs.h:348
__in UCHAR __in POWER_STATE __in_opt PVOID __in PIO_STATUS_BLOCK IoStatus
Definition: mxum.h:159
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
#define PIN_WAIT
uint64 Length
Definition: DriveVolume.h:48
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
char * PCHAR
Definition: typedefs.h:51
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
Definition: wdfdevice.h:4533

Referenced by Ext2ReadFile().

◆ Ext2ReadVolume()

NTSTATUS Ext2ReadVolume ( IN PEXT2_IRP_CONTEXT  IrpContext)

Definition at line 64 of file read.c.

65{
67
70 PEXT2_FCBVCB FcbOrVcb = NULL;
72
74
75 PIRP Irp = NULL;
76 PIO_STACK_LOCATION IoStackLocation = NULL;
77
80
81 BOOLEAN PagingIo;
82 BOOLEAN Nocache;
83 BOOLEAN SynchronousIo;
84 BOOLEAN MainResourceAcquired = FALSE;
85
87 EXT2_EXTENT BlockArray;
88
89 _SEH2_TRY {
90
91 ASSERT(IrpContext);
92 ASSERT((IrpContext->Identifier.Type == EXT2ICX) &&
93 (IrpContext->Identifier.Size == sizeof(EXT2_IRP_CONTEXT)));
94
95 DeviceObject = IrpContext->DeviceObject;
96 Vcb = (PEXT2_VCB) DeviceObject->DeviceExtension;
97 ASSERT(Vcb != NULL);
98 ASSERT((Vcb->Identifier.Type == EXT2VCB) &&
99 (Vcb->Identifier.Size == sizeof(EXT2_VCB)));
100
101 FileObject = IrpContext->FileObject;
102 FcbOrVcb = (PEXT2_FCBVCB) FileObject->FsContext;
103 ASSERT(FcbOrVcb);
104
105 if (!(FcbOrVcb->Identifier.Type == EXT2VCB && (PVOID)FcbOrVcb == (PVOID)Vcb)) {
106
109 }
110
111 Ccb = (PEXT2_CCB) FileObject->FsContext2;
112 Irp = IrpContext->Irp;
113 Irp->IoStatus.Information = 0;
114 IoStackLocation = IoGetCurrentIrpStackLocation(Irp);
115
116 Length = IoStackLocation->Parameters.Read.Length;
117 ByteOffset = IoStackLocation->Parameters.Read.ByteOffset;
118
119 PagingIo = IsFlagOn(Irp->Flags, IRP_PAGING_IO);
120 Nocache = IsFlagOn(Irp->Flags, IRP_NOCACHE) || (Ccb != NULL);
121 SynchronousIo = IsFlagOn(FileObject->Flags, FO_SYNCHRONOUS_IO);
122
123 if (PagingIo) {
124 ASSERT(Nocache);
125 }
126
127 if (Length == 0) {
128 Irp->IoStatus.Information = 0;
131 }
132
133 if (FlagOn(IrpContext->MinorFunction, IRP_MN_DPC)) {
134 ClearFlag(IrpContext->MinorFunction, IRP_MN_DPC);
137 }
138
139 if (ByteOffset.QuadPart >=
140 Vcb->PartitionInformation.PartitionLength.QuadPart ) {
141 Irp->IoStatus.Information = 0;
144 }
145
146 if (ByteOffset.QuadPart + Length > Vcb->Header.FileSize.QuadPart) {
147 Length = (ULONG)(Vcb->Header.FileSize.QuadPart - ByteOffset.QuadPart);
148 }
149
150 /*
151 * User direct volume access
152 */
153
154 if (Ccb != NULL && !PagingIo) {
155
157 &Vcb->MainResource,
158 IsFlagOn(IrpContext->Flags, IRP_CONTEXT_FLAG_WAIT) )) {
161 }
162 MainResourceAcquired = TRUE;
163
165
166 if (!FlagOn(Vcb->Flags, VCB_VOLUME_LOCKED)) {
167 Ext2FlushVolume(IrpContext, Vcb, FALSE);
168 }
169
171 }
172
173 ExReleaseResourceLite(&Vcb->MainResource);
174 MainResourceAcquired = FALSE;
175
176 /* will do Nocache i/o */
177 }
178
179 /*
180 * I/O to volume StreamObject
181 */
182
183 if (!Nocache) {
184
185 if (IsFlagOn(IrpContext->MinorFunction, IRP_MN_MDL)) {
186
187 CcMdlRead(
188 Vcb->Volume,
189 &ByteOffset,
190 Length,
191 &Irp->MdlAddress,
192 &Irp->IoStatus );
193
194 Status = Irp->IoStatus.Status;
195
196 } else {
197
199 if (Buffer == NULL) {
200 DbgBreak();
203 }
204
205 if (!CcCopyRead(
206 Vcb->Volume,
207 &ByteOffset,
208 Length,
209 Ext2CanIWait(),
210 Buffer,
211 &Irp->IoStatus )) {
214 }
215
216 Status = Irp->IoStatus.Status;
217 }
218
219 } else {
220
221 Length &= ~((ULONG)SECTOR_SIZE - 1);
223 IrpContext->Irp,
224 Length,
226
227 if (!NT_SUCCESS(Status)) {
229 }
230
231 BlockArray.Irp = NULL;
232 BlockArray.Lba = ByteOffset.QuadPart;
233 BlockArray.Offset = 0;
234 BlockArray.Length = Length;
235 BlockArray.Next = NULL;
236
237 Status = Ext2ReadWriteBlocks(IrpContext,
238 Vcb,
239 &BlockArray,
240 Length );
241
242 Irp = IrpContext->Irp;
243 if (!Irp) {
245 }
246 }
247
248 } _SEH2_FINALLY {
249
250 if (MainResourceAcquired) {
251 ExReleaseResourceLite(&Vcb->MainResource);
252 }
253
254 if (!IrpContext->ExceptionInProgress) {
255
256 if (Irp) {
257
258 if (Status == STATUS_PENDING &&
259 !IsFlagOn(IrpContext->Flags, IRP_CONTEXT_FLAG_REQUEUED)) {
260
262 IrpContext->Irp,
263 Length,
265
266 if (NT_SUCCESS(Status)) {
267 Status = Ext2QueueRequest(IrpContext);
268 } else {
269 Ext2CompleteIrpContext(IrpContext, Status);
270 }
271
272 } else {
273
274 if (NT_SUCCESS(Status)) {
275
276 if (!PagingIo) {
277
278 if (SynchronousIo) {
279
280 FileObject->CurrentByteOffset.QuadPart =
281 ByteOffset.QuadPart + Irp->IoStatus.Information;
282 }
283
285 }
286 }
287
288 Ext2CompleteIrpContext(IrpContext, Status);;
289 }
290
291 } else {
292 Ext2FreeIrpContext(IrpContext);
293 }
294 }
295 } _SEH2_END;
296
297 return Status;
298}
#define SetFlag(_F, _SF)
Definition: ext2fs.h:187
#define CCB_VOLUME_DASD_PURGE
Definition: ext2fs.h:1032
NTSTATUS Ext2FlushVolume(IN PEXT2_IRP_CONTEXT IrpContext, IN PEXT2_VCB Vcb, IN BOOLEAN bShutDown)
Definition: flush.c:43
ULONG Length
Definition: ext2fs.h:1122
LONGLONG Lba
Definition: ext2fs.h:1120
struct _EXT2_EXTENT * Next
Definition: ext2fs.h:1124
PIRP Irp
Definition: ext2fs.h:1123
ULONG Offset
Definition: ext2fs.h:1121

Referenced by Ext2Read().

Variable Documentation

◆ Ext2Global

PEXT2_GLOBAL Ext2Global
extern

Definition at line 16 of file init.c.

Referenced by Ext2ReadFile().