ReactOS  0.4.14-dev-583-g2a1ba2c
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 74 of file io.c.

80 {
81  PMDL Mdl = Irp->MdlAddress;
82 
83  /* Unlock MDL Pages, page 167. */
84  DPRINT("MiSimpleReadComplete %p\n", Irp);
85  while (Mdl)
86  {
87  DPRINT("MDL Unlock %p\n", Mdl);
88  MmUnlockPages(Mdl);
89  Mdl = Mdl->Next;
90  }
91 
92  /* Check if there's an MDL */
93  while ((Mdl = Irp->MdlAddress))
94  {
95  /* Clear all of them */
96  Irp->MdlAddress = Mdl->Next;
97  IoFreeMdl(Mdl);
98  }
99 
100  return STATUS_SUCCESS;
101 }
_In_ PIRP Irp
Definition: csq.h:116
VOID NTAPI MmUnlockPages(IN PMDL Mdl)
Definition: mdlsup.c:1439
void DPRINT(...)
Definition: polytest.cpp:61
VOID NTAPI IoFreeMdl(PMDL Mdl)
Definition: iomdl.c:146
return STATUS_SUCCESS
Definition: btrfs.c:2938

◆ _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 205 of file io.c.

212 {
214  PIRP Irp = NULL;
215  KEVENT ReadWait;
218 
221  ASSERT(Buffer);
223 
226 
227  DPRINT("PAGING WRITE: FileObject %p <%wZ> Offset 0x%I64x Length %lu (%s:%d)\n",
228  FileObject,
229  &FileObject->FileName,
230  FileOffset->QuadPart,
231  Length,
232  File,
233  Line);
234 
236 
238  DeviceObject,
239  Buffer,
240  Length,
241  FileOffset,
242  ReadStatus);
243 
244  if (!Irp)
245  {
246  return STATUS_NO_MEMORY;
247  }
248 
250 
251  Irp->UserEvent = &ReadWait;
252  Irp->Tail.Overlay.OriginalFileObject = FileObject;
253  Irp->Tail.Overlay.Thread = PsGetCurrentThread();
257  IrpSp->CompletionRoutine = MiSimpleReadComplete;
258 
259  DPRINT("Call Driver\n");
261  DPRINT("Status %x\n", Status);
262 
263  if (Status == STATUS_PENDING)
264  {
265  DPRINT("KeWaitForSingleObject(&ReadWait)\n");
266  if (!NT_SUCCESS(KeWaitForSingleObject(&ReadWait,
267  Suspended,
268  KernelMode,
269  FALSE,
270  NULL)))
271  {
272  DPRINT1("Warning: Failed to wait for synchronous IRP\n");
273  ASSERT(FALSE);
274  return Status;
275  }
276  }
277 
278  DPRINT("Paging IO Done: %08x\n", ReadStatus->Status);
279  return ReadStatus->Status;
280 }
#define PsGetCurrentThread()
Definition: env_spec_w32.h:81
_In_ PIRP Irp
Definition: csq.h:116
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
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
Definition: bufpool.h:45
PDEVICE_OBJECT NTAPI MmGetDeviceObjectForFile(IN PFILE_OBJECT FileObject)
Definition: io.c:62
PIO_COMPLETION_ROUTINE CompletionRoutine
Definition: iotypes.h:2958
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_PENDING
Definition: ntstatus.h:82
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
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
#define SL_INVOKE_ON_ERROR
Definition: iotypes.h:2973
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
Definition: ncftp.h:79
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetNextIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2647
Status
Definition: gdiplustypes.h:24
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
PFILE_OBJECT FileObject
Definition: iotypes.h:2813
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
#define SL_INVOKE_ON_SUCCESS
Definition: iotypes.h:2972
_In_ PFCB _In_ LONGLONG FileOffset
Definition: cdprocs.h:151
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4157
#define STATUS_NO_MEMORY
Definition: ntstatus.h:246
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
static USHORT ReadStatus(PUCHAR ReadDataPort)
Definition: hardware.c:116
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 296 of file io.c.

302 {
304  PVOID Hyperspace;
306  KIRQL OldIrql;
308 
309  if (!PageBuffer) return STATUS_NO_MEMORY;
310 
311  Hyperspace = MiMapPageInHyperSpace(PsGetCurrentProcess(), Page, &OldIrql);
312  if (!Hyperspace)
313  {
314  ExFreePool(PageBuffer);
315  return STATUS_NO_MEMORY;
316  }
317  RtlCopyMemory(PageBuffer, Hyperspace, PAGE_SIZE);
319 
320  DPRINT("MiWriteBackPage(%wZ,%08x%08x,%s:%d)\n",
321  &FileObject->FileName,
322  FileOffset->u.HighPart,
323  FileOffset->u.LowPart,
324  File,
325  Line);
326 
328  FileOffset,
329  PageBuffer,
330  Length,
331  &Iosb);
332 
333  ExFreePool(PageBuffer);
334 
335  if (!NT_SUCCESS(Status))
336  {
337  DPRINT1("MiSimpleWrite failed (%x)\n", Status);
338  }
339 
340  return Status;
341 }
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
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
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
return Iosb
Definition: create.c:4426
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
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:803
#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
Status
Definition: gdiplustypes.h:24
_In_ PFCB _In_ LONGLONG FileOffset
Definition: cdprocs.h:151
#define STATUS_NO_MEMORY
Definition: ntstatus.h:246
#define DPRINT1
Definition: precomp.h:8
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 114 of file io.c.

120 {
122  PIRP Irp = NULL;
123  KEVENT ReadWait;
126 
129  ASSERT(Buffer);
131 
134  ReadStatus->Information = 0;
135 
137 
138  DPRINT("PAGING READ: FileObject %p <%wZ> Offset %08x%08x Length %ul\n",
139  FileObject,
140  &FileObject->FileName,
141  FileOffset->HighPart,
142  FileOffset->LowPart,
143  Length);
144 
146 
148  DeviceObject,
149  Buffer,
150  Length,
151  FileOffset,
152  ReadStatus);
153 
154  if (!Irp)
155  {
156  return STATUS_NO_MEMORY;
157  }
158 
160 
161  Irp->UserEvent = &ReadWait;
162  Irp->Tail.Overlay.OriginalFileObject = FileObject;
163  Irp->Tail.Overlay.Thread = PsGetCurrentThread();
167  IrpSp->CompletionRoutine = MiSimpleReadComplete;
168 
169  /* Non paging case, the FileObject will be dereferenced at completion */
170  if (!Paging)
172 
174  if (Status == STATUS_PENDING)
175  {
176  DPRINT("KeWaitForSingleObject(&ReadWait)\n");
177  if (!NT_SUCCESS(KeWaitForSingleObject(&ReadWait,
178  Suspended,
179  KernelMode,
180  FALSE,
181  NULL)))
182  {
183  DPRINT1("Warning: Failed to wait for synchronous IRP\n");
184  ASSERT(FALSE);
185  return Status;
186  }
187  }
188 
189  DPRINT("Paging IO Done: %08x\n", ReadStatus->Status);
190  /* When "ReadStatus->Information > 0" is false and "ReadStatus->Status == STATUS_END_OF_FILE" is true
191  * it means that read pointer is out of file, so we must fail */
192  Status = ReadStatus->Status == STATUS_END_OF_FILE && ReadStatus->Information > 0 ? STATUS_SUCCESS : ReadStatus->Status;
193  return Status;
194 }
#define PsGetCurrentThread()
Definition: env_spec_w32.h:81
_In_ PIRP Irp
Definition: csq.h:116
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:451
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
Definition: bufpool.h:45
PDEVICE_OBJECT NTAPI MmGetDeviceObjectForFile(IN PFILE_OBJECT FileObject)
Definition: io.c:62
PIO_COMPLETION_ROUTINE CompletionRoutine
Definition: iotypes.h:2958
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_PENDING
Definition: ntstatus.h:82
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
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
#define SL_INVOKE_ON_ERROR
Definition: iotypes.h:2973
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetNextIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2647
Status
Definition: gdiplustypes.h:24
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
PFILE_OBJECT FileObject
Definition: iotypes.h:2813
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
#define SL_INVOKE_ON_SUCCESS
Definition: iotypes.h:2972
_In_ PFCB _In_ LONGLONG FileOffset
Definition: cdprocs.h:151
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4157
#define STATUS_NO_MEMORY
Definition: ntstatus.h:246
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
static USHORT ReadStatus(PUCHAR ReadDataPort)
Definition: hardware.c:116
return STATUS_SUCCESS
Definition: btrfs.c:2938
#define IRP_SYNCHRONOUS_PAGING_IO

Referenced by CcZeroData(), ExeFmtpReadFile(), and KdbpReadSymFile().

◆ MmGetDeviceObjectForFile()

PDEVICE_OBJECT NTAPI MmGetDeviceObjectForFile ( IN PFILE_OBJECT  FileObject)

Definition at line 62 of file io.c.

63 {
65 }
PDEVICE_OBJECT NTAPI IoGetRelatedDeviceObject(IN PFILE_OBJECT FileObject)
Definition: device.c:1539
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593

Referenced by _MiSimpleWrite(), and MiSimpleRead().

Variable Documentation

◆ CcpLazyWriteEvent

KEVENT CcpLazyWriteEvent

Definition at line 58 of file io.c.

Referenced by CcInitializeCacheManager().

◆ MiWriteMutex

FAST_MUTEX MiWriteMutex

Definition at line 283 of file io.c.

◆ MpwThreadEvent

KEVENT MpwThreadEvent