ReactOS  0.4.14-dev-390-g34947ad
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;
259  PMSFS_FCB Fcb;
260  PMSFS_CCB Ccb;
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,
298  MSFS_MESSAGE,
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 }
#define KeLockMutex(x)
Definition: msfs.h:69
LIST_ENTRY FcbListEntry
Definition: ntfs.h:526
KMUTEX FcbListLock
Definition: msfs.h:20
_In_ PIRP Irp
Definition: csq.h:116
FORCEINLINE BOOLEAN RemoveEntryList(_In_ PLIST_ENTRY Entry)
Definition: rtlfuncs.h:105
UCHAR KIRQL
Definition: env_spec_w32.h:591
_In_ PIO_STACK_LOCATION _Inout_ PFILE_OBJECT FileObject
Definition: create.c:4157
PVOID DeviceExtension
Definition: env_spec_w32.h:418
LIST_ENTRY FcbListHead
Definition: msfs.h:19
smooth NULL
Definition: ftsmooth.c:416
#define IoCompleteRequest
Definition: irp.c:1240
void DPRINT(...)
Definition: polytest.cpp:61
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
#define KeAcquireSpinLock(sl, irql)
Definition: env_spec_w32.h:609
* PFILE_OBJECT
Definition: iotypes.h:1955
CHAR Message[80]
Definition: alive.c:5
_Inout_ PFILE_OBJECT _In_ TYPE_OF_OPEN PFCB _In_opt_ PCCB Ccb
Definition: cdprocs.h:593
#define KeUnlockMutex(x)
Definition: msfs.h:75
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
PFILE_OBJECT FileObject
Definition: iotypes.h:2813
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
#define IO_NO_INCREMENT
Definition: iotypes.h:566
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
Definition: msfs.h:24
_In_ PFCB Fcb
Definition: cdprocs.h:151
return STATUS_SUCCESS
Definition: btrfs.c:2938
Definition: msfs.h:54

◆ 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;
29  PMSFS_FCB Fcb;
30  PMSFS_CCB Ccb;
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 
43  Ccb = ExAllocatePoolWithTag(NonPagedPool, sizeof(MSFS_CCB), 'cFsM');
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,
58  MSFS_FCB,
59  FcbListEntry);
60 
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 
77  return STATUS_UNSUCCESSFUL;
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 KeLockMutex(x)
Definition: msfs.h:69
#define TRUE
Definition: types.h:120
KMUTEX FcbListLock
Definition: msfs.h:20
_In_ PIRP Irp
Definition: csq.h:116
#define InsertTailList(ListHead, Entry)
UCHAR KIRQL
Definition: env_spec_w32.h:591
_In_ PIO_STACK_LOCATION _Inout_ PFILE_OBJECT FileObject
Definition: create.c:4157
PVOID DeviceExtension
Definition: env_spec_w32.h:418
LIST_ENTRY FcbListHead
Definition: msfs.h:19
smooth NULL
Definition: ftsmooth.c:416
#define IoCompleteRequest
Definition: irp.c:1240
void DPRINT(...)
Definition: polytest.cpp:61
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
#define KeAcquireSpinLock(sl, irql)
Definition: env_spec_w32.h:609
* PFILE_OBJECT
Definition: iotypes.h:1955
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
#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
struct _FCB::@708::@711 Fcb
PUNICODE_STRING FileName
Definition: iotypes.h:2793
_Inout_ PFILE_OBJECT _In_ TYPE_OF_OPEN PFCB _In_opt_ PCCB Ccb
Definition: cdprocs.h:593
Definition: typedefs.h:117
#define KeUnlockMutex(x)
Definition: msfs.h:75
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
PFILE_OBJECT FileObject
Definition: iotypes.h:2813
#define STATUS_NO_MEMORY
Definition: ntstatus.h:246
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
#define IO_NO_INCREMENT
Definition: iotypes.h:566
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
Definition: msfs.h:24
_In_ PFCB Fcb
Definition: cdprocs.h:151
return STATUS_SUCCESS
Definition: btrfs.c:2938
Definition: msfs.h:54
#define FO_MAILSLOT
Definition: iotypes.h:1741
struct task_struct * current
Definition: linux.c:32

◆ 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;
113  PMSFS_FCB Fcb;
114  PMSFS_CCB Ccb;
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 
129  Fcb = ExAllocatePoolWithTag(NonPagedPool, sizeof(MSFS_FCB), 'fFsM');
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);
142  Fcb->Name.Buffer = ExAllocatePoolWithTag(NonPagedPool,
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 
158 
159  Ccb = ExAllocatePoolWithTag(NonPagedPool, sizeof(MSFS_CCB), 'cFsM');
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 }
#define KeLockMutex(x)
Definition: msfs.h:69
LIST_ENTRY FcbListEntry
Definition: ntfs.h:526
#define TRUE
Definition: types.h:120
IO_CSQ_ACQUIRE_LOCK MsfsAcquireLock
Definition: msfs.h:117
KMUTEX FcbListLock
Definition: msfs.h:20
_In_ PIRP Irp
Definition: csq.h:116
IO_CSQ_COMPLETE_CANCELED_IRP MsfsCompleteCanceledIrp
Definition: msfs.h:125
#define InsertTailList(ListHead, Entry)
NTSYSAPI VOID NTAPI RtlCopyUnicodeString(PUNICODE_STRING DestinationString, PUNICODE_STRING SourceString)
UCHAR KIRQL
Definition: env_spec_w32.h:591
#define UNICODE_NULL
_In_ PIO_STACK_LOCATION _Inout_ PFILE_OBJECT FileObject
Definition: create.c:4157
FORCEINLINE VOID KeInitializeSpinLock(_Out_ PKSPIN_LOCK SpinLock)
Definition: kefuncs.h:251
PVOID DeviceExtension
Definition: env_spec_w32.h:418
LIST_ENTRY FcbListHead
Definition: msfs.h:19
smooth NULL
Definition: ftsmooth.c:416
#define IoCompleteRequest
Definition: irp.c:1240
void DPRINT(...)
Definition: polytest.cpp:61
Definition: bufpool.h:45
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
IO_CSQ_RELEASE_LOCK MsfsReleaseLock
Definition: msfs.h:121
#define KeAcquireSpinLock(sl, irql)
Definition: env_spec_w32.h:609
* PFILE_OBJECT
Definition: iotypes.h:1955
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
#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
struct _FCB::@708::@711 Fcb
PUNICODE_STRING FileName
Definition: iotypes.h:2793
_Inout_ PFILE_OBJECT _In_ TYPE_OF_OPEN PFCB _In_opt_ PCCB Ccb
Definition: cdprocs.h:593
Definition: typedefs.h:117
IO_CSQ_INSERT_IRP MsfsInsertIrp
Definition: msfs.h:105
#define KeUnlockMutex(x)
Definition: msfs.h:75
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
PFILE_OBJECT FileObject
Definition: iotypes.h:2813
IO_CSQ_PEEK_NEXT_IRP MsfsPeekNextIrp
Definition: msfs.h:113
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
#define STATUS_NO_MEMORY
Definition: ntstatus.h:246
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
IO_CSQ_REMOVE_IRP MsfsRemoveIrp
Definition: msfs.h:109
#define IO_NO_INCREMENT
Definition: iotypes.h:566
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 ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
Definition: msfs.h:24
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2772
_In_ PFCB Fcb
Definition: cdprocs.h:151
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34
return STATUS_SUCCESS
Definition: btrfs.c:2938
Definition: msfs.h:54
#define FO_MAILSLOT
Definition: iotypes.h:1741
struct task_struct * current
Definition: linux.c:32