ReactOS 0.4.15-dev-8235-gcd88a97
create.c File Reference
#include "msfs.h"
#include <ndk/iotypes.h>
#include <debug.h>
Include dependency graph for create.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

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)
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 16 of file create.c.

Function Documentation

◆ 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)
_In_ PFCB Fcb
Definition: cdprocs.h:159
_Inout_ PFILE_OBJECT _In_ TYPE_OF_OPEN PFCB _In_opt_ PCCB Ccb
Definition: cdprocs.h:592
_In_ PIRP Irp
Definition: csq.h:116
#define NULL
Definition: types.h:112
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 KeAcquireSpinLock(sl, irql)
Definition: env_spec_w32.h:609
#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
#define STATUS_SUCCESS
Definition: shellext.h:65
#define DPRINT
Definition: sndvol32.h:73
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
Definition: msfs.h:25
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
_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

◆ 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 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
#define STATUS_NO_MEMORY
Definition: ntstatus.h:260
ULONG Flags
Definition: ntfs.h:536
struct _FCB::@727::@730 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
struct _IO_STACK_LOCATION::@3991::@3994 CreateMailslot
union _IO_STACK_LOCATION::@1573 Parameters