ReactOS 0.4.15-dev-7953-g1f49173
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:
{ \
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); \
} \
}
@ UserFileOpen
Definition: cdprocs.h:577
struct _VCB VCB
FAT_DATA FatData
Definition: fatdata.c:56
@ DirectoryFile
Definition: fatprocs.h:1046
@ VirtualVolumeFile
Definition: fatprocs.h:1045
FORCEINLINE ULONG KeGetCurrentProcessorNumber(VOID)
Definition: ke.h:341
ULONG NumberProcessors
Definition: fatstruc.h:81
uint32_t ULONG
Definition: typedefs.h:59

◆ 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:
{ \
RtlZeroMemory((AT), (BYTE_COUNT)); \
FatRaiseStatus( 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:34
#define STATUS_INVALID_USER_BUFFER
Definition: udferr_usr.h:166

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
119NTAPI
120FatFsdRead (
121 _In_ PVOLUME_DEVICE_OBJECT VolumeDeviceObject,
123 )
124
125/*++
126
127Routine 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
136Arguments:
137
138 VolumeDeviceObject - Supplies the volume device object where the
139 file being Read exists
140
141 Irp - Supplies the Irp being processed
142
143Return 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
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
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}
static PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(PIRP Irp)
unsigned char BOOLEAN
#define VOID
Definition: acefi.h:82
LONG NTSTATUS
Definition: precomp.h:26
#define CanFsdWait(I)
Definition: cdprocs.h:2001
_In_ PFCB Fcb
Definition: cdprocs.h:159
#define try_return(S)
Definition: cdprocs.h:2179
FCB * PFCB
Definition: cdstruc.h:1040
_In_ PIRP Irp
Definition: csq.h:116
#define NULL
Definition: types.h:112
#define FALSE
Definition: types.h:117
#define NodeType(P)
Definition: nodetype.h:51
#define FAT_NTC_FCB
Definition: nodetype.h:29
#define KeWaitForSingleObject(pEvt, foo, a, b, c)
Definition: env_spec_w32.h:478
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
#define FlagOn(_F, _SF)
Definition: ext2fs.h:179
NTSTATUS FatCompleteMdl(IN PIRP_CONTEXT IrpContext, IN PIRP Irp)
Definition: cachesup.c:1728
VOID FatPagingFileIo(IN PIRP Irp, IN PFCB Fcb)
Definition: deviosup.c:211
ULONG FatExceptionFilter(IN PIRP_CONTEXT IrpContext, IN PEXCEPTION_POINTERS ExceptionPointer)
Definition: fatdata.c:204
BOOLEAN FatIsIrpTopLevel(IN PIRP Irp)
Definition: fatdata.c:817
#define DebugTrace(INDENT, LEVEL, X, Y)
Definition: fatdata.h:313
IN PFCB IN PCCB IN TYPE_OF_OPEN IN BOOLEAN IN BOOLEAN TopLevel
Definition: fatprocs.h:2417
#define FatDeviceIsFatFsdo(D)
Definition: fatprocs.h:3095
PIRP_CONTEXT FatCreateIrpContext(IN PIRP Irp, IN BOOLEAN Wait)
Definition: strucsup.c:2301
#define FCB_STATE_PAGING_FILE
Definition: fatstruc.h:1195
#define OVERFLOW_READ_THRESHHOLD
Definition: read.c:42
#define Dbg
Definition: read.c:29
VOID NTAPI FatOverflowPagingFileRead(IN PVOID Context, IN PKEVENT Event)
Definition: read.c:1706
#define FsRtlEnterFileSystem
#define FsRtlExitFileSystem
Status
Definition: gdiplustypes.h:25
#define NOTHING
Definition: input_list.c:10
IoMarkIrpPending(Irp)
#define _Function_class_(x)
Definition: ms_sal.h:2946
#define _Inout_
Definition: ms_sal.h:378
#define _In_
Definition: ms_sal.h:308
_In_ NDIS_HANDLE _In_ PNDIS_PACKET Packet
Definition: ndis.h:1549
#define KernelMode
Definition: asm.h:34
DRIVER_DISPATCH(nfs41_FsdDispatch)
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:317
@ NotificationEvent
VOID NTAPI IoSetTopLevelIrp(IN PIRP Irp)
Definition: irp.c:2000
#define STATUS_PENDING
Definition: ntstatus.h:82
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:159
#define _SEH2_GetExceptionInformation()
Definition: pseh2_64.h:158
#define IRP_MJ_READ
Definition: rdpdr.c:46
VOID NTAPI FsRtlPostPagingFileStackOverflow(IN PVOID Context, IN PKEVENT Event, IN PFSRTL_STACK_OVERFLOW_ROUTINE StackOverflowRoutine)
Definition: stackovf.c:206
Definition: cdstruc.h:902
ULONG FcbState
Definition: cdstruc.h:971
PFILE_OBJECT FileObject
Definition: iotypes.h:3169
#define NTAPI
Definition: typedefs.h:36
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
#define IRP_MN_COMPLETE
Definition: iotypes.h:4420
@ Executive
Definition: ketypes.h:415

◆ FatOverflowPagingFileRead()

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

Definition at line 1706 of file read.c.

1731{
1733
1734 FatPagingFileIo( Packet->Irp, Packet->Fcb );
1735
1736 //
1737 // Set the stack overflow item's event to tell the original
1738 // thread that we're done.
1739 //
1740
1741 KeSetEvent( Event, 0, FALSE );
1742
1743 return;
1744}
#define KeSetEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:476