ReactOS 0.4.16-dev-336-gb667d82
msfs.h File Reference
#include <ntifs.h>
Include dependency graph for msfs.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  _MSFS_DEVICE_EXTENSION
 
struct  _MSFS_FCB
 
struct  _MSFS_DPC_CTX
 
struct  _MSFS_CCB
 
struct  _MSFS_MESSAGE
 

Macros

#define DEFAULTAPI   NTAPI
 
#define KeLockMutex(x)
 
#define KeUnlockMutex(x)   KeReleaseMutex(x, FALSE);
 

Typedefs

typedef struct _MSFS_DEVICE_EXTENSION MSFS_DEVICE_EXTENSION
 
typedef struct _MSFS_DEVICE_EXTENSIONPMSFS_DEVICE_EXTENSION
 
typedef struct _MSFS_FCB MSFS_FCB
 
typedef struct _MSFS_FCBPMSFS_FCB
 
typedef struct _MSFS_DPC_CTX MSFS_DPC_CTX
 
typedef struct _MSFS_DPC_CTXPMSFS_DPC_CTX
 
typedef struct _MSFS_CCB MSFS_CCB
 
typedef struct _MSFS_CCBPMSFS_CCB
 
typedef struct _MSFS_MESSAGE MSFS_MESSAGE
 
typedef struct _MSFS_MESSAGEPMSFS_MESSAGE
 

Functions

NTSTATUS DEFAULTAPI MsfsCreate (PDEVICE_OBJECT DeviceObject, PIRP Irp)
 
NTSTATUS DEFAULTAPI MsfsCreateMailslot (PDEVICE_OBJECT DeviceObject, PIRP Irp)
 
NTSTATUS DEFAULTAPI MsfsClose (PDEVICE_OBJECT DeviceObject, PIRP Irp)
 
NTSTATUS DEFAULTAPI MsfsQueryInformation (PDEVICE_OBJECT DeviceObject, PIRP Irp)
 
NTSTATUS DEFAULTAPI MsfsSetInformation (PDEVICE_OBJECT DeviceObject, PIRP Irp)
 
NTSTATUS DEFAULTAPI MsfsRead (PDEVICE_OBJECT DeviceObject, PIRP Irp)
 
NTSTATUS DEFAULTAPI MsfsWrite (PDEVICE_OBJECT DeviceObject, PIRP Irp)
 
NTSTATUS DEFAULTAPI MsfsFileSystemControl (PDEVICE_OBJECT DeviceObject, PIRP Irp)
 
NTSTATUS NTAPI DriverEntry (PDRIVER_OBJECT DriverObject, PUNICODE_STRING RegistryPath)
 
VOID NTAPI MsfsInsertIrp (PIO_CSQ Csq, PIRP Irp)
 
VOID NTAPI MsfsRemoveIrp (PIO_CSQ Csq, PIRP Irp)
 
PIRP NTAPI MsfsPeekNextIrp (PIO_CSQ Csq, PIRP Irp, PVOID PeekContext)
 
VOID NTAPI MsfsAcquireLock (PIO_CSQ Csq, PKIRQL Irql)
 
VOID NTAPI MsfsReleaseLock (PIO_CSQ Csq, KIRQL Irql)
 
VOID NTAPI MsfsCompleteCanceledIrp (PIO_CSQ pCsq, PIRP Irp)
 
VOID NTAPI MsfsTimeout (PKDPC Dpc, PVOID DeferredContext, PVOID SystemArgument1, PVOID SystemArgument2)
 

Variables

DRIVER_DISPATCH MsfsCreate
 
DRIVER_DISPATCH MsfsCreateMailslot
 
DRIVER_DISPATCH MsfsClose
 
DRIVER_DISPATCH MsfsQueryInformation
 
DRIVER_DISPATCH MsfsSetInformation
 
DRIVER_DISPATCH MsfsRead
 
DRIVER_DISPATCH MsfsWrite
 
DRIVER_DISPATCH MsfsFileSystemControl
 
IO_CSQ_INSERT_IRP MsfsInsertIrp
 
IO_CSQ_REMOVE_IRP MsfsRemoveIrp
 
IO_CSQ_PEEK_NEXT_IRP MsfsPeekNextIrp
 
IO_CSQ_ACQUIRE_LOCK MsfsAcquireLock
 
IO_CSQ_RELEASE_LOCK MsfsReleaseLock
 
IO_CSQ_COMPLETE_CANCELED_IRP MsfsCompleteCanceledIrp
 
KDEFERRED_ROUTINE MsfsTimeout
 

Macro Definition Documentation

◆ DEFAULTAPI

#define DEFAULTAPI   NTAPI

Definition at line 15 of file msfs.h.

◆ KeLockMutex

#define KeLockMutex (   x)
Value:
FALSE, \
NULL);
#define NULL
Definition: types.h:112
#define FALSE
Definition: types.h:117
#define KeWaitForSingleObject(pEvt, foo, a, b, c)
Definition: env_spec_w32.h:478
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
#define KernelMode
Definition: asm.h:34
@ Executive
Definition: ketypes.h:415

Definition at line 69 of file msfs.h.

◆ KeUnlockMutex

#define KeUnlockMutex (   x)    KeReleaseMutex(x, FALSE);

Definition at line 75 of file msfs.h.

Typedef Documentation

◆ MSFS_CCB

◆ MSFS_DEVICE_EXTENSION

◆ MSFS_DPC_CTX

◆ MSFS_FCB

◆ MSFS_MESSAGE

◆ PMSFS_CCB

◆ PMSFS_DEVICE_EXTENSION

◆ PMSFS_DPC_CTX

◆ PMSFS_FCB

◆ PMSFS_MESSAGE

Function Documentation

◆ DriverEntry()

NTSTATUS NTAPI DriverEntry ( PDRIVER_OBJECT  DriverObject,
PUNICODE_STRING  RegistryPath 
)

Definition at line 16 of file battc.c.

18{
19 DPRINT("Battery class driver initialized\n");
20
21 return STATUS_SUCCESS;
22}
#define STATUS_SUCCESS
Definition: shellext.h:65
#define DPRINT
Definition: sndvol32.h:73

◆ MsfsAcquireLock()

VOID NTAPI MsfsAcquireLock ( PIO_CSQ  Csq,
PKIRQL  Irql 
)

Definition at line 80 of file msfssup.c.

81{
83
84 Fcb = CONTAINING_RECORD(Csq, MSFS_FCB, CancelSafeQueue);
85 KeAcquireSpinLock(&Fcb->QueueLock, Irql);
86}
_In_ PFCB Fcb
Definition: cdprocs.h:159
_Out_ PKIRQL Irql
Definition: csq.h:179
IO_CSQ Csq
Definition: csqrtns.c:46
#define KeAcquireSpinLock(sl, irql)
Definition: env_spec_w32.h:609
Definition: msfs.h:25
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260

◆ MsfsClose()

NTSTATUS DEFAULTAPI MsfsClose ( PDEVICE_OBJECT  DeviceObject,
PIRP  Irp 
)

Definition at line 253 of file create.c.

255{
256 PIO_STACK_LOCATION IoStack;
258 PMSFS_DEVICE_EXTENSION DeviceExtension;
262 KIRQL oldIrql;
263
264 DPRINT("MsfsClose(DeviceObject %p Irp %p)\n", DeviceObject, Irp);
265
267 DeviceExtension = DeviceObject->DeviceExtension;
268 FileObject = IoStack->FileObject;
269
270 KeLockMutex(&DeviceExtension->FcbListLock);
271
272 if (DeviceExtension->FcbListHead.Flink == &DeviceExtension->FcbListHead)
273 {
274 KeUnlockMutex(&DeviceExtension->FcbListLock);
275
276 Irp->IoStatus.Status = STATUS_SUCCESS;
277 Irp->IoStatus.Information = 0;
278
280
281 return STATUS_SUCCESS;
282 }
283
284 Fcb = FileObject->FsContext;
285 Ccb = FileObject->FsContext2;
286
287 DPRINT("Mailslot name: %wZ\n", &Fcb->Name);
288
289 Fcb->ReferenceCount--;
290 if (Fcb->ServerCcb == Ccb)
291 {
292 /* delete all messages from message-list */
293 KeAcquireSpinLock(&Fcb->MessageListLock, &oldIrql);
294
295 while (Fcb->MessageListHead.Flink != &Fcb->MessageListHead)
296 {
297 Message = CONTAINING_RECORD(Fcb->MessageListHead.Flink,
299 MessageListEntry);
300 RemoveEntryList(Fcb->MessageListHead.Flink);
301 ExFreePoolWithTag(Message, 'rFsM');
302 }
303
304 Fcb->MessageCount = 0;
305
306 KeReleaseSpinLock(&Fcb->MessageListLock, oldIrql);
307 Fcb->ServerCcb = NULL;
308 }
309
310 KeAcquireSpinLock(&Fcb->CcbListLock, &oldIrql);
311 RemoveEntryList(&Ccb->CcbListEntry);
312 KeReleaseSpinLock(&Fcb->CcbListLock, oldIrql);
313 ExFreePoolWithTag(Ccb, 'cFsM');
314 FileObject->FsContext2 = NULL;
315
316 if (Fcb->ReferenceCount == 0)
317 {
318 DPRINT("ReferenceCount == 0: Deleting mailslot data\n");
320 ExFreePoolWithTag(Fcb->Name.Buffer, 'NFsM');
321 ExFreePoolWithTag(Fcb, 'fFsM');
322 }
323
324 KeUnlockMutex(&DeviceExtension->FcbListLock);
325
326 Irp->IoStatus.Status = STATUS_SUCCESS;
327 Irp->IoStatus.Information = 0;
328
330
331 return STATUS_SUCCESS;
332}
static PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(PIRP Irp)
_Inout_ PFILE_OBJECT _In_ TYPE_OF_OPEN PFCB _In_opt_ PCCB Ccb
Definition: cdprocs.h:592
_In_ PIRP Irp
Definition: csq.h:116
static const WCHAR Message[]
Definition: register.c:74
#define RemoveEntryList(Entry)
Definition: env_spec_w32.h:986
UCHAR KIRQL
Definition: env_spec_w32.h:591
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1109
#define KeUnlockMutex(x)
Definition: msfs.h:75
#define KeLockMutex(x)
Definition: msfs.h:69
#define IoCompleteRequest
Definition: irp.c:1240
LIST_ENTRY FcbListEntry
Definition: ntfs.h:530
PFILE_OBJECT FileObject
Definition: iotypes.h:3169
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
Definition: msfs.h:55
KMUTEX FcbListLock
Definition: msfs.h:20
LIST_ENTRY FcbListHead
Definition: msfs.h:19
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
_In_ WDFREQUEST _In_ WDFFILEOBJECT FileObject
Definition: wdfdevice.h:550
#define IO_NO_INCREMENT
Definition: iotypes.h:598
* PFILE_OBJECT
Definition: iotypes.h:1998

◆ MsfsCompleteCanceledIrp()

VOID NTAPI MsfsCompleteCanceledIrp ( PIO_CSQ  pCsq,
PIRP  Irp 
)

Definition at line 99 of file msfssup.c.

100{
101
103
104 Irp->IoStatus.Status = STATUS_CANCELLED;
105 Irp->IoStatus.Information = 0;
107}
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:325
#define STATUS_CANCELLED
Definition: udferr_usr.h:170

◆ MsfsCreate()

NTSTATUS DEFAULTAPI MsfsCreate ( PDEVICE_OBJECT  DeviceObject,
PIRP  Irp 
)

Definition at line 23 of file create.c.

25{
26 PIO_STACK_LOCATION IoStack;
28 PMSFS_DEVICE_EXTENSION DeviceExtension;
32 PLIST_ENTRY current_entry;
33 KIRQL oldIrql;
34
35 DPRINT("MsfsCreate(DeviceObject %p Irp %p)\n", DeviceObject, Irp);
36
38 DeviceExtension = DeviceObject->DeviceExtension;
39 FileObject = IoStack->FileObject;
40
41 DPRINT("Mailslot name: %wZ\n", &FileObject->FileName);
42
44 if (Ccb == NULL)
45 {
46 Irp->IoStatus.Status = STATUS_NO_MEMORY;
47 Irp->IoStatus.Information = 0;
48
50 return STATUS_NO_MEMORY;
51 }
52
53 KeLockMutex(&DeviceExtension->FcbListLock);
54 current_entry = DeviceExtension->FcbListHead.Flink;
55 while (current_entry != &DeviceExtension->FcbListHead)
56 {
57 current = CONTAINING_RECORD(current_entry,
59 FcbListEntry);
60
61 if (!RtlCompareUnicodeString(&FileObject->FileName, &current->Name, TRUE))
62 break;
63
64 current_entry = current_entry->Flink;
65 }
66
67 if (current_entry == &DeviceExtension->FcbListHead)
68 {
69 ExFreePoolWithTag(Ccb, 'cFsM');
70 KeUnlockMutex(&DeviceExtension->FcbListLock);
71
72 Irp->IoStatus.Status = STATUS_UNSUCCESSFUL;
73 Irp->IoStatus.Information = 0;
74
76
78 }
79
80 Fcb = current;
81
82 KeAcquireSpinLock(&Fcb->CcbListLock, &oldIrql);
83 InsertTailList(&Fcb->CcbListHead, &Ccb->CcbListEntry);
84 KeReleaseSpinLock(&Fcb->CcbListLock, oldIrql);
85
86 Fcb->ReferenceCount++;
87
88 Ccb->Fcb = Fcb;
89
90 KeUnlockMutex(&DeviceExtension->FcbListLock);
91
92 FileObject->FsContext = Fcb;
93 FileObject->FsContext2 = Ccb;
95
96 Irp->IoStatus.Status = STATUS_SUCCESS;
97 Irp->IoStatus.Information = 0;
98
100
101 return STATUS_SUCCESS;
102}
#define STATUS_NO_MEMORY
Definition: d3dkmdt.h:51
#define TRUE
Definition: types.h:120
#define InsertTailList(ListHead, Entry)
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
ULONG RtlCompareUnicodeString(PUNICODE_STRING s1, PUNICODE_STRING s2, BOOLEAN UpCase)
Definition: string_lib.cpp:31
#define NonPagedPool
Definition: env_spec_w32.h:307
struct task_struct * current
Definition: linux.c:32
ULONG Flags
Definition: ntfs.h:536
struct _FCB::@731::@734 Fcb
Definition: typedefs.h:120
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
#define FO_MAILSLOT
Definition: iotypes.h:1784

◆ MsfsCreateMailslot()

NTSTATUS DEFAULTAPI MsfsCreateMailslot ( PDEVICE_OBJECT  DeviceObject,
PIRP  Irp 
)

Definition at line 107 of file create.c.

109{
110 PIO_STACK_LOCATION IoStack;
112 PMSFS_DEVICE_EXTENSION DeviceExtension;
115 KIRQL oldIrql;
116 PLIST_ENTRY current_entry;
119
120 DPRINT("MsfsCreateMailslot(DeviceObject %p Irp %p)\n", DeviceObject, Irp);
121
123 DeviceExtension = DeviceObject->DeviceExtension;
124 FileObject = IoStack->FileObject;
125 Buffer = IoStack->Parameters.CreateMailslot.Parameters;
126
127 DPRINT("Mailslot name: %wZ\n", &FileObject->FileName);
128
130 if (Fcb == NULL)
131 {
132 Irp->IoStatus.Status = STATUS_NO_MEMORY;
133 Irp->IoStatus.Information = 0;
134
136
137 return STATUS_NO_MEMORY;
138 }
139
140 Fcb->Name.Length = FileObject->FileName.Length;
141 Fcb->Name.MaximumLength = Fcb->Name.Length + sizeof(UNICODE_NULL);
143 Fcb->Name.MaximumLength,
144 'NFsM');
145 if (Fcb->Name.Buffer == NULL)
146 {
147 ExFreePoolWithTag(Fcb, 'fFsM');
148
149 Irp->IoStatus.Status = STATUS_NO_MEMORY;
150 Irp->IoStatus.Information = 0;
151
153
154 return STATUS_NO_MEMORY;
155 }
156
157 RtlCopyUnicodeString(&Fcb->Name, &FileObject->FileName);
158
160 if (Ccb == NULL)
161 {
162 ExFreePoolWithTag(Fcb->Name.Buffer, 'NFsM');
163 ExFreePoolWithTag(Fcb, 'fFsM');
164
165 Irp->IoStatus.Status = STATUS_NO_MEMORY;
166 Irp->IoStatus.Information = 0;
167
169
170 return STATUS_NO_MEMORY;
171 }
172
173 Fcb->ReferenceCount = 0;
174 InitializeListHead(&Fcb->CcbListHead);
175 KeInitializeSpinLock(&Fcb->CcbListLock);
176
177 Fcb->MaxMessageSize = Buffer->MaximumMessageSize;
178 Fcb->MessageCount = 0;
179 Fcb->TimeOut = Buffer->ReadTimeout;
180
181 InitializeListHead(&Fcb->MessageListHead);
182 KeInitializeSpinLock(&Fcb->MessageListLock);
183
184 KeInitializeSpinLock(&Fcb->QueueLock);
185 InitializeListHead(&Fcb->PendingIrpQueue);
186 IoCsqInitialize(&Fcb->CancelSafeQueue,
193
194 KeLockMutex(&DeviceExtension->FcbListLock);
195 current_entry = DeviceExtension->FcbListHead.Flink;
196 while (current_entry != &DeviceExtension->FcbListHead)
197 {
198 current = CONTAINING_RECORD(current_entry,
199 MSFS_FCB,
200 FcbListEntry);
201
202 if (!RtlCompareUnicodeString(&Fcb->Name, &current->Name, TRUE))
203 break;
204
205 current_entry = current_entry->Flink;
206 }
207
208 if (current_entry != &DeviceExtension->FcbListHead)
209 {
210 ExFreePoolWithTag(Fcb->Name.Buffer, 'NFsM');
211 ExFreePoolWithTag(Fcb, 'fFsM');
212 ExFreePoolWithTag(Ccb, 'cFsM');
213
214 KeUnlockMutex(&DeviceExtension->FcbListLock);
215
216 Irp->IoStatus.Status = STATUS_UNSUCCESSFUL;
217 Irp->IoStatus.Information = 0;
218
220
221 return STATUS_UNSUCCESSFUL;
222 }
223 else
224 {
225 InsertTailList(&DeviceExtension->FcbListHead,
226 &Fcb->FcbListEntry);
227 }
228
229 KeAcquireSpinLock(&Fcb->CcbListLock, &oldIrql);
230 InsertTailList(&Fcb->CcbListHead, &Ccb->CcbListEntry);
231 KeReleaseSpinLock(&Fcb->CcbListLock, oldIrql);
232
233 Fcb->ReferenceCount++;
234 Fcb->ServerCcb = Ccb;
235 Ccb->Fcb = Fcb;
236
237 KeUnlockMutex(&DeviceExtension->FcbListLock);
238
239 FileObject->FsContext = Fcb;
240 FileObject->FsContext2 = Ccb;
242
243 Irp->IoStatus.Status = STATUS_SUCCESS;
244 Irp->IoStatus.Information = 0;
245
247
248 return STATUS_SUCCESS;
249}
Definition: bufpool.h:45
NTKERNELAPI NTSTATUS NTAPI IoCsqInitialize(_Out_ PIO_CSQ Csq, _In_ PIO_CSQ_INSERT_IRP CsqInsertIrp, _In_ PIO_CSQ_REMOVE_IRP CsqRemoveIrp, _In_ PIO_CSQ_PEEK_NEXT_IRP CsqPeekNextIrp, _In_ PIO_CSQ_ACQUIRE_LOCK CsqAcquireLock, _In_ PIO_CSQ_RELEASE_LOCK CsqReleaseLock, _In_ PIO_CSQ_COMPLETE_CANCELED_IRP CsqCompleteCanceledIrp)
Set up a CSQ struct to initialize the queue.
Definition: csq.c:103
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
#define KeInitializeSpinLock(sl)
Definition: env_spec_w32.h:604
IO_CSQ_REMOVE_IRP MsfsRemoveIrp
Definition: msfs.h:109
IO_CSQ_ACQUIRE_LOCK MsfsAcquireLock
Definition: msfs.h:117
IO_CSQ_RELEASE_LOCK MsfsReleaseLock
Definition: msfs.h:121
IO_CSQ_COMPLETE_CANCELED_IRP MsfsCompleteCanceledIrp
Definition: msfs.h:125
IO_CSQ_PEEK_NEXT_IRP MsfsPeekNextIrp
Definition: msfs.h:113
IO_CSQ_INSERT_IRP MsfsInsertIrp
Definition: msfs.h:105
NTSYSAPI VOID NTAPI RtlCopyUnicodeString(PUNICODE_STRING DestinationString, PUNICODE_STRING SourceString)
#define UNICODE_NULL
union _IO_STACK_LOCATION::@1581 Parameters
struct _IO_STACK_LOCATION::@3980::@3983 CreateMailslot

◆ MsfsFileSystemControl()

NTSTATUS DEFAULTAPI MsfsFileSystemControl ( PDEVICE_OBJECT  DeviceObject,
PIRP  Irp 
)

Definition at line 19 of file fsctrl.c.

21{
22 PIO_STACK_LOCATION IoStack;
26
27 DPRINT1("MsfsFileSystemControl(DeviceObject %p Irp %p)\n", DeviceObject, Irp);
28
30 FileObject = IoStack->FileObject;
31 Fcb = FileObject->FsContext;
32
33 DPRINT1("Mailslot name: %wZ\n", &Fcb->Name);
34
35 switch (IoStack->Parameters.FileSystemControl.FsControlCode)
36 {
37 default:
39 }
40
41 Irp->IoStatus.Status = Status;
42 Irp->IoStatus.Information = 0;
44
45 return Status;
46}
LONG NTSTATUS
Definition: precomp.h:26
#define DPRINT1
Definition: precomp.h:8
#define STATUS_NOT_IMPLEMENTED
Definition: d3dkmdt.h:42
Status
Definition: gdiplustypes.h:25
struct _IO_STACK_LOCATION::@3980::@3995 FileSystemControl

◆ MsfsInsertIrp()

VOID NTAPI MsfsInsertIrp ( PIO_CSQ  Csq,
PIRP  Irp 
)

Definition at line 18 of file msfssup.c.

19{
21
22 Fcb = CONTAINING_RECORD(Csq, MSFS_FCB, CancelSafeQueue);
23 InsertTailList(&Fcb->PendingIrpQueue, &Irp->Tail.Overlay.ListEntry);
24}

◆ MsfsPeekNextIrp()

PIRP NTAPI MsfsPeekNextIrp ( PIO_CSQ  Csq,
PIRP  Irp,
PVOID  PeekContext 
)

Definition at line 35 of file msfssup.c.

36{
38 PIRP NextIrp = NULL;
39 PLIST_ENTRY NextEntry, ListHead;
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
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}
_In_opt_ PIRP _In_opt_ PVOID PeekContext
Definition: csq.h:160
_In_ WDFREQUEST _In_ PIO_STACK_LOCATION Stack
Definition: wdfrequest.h:639

◆ MsfsQueryInformation()

NTSTATUS DEFAULTAPI MsfsQueryInformation ( PDEVICE_OBJECT  DeviceObject,
PIRP  Irp 
)

Definition at line 72 of file finfo.c.

74{
75 PIO_STACK_LOCATION IoStack;
80 PVOID SystemBuffer;
83
84 DPRINT("MsfsQueryInformation(DeviceObject %p Irp %p)\n",
86
88 FileInformationClass = IoStack->Parameters.QueryFile.FileInformationClass;
89 FileObject = IoStack->FileObject;
90 Fcb = (PMSFS_FCB)FileObject->FsContext;
91 Ccb = (PMSFS_CCB)FileObject->FsContext2;
92
93 DPRINT("Mailslot name: %wZ\n", &Fcb->Name);
94
95 /* querying information is not permitted on client side */
96 if (Fcb->ServerCcb != Ccb)
97 {
99
100 Irp->IoStatus.Status = Status;
101 Irp->IoStatus.Information = 0;
102
104
105 return Status;
106 }
107
108 SystemBuffer = Irp->AssociatedIrp.SystemBuffer;
109 BufferLength = IoStack->Parameters.QueryFile.Length;
110
111 switch (FileInformationClass)
112 {
115 SystemBuffer,
116 &BufferLength);
117 break;
118
119 default:
121 }
122
123 Irp->IoStatus.Status = Status;
124 if (NT_SUCCESS(Status))
125 Irp->IoStatus.Information =
126 IoStack->Parameters.QueryFile.Length - BufferLength;
127 else
128 Irp->IoStatus.Information = 0;
130
131 return Status;
132}
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
@ FileMailslotQueryInformation
Definition: from_kernel.h:87
enum _FILE_INFORMATION_CLASS FILE_INFORMATION_CLASS
Definition: directory.c:44
static OUT PIO_STATUS_BLOCK OUT PVOID IN ULONG IN FILE_INFORMATION_CLASS FileInformationClass
Definition: pipe.c:75
static NTSTATUS MsfsQueryMailslotInformation(PMSFS_FCB Fcb, PFILE_MAILSLOT_QUERY_INFORMATION Buffer, PULONG BufferLength)
Definition: finfo.c:24
struct _MSFS_FCB * PMSFS_FCB
struct _IO_STACK_LOCATION::@3980::@3989 QueryFile
uint32_t ULONG
Definition: typedefs.h:59
#define STATUS_ACCESS_DENIED
Definition: udferr_usr.h:145
_Must_inspect_result_ _In_ WDFDEVICE _In_ DEVICE_REGISTRY_PROPERTY _In_ ULONG BufferLength
Definition: wdfdevice.h:3771

◆ MsfsRead()

NTSTATUS DEFAULTAPI MsfsRead ( PDEVICE_OBJECT  DeviceObject,
PIRP  Irp 
)

Definition at line 20 of file rw.c.

22{
23 PIO_STACK_LOCATION IoStack;
28 KIRQL oldIrql;
30 ULONG LengthRead = 0;
35 PKDPC Dpc;
37
38 DPRINT("MsfsRead(DeviceObject %p Irp %p)\n", DeviceObject, Irp);
39
41 FileObject = IoStack->FileObject;
42 Fcb = (PMSFS_FCB)FileObject->FsContext;
43 Ccb = (PMSFS_CCB)FileObject->FsContext2;
44
45 DPRINT("MailslotName: %wZ\n", &Fcb->Name);
46
47 /* reading is not permitted on client side */
48 if (Fcb->ServerCcb != Ccb)
49 {
50 Irp->IoStatus.Status = STATUS_ACCESS_DENIED;
51 Irp->IoStatus.Information = 0;
52
54
56 }
57
58 Length = IoStack->Parameters.Read.Length;
59 if (Irp->MdlAddress)
61 else
62 Buffer = Irp->UserBuffer;
63
64
65 KeAcquireSpinLock(&Fcb->MessageListLock, &oldIrql);
66 if (Fcb->MessageCount > 0)
67 {
68 Entry = RemoveHeadList(&Fcb->MessageListHead);
69 Fcb->MessageCount--;
70 KeReleaseSpinLock(&Fcb->MessageListLock, oldIrql);
71
72 /* copy current message into buffer */
73 Message = CONTAINING_RECORD(Entry, MSFS_MESSAGE, MessageListEntry);
74 memcpy(Buffer, &Message->Buffer, min(Message->Size,Length));
75 LengthRead = Message->Size;
76
78
79 Irp->IoStatus.Status = STATUS_SUCCESS;
80 Irp->IoStatus.Information = LengthRead;
82
83 return STATUS_SUCCESS;
84 }
85 else
86 {
87 KeReleaseSpinLock(&Fcb->MessageListLock, oldIrql);
88 }
89
90 Timeout = Fcb->TimeOut;
91 if (Timeout.HighPart == 0 && Timeout.LowPart == 0)
92 {
93 Irp->IoStatus.Status = STATUS_IO_TIMEOUT;
94 Irp->IoStatus.Information = 0;
96
97 return STATUS_IO_TIMEOUT;
98 }
99
101 if (Context == NULL)
102 {
103 Irp->IoStatus.Status = STATUS_INSUFFICIENT_RESOURCES;
104 Irp->IoStatus.Information = 0;
106
108 }
109
111 IoCsqInsertIrp(&Fcb->CancelSafeQueue, Irp, &Context->CsqContext);
112 Timer = &Context->Timer;
113 Dpc = &Context->Dpc;
114 Context->Csq = &Fcb->CancelSafeQueue;
115 Irp->Tail.Overlay.DriverContext[0] = Context;
116
117 /* No timer for INFINITY_WAIT */
118 if (Timeout.QuadPart != -1)
119 {
123 }
124
126
127 return STATUS_PENDING;
128}
NTKERNELAPI VOID NTAPI IoCsqInsertIrp(_Inout_ PIO_CSQ Csq, _Inout_ PIRP Irp, _Out_opt_ PIO_CSQ_IRP_CONTEXT Context)
Insert an IRP into the CSQ.
Definition: csq.c:177
#define STATUS_PENDING
Definition: d3dkmdt.h:43
VOID NTAPI KeInitializeDpc(IN PKDPC Dpc, IN PKDEFERRED_ROUTINE DeferredRoutine, IN PVOID DeferredContext)
Definition: dpc.c:712
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
#define RemoveHeadList(ListHead)
Definition: env_spec_w32.h:964
IoMarkIrpPending(Irp)
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
@ NormalPagePriority
Definition: imports.h:54
#define min(a, b)
Definition: monoChain.cc:55
KDEFERRED_ROUTINE MsfsTimeout
Definition: msfs.h:129
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
@ SynchronizationEvent
static ULONG Timeout
Definition: ping.c:61
base of all file and directory entries
Definition: entries.h:83
struct _IO_STACK_LOCATION::@3980::@3984 Read
Definition: ketypes.h:699
BOOLEAN NTAPI KeSetTimer(IN OUT PKTIMER Timer, IN LARGE_INTEGER DueTime, IN PKDPC Dpc OPTIONAL)
Definition: timerobj.c:281
VOID NTAPI KeInitializeTimer(OUT PKTIMER Timer)
Definition: timerobj.c:233
#define STATUS_IO_TIMEOUT
Definition: udferr_usr.h:163
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_Must_inspect_result_ _In_ PWDF_DPC_CONFIG _In_ PWDF_OBJECT_ATTRIBUTES _Out_ WDFDPC * Dpc
Definition: wdfdpc.h:112
#define MmGetSystemAddressForMdlSafe(_Mdl, _Priority)

◆ MsfsReleaseLock()

VOID NTAPI MsfsReleaseLock ( PIO_CSQ  Csq,
KIRQL  Irql 
)

Definition at line 90 of file msfssup.c.

91{
93
94 Fcb = CONTAINING_RECORD(Csq, MSFS_FCB, CancelSafeQueue);
95 KeReleaseSpinLock(&Fcb->QueueLock, Irql);
96}

◆ MsfsRemoveIrp()

VOID NTAPI MsfsRemoveIrp ( PIO_CSQ  Csq,
PIRP  Irp 
)

Definition at line 27 of file msfssup.c.

28{
30
31 RemoveEntryList(&Irp->Tail.Overlay.ListEntry);
32}

◆ MsfsSetInformation()

NTSTATUS DEFAULTAPI MsfsSetInformation ( PDEVICE_OBJECT  DeviceObject,
PIRP  Irp 
)

Definition at line 136 of file finfo.c.

138{
139 PIO_STACK_LOCATION IoStack;
144 PVOID SystemBuffer;
147
148 DPRINT("MsfsSetInformation(DeviceObject %p Irp %p)\n", DeviceObject, Irp);
149
151 FileInformationClass = IoStack->Parameters.QueryFile.FileInformationClass;
152 FileObject = IoStack->FileObject;
153 Fcb = (PMSFS_FCB)FileObject->FsContext;
154 Ccb = (PMSFS_CCB)FileObject->FsContext2;
155
156 DPRINT("Mailslot name: %wZ\n", &Fcb->Name);
157
158 /* setting information is not permitted on client side */
159 if (Fcb->ServerCcb != Ccb)
160 {
162
163 Irp->IoStatus.Status = Status;
164 Irp->IoStatus.Information = 0;
165
167
168 return Status;
169 }
170
171 SystemBuffer = Irp->AssociatedIrp.SystemBuffer;
172 BufferLength = IoStack->Parameters.QueryFile.Length;
173
174 DPRINT("FileInformationClass %d\n", FileInformationClass);
175 DPRINT("SystemBuffer %p\n", SystemBuffer);
176
177 switch (FileInformationClass)
178 {
181 SystemBuffer,
182 &BufferLength);
183 break;
184
185 default:
187 }
188
189 Irp->IoStatus.Status = Status;
190 Irp->IoStatus.Information = 0;
192
193 return Status;
194}
@ FileMailslotSetInformation
Definition: from_kernel.h:88
static NTSTATUS MsfsSetMailslotInformation(PMSFS_FCB Fcb, PFILE_MAILSLOT_SET_INFORMATION Buffer, PULONG BufferLength)
Definition: finfo.c:58

◆ MsfsTimeout()

VOID NTAPI MsfsTimeout ( PKDPC  Dpc,
PVOID  DeferredContext,
PVOID  SystemArgument1,
PVOID  SystemArgument2 
)

Definition at line 110 of file msfssup.c.

114{
116 PIRP Irp;
117
119
120 /* Try to get the IRP */
121 Irp = IoCsqRemoveIrp(Context->Csq, &Context->CsqContext);
122 if (Irp != NULL)
123 {
124 /* It timed out, complete it (it's ours) and free context */
125 Irp->IoStatus.Status = STATUS_IO_TIMEOUT;
127 ExFreePoolWithTag(Context, 'NFsM');
128 }
129 else
130 {
131 /* We were racing with writing and failed, signal we're done */
133 }
134}
NTKERNELAPI PIRP NTAPI IoCsqRemoveIrp(_Inout_ PIO_CSQ Csq, _Inout_ PIO_CSQ_IRP_CONTEXT Context)
Remove anb IRP from the queue.
Definition: csq.c:326
#define KeSetEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:476
struct _MSFS_DPC_CTX * PMSFS_DPC_CTX
_In_opt_ PVOID DeferredContext
Definition: ketypes.h:687

◆ MsfsWrite()

NTSTATUS DEFAULTAPI MsfsWrite ( PDEVICE_OBJECT  DeviceObject,
PIRP  Irp 
)

Definition at line 132 of file rw.c.

134{
135 PIO_STACK_LOCATION IoStack;
140 KIRQL oldIrql;
143 PIRP CsqIrp;
145
146 DPRINT("MsfsWrite(DeviceObject %p Irp %p)\n", DeviceObject, Irp);
147
149 FileObject = IoStack->FileObject;
150 Fcb = (PMSFS_FCB)FileObject->FsContext;
151 Ccb = (PMSFS_CCB)FileObject->FsContext2;
152
153 DPRINT("MailslotName: %wZ\n", &Fcb->Name);
154
155 /* writing is not permitted on server side */
156 if (Fcb->ServerCcb == Ccb)
157 {
158 Irp->IoStatus.Status = STATUS_ACCESS_DENIED;
159 Irp->IoStatus.Information = 0;
160
162
164 }
165
166 Length = IoStack->Parameters.Write.Length;
167 if (Irp->MdlAddress)
169 else
170 Buffer = Irp->UserBuffer;
171
172 DPRINT("Length: %lu Message: %s\n", Length, (PUCHAR)Buffer);
173
174 /* Allocate new message */
176 sizeof(MSFS_MESSAGE) + Length,
177 'rFsM');
178 if (Message == NULL)
179 {
180 Irp->IoStatus.Status = STATUS_NO_MEMORY;
181 Irp->IoStatus.Information = 0;
182
184
185 return STATUS_NO_MEMORY;
186 }
187
188 Message->Size = Length;
189 memcpy(&Message->Buffer, Buffer, Length);
190
191 KeAcquireSpinLock(&Fcb->MessageListLock, &oldIrql);
192 InsertTailList(&Fcb->MessageListHead, &Message->MessageListEntry);
193 Fcb->MessageCount++;
194 KeReleaseSpinLock(&Fcb->MessageListLock, oldIrql);
195
196 CsqIrp = IoCsqRemoveNextIrp(&Fcb->CancelSafeQueue, NULL);
197 if (CsqIrp != NULL)
198 {
199 /* Get the context */
200 Context = CsqIrp->Tail.Overlay.DriverContext[0];
201 /* DPC was queued, wait for it to fail (IRP is ours) */
202 if (Fcb->TimeOut.QuadPart != -1 && !KeCancelTimer(&Context->Timer))
203 {
205 }
206
207 /* Free context & attempt read */
208 ExFreePoolWithTag(Context, 'NFsM');
209 MsfsRead(DeviceObject, CsqIrp);
210 }
211
212 Irp->IoStatus.Status = STATUS_SUCCESS;
213 Irp->IoStatus.Information = Length;
214
216
217 return STATUS_SUCCESS;
218}
NTKERNELAPI PIRP NTAPI IoCsqRemoveNextIrp(_Inout_ PIO_CSQ Csq, _In_opt_ PVOID PeekContext)
IoCsqRemoveNextIrp - Removes the next IRP from the queue.
Definition: csq.c:398
DRIVER_DISPATCH MsfsRead
Definition: msfs.h:92
struct _IO_STACK_LOCATION::@3980::@3985 Write
BOOLEAN NTAPI KeCancelTimer(IN OUT PKTIMER Timer)
Definition: timerobj.c:206
unsigned char * PUCHAR
Definition: typedefs.h:53

Variable Documentation

◆ MsfsAcquireLock

IO_CSQ_ACQUIRE_LOCK MsfsAcquireLock

Definition at line 117 of file msfs.h.

Referenced by MsfsCreateMailslot().

◆ MsfsClose

DRIVER_DISPATCH MsfsClose

Definition at line 83 of file msfs.h.

Referenced by DriverEntry().

◆ MsfsCompleteCanceledIrp

IO_CSQ_COMPLETE_CANCELED_IRP MsfsCompleteCanceledIrp

Definition at line 125 of file msfs.h.

Referenced by MsfsCreateMailslot().

◆ MsfsCreate

DRIVER_DISPATCH MsfsCreate

Definition at line 77 of file msfs.h.

Referenced by DriverEntry().

◆ MsfsCreateMailslot

DRIVER_DISPATCH MsfsCreateMailslot

Definition at line 80 of file msfs.h.

Referenced by DriverEntry().

◆ MsfsFileSystemControl

DRIVER_DISPATCH MsfsFileSystemControl

Definition at line 98 of file msfs.h.

Referenced by DriverEntry().

◆ MsfsInsertIrp

IO_CSQ_INSERT_IRP MsfsInsertIrp

Definition at line 105 of file msfs.h.

Referenced by MsfsCreateMailslot().

◆ MsfsPeekNextIrp

IO_CSQ_PEEK_NEXT_IRP MsfsPeekNextIrp

Definition at line 113 of file msfs.h.

Referenced by MsfsCreateMailslot().

◆ MsfsQueryInformation

DRIVER_DISPATCH MsfsQueryInformation

Definition at line 86 of file msfs.h.

Referenced by DriverEntry().

◆ MsfsRead

DRIVER_DISPATCH MsfsRead

Definition at line 92 of file msfs.h.

Referenced by DriverEntry(), and MsfsWrite().

◆ MsfsReleaseLock

IO_CSQ_RELEASE_LOCK MsfsReleaseLock

Definition at line 121 of file msfs.h.

Referenced by MsfsCreateMailslot().

◆ MsfsRemoveIrp

IO_CSQ_REMOVE_IRP MsfsRemoveIrp

Definition at line 109 of file msfs.h.

Referenced by MsfsCreateMailslot().

◆ MsfsSetInformation

DRIVER_DISPATCH MsfsSetInformation

Definition at line 89 of file msfs.h.

Referenced by DriverEntry().

◆ MsfsTimeout

KDEFERRED_ROUTINE MsfsTimeout

Definition at line 129 of file msfs.h.

Referenced by MsfsRead().

◆ MsfsWrite

DRIVER_DISPATCH MsfsWrite

Definition at line 95 of file msfs.h.

Referenced by DriverEntry().