2 * PROJECT: ReactOS Kernel
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: ntoskrnl/include/io_x.h
5 * PURPOSE: Internal Inlined Functions for the I/O Manager
6 * PROGRAMMERS: Alex Ionescu (alex.ionescu@reactos.org)
12 IopLockFileObject(IN PFILE_OBJECT FileObject
)
14 /* Lock the FO and check for contention */
15 InterlockedIncrement((PLONG
)&FileObject
->Waiters
);
16 while (InterlockedCompareExchange((PLONG
)&FileObject
->Busy
, TRUE
, FALSE
) != FALSE
)
18 /* FIXME - pause for a little while? */
20 InterlockedDecrement((PLONG
)&FileObject
->Waiters
);
26 IopUnlockFileObject(IN PFILE_OBJECT FileObject
)
28 /* Unlock the FO and wake any waiters up */
29 InterlockedExchange((PLONG
)&FileObject
->Busy
, FALSE
);
30 if (FileObject
->Waiters
) KeSetEvent(&FileObject
->Lock
, 0, FALSE
);
35 IopQueueIrpToThread(IN PIRP Irp
)
39 /* Raise to APC Level */
40 KeRaiseIrql(APC_LEVEL
, &OldIrql
);
42 /* Insert it into the list */
43 InsertHeadList(&Irp
->Tail
.Overlay
.Thread
->IrpList
, &Irp
->ThreadListEntry
);
51 IopUnQueueIrpFromThread(IN PIRP Irp
)
53 /* Remove it from the list and reset it */
54 RemoveEntryList(&Irp
->ThreadListEntry
);
55 InitializeListHead(&Irp
->ThreadListEntry
);
61 IopUpdateOperationCount(IN IOP_TRANSFER_TYPE Type
)
63 PLARGE_INTEGER CountToChange
;
65 /* Make sure I/O operations are being counted */
66 if (IoCountOperations
)
68 if (Type
== IopReadTransfer
)
70 /* Increase read count */
71 IoReadOperationCount
++;
72 CountToChange
= &PsGetCurrentProcess()->ReadOperationCount
;
74 else if (Type
== IopWriteTransfer
)
76 /* Increase write count */
77 IoWriteOperationCount
++;
78 CountToChange
= &PsGetCurrentProcess()->WriteOperationCount
;
82 /* Increase other count */
83 IoOtherOperationCount
++;
84 CountToChange
= &PsGetCurrentProcess()->OtherOperationCount
;
87 /* Increase the process-wide count */
88 ExInterlockedAddLargeStatistic(CountToChange
, 1);
95 IopUpdateTransferCount(IN IOP_TRANSFER_TYPE Type
, IN ULONG TransferCount
)
97 PLARGE_INTEGER CountToChange
;
98 PLARGE_INTEGER TransferToChange
;
100 /* Make sure I/O operations are being counted */
101 if (IoCountOperations
)
103 if (Type
== IopReadTransfer
)
105 /* Increase read count */
106 CountToChange
= &PsGetCurrentProcess()->ReadTransferCount
;
107 TransferToChange
= &IoReadTransferCount
;
109 else if (Type
== IopWriteTransfer
)
111 /* Increase write count */
112 CountToChange
= &PsGetCurrentProcess()->WriteTransferCount
;
113 TransferToChange
= &IoWriteTransferCount
;
117 /* Increase other count */
118 CountToChange
= &PsGetCurrentProcess()->OtherTransferCount
;
119 TransferToChange
= &IoOtherTransferCount
;
122 /* Increase the process-wide count */
123 ExInterlockedAddLargeStatistic(CountToChange
, TransferCount
);
125 /* Increase global count */
126 ExInterlockedAddLargeStatistic(TransferToChange
, TransferCount
);
133 IopValidateOpenPacket(IN POPEN_PACKET OpenPacket
)
135 /* Validate the packet */
137 (OpenPacket
->Type
!= IO_TYPE_OPEN_PACKET
) ||
138 (OpenPacket
->Size
!= sizeof(OPEN_PACKET
)))