ReactOS  0.4.14-dev-1233-gf5658fd
read.c File Reference
#include "fatprocs.h"
Include dependency graph for read.c:

Go to the source code of this file.

Macros

#define BugCheckFileId   (FAT_BUG_CHECK_READ)
 
#define Dbg   (DEBUG_TRACE_READ)
 
#define OVERFLOW_READ_THRESHHOLD   (0x1000)
 
#define SafeZeroMemory(AT, BYTE_COUNT)
 
#define CollectReadStats(VCB, OPEN_TYPE, BYTE_COUNT)
 

Functions

 _Requires_lock_held_ (_Global_critical_region_)
 
VOID NTAPI FatOverflowPagingFileRead (IN PVOID Context, IN PKEVENT Event)
 

Macro Definition Documentation

◆ BugCheckFileId

#define BugCheckFileId   (FAT_BUG_CHECK_READ)

Definition at line 23 of file read.c.

◆ CollectReadStats

#define CollectReadStats (   VCB,
  OPEN_TYPE,
  BYTE_COUNT 
)
Value:
{ \
PFILESYSTEM_STATISTICS Stats = &(VCB)->Statistics[KeGetCurrentProcessorNumber() % FatData.NumberProcessors].Common; \
if (((OPEN_TYPE) == UserFileOpen)) { \
Stats->UserFileReads += 1; \
Stats->UserFileReadBytes += (ULONG)(BYTE_COUNT); \
} else if (((OPEN_TYPE) == VirtualVolumeFile || ((OPEN_TYPE) == DirectoryFile))) { \
Stats->MetaDataReads += 1; \
Stats->MetaDataReadBytes += (ULONG)(BYTE_COUNT); \
} \
}
FORCEINLINE ULONG KeGetCurrentProcessorNumber(VOID)
Definition: ke.h:337
ULONG NumberProcessors
Definition: fatstruc.h:80
struct _VCB VCB
FAT_DATA FatData
Definition: fatdata.c:56
unsigned int ULONG
Definition: retypes.h:1

◆ Dbg

#define Dbg   (DEBUG_TRACE_READ)

Definition at line 29 of file read.c.

◆ OVERFLOW_READ_THRESHHOLD

#define OVERFLOW_READ_THRESHHOLD   (0x1000)

Definition at line 42 of file read.c.

◆ SafeZeroMemory

#define SafeZeroMemory (   AT,
  BYTE_COUNT 
)
Value:
{ \
_SEH2_TRY { \
RtlZeroMemory((AT), (BYTE_COUNT)); \
FatRaiseStatus( IrpContext, STATUS_INVALID_USER_BUFFER ); \
}
#define STATUS_INVALID_USER_BUFFER
Definition: udferr_usr.h:166
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
_SEH2_END
Definition: create.c:4424
#define AT
Definition: mbstring.h:34
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6

Function Documentation

◆ _Requires_lock_held_()

_Requires_lock_held_ ( _Global_critical_region_  )

Definition at line 50 of file read.c.

85  { \
86  _SEH2_TRY { \
87  RtlZeroMemory((AT), (BYTE_COUNT)); \
89  FatRaiseStatus( IrpContext, STATUS_INVALID_USER_BUFFER ); \
90  } _SEH2_END \
91 }
92 
93 //
94 // Macro to increment appropriate performance counters.
95 //
96 
97 #define CollectReadStats(VCB,OPEN_TYPE,BYTE_COUNT) { \
98  PFILESYSTEM_STATISTICS Stats = &(VCB)->Statistics[KeGetCurrentProcessorNumber() % FatData.NumberProcessors].Common; \
99  if (((OPEN_TYPE) == UserFileOpen)) { \
100  Stats->UserFileReads += 1; \
101  Stats->UserFileReadBytes += (ULONG)(BYTE_COUNT); \
102  } else if (((OPEN_TYPE) == VirtualVolumeFile || ((OPEN_TYPE) == DirectoryFile))) { \
103  Stats->MetaDataReads += 1; \
104  Stats->MetaDataReadBytes += (ULONG)(BYTE_COUNT); \
105  } \
106 }
107 
108 
109 #ifdef ALLOC_PRAGMA
110 #pragma alloc_text(PAGE, FatStackOverflowRead)
111 #pragma alloc_text(PAGE, FatPostStackOverflowRead)
112 #pragma alloc_text(PAGE, FatCommonRead)
113 #endif
114 
115 
118 NTSTATUS
119 NTAPI
120 FatFsdRead (
121  _In_ PVOLUME_DEVICE_OBJECT VolumeDeviceObject,
123  )
124 
125 /*++
126 
127 Routine Description:
128 
129  This is the driver entry to the common read routine for NtReadFile calls.
130  For synchronous requests, the CommonRead is called with Wait == TRUE,
131  which means the request will always be completed in the current thread,
132  and never passed to the Fsp. If it is not a synchronous request,
133  CommonRead is called with Wait == FALSE, which means the request
134  will be passed to the Fsp only if there is a need to block.
135 
136 Arguments:
137 
138  VolumeDeviceObject - Supplies the volume device object where the
139  file being Read exists
140 
141  Irp - Supplies the Irp being processed
142 
143 Return Value:
144 
145  NTSTATUS - The FSD status for the IRP
146 
147 --*/
148 
149 {
150  PFCB Fcb = NULL;
152  PIRP_CONTEXT IrpContext = NULL;
153 
155 
156  DebugTrace(+1, Dbg, "FatFsdRead\n", 0);
157 
158  //
159  // Call the common Read routine, with blocking allowed if synchronous
160  //
161 
163 
164  //
165  // We are first going to do a quick check for paging file IO. Since this
166  // is a fast path, we must replicate the check for the fsdo.
167  //
168 
170 
172 
173  if ((NodeType(Fcb) == FAT_NTC_FCB) &&
175 
176  //
177  // Do the usual STATUS_PENDING things.
178  //
179 
181 
182  //
183  // If there is not enough stack to do this read, then post this
184  // read to the overflow queue.
185  //
186 
187  if (IoGetRemainingStackSize() < OVERFLOW_READ_THRESHHOLD) {
188 
189  KEVENT Event;
191 
192  Packet.Irp = Irp;
193  Packet.Fcb = Fcb;
194 
196 
198 
199  //
200  // And wait for the worker thread to complete the item
201  //
202 
204 
205  } else {
206 
207  //
208  // Perform the actual IO, it will be completed when the io finishes.
209  //
210 
211  FatPagingFileIo( Irp, Fcb );
212  }
213 
215 
216  return STATUS_PENDING;
217  }
218  }
219 
220  _SEH2_TRY {
221 
223 
224  IrpContext = FatCreateIrpContext( Irp, CanFsdWait( Irp ) );
225 
226  //
227  // If this is an Mdl complete request, don't go through
228  // common read.
229  //
230 
231  if ( FlagOn(IrpContext->MinorFunction, IRP_MN_COMPLETE) ) {
232 
233  DebugTrace(0, Dbg, "Calling FatCompleteMdl\n", 0 );
234  try_return( Status = FatCompleteMdl( IrpContext, Irp ));
235  }
236 
237  //
238  // Check if we have enough stack space to process this request. If there
239  // isn't enough then we will pass the request off to the stack overflow thread.
240  //
241 
242  if (IoGetRemainingStackSize() < OVERFLOW_READ_THRESHHOLD) {
243 
244  DebugTrace(0, Dbg, "Passing StackOverflowRead off\n", 0 );
245  try_return( Status = FatPostStackOverflowRead( IrpContext, Irp, Fcb ) );
246  }
247 
248  Status = FatCommonRead( IrpContext, Irp );
249 
250  try_exit: NOTHING;
252 
253  //
254  // We had some trouble trying to perform the requested
255  // operation, so we'll abort the I/O request with
256  // the error status that we get back from the
257  // execption code
258  //
259 
260  Status = FatProcessException( IrpContext, Irp, _SEH2_GetExceptionCode() );
261  } _SEH2_END;
262 
263  if (TopLevel) { IoSetTopLevelIrp( NULL ); }
264 
266 
267  //
268  // And return to our caller
269  //
270 
271  DebugTrace(-1, Dbg, "FatFsdRead -> %08lx\n", Status);
272 
273  UNREFERENCED_PARAMETER( VolumeDeviceObject );
274 
275  return Status;
276 }
#define FsRtlEnterFileSystem
BOOLEAN FatIsIrpTopLevel(IN PIRP Irp)
Definition: fatdata.c:817
_In_ NDIS_HANDLE _In_ PNDIS_PACKET Packet
Definition: ndis.h:1548
#define FsRtlExitFileSystem
_In_ PIRP Irp
Definition: csq.h:116
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:323
Definition: cdstruc.h:908
LONG NTSTATUS
Definition: precomp.h:26
#define FatDeviceIsFatFsdo(D)
Definition: fatprocs.h:3083
#define DebugTrace(INDENT, LEVEL, X, Y)
Definition: fatdata.h:313
VOID NTAPI FsRtlPostPagingFileStackOverflow(IN PVOID Context, IN PKEVENT Event, IN PFSRTL_STACK_OVERFLOW_ROUTINE StackOverflowRoutine)
Definition: stackovf.c:206
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
_SEH2_TRY
Definition: create.c:4250
IN PFCB IN PCCB IN TYPE_OF_OPEN IN BOOLEAN IN BOOLEAN TopLevel
Definition: fatprocs.h:2401
#define IRP_MN_COMPLETE
Definition: iotypes.h:4064
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
#define FCB_STATE_PAGING_FILE
Definition: fatstruc.h:1194
VOID FatPagingFileIo(IN PIRP Irp, IN PFCB Fcb)
Definition: deviosup.c:211
#define STATUS_INVALID_USER_BUFFER
Definition: udferr_usr.h:166
_In_ PVOID _In_ ULONG Event
Definition: iotypes.h:435
#define _SEH2_GetExceptionInformation()
Definition: pseh2_64.h:11
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
#define OVERFLOW_READ_THRESHHOLD
Definition: read.c:42
VOID NTAPI FatOverflowPagingFileRead(IN PVOID Context, IN PKEVENT Event)
Definition: read.c:1714
NodeType
Definition: Node.h:5
PIRP_CONTEXT FatCreateIrpContext(IN PIRP Irp, IN BOOLEAN Wait)
Definition: strucsup.c:2300
#define STATUS_PENDING
Definition: ntstatus.h:82
#define try_return(S)
Definition: cdprocs.h:2189
FCB * PFCB
Definition: cdstruc.h:1046
#define _Inout_
Definition: no_sal2.h:244
#define CanFsdWait(I)
Definition: cdprocs.h:2011
#define Dbg
Definition: read.c:29
VOID NTAPI IoSetTopLevelIrp(IN PIRP Irp)
Definition: irp.c:2000
#define VOID
Definition: acefi.h:82
#define NOTHING
Definition: env_spec_w32.h:461
#define FlagOn(_F, _SF)
Definition: ext2fs.h:179
DRIVER_DISPATCH(nfs41_FsdDispatch)
Status
Definition: gdiplustypes.h:24
_Function_class_(IO_COMPLETION_ROUTINE)
Definition: read.c:65
#define _In_
Definition: no_sal2.h:204
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
PFILE_OBJECT FileObject
Definition: iotypes.h:2813
_SEH2_END
Definition: create.c:4424
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
ULONG FatExceptionFilter(IN PIRP_CONTEXT IrpContext, IN PEXCEPTION_POINTERS ExceptionPointer)
Definition: fatdata.c:204
NTSTATUS FatCompleteMdl(IN PIRP_CONTEXT IrpContext, IN PIRP Irp)
Definition: cachesup.c:1728
#define IRP_MJ_READ
Definition: rdpdr.c:46
#define AT
Definition: mbstring.h:34
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:12
_In_ PFCB Fcb
Definition: cdprocs.h:151
IoMarkIrpPending(Irp)
ULONG FcbState
Definition: cdstruc.h:977
#define FAT_NTC_FCB
Definition: nodetype.h:29

◆ FatOverflowPagingFileRead()

VOID NTAPI FatOverflowPagingFileRead ( IN PVOID  Context,
IN PKEVENT  Event 
)

Definition at line 1714 of file read.c.

1739 {
1741 
1742  FatPagingFileIo( Packet->Irp, Packet->Fcb );
1743 
1744  //
1745  // Set the stack overflow item's event to tell the original
1746  // thread that we're done.
1747  //
1748 
1749  KeSetEvent( Event, 0, FALSE );
1750 
1751  return;
1752 }
_In_ NDIS_HANDLE _In_ PNDIS_PACKET Packet
Definition: ndis.h:1548
LONG NTAPI KeSetEvent(IN PKEVENT Event, IN KPRIORITY Increment, IN BOOLEAN Wait)
Definition: eventobj.c:159
VOID FatPagingFileIo(IN PIRP Irp, IN PFCB Fcb)
Definition: deviosup.c:211
struct tagContext Context
Definition: acpixf.h:1034