[MSFS]
[reactos.git] / reactos / drivers / filesystems / msfs / msfssup.c
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS kernel
4 * FILE: drivers/filesystems/msfs/msfssup.c
5 * PURPOSE: Mailslot filesystem
6 * PROGRAMMER: Nikita Pechenkin (n.pechenkin@mail.ru)
7 */
8
9 /* INCLUDES ******************************************************************/
10 #include "msfs.h"
11
12 #define NDEBUG
13 #include <debug.h>
14
15 /* FUNCTIONS *****************************************************************/
16
17 VOID NTAPI
18 MsfsInsertIrp(PIO_CSQ Csq, PIRP Irp)
19 {
20 PMSFS_FCB Fcb;
21
22 Fcb = CONTAINING_RECORD(Csq, MSFS_FCB, CancelSafeQueue);
23 InsertTailList(&Fcb->PendingIrpQueue, &Irp->Tail.Overlay.ListEntry);
24 }
25
26 VOID NTAPI
27 MsfsRemoveIrp(PIO_CSQ Csq, PIRP Irp)
28 {
29 UNREFERENCED_PARAMETER(Csq);
30
31 RemoveEntryList(&Irp->Tail.Overlay.ListEntry);
32 }
33
34 PIRP NTAPI
35 MsfsPeekNextIrp(PIO_CSQ Csq, PIRP Irp, PVOID PeekContext)
36 {
37 PMSFS_FCB Fcb;
38 PIRP NextIrp = NULL;
39 PLIST_ENTRY NextEntry, ListHead;
40 PIO_STACK_LOCATION Stack;
41
42 Fcb = CONTAINING_RECORD(Csq, MSFS_FCB, CancelSafeQueue);
43
44 ListHead = &Fcb->PendingIrpQueue;
45
46 if (Irp == NULL)
47 {
48 NextEntry = ListHead->Flink;
49 }
50 else
51 {
52 NextEntry = Irp->Tail.Overlay.ListEntry.Flink;
53 }
54
55 for (; NextEntry != ListHead; NextEntry = NextEntry->Flink)
56 {
57 NextIrp = CONTAINING_RECORD(NextEntry, IRP, Tail.Overlay.ListEntry);
58
59 Stack = IoGetCurrentIrpStackLocation(NextIrp);
60
61 if (PeekContext)
62 {
63 if (Stack->FileObject == (PFILE_OBJECT)PeekContext)
64 {
65 break;
66 }
67 }
68 else
69 {
70 break;
71 }
72
73 NextIrp = NULL;
74 }
75
76 return NextIrp;
77 }
78
79 VOID NTAPI
80 MsfsAcquireLock(PIO_CSQ Csq, PKIRQL Irql)
81 {
82 PMSFS_FCB Fcb;
83
84 Fcb = CONTAINING_RECORD(Csq, MSFS_FCB, CancelSafeQueue);
85 KeAcquireSpinLock(&Fcb->QueueLock, Irql);
86 }
87
88
89 VOID NTAPI
90 MsfsReleaseLock(PIO_CSQ Csq, KIRQL Irql)
91 {
92 PMSFS_FCB Fcb;
93
94 Fcb = CONTAINING_RECORD(Csq, MSFS_FCB, CancelSafeQueue);
95 KeReleaseSpinLock(&Fcb->QueueLock, Irql);
96 }
97
98 VOID NTAPI
99 MsfsCompleteCanceledIrp(PIO_CSQ Csq, PIRP Irp)
100 {
101
102 UNREFERENCED_PARAMETER(Csq);
103
104 Irp->IoStatus.Status = STATUS_CANCELLED;
105 Irp->IoStatus.Information = 0;
106 IoCompleteRequest(Irp, IO_NO_INCREMENT);
107 }
108
109 VOID NTAPI
110 MsfsTimeout(PKDPC Dpc,
111 PVOID DeferredContext,
112 PVOID SystemArgument1,
113 PVOID SystemArgument2)
114 {
115 PMSFS_DPC_CTX Context;
116 PIRP Irp;
117
118 Context = (PMSFS_DPC_CTX)DeferredContext;
119
120 Irp = IoCsqRemoveIrp(Context->Csq, &Context->CsqContext);
121 if (Irp != NULL)
122 {
123 Irp->IoStatus.Status = STATUS_IO_TIMEOUT;
124 IoCompleteRequest(Irp, IO_NO_INCREMENT);
125 }
126
127 ExFreePool(Context);
128 }
129
130 /* EOF */