ReactOS  0.4.15-dev-5463-g138eb58
io_x.h
Go to the documentation of this file.
1 /*
2 * PROJECT: ReactOS Kernel
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: ntoskrnl/include/internal/io_x.h
5 * PURPOSE: Internal Inlined Functions for the I/O Manager
6 * PROGRAMMERS: Alex Ionescu (alex.ionescu@reactos.org)
7 */
8 
9 static
10 __inline
14  _In_ KPROCESSOR_MODE WaitMode)
15 {
16  BOOLEAN LockFailed;
17 
18  /* Lock the FO and check for contention */
20  {
22  return STATUS_SUCCESS;
23  }
24  else
25  {
27  WaitMode,
29  &LockFailed);
30  }
31 }
32 
33 static
34 __inline
35 VOID
37 {
38  /* Unlock the FO and wake any waiters up */
40  if (FileObject->Waiters)
41  {
43  }
45 }
46 
48 VOID
50 {
51  PETHREAD Thread = Irp->Tail.Overlay.Thread;
52 
53  /* Disable special kernel APCs so we can't race with IopCompleteRequest.
54  * IRP's thread must be the current thread */
56 
57  /* Insert it into the list */
58  InsertHeadList(&Thread->IrpList, &Irp->ThreadListEntry);
59 
60  /* Leave the guarded region */
62 }
63 
65 VOID
67 {
68  /* Special kernel APCs must be disabled so we can't race with
69  * IopCompleteRequest (or because we are called from there) */
71 
72  /* Remove it from the list and reset it */
73  if (IsListEmpty(&Irp->ThreadListEntry))
74  return;
75  RemoveEntryList(&Irp->ThreadListEntry);
76  InitializeListHead(&Irp->ThreadListEntry);
77 }
78 
79 static
80 __inline
81 VOID
83 {
84  PLARGE_INTEGER CountToChange;
85 
86  /* Make sure I/O operations are being counted */
88  {
89  if (Type == IopReadTransfer)
90  {
91  /* Increase read count */
93  CountToChange = &PsGetCurrentProcess()->ReadOperationCount;
94  }
95  else if (Type == IopWriteTransfer)
96  {
97  /* Increase write count */
99  CountToChange = &PsGetCurrentProcess()->WriteOperationCount;
100  }
101  else
102  {
103  /* Increase other count */
105  CountToChange = &PsGetCurrentProcess()->OtherOperationCount;
106  }
107 
108  /* Increase the process-wide count */
109  ExInterlockedAddLargeStatistic(CountToChange, 1);
110  }
111 }
112 
113 static
114 __inline
115 VOID
117 {
118  PLARGE_INTEGER CountToChange;
119  PLARGE_INTEGER TransferToChange;
120 
121  /* Make sure I/O operations are being counted */
122  if (IoCountOperations)
123  {
124  if (Type == IopReadTransfer)
125  {
126  /* Increase read count */
127  CountToChange = &PsGetCurrentProcess()->ReadTransferCount;
128  TransferToChange = &IoReadTransferCount;
129  }
130  else if (Type == IopWriteTransfer)
131  {
132  /* Increase write count */
133  CountToChange = &PsGetCurrentProcess()->WriteTransferCount;
134  TransferToChange = &IoWriteTransferCount;
135  }
136  else
137  {
138  /* Increase other count */
139  CountToChange = &PsGetCurrentProcess()->OtherTransferCount;
140  TransferToChange = &IoOtherTransferCount;
141  }
142 
143  /* Increase the process-wide count */
144  ExInterlockedAddLargeStatistic(CountToChange, TransferCount);
145 
146  /* Increase global count */
147  ExInterlockedAddLargeStatistic(TransferToChange, TransferCount);
148  }
149 }
150 
151 static
152 __inline
153 BOOLEAN
155 {
156  /* Validate the packet */
157  if (!(OpenPacket) ||
158  (OpenPacket->Type != IO_TYPE_OPEN_PACKET) ||
159  (OpenPacket->Size != sizeof(OPEN_PACKET)))
160  {
161  /* Fail */
162  return FALSE;
163  }
164 
165  /* Good packet */
166  return TRUE;
167 }
#define IN
Definition: typedefs.h:39
LARGE_INTEGER IoWriteTransferCount
Definition: iomgr.c:42
BOOLEAN NTAPI KeAreAllApcsDisabled(VOID)
Definition: apc.c:985
static __inline VOID IopUpdateTransferCount(IN IOP_TRANSFER_TYPE Type, IN ULONG TransferCount)
Definition: io_x.h:116
static __inline BOOLEAN IopValidateOpenPacket(IN POPEN_PACKET OpenPacket)
Definition: io_x.h:154
#define TRUE
Definition: types.h:120
LARGE_INTEGER IoReadTransferCount
Definition: iomgr.c:40
#define BooleanFlagOn(F, SF)
Definition: ext2fs.h:183
FORCEINLINE VOID InsertHeadList(_Inout_ PLIST_ENTRY ListHead, _Inout_ __drv_aliasesMem PLIST_ENTRY Entry)
Definition: rtlfuncs.h:201
#define IO_TYPE_OPEN_PACKET
LONG NTSTATUS
Definition: precomp.h:26
KTHREAD Tcb
Definition: pstypes.h:1103
#define NT_VERIFY(exp)
Definition: rtlfuncs.h:3287
#define ExInterlockedAddLargeStatistic(Addend, Increment)
Definition: exfuncs.h:850
LONG NTAPI KeSetEvent(IN PKEVENT Event, IN KPRIORITY Increment, IN BOOLEAN Wait)
Definition: eventobj.c:159
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
ULONG IoWriteOperationCount
Definition: iomgr.c:41
ULONG IoReadOperationCount
Definition: iomgr.c:39
FORCEINLINE BOOLEAN RemoveEntryList(_In_ PLIST_ENTRY Entry)
Definition: rtlfuncs.h:105
static __inline NTSTATUS IopLockFileObject(_In_ PFILE_OBJECT FileObject, _In_ KPROCESSOR_MODE WaitMode)
Definition: io_x.h:12
#define FALSE
Definition: types.h:117
_In_ PIRP Irp
Definition: csq.h:116
#define PsGetCurrentProcess
Definition: psfuncs.h:17
unsigned char BOOLEAN
#define _In_
Definition: ms_sal.h:308
FORCEINLINE VOID IopQueueIrpToThread(IN PIRP Irp)
Definition: io_x.h:49
_In_ WDFREQUEST _In_ WDFFILEOBJECT FileObject
Definition: wdfdevice.h:547
enum _IOP_TRANSFER_TYPE IOP_TRANSFER_TYPE
#define ASSERT(a)
Definition: mode.c:44
#define ObDereferenceObject
Definition: obfuncs.h:203
Type
Definition: Type.h:6
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2652
CCHAR KPROCESSOR_MODE
Definition: ketypes.h:7
* PFILE_OBJECT
Definition: iotypes.h:1998
LARGE_INTEGER IoOtherTransferCount
Definition: iomgr.c:44
#define KeEnterGuardedRegionThread(_Thread)
Definition: ke_x.h:27
BOOLEAN IoCountOperations
Definition: iomgr.c:38
#define InterlockedExchange
Definition: armddk.h:54
FORCEINLINE VOID IopUnQueueIrpFromThread(IN PIRP Irp)
Definition: io_x.h:66
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
#define FORCEINLINE
Definition: wdftypes.h:67
#define FO_ALERTABLE_IO
Definition: iotypes.h:1777
static __inline VOID IopUnlockFileObject(IN PFILE_OBJECT FileObject)
Definition: io_x.h:36
#define ObReferenceObject
Definition: obfuncs.h:204
static __inline VOID IopUpdateOperationCount(IN IOP_TRANSFER_TYPE Type)
Definition: io_x.h:82
unsigned int ULONG
Definition: retypes.h:1
#define IO_NO_INCREMENT
Definition: iotypes.h:598
#define KeLeaveGuardedRegionThread(_Thread)
Definition: ke_x.h:48
NTSTATUS NTAPI IopAcquireFileObjectLock(_In_ PFILE_OBJECT FileObject, _In_ KPROCESSOR_MODE AccessMode, _In_ BOOLEAN Alertable, _Out_ PBOOLEAN LockFailed)
Definition: file.c:2449
#define STATUS_SUCCESS
Definition: shellext.h:65
ULONG IoOtherOperationCount
Definition: iomgr.c:43
signed int * PLONG
Definition: retypes.h:5
LIST_ENTRY IrpList
Definition: pstypes.h:1144