ReactOS  0.4.15-dev-1377-ga59cecd
io.c File Reference
#include <ntoskrnl.h>
#include "newmm.h"
#include <debug.h>
#include <reactos/exeformat.h>
Include dependency graph for io.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

PDEVICE_OBJECT NTAPI MmGetDeviceObjectForFile (IN PFILE_OBJECT FileObject)
 
 _Function_class_ (IO_COMPLETION_ROUTINE)
 
NTSTATUS NTAPI MiSimpleRead (PFILE_OBJECT FileObject, PLARGE_INTEGER FileOffset, PVOID Buffer, ULONG Length, BOOLEAN Paging, PIO_STATUS_BLOCK ReadStatus)
 
NTSTATUS NTAPI _MiSimpleWrite (PFILE_OBJECT FileObject, PLARGE_INTEGER FileOffset, PVOID Buffer, ULONG Length, PIO_STATUS_BLOCK ReadStatus, const char *File, int Line)
 
NTSTATUS NTAPI _MiWriteBackPage (PFILE_OBJECT FileObject, PLARGE_INTEGER FileOffset, ULONG Length, PFN_NUMBER Page, const char *File, int Line)
 

Variables

KEVENT CcpLazyWriteEvent
 
KEVENT MpwThreadEvent
 
FAST_MUTEX MiWriteMutex
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 49 of file io.c.

Function Documentation

◆ _Function_class_()

_Function_class_ ( IO_COMPLETION_ROUTINE  )

Definition at line 69 of file io.c.

75 {
76  PMDL Mdl = Irp->MdlAddress;
77 
78  /* Unlock MDL Pages, page 167. */
79  DPRINT("MiSimpleReadComplete %p\n", Irp);
80  while (Mdl)
81  {
82  DPRINT("MDL Unlock %p\n", Mdl);
84  Mdl = Mdl->Next;
85  }
86 
87  /* Check if there's an MDL */
88  while ((Mdl = Irp->MdlAddress))
89  {
90  /* Clear all of them */
91  Irp->MdlAddress = Mdl->Next;
92  IoFreeMdl(Mdl);
93  }
94 
95  return STATUS_SUCCESS;
96 }
VOID NTAPI MmUnlockPages(IN PMDL Mdl)
Definition: mdlsup.c:1439
_In_ PIRP Irp
Definition: csq.h:116
void DPRINT(...)
Definition: polytest.cpp:61
VOID NTAPI IoFreeMdl(PMDL Mdl)
Definition: iomdl.c:146
_In_ WDFDEVICE _In_ PVOID _In_opt_ PMDL Mdl
#define STATUS_SUCCESS
Definition: shellext.h:65

◆ _MiSimpleWrite()

NTSTATUS NTAPI _MiSimpleWrite ( PFILE_OBJECT  FileObject,
PLARGE_INTEGER  FileOffset,
PVOID  Buffer,
ULONG  Length,
PIO_STATUS_BLOCK  ReadStatus,
const char File,
int  Line 
)

Definition at line 200 of file io.c.

207 {
209  PIRP Irp = NULL;
210  KEVENT ReadWait;
213 
216  ASSERT(Buffer);
218 
221 
222  DPRINT("PAGING WRITE: FileObject %p <%wZ> Offset 0x%I64x Length %lu (%s:%d)\n",
223  FileObject,
224  &FileObject->FileName,
225  FileOffset->QuadPart,
226  Length,
227  File,
228  Line);
229 
231 
233  DeviceObject,
234  Buffer,
235  Length,
236  FileOffset,
237  ReadStatus);
238 
239  if (!Irp)
240  {
241  return STATUS_NO_MEMORY;
242  }
243 
245 
246  Irp->UserEvent = &ReadWait;
247  Irp->Tail.Overlay.OriginalFileObject = FileObject;
248  Irp->Tail.Overlay.Thread = PsGetCurrentThread();
252  IrpSp->CompletionRoutine = MiSimpleReadComplete;
253 
254  DPRINT("Call Driver\n");
256  DPRINT("Status %x\n", Status);
257 
258  if (Status == STATUS_PENDING)
259  {
260  DPRINT("KeWaitForSingleObject(&ReadWait)\n");
261  if (!NT_SUCCESS(KeWaitForSingleObject(&ReadWait,
262  Suspended,
263  KernelMode,
264  FALSE,
265  NULL)))
266  {
267  DPRINT1("Warning: Failed to wait for synchronous IRP\n");
268  ASSERT(FALSE);
269  return Status;
270  }
271  }
272 
273  DPRINT("Paging IO Done: %08x\n", ReadStatus->Status);
274  return ReadStatus->Status;
275 }
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
#define PsGetCurrentThread()
Definition: env_spec_w32.h:81
LONG NTSTATUS
Definition: precomp.h:26
#define IRP_NOCACHE
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
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
#define FALSE
Definition: types.h:117
_In_ PIRP Irp
Definition: csq.h:116
void DPRINT(...)
Definition: polytest.cpp:61
Definition: bufpool.h:45
PDEVICE_OBJECT NTAPI MmGetDeviceObjectForFile(IN PFILE_OBJECT FileObject)
Definition: io.c:57
PIO_COMPLETION_ROUTINE CompletionRoutine
Definition: iotypes.h:3293
_In_ WDFREQUEST _In_ WDFFILEOBJECT FileObject
Definition: wdfdevice.h:547
Status
Definition: gdiplustypes.h:24
#define ASSERT(a)
Definition: mode.c:45
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_PENDING
Definition: ntstatus.h:82
static USHORT ReadStatus(IN PUCHAR ReadDataPort)
Definition: hardware.c:128
PIRP NTAPI IoBuildAsynchronousFsdRequest(IN ULONG MajorFunction, IN PDEVICE_OBJECT DeviceObject, IN PVOID Buffer, IN ULONG Length, IN PLARGE_INTEGER StartingOffset, IN PIO_STATUS_BLOCK IoStatusBlock)
Definition: irp.c:750
#define SL_INVOKE_ON_ERROR
Definition: iotypes.h:3308
Definition: ncftp.h:79
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetNextIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2691
PFILE_OBJECT FileObject
Definition: iotypes.h:3148
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
#define SL_INVOKE_ON_SUCCESS
Definition: iotypes.h:3307
_In_ PFCB _In_ LONGLONG FileOffset
Definition: cdprocs.h:159
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4137
#define STATUS_NO_MEMORY
Definition: ntstatus.h:260
#define NULL
Definition: types.h:112
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218
#define IRP_PAGING_IO
#define DPRINT1
Definition: precomp.h:8
#define IRP_SYNCHRONOUS_API
#define IRP_MJ_WRITE
Definition: rdpdr.c:47
Definition: File.h:15
#define IRP_SYNCHRONOUS_PAGING_IO

◆ _MiWriteBackPage()

NTSTATUS NTAPI _MiWriteBackPage ( PFILE_OBJECT  FileObject,
PLARGE_INTEGER  FileOffset,
ULONG  Length,
PFN_NUMBER  Page,
const char File,
int  Line 
)

Definition at line 291 of file io.c.

297 {
299  PVOID Hyperspace;
301  KIRQL OldIrql;
303 
304  if (!PageBuffer) return STATUS_NO_MEMORY;
305 
306  Hyperspace = MiMapPageInHyperSpace(PsGetCurrentProcess(), Page, &OldIrql);
307  if (!Hyperspace)
308  {
309  ExFreePool(PageBuffer);
310  return STATUS_NO_MEMORY;
311  }
312  RtlCopyMemory(PageBuffer, Hyperspace, PAGE_SIZE);
314 
315  DPRINT("MiWriteBackPage(%wZ,%08x%08x,%s:%d)\n",
316  &FileObject->FileName,
317  FileOffset->u.HighPart,
318  FileOffset->u.LowPart,
319  File,
320  Line);
321 
323  FileOffset,
324  PageBuffer,
325  Length,
326  &Iosb);
327 
328  ExFreePool(PageBuffer);
329 
330  if (!NT_SUCCESS(Status))
331  {
332  DPRINT1("MiSimpleWrite failed (%x)\n", Status);
333  }
334 
335  return Status;
336 }
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
LONG NTSTATUS
Definition: precomp.h:26
UCHAR KIRQL
Definition: env_spec_w32.h:591
#define PsGetCurrentProcess
Definition: psfuncs.h:17
PVOID NTAPI MiMapPageInHyperSpace(IN PEPROCESS Process, IN PFN_NUMBER Page, IN PKIRQL OldIrql)
Definition: hypermap.c:30
void DPRINT(...)
Definition: polytest.cpp:61
_In_ WDFREQUEST _In_ WDFFILEOBJECT FileObject
Definition: wdfdevice.h:547
Status
Definition: gdiplustypes.h:24
return Iosb
Definition: create.c:4402
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
Definition: ncftp.h:79
VOID NTAPI MiUnmapPageInHyperSpace(IN PEPROCESS Process, IN PVOID Address, IN KIRQL OldIrql)
Definition: hypermap.c:93
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:790
#define MiSimpleWrite(F, O, B, L, R)
Definition: newmm.h:198
#define ExAllocatePool(type, size)
Definition: fbtusb.h:44
#define PAGE_SIZE
Definition: env_spec_w32.h:49
_In_ PFCB _In_ LONGLONG FileOffset
Definition: cdprocs.h:159
#define STATUS_NO_MEMORY
Definition: ntstatus.h:260
#define DPRINT1
Definition: precomp.h:8
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
Definition: File.h:15
#define ExFreePool(addr)
Definition: env_spec_w32.h:352

◆ MiSimpleRead()

NTSTATUS NTAPI MiSimpleRead ( PFILE_OBJECT  FileObject,
PLARGE_INTEGER  FileOffset,
PVOID  Buffer,
ULONG  Length,
BOOLEAN  Paging,
PIO_STATUS_BLOCK  ReadStatus 
)

Definition at line 109 of file io.c.

115 {
117  PIRP Irp = NULL;
118  KEVENT ReadWait;
121 
124  ASSERT(Buffer);
126 
129  ReadStatus->Information = 0;
130 
132 
133  DPRINT("PAGING READ: FileObject %p <%wZ> Offset %08x%08x Length %ul\n",
134  FileObject,
135  &FileObject->FileName,
136  FileOffset->HighPart,
137  FileOffset->LowPart,
138  Length);
139 
141 
143  DeviceObject,
144  Buffer,
145  Length,
146  FileOffset,
147  ReadStatus);
148 
149  if (!Irp)
150  {
151  return STATUS_NO_MEMORY;
152  }
153 
155 
156  Irp->UserEvent = &ReadWait;
157  Irp->Tail.Overlay.OriginalFileObject = FileObject;
158  Irp->Tail.Overlay.Thread = PsGetCurrentThread();
162  IrpSp->CompletionRoutine = MiSimpleReadComplete;
163 
164  /* Non paging case, the FileObject will be dereferenced at completion */
165  if (!Paging)
167 
169  if (Status == STATUS_PENDING)
170  {
171  DPRINT("KeWaitForSingleObject(&ReadWait)\n");
172  if (!NT_SUCCESS(KeWaitForSingleObject(&ReadWait,
173  Suspended,
174  KernelMode,
175  FALSE,
176  NULL)))
177  {
178  DPRINT1("Warning: Failed to wait for synchronous IRP\n");
179  ASSERT(FALSE);
180  return Status;
181  }
182  }
183 
184  DPRINT("Paging IO Done: %08x\n", ReadStatus->Status);
185  /* When "ReadStatus->Information > 0" is false and "ReadStatus->Status == STATUS_END_OF_FILE" is true
186  * it means that read pointer is out of file, so we must fail */
187  Status = ReadStatus->Status == STATUS_END_OF_FILE && ReadStatus->Information > 0 ? STATUS_SUCCESS : ReadStatus->Status;
188  return Status;
189 }
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
#define PsGetCurrentThread()
Definition: env_spec_w32.h:81
LONG NTSTATUS
Definition: precomp.h:26
#define IRP_NOCACHE
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
#define STATUS_END_OF_FILE
Definition: shellext.h:67
#define STATUS_INTERNAL_ERROR
Definition: ntstatus.h:465
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
#define FALSE
Definition: types.h:117
_In_ PIRP Irp
Definition: csq.h:116
void DPRINT(...)
Definition: polytest.cpp:61
Definition: bufpool.h:45
PDEVICE_OBJECT NTAPI MmGetDeviceObjectForFile(IN PFILE_OBJECT FileObject)
Definition: io.c:57
PIO_COMPLETION_ROUTINE CompletionRoutine
Definition: iotypes.h:3293
_In_ WDFREQUEST _In_ WDFFILEOBJECT FileObject
Definition: wdfdevice.h:547
Status
Definition: gdiplustypes.h:24
#define ASSERT(a)
Definition: mode.c:45
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_PENDING
Definition: ntstatus.h:82
static USHORT ReadStatus(IN PUCHAR ReadDataPort)
Definition: hardware.c:128
PIRP NTAPI IoBuildAsynchronousFsdRequest(IN ULONG MajorFunction, IN PDEVICE_OBJECT DeviceObject, IN PVOID Buffer, IN ULONG Length, IN PLARGE_INTEGER StartingOffset, IN PIO_STATUS_BLOCK IoStatusBlock)
Definition: irp.c:750
#define SL_INVOKE_ON_ERROR
Definition: iotypes.h:3308
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetNextIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2691
PFILE_OBJECT FileObject
Definition: iotypes.h:3148
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
#define SL_INVOKE_ON_SUCCESS
Definition: iotypes.h:3307
_In_ PFCB _In_ LONGLONG FileOffset
Definition: cdprocs.h:159
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4137
#define STATUS_NO_MEMORY
Definition: ntstatus.h:260
#define NULL
Definition: types.h:112
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218
#define IRP_PAGING_IO
#define DPRINT1
Definition: precomp.h:8
#define IRP_MJ_READ
Definition: rdpdr.c:46
#define ObReferenceObject
Definition: obfuncs.h:204
#define IRP_SYNCHRONOUS_API
#define STATUS_SUCCESS
Definition: shellext.h:65
#define IRP_SYNCHRONOUS_PAGING_IO

Referenced by CcZeroData(), and ExeFmtpReadFile().

◆ MmGetDeviceObjectForFile()

PDEVICE_OBJECT NTAPI MmGetDeviceObjectForFile ( IN PFILE_OBJECT  FileObject)

Definition at line 57 of file io.c.

58 {
60 }
PDEVICE_OBJECT NTAPI IoGetRelatedDeviceObject(IN PFILE_OBJECT FileObject)
Definition: device.c:1539
_In_ WDFREQUEST _In_ WDFFILEOBJECT FileObject
Definition: wdfdevice.h:547

Referenced by _MiSimpleWrite(), and MiSimpleRead().

Variable Documentation

◆ CcpLazyWriteEvent

KEVENT CcpLazyWriteEvent

Definition at line 53 of file io.c.

Referenced by CcInitializeCacheManager().

◆ MiWriteMutex

FAST_MUTEX MiWriteMutex

Definition at line 278 of file io.c.

◆ MpwThreadEvent

KEVENT MpwThreadEvent