mirror of
https://github.com/reactos/reactos.git
synced 2025-02-23 17:05:46 +00:00
The MSFS_MAILSLOT struct is actually an FCB (File Control Block). Rename it accordingly and store pointers to it in FileObject->FsContext.
svn path=/trunk/; revision=21815
This commit is contained in:
parent
7b09374005
commit
c5fa9029dc
6 changed files with 132 additions and 128 deletions
|
@ -24,9 +24,9 @@ MsfsCreate(PDEVICE_OBJECT DeviceObject,
|
|||
PIO_STACK_LOCATION IoStack;
|
||||
PFILE_OBJECT FileObject;
|
||||
PMSFS_DEVICE_EXTENSION DeviceExtension;
|
||||
PMSFS_MAILSLOT Mailslot;
|
||||
PMSFS_FCB Fcb;
|
||||
PMSFS_CCB Ccb;
|
||||
PMSFS_MAILSLOT current = NULL;
|
||||
PMSFS_FCB current = NULL;
|
||||
PLIST_ENTRY current_entry;
|
||||
KIRQL oldIrql;
|
||||
|
||||
|
@ -49,13 +49,13 @@ MsfsCreate(PDEVICE_OBJECT DeviceObject,
|
|||
return(STATUS_NO_MEMORY);
|
||||
}
|
||||
|
||||
KeLockMutex(&DeviceExtension->MailslotListLock);
|
||||
current_entry = DeviceExtension->MailslotListHead.Flink;
|
||||
while (current_entry != &DeviceExtension->MailslotListHead)
|
||||
KeLockMutex(&DeviceExtension->FcbListLock);
|
||||
current_entry = DeviceExtension->FcbListHead.Flink;
|
||||
while (current_entry != &DeviceExtension->FcbListHead)
|
||||
{
|
||||
current = CONTAINING_RECORD(current_entry,
|
||||
MSFS_MAILSLOT,
|
||||
MailslotListEntry);
|
||||
MSFS_FCB,
|
||||
FcbListEntry);
|
||||
|
||||
if (!RtlCompareUnicodeString(&FileObject->FileName, ¤t->Name, TRUE))
|
||||
{
|
||||
|
@ -65,10 +65,10 @@ MsfsCreate(PDEVICE_OBJECT DeviceObject,
|
|||
current_entry = current_entry->Flink;
|
||||
}
|
||||
|
||||
if (current_entry == &DeviceExtension->MailslotListHead)
|
||||
if (current_entry == &DeviceExtension->FcbListHead)
|
||||
{
|
||||
ExFreePool(Ccb);
|
||||
KeUnlockMutex(&DeviceExtension->MailslotListLock);
|
||||
KeUnlockMutex(&DeviceExtension->FcbListLock);
|
||||
|
||||
Irp->IoStatus.Status = STATUS_UNSUCCESSFUL;
|
||||
Irp->IoStatus.Information = 0;
|
||||
|
@ -78,18 +78,20 @@ MsfsCreate(PDEVICE_OBJECT DeviceObject,
|
|||
return(STATUS_UNSUCCESSFUL);
|
||||
}
|
||||
|
||||
Mailslot = current;
|
||||
Fcb = current;
|
||||
DPRINT1("Fcb: %p\n", Fcb);
|
||||
|
||||
KeAcquireSpinLock(&Mailslot->CcbListLock, &oldIrql);
|
||||
InsertTailList(&Mailslot->CcbListHead, &Ccb->CcbListEntry);
|
||||
KeReleaseSpinLock(&Mailslot->CcbListLock, oldIrql);
|
||||
KeAcquireSpinLock(&Fcb->CcbListLock, &oldIrql);
|
||||
InsertTailList(&Fcb->CcbListHead, &Ccb->CcbListEntry);
|
||||
KeReleaseSpinLock(&Fcb->CcbListLock, oldIrql);
|
||||
|
||||
Mailslot->ReferenceCount++;
|
||||
Fcb->ReferenceCount++;
|
||||
|
||||
Ccb->Mailslot = Mailslot;
|
||||
Ccb->Fcb = Fcb;
|
||||
|
||||
KeUnlockMutex(&DeviceExtension->MailslotListLock);
|
||||
KeUnlockMutex(&DeviceExtension->FcbListLock);
|
||||
|
||||
FileObject->FsContext = Fcb;
|
||||
FileObject->FsContext2 = Ccb;
|
||||
FileObject->Flags |= FO_MAILSLOT;
|
||||
|
||||
|
@ -109,11 +111,11 @@ MsfsCreateMailslot(PDEVICE_OBJECT DeviceObject,
|
|||
PEXTENDED_IO_STACK_LOCATION IoStack;
|
||||
PFILE_OBJECT FileObject;
|
||||
PMSFS_DEVICE_EXTENSION DeviceExtension;
|
||||
PMSFS_MAILSLOT Mailslot;
|
||||
PMSFS_FCB Fcb;
|
||||
PMSFS_CCB Ccb;
|
||||
KIRQL oldIrql;
|
||||
PLIST_ENTRY current_entry;
|
||||
PMSFS_MAILSLOT current;
|
||||
PMSFS_FCB current;
|
||||
PMAILSLOT_CREATE_PARAMETERS Buffer;
|
||||
|
||||
DPRINT("MsfsCreateMailslot(DeviceObject %p Irp %p)\n", DeviceObject, Irp);
|
||||
|
@ -125,8 +127,8 @@ MsfsCreateMailslot(PDEVICE_OBJECT DeviceObject,
|
|||
|
||||
DPRINT("Mailslot name: %wZ\n", &FileObject->FileName);
|
||||
|
||||
Mailslot = ExAllocatePool(NonPagedPool, sizeof(MSFS_MAILSLOT));
|
||||
if (Mailslot == NULL)
|
||||
Fcb = ExAllocatePool(NonPagedPool, sizeof(MSFS_FCB));
|
||||
if (Fcb == NULL)
|
||||
{
|
||||
Irp->IoStatus.Status = STATUS_NO_MEMORY;
|
||||
Irp->IoStatus.Information = 0;
|
||||
|
@ -136,12 +138,12 @@ MsfsCreateMailslot(PDEVICE_OBJECT DeviceObject,
|
|||
return(STATUS_NO_MEMORY);
|
||||
}
|
||||
|
||||
Mailslot->Name.Length = FileObject->FileName.Length;
|
||||
Mailslot->Name.MaximumLength = Mailslot->Name.Length + sizeof(UNICODE_NULL);
|
||||
Mailslot->Name.Buffer = ExAllocatePool(NonPagedPool, Mailslot->Name.MaximumLength);
|
||||
if (Mailslot->Name.Buffer == NULL)
|
||||
Fcb->Name.Length = FileObject->FileName.Length;
|
||||
Fcb->Name.MaximumLength = Fcb->Name.Length + sizeof(UNICODE_NULL);
|
||||
Fcb->Name.Buffer = ExAllocatePool(NonPagedPool, Fcb->Name.MaximumLength);
|
||||
if (Fcb->Name.Buffer == NULL)
|
||||
{
|
||||
ExFreePool(Mailslot);
|
||||
ExFreePool(Fcb);
|
||||
|
||||
Irp->IoStatus.Status = STATUS_NO_MEMORY;
|
||||
Irp->IoStatus.Information = 0;
|
||||
|
@ -151,12 +153,13 @@ MsfsCreateMailslot(PDEVICE_OBJECT DeviceObject,
|
|||
return(STATUS_NO_MEMORY);
|
||||
}
|
||||
|
||||
RtlCopyUnicodeString(&Mailslot->Name, &FileObject->FileName);
|
||||
RtlCopyUnicodeString(&Fcb->Name, &FileObject->FileName);
|
||||
|
||||
Ccb = ExAllocatePool(NonPagedPool, sizeof(MSFS_CCB));
|
||||
if (Ccb == NULL)
|
||||
{
|
||||
ExFreePool(Mailslot);
|
||||
ExFreePool(Fcb->Name.Buffer);
|
||||
ExFreePool(Fcb);
|
||||
|
||||
Irp->IoStatus.Status = STATUS_NO_MEMORY;
|
||||
Irp->IoStatus.Information = 0;
|
||||
|
@ -166,29 +169,29 @@ MsfsCreateMailslot(PDEVICE_OBJECT DeviceObject,
|
|||
return(STATUS_NO_MEMORY);
|
||||
}
|
||||
|
||||
Mailslot->ReferenceCount = 0;
|
||||
InitializeListHead(&Mailslot->CcbListHead);
|
||||
KeInitializeSpinLock(&Mailslot->CcbListLock);
|
||||
Fcb->ReferenceCount = 0;
|
||||
InitializeListHead(&Fcb->CcbListHead);
|
||||
KeInitializeSpinLock(&Fcb->CcbListLock);
|
||||
|
||||
Mailslot->MaxMessageSize = Buffer->MaximumMessageSize;
|
||||
Mailslot->MessageCount = 0;
|
||||
Mailslot->TimeOut = Buffer->ReadTimeout;
|
||||
KeInitializeEvent(&Mailslot->MessageEvent,
|
||||
Fcb->MaxMessageSize = Buffer->MaximumMessageSize;
|
||||
Fcb->MessageCount = 0;
|
||||
Fcb->TimeOut = Buffer->ReadTimeout;
|
||||
KeInitializeEvent(&Fcb->MessageEvent,
|
||||
NotificationEvent,
|
||||
FALSE);
|
||||
|
||||
InitializeListHead(&Mailslot->MessageListHead);
|
||||
KeInitializeSpinLock(&Mailslot->MessageListLock);
|
||||
InitializeListHead(&Fcb->MessageListHead);
|
||||
KeInitializeSpinLock(&Fcb->MessageListLock);
|
||||
|
||||
KeLockMutex(&DeviceExtension->MailslotListLock);
|
||||
current_entry = DeviceExtension->MailslotListHead.Flink;
|
||||
while (current_entry != &DeviceExtension->MailslotListHead)
|
||||
KeLockMutex(&DeviceExtension->FcbListLock);
|
||||
current_entry = DeviceExtension->FcbListHead.Flink;
|
||||
while (current_entry != &DeviceExtension->FcbListHead)
|
||||
{
|
||||
current = CONTAINING_RECORD(current_entry,
|
||||
MSFS_MAILSLOT,
|
||||
MailslotListEntry);
|
||||
MSFS_FCB,
|
||||
FcbListEntry);
|
||||
|
||||
if (!RtlCompareUnicodeString(&Mailslot->Name, ¤t->Name, TRUE))
|
||||
if (!RtlCompareUnicodeString(&Fcb->Name, ¤t->Name, TRUE))
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
@ -196,29 +199,30 @@ MsfsCreateMailslot(PDEVICE_OBJECT DeviceObject,
|
|||
current_entry = current_entry->Flink;
|
||||
}
|
||||
|
||||
if (current_entry != &DeviceExtension->MailslotListHead)
|
||||
if (current_entry != &DeviceExtension->FcbListHead)
|
||||
{
|
||||
RtlFreeUnicodeString(&Mailslot->Name);
|
||||
ExFreePool(Mailslot);
|
||||
ExFreePool(Fcb->Name.Buffer);
|
||||
ExFreePool(Fcb);
|
||||
|
||||
Mailslot = current;
|
||||
Fcb = current;
|
||||
}
|
||||
else
|
||||
{
|
||||
InsertTailList(&DeviceExtension->MailslotListHead,
|
||||
&Mailslot->MailslotListEntry);
|
||||
InsertTailList(&DeviceExtension->FcbListHead,
|
||||
&Fcb->FcbListEntry);
|
||||
}
|
||||
|
||||
KeAcquireSpinLock(&Mailslot->CcbListLock, &oldIrql);
|
||||
InsertTailList(&Mailslot->CcbListHead, &Ccb->CcbListEntry);
|
||||
KeReleaseSpinLock(&Mailslot->CcbListLock, oldIrql);
|
||||
KeAcquireSpinLock(&Fcb->CcbListLock, &oldIrql);
|
||||
InsertTailList(&Fcb->CcbListHead, &Ccb->CcbListEntry);
|
||||
KeReleaseSpinLock(&Fcb->CcbListLock, oldIrql);
|
||||
|
||||
Mailslot->ReferenceCount++;
|
||||
Mailslot->ServerCcb = Ccb;
|
||||
Ccb->Mailslot = Mailslot;
|
||||
Fcb->ReferenceCount++;
|
||||
Fcb->ServerCcb = Ccb;
|
||||
Ccb->Fcb = Fcb;
|
||||
|
||||
KeUnlockMutex(&DeviceExtension->MailslotListLock);
|
||||
KeUnlockMutex(&DeviceExtension->FcbListLock);
|
||||
|
||||
FileObject->FsContext = Fcb;
|
||||
FileObject->FsContext2 = Ccb;
|
||||
FileObject->Flags |= FO_MAILSLOT;
|
||||
|
||||
|
@ -238,7 +242,7 @@ MsfsClose(PDEVICE_OBJECT DeviceObject,
|
|||
PIO_STACK_LOCATION IoStack;
|
||||
PFILE_OBJECT FileObject;
|
||||
PMSFS_DEVICE_EXTENSION DeviceExtension;
|
||||
PMSFS_MAILSLOT Mailslot;
|
||||
PMSFS_FCB Fcb;
|
||||
PMSFS_CCB Ccb;
|
||||
PMSFS_MESSAGE Message;
|
||||
KIRQL oldIrql;
|
||||
|
@ -249,11 +253,11 @@ MsfsClose(PDEVICE_OBJECT DeviceObject,
|
|||
DeviceExtension = DeviceObject->DeviceExtension;
|
||||
FileObject = IoStack->FileObject;
|
||||
|
||||
KeLockMutex(&DeviceExtension->MailslotListLock);
|
||||
KeLockMutex(&DeviceExtension->FcbListLock);
|
||||
|
||||
if (DeviceExtension->MailslotListHead.Flink == &DeviceExtension->MailslotListHead)
|
||||
if (DeviceExtension->FcbListHead.Flink == &DeviceExtension->FcbListHead)
|
||||
{
|
||||
KeUnlockMutex(&DeviceExtension->MailslotListLock);
|
||||
KeUnlockMutex(&DeviceExtension->FcbListLock);
|
||||
|
||||
Irp->IoStatus.Status = STATUS_SUCCESS;
|
||||
Irp->IoStatus.Information = 0;
|
||||
|
@ -263,46 +267,46 @@ MsfsClose(PDEVICE_OBJECT DeviceObject,
|
|||
return(STATUS_SUCCESS);
|
||||
}
|
||||
|
||||
Fcb = FileObject->FsContext;
|
||||
Ccb = FileObject->FsContext2;
|
||||
Mailslot = Ccb->Mailslot;
|
||||
|
||||
DPRINT("Mailslot name: %wZ\n", &Mailslot->Name);
|
||||
DPRINT("Mailslot name: %wZ\n", &Fcb->Name);
|
||||
|
||||
Mailslot->ReferenceCount--;
|
||||
if (Mailslot->ServerCcb == Ccb)
|
||||
Fcb->ReferenceCount--;
|
||||
if (Fcb->ServerCcb == Ccb)
|
||||
{
|
||||
/* delete all messages from message-list */
|
||||
KeAcquireSpinLock(&Mailslot->MessageListLock, &oldIrql);
|
||||
KeAcquireSpinLock(&Fcb->MessageListLock, &oldIrql);
|
||||
|
||||
while (Mailslot->MessageListHead.Flink != &Mailslot->MessageListHead)
|
||||
while (Fcb->MessageListHead.Flink != &Fcb->MessageListHead)
|
||||
{
|
||||
Message = CONTAINING_RECORD(Mailslot->MessageListHead.Flink,
|
||||
Message = CONTAINING_RECORD(Fcb->MessageListHead.Flink,
|
||||
MSFS_MESSAGE,
|
||||
MessageListEntry);
|
||||
RemoveEntryList(Mailslot->MessageListHead.Flink);
|
||||
RemoveEntryList(Fcb->MessageListHead.Flink);
|
||||
ExFreePool(Message);
|
||||
}
|
||||
Mailslot->MessageCount = 0;
|
||||
Fcb->MessageCount = 0;
|
||||
|
||||
KeReleaseSpinLock(&Mailslot->MessageListLock, oldIrql);
|
||||
Mailslot->ServerCcb = NULL;
|
||||
KeReleaseSpinLock(&Fcb->MessageListLock, oldIrql);
|
||||
Fcb->ServerCcb = NULL;
|
||||
}
|
||||
|
||||
KeAcquireSpinLock(&Mailslot->CcbListLock, &oldIrql);
|
||||
KeAcquireSpinLock(&Fcb->CcbListLock, &oldIrql);
|
||||
RemoveEntryList(&Ccb->CcbListEntry);
|
||||
KeReleaseSpinLock(&Mailslot->CcbListLock, oldIrql);
|
||||
KeReleaseSpinLock(&Fcb->CcbListLock, oldIrql);
|
||||
ExFreePool(Ccb);
|
||||
FileObject->FsContext2 = NULL;
|
||||
|
||||
if (Mailslot->ReferenceCount == 0)
|
||||
if (Fcb->ReferenceCount == 0)
|
||||
{
|
||||
DPRINT1("ReferenceCount == 0: Deleting mailslot data\n");
|
||||
RtlFreeUnicodeString(&Mailslot->Name);
|
||||
RemoveEntryList(&Mailslot->MailslotListEntry);
|
||||
ExFreePool(Mailslot);
|
||||
RemoveEntryList(&Fcb->FcbListEntry);
|
||||
ExFreePool(Fcb->Name.Buffer);
|
||||
ExFreePool(Fcb);
|
||||
}
|
||||
|
||||
KeUnlockMutex(&DeviceExtension->MailslotListLock);
|
||||
KeUnlockMutex(&DeviceExtension->FcbListLock);
|
||||
|
||||
Irp->IoStatus.Status = STATUS_SUCCESS;
|
||||
Irp->IoStatus.Information = 0;
|
||||
|
|
|
@ -22,20 +22,20 @@ MsfsQueryMailslotInformation(PMSFS_CCB Ccb,
|
|||
PFILE_MAILSLOT_QUERY_INFORMATION Buffer,
|
||||
PULONG BufferLength)
|
||||
{
|
||||
PMSFS_MAILSLOT Mailslot;
|
||||
PMSFS_FCB Fcb;
|
||||
KIRQL oldIrql;
|
||||
|
||||
if (*BufferLength < sizeof(FILE_MAILSLOT_QUERY_INFORMATION))
|
||||
return(STATUS_BUFFER_OVERFLOW);
|
||||
|
||||
Mailslot = Ccb->Mailslot;
|
||||
Fcb = Ccb->Fcb;
|
||||
|
||||
Buffer->MaximumMessageSize = Mailslot->MaxMessageSize;
|
||||
Buffer->ReadTimeout = Mailslot->TimeOut;
|
||||
Buffer->MaximumMessageSize = Fcb->MaxMessageSize;
|
||||
Buffer->ReadTimeout = Fcb->TimeOut;
|
||||
|
||||
KeAcquireSpinLock(&Mailslot->MessageListLock, &oldIrql);
|
||||
Buffer->MessagesAvailable = Mailslot->MessageCount;
|
||||
if (Mailslot->MessageCount == 0)
|
||||
KeAcquireSpinLock(&Fcb->MessageListLock, &oldIrql);
|
||||
Buffer->MessagesAvailable = Fcb->MessageCount;
|
||||
if (Fcb->MessageCount == 0)
|
||||
{
|
||||
Buffer->NextMessageSize = MAILSLOT_NO_MESSAGE;
|
||||
}
|
||||
|
@ -44,7 +44,7 @@ MsfsQueryMailslotInformation(PMSFS_CCB Ccb,
|
|||
/* FIXME: read size of first message (head) */
|
||||
Buffer->NextMessageSize = 0;
|
||||
}
|
||||
KeReleaseSpinLock(&Mailslot->MessageListLock, oldIrql);
|
||||
KeReleaseSpinLock(&Fcb->MessageListLock, oldIrql);
|
||||
|
||||
*BufferLength -= sizeof(FILE_MAILSLOT_QUERY_INFORMATION);
|
||||
|
||||
|
@ -60,7 +60,7 @@ MsfsSetMailslotInformation(PMSFS_CCB Ccb,
|
|||
if (*BufferLength < sizeof(FILE_MAILSLOT_SET_INFORMATION))
|
||||
return(STATUS_BUFFER_OVERFLOW);
|
||||
|
||||
Ccb->Mailslot->TimeOut = *Buffer->ReadTimeout;
|
||||
Ccb->Fcb->TimeOut = *Buffer->ReadTimeout;
|
||||
|
||||
return(STATUS_SUCCESS);
|
||||
}
|
||||
|
@ -74,8 +74,8 @@ MsfsQueryInformation(PDEVICE_OBJECT DeviceObject,
|
|||
FILE_INFORMATION_CLASS FileInformationClass;
|
||||
PFILE_OBJECT FileObject;
|
||||
PMSFS_DEVICE_EXTENSION DeviceExtension;
|
||||
PMSFS_FCB Fcb;
|
||||
PMSFS_CCB Ccb;
|
||||
PMSFS_MAILSLOT Mailslot;
|
||||
PVOID SystemBuffer;
|
||||
ULONG BufferLength;
|
||||
NTSTATUS Status;
|
||||
|
@ -87,12 +87,12 @@ MsfsQueryInformation(PDEVICE_OBJECT DeviceObject,
|
|||
DeviceExtension = DeviceObject->DeviceExtension;
|
||||
FileObject = IoStack->FileObject;
|
||||
Ccb = (PMSFS_CCB)FileObject->FsContext2;
|
||||
Mailslot = Ccb->Mailslot;
|
||||
Fcb = Ccb->Fcb;
|
||||
|
||||
DPRINT("Mailslot name: %wZ\n", &Mailslot->Name);
|
||||
DPRINT("Mailslot name: %wZ\n", &Fcb->Name);
|
||||
|
||||
/* querying information is not permitted on client side */
|
||||
if (Ccb->Mailslot->ServerCcb != Ccb)
|
||||
if (Ccb->Fcb->ServerCcb != Ccb)
|
||||
{
|
||||
Status = STATUS_ACCESS_DENIED;
|
||||
|
||||
|
@ -139,8 +139,8 @@ MsfsSetInformation(PDEVICE_OBJECT DeviceObject,
|
|||
PIO_STACK_LOCATION IoStack;
|
||||
FILE_INFORMATION_CLASS FileInformationClass;
|
||||
PFILE_OBJECT FileObject;
|
||||
PMSFS_FCB Fcb;
|
||||
PMSFS_CCB Ccb;
|
||||
PMSFS_MAILSLOT Mailslot;
|
||||
PVOID SystemBuffer;
|
||||
ULONG BufferLength;
|
||||
NTSTATUS Status;
|
||||
|
@ -151,12 +151,12 @@ MsfsSetInformation(PDEVICE_OBJECT DeviceObject,
|
|||
FileInformationClass = IoStack->Parameters.QueryFile.FileInformationClass;
|
||||
FileObject = IoStack->FileObject;
|
||||
Ccb = (PMSFS_CCB)FileObject->FsContext2;
|
||||
Mailslot = Ccb->Mailslot;
|
||||
Fcb = Ccb->Fcb;
|
||||
|
||||
DPRINT("Mailslot name: %wZ\n", &Mailslot->Name);
|
||||
DPRINT("Mailslot name: %wZ\n", &Fcb->Name);
|
||||
|
||||
/* setting information is not permitted on client side */
|
||||
if (Ccb->Mailslot->ServerCcb != Ccb)
|
||||
if (Ccb->Fcb->ServerCcb != Ccb)
|
||||
{
|
||||
Status = STATUS_ACCESS_DENIED;
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@ MsfsFileSystemControl(PDEVICE_OBJECT DeviceObject,
|
|||
{
|
||||
PIO_STACK_LOCATION IoStack;
|
||||
PFILE_OBJECT FileObject;
|
||||
PMSFS_MAILSLOT Mailslot;
|
||||
PMSFS_FCB Fcb;
|
||||
PMSFS_CCB Ccb;
|
||||
NTSTATUS Status;
|
||||
|
||||
|
@ -32,9 +32,9 @@ MsfsFileSystemControl(PDEVICE_OBJECT DeviceObject,
|
|||
IoStack = IoGetCurrentIrpStackLocation(Irp);
|
||||
FileObject = IoStack->FileObject;
|
||||
Ccb = FileObject->FsContext2;
|
||||
Mailslot = Ccb->Mailslot;
|
||||
Fcb = Ccb->Fcb;
|
||||
|
||||
DPRINT1("Mailslot name: %wZ\n", &Mailslot->Name);
|
||||
DPRINT1("Mailslot name: %wZ\n", &Fcb->Name);
|
||||
|
||||
switch (IoStack->Parameters.FileSystemControl.FsControlCode)
|
||||
{
|
||||
|
|
|
@ -71,8 +71,8 @@ DriverEntry(PDRIVER_OBJECT DriverObject,
|
|||
|
||||
/* initialize device extension */
|
||||
DeviceExtension = DeviceObject->DeviceExtension;
|
||||
InitializeListHead(&DeviceExtension->MailslotListHead);
|
||||
KeInitializeMutex(&DeviceExtension->MailslotListLock,
|
||||
InitializeListHead(&DeviceExtension->FcbListHead);
|
||||
KeInitializeMutex(&DeviceExtension->FcbListLock,
|
||||
0);
|
||||
|
||||
return(STATUS_SUCCESS);
|
||||
|
|
|
@ -22,14 +22,14 @@
|
|||
|
||||
typedef struct _MSFS_DEVICE_EXTENSION
|
||||
{
|
||||
LIST_ENTRY MailslotListHead;
|
||||
KMUTEX MailslotListLock;
|
||||
LIST_ENTRY FcbListHead;
|
||||
KMUTEX FcbListLock;
|
||||
} MSFS_DEVICE_EXTENSION, *PMSFS_DEVICE_EXTENSION;
|
||||
|
||||
typedef struct _MSFS_MAILSLOT
|
||||
typedef struct _MSFS_FCB
|
||||
{
|
||||
UNICODE_STRING Name;
|
||||
LIST_ENTRY MailslotListEntry;
|
||||
LIST_ENTRY FcbListEntry;
|
||||
KSPIN_LOCK CcbListLock;
|
||||
LIST_ENTRY CcbListHead;
|
||||
struct _MSFS_CCB *ServerCcb;
|
||||
|
@ -40,12 +40,12 @@ typedef struct _MSFS_MAILSLOT
|
|||
ULONG MessageCount;
|
||||
KSPIN_LOCK MessageListLock;
|
||||
LIST_ENTRY MessageListHead;
|
||||
} MSFS_MAILSLOT, *PMSFS_MAILSLOT;
|
||||
} MSFS_FCB, *PMSFS_FCB;
|
||||
|
||||
typedef struct _MSFS_CCB
|
||||
{
|
||||
LIST_ENTRY CcbListEntry;
|
||||
PMSFS_MAILSLOT Mailslot;
|
||||
PMSFS_FCB Fcb;
|
||||
} MSFS_CCB, *PMSFS_CCB;
|
||||
|
||||
typedef struct _MSFS_MESSAGE
|
||||
|
|
|
@ -23,7 +23,7 @@ MsfsRead(PDEVICE_OBJECT DeviceObject,
|
|||
{
|
||||
PIO_STACK_LOCATION IoStack;
|
||||
PFILE_OBJECT FileObject;
|
||||
PMSFS_MAILSLOT Mailslot;
|
||||
PMSFS_FCB Fcb;
|
||||
PMSFS_CCB Ccb;
|
||||
PMSFS_MESSAGE Message;
|
||||
KIRQL oldIrql;
|
||||
|
@ -36,13 +36,13 @@ MsfsRead(PDEVICE_OBJECT DeviceObject,
|
|||
|
||||
IoStack = IoGetCurrentIrpStackLocation (Irp);
|
||||
FileObject = IoStack->FileObject;
|
||||
Fcb = (PMSFS_FCB)FileObject->FsContext;
|
||||
Ccb = (PMSFS_CCB)FileObject->FsContext2;
|
||||
Mailslot = Ccb->Mailslot;
|
||||
|
||||
DPRINT("MailslotName: %wZ\n", &Mailslot->Name);
|
||||
DPRINT("MailslotName: %wZ\n", &Fcb->Name);
|
||||
|
||||
/* reading is not permitted on client side */
|
||||
if (Ccb->Mailslot->ServerCcb != Ccb)
|
||||
if (Fcb->ServerCcb != Ccb)
|
||||
{
|
||||
Irp->IoStatus.Status = STATUS_ACCESS_DENIED;
|
||||
Irp->IoStatus.Information = 0;
|
||||
|
@ -58,29 +58,29 @@ MsfsRead(PDEVICE_OBJECT DeviceObject,
|
|||
else
|
||||
Buffer = Irp->UserBuffer;
|
||||
|
||||
Status = KeWaitForSingleObject(&Mailslot->MessageEvent,
|
||||
Status = KeWaitForSingleObject(&Fcb->MessageEvent,
|
||||
UserRequest,
|
||||
KernelMode,
|
||||
FALSE,
|
||||
NULL); /* FIXME: handle timeout */
|
||||
if ((NT_SUCCESS(Status)) && (Mailslot->MessageCount > 0))
|
||||
if ((NT_SUCCESS(Status)) && (Fcb->MessageCount > 0))
|
||||
{
|
||||
/* copy current message into buffer */
|
||||
Message = CONTAINING_RECORD(Mailslot->MessageListHead.Flink,
|
||||
Message = CONTAINING_RECORD(Fcb->MessageListHead.Flink,
|
||||
MSFS_MESSAGE,
|
||||
MessageListEntry);
|
||||
memcpy(Buffer, &Message->Buffer, min(Message->Size,Length));
|
||||
LengthRead = Message->Size;
|
||||
|
||||
KeAcquireSpinLock(&Mailslot->MessageListLock, &oldIrql);
|
||||
RemoveHeadList(&Mailslot->MessageListHead);
|
||||
KeReleaseSpinLock(&Mailslot->MessageListLock, oldIrql);
|
||||
KeAcquireSpinLock(&Fcb->MessageListLock, &oldIrql);
|
||||
RemoveHeadList(&Fcb->MessageListHead);
|
||||
KeReleaseSpinLock(&Fcb->MessageListLock, oldIrql);
|
||||
|
||||
ExFreePool(Message);
|
||||
Mailslot->MessageCount--;
|
||||
if (Mailslot->MessageCount == 0)
|
||||
Fcb->MessageCount--;
|
||||
if (Fcb->MessageCount == 0)
|
||||
{
|
||||
KeClearEvent(&Mailslot->MessageEvent);
|
||||
KeClearEvent(&Fcb->MessageEvent);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -99,7 +99,7 @@ MsfsWrite(PDEVICE_OBJECT DeviceObject,
|
|||
{
|
||||
PIO_STACK_LOCATION IoStack;
|
||||
PFILE_OBJECT FileObject;
|
||||
PMSFS_MAILSLOT Mailslot;
|
||||
PMSFS_FCB Fcb;
|
||||
PMSFS_CCB Ccb;
|
||||
PMSFS_MESSAGE Message;
|
||||
KIRQL oldIrql;
|
||||
|
@ -110,13 +110,13 @@ MsfsWrite(PDEVICE_OBJECT DeviceObject,
|
|||
|
||||
IoStack = IoGetCurrentIrpStackLocation (Irp);
|
||||
FileObject = IoStack->FileObject;
|
||||
Fcb = (PMSFS_FCB)FileObject->FsContext;
|
||||
Ccb = (PMSFS_CCB)FileObject->FsContext2;
|
||||
Mailslot = Ccb->Mailslot;
|
||||
|
||||
DPRINT("MailslotName: %wZ\n", &Mailslot->Name);
|
||||
DPRINT("MailslotName: %wZ\n", &Fcb->Name);
|
||||
|
||||
/* writing is not permitted on server side */
|
||||
if (Ccb->Mailslot->ServerCcb == Ccb)
|
||||
if (Fcb->ServerCcb == Ccb)
|
||||
{
|
||||
Irp->IoStatus.Status = STATUS_ACCESS_DENIED;
|
||||
Irp->IoStatus.Information = 0;
|
||||
|
@ -150,14 +150,14 @@ MsfsWrite(PDEVICE_OBJECT DeviceObject,
|
|||
Message->Size = Length;
|
||||
memcpy(&Message->Buffer, Buffer, Length);
|
||||
|
||||
KeAcquireSpinLock(&Mailslot->MessageListLock, &oldIrql);
|
||||
InsertTailList(&Mailslot->MessageListHead, &Message->MessageListEntry);
|
||||
KeReleaseSpinLock(&Mailslot->MessageListLock, oldIrql);
|
||||
KeAcquireSpinLock(&Fcb->MessageListLock, &oldIrql);
|
||||
InsertTailList(&Fcb->MessageListHead, &Message->MessageListEntry);
|
||||
KeReleaseSpinLock(&Fcb->MessageListLock, oldIrql);
|
||||
|
||||
Mailslot->MessageCount++;
|
||||
if (Mailslot->MessageCount == 1)
|
||||
Fcb->MessageCount++;
|
||||
if (Fcb->MessageCount == 1)
|
||||
{
|
||||
KeSetEvent(&Mailslot->MessageEvent,
|
||||
KeSetEvent(&Fcb->MessageEvent,
|
||||
0,
|
||||
FALSE);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue