2009-12-10 20:26:58 +00:00
|
|
|
/*
|
2001-05-05 15:21:05 +00:00
|
|
|
* COPYRIGHT: See COPYING in the top level directory
|
|
|
|
* PROJECT: ReactOS kernel
|
2009-12-10 20:26:58 +00:00
|
|
|
* FILE: drivers/filesystems/msfs/rw.c
|
2001-05-05 15:21:05 +00:00
|
|
|
* PURPOSE: Mailslot filesystem
|
2006-05-07 11:14:41 +00:00
|
|
|
* PROGRAMMER: Eric Kohl
|
2015-10-10 08:29:05 +00:00
|
|
|
* Nikita Pechenkin (n.pechenkin@mail.ru)
|
2001-05-05 15:21:05 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* INCLUDES ******************************************************************/
|
|
|
|
|
|
|
|
#include "msfs.h"
|
|
|
|
|
2001-06-12 12:35:42 +00:00
|
|
|
#define NDEBUG
|
2001-05-05 15:21:05 +00:00
|
|
|
#include <debug.h>
|
|
|
|
|
|
|
|
/* FUNCTIONS *****************************************************************/
|
|
|
|
|
2005-09-04 23:18:34 +00:00
|
|
|
NTSTATUS DEFAULTAPI
|
2001-05-05 15:21:05 +00:00
|
|
|
MsfsRead(PDEVICE_OBJECT DeviceObject,
|
2006-05-07 11:14:41 +00:00
|
|
|
PIRP Irp)
|
2001-05-05 15:21:05 +00:00
|
|
|
{
|
2006-05-07 11:14:41 +00:00
|
|
|
PIO_STACK_LOCATION IoStack;
|
|
|
|
PFILE_OBJECT FileObject;
|
|
|
|
PMSFS_FCB Fcb;
|
|
|
|
PMSFS_CCB Ccb;
|
|
|
|
PMSFS_MESSAGE Message;
|
|
|
|
KIRQL oldIrql;
|
|
|
|
ULONG Length;
|
|
|
|
ULONG LengthRead = 0;
|
|
|
|
PVOID Buffer;
|
2015-10-10 08:29:05 +00:00
|
|
|
LARGE_INTEGER Timeout;
|
|
|
|
PKTIMER Timer;
|
|
|
|
PMSFS_DPC_CTX Context;
|
|
|
|
PKDPC Dpc;
|
2015-10-10 12:08:45 +00:00
|
|
|
PLIST_ENTRY Entry;
|
2006-05-07 11:14:41 +00:00
|
|
|
|
|
|
|
DPRINT("MsfsRead(DeviceObject %p Irp %p)\n", DeviceObject, Irp);
|
|
|
|
|
|
|
|
IoStack = IoGetCurrentIrpStackLocation (Irp);
|
|
|
|
FileObject = IoStack->FileObject;
|
|
|
|
Fcb = (PMSFS_FCB)FileObject->FsContext;
|
|
|
|
Ccb = (PMSFS_CCB)FileObject->FsContext2;
|
|
|
|
|
|
|
|
DPRINT("MailslotName: %wZ\n", &Fcb->Name);
|
|
|
|
|
|
|
|
/* reading is not permitted on client side */
|
|
|
|
if (Fcb->ServerCcb != Ccb)
|
|
|
|
{
|
|
|
|
Irp->IoStatus.Status = STATUS_ACCESS_DENIED;
|
|
|
|
Irp->IoStatus.Information = 0;
|
|
|
|
|
|
|
|
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
|
|
|
|
|
|
|
return STATUS_ACCESS_DENIED;
|
|
|
|
}
|
|
|
|
|
|
|
|
Length = IoStack->Parameters.Read.Length;
|
|
|
|
if (Irp->MdlAddress)
|
2015-09-15 09:40:30 +00:00
|
|
|
Buffer = MmGetSystemAddressForMdlSafe(Irp->MdlAddress, NormalPagePriority);
|
2006-05-07 11:14:41 +00:00
|
|
|
else
|
|
|
|
Buffer = Irp->UserBuffer;
|
|
|
|
|
2015-10-10 08:29:05 +00:00
|
|
|
|
2015-10-10 12:33:22 +00:00
|
|
|
KeAcquireSpinLock(&Fcb->MessageListLock, &oldIrql);
|
2015-10-10 08:29:05 +00:00
|
|
|
if (Fcb->MessageCount > 0)
|
2006-05-07 11:14:41 +00:00
|
|
|
{
|
2015-10-10 12:08:45 +00:00
|
|
|
Entry = RemoveHeadList(&Fcb->MessageListHead);
|
2015-10-10 12:33:22 +00:00
|
|
|
Fcb->MessageCount--;
|
2015-10-10 12:08:45 +00:00
|
|
|
KeReleaseSpinLock(&Fcb->MessageListLock, oldIrql);
|
2015-10-10 08:29:05 +00:00
|
|
|
|
2015-10-10 12:08:45 +00:00
|
|
|
/* copy current message into buffer */
|
|
|
|
Message = CONTAINING_RECORD(Entry, MSFS_MESSAGE, MessageListEntry);
|
2015-10-10 08:29:05 +00:00
|
|
|
memcpy(Buffer, &Message->Buffer, min(Message->Size,Length));
|
|
|
|
LengthRead = Message->Size;
|
|
|
|
|
|
|
|
ExFreePoolWithTag(Message, 'rFsM');
|
2001-05-05 15:21:05 +00:00
|
|
|
|
2015-10-10 08:29:05 +00:00
|
|
|
Irp->IoStatus.Status = STATUS_SUCCESS;
|
|
|
|
Irp->IoStatus.Information = LengthRead;
|
|
|
|
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
2001-05-05 15:21:05 +00:00
|
|
|
|
2015-10-10 08:29:05 +00:00
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
2015-10-10 12:33:22 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
KeReleaseSpinLock(&Fcb->MessageListLock, oldIrql);
|
|
|
|
}
|
2015-10-10 08:29:05 +00:00
|
|
|
|
|
|
|
Timeout = Fcb->TimeOut;
|
|
|
|
if (Timeout.HighPart == 0 && Timeout.LowPart == 0)
|
|
|
|
{
|
|
|
|
Irp->IoStatus.Status = STATUS_IO_TIMEOUT;
|
|
|
|
Irp->IoStatus.Information = 0;
|
|
|
|
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
|
|
|
|
|
|
|
return STATUS_IO_TIMEOUT;
|
|
|
|
}
|
|
|
|
|
|
|
|
Context = ExAllocatePoolWithTag(NonPagedPool, sizeof(MSFS_DPC_CTX), 'NFsM');
|
|
|
|
if (Context == NULL)
|
|
|
|
{
|
|
|
|
Irp->IoStatus.Status = STATUS_INSUFFICIENT_RESOURCES;
|
|
|
|
Irp->IoStatus.Information = 0;
|
|
|
|
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
|
|
|
|
|
|
|
return STATUS_INSUFFICIENT_RESOURCES;
|
|
|
|
}
|
|
|
|
|
2015-10-10 12:50:33 +00:00
|
|
|
KeInitializeEvent(&Context->Event, SynchronizationEvent, FALSE);
|
2015-10-10 08:29:05 +00:00
|
|
|
IoCsqInsertIrp(&Fcb->CancelSafeQueue, Irp, &Context->CsqContext);
|
|
|
|
Timer = &Context->Timer;
|
|
|
|
Dpc = &Context->Dpc;
|
|
|
|
Context->Csq = &Fcb->CancelSafeQueue;
|
2015-10-10 12:50:33 +00:00
|
|
|
Irp->Tail.Overlay.DriverContext[0] = Context;
|
2001-05-05 15:21:05 +00:00
|
|
|
|
2015-10-10 08:29:05 +00:00
|
|
|
/* No timer for INFINITY_WAIT */
|
|
|
|
if (Timeout.QuadPart != -1)
|
|
|
|
{
|
|
|
|
KeInitializeTimer(Timer);
|
|
|
|
KeInitializeDpc(Dpc, MsfsTimeout, (PVOID)Context);
|
|
|
|
KeSetTimer(Timer, Timeout, Dpc);
|
|
|
|
}
|
|
|
|
|
|
|
|
IoMarkIrpPending(Irp);
|
|
|
|
|
|
|
|
return STATUS_PENDING;
|
2001-05-05 15:21:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-09-04 23:18:34 +00:00
|
|
|
NTSTATUS DEFAULTAPI
|
2001-05-05 15:21:05 +00:00
|
|
|
MsfsWrite(PDEVICE_OBJECT DeviceObject,
|
2006-05-07 11:14:41 +00:00
|
|
|
PIRP Irp)
|
2001-05-05 15:21:05 +00:00
|
|
|
{
|
2006-05-07 11:14:41 +00:00
|
|
|
PIO_STACK_LOCATION IoStack;
|
|
|
|
PFILE_OBJECT FileObject;
|
|
|
|
PMSFS_FCB Fcb;
|
|
|
|
PMSFS_CCB Ccb;
|
|
|
|
PMSFS_MESSAGE Message;
|
|
|
|
KIRQL oldIrql;
|
|
|
|
ULONG Length;
|
|
|
|
PVOID Buffer;
|
2015-10-10 08:29:05 +00:00
|
|
|
PIRP CsqIrp;
|
2015-10-10 12:50:33 +00:00
|
|
|
PMSFS_DPC_CTX Context;
|
2005-05-08 02:16:32 +00:00
|
|
|
|
2006-05-07 11:14:41 +00:00
|
|
|
DPRINT("MsfsWrite(DeviceObject %p Irp %p)\n", DeviceObject, Irp);
|
2005-05-08 02:16:32 +00:00
|
|
|
|
2006-05-07 11:14:41 +00:00
|
|
|
IoStack = IoGetCurrentIrpStackLocation (Irp);
|
|
|
|
FileObject = IoStack->FileObject;
|
|
|
|
Fcb = (PMSFS_FCB)FileObject->FsContext;
|
|
|
|
Ccb = (PMSFS_CCB)FileObject->FsContext2;
|
2005-05-08 02:16:32 +00:00
|
|
|
|
2006-05-07 11:14:41 +00:00
|
|
|
DPRINT("MailslotName: %wZ\n", &Fcb->Name);
|
2005-05-08 02:16:32 +00:00
|
|
|
|
2006-05-07 11:14:41 +00:00
|
|
|
/* writing is not permitted on server side */
|
|
|
|
if (Fcb->ServerCcb == Ccb)
|
|
|
|
{
|
|
|
|
Irp->IoStatus.Status = STATUS_ACCESS_DENIED;
|
|
|
|
Irp->IoStatus.Information = 0;
|
2005-05-08 02:16:32 +00:00
|
|
|
|
2006-05-07 11:14:41 +00:00
|
|
|
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
2005-05-08 02:16:32 +00:00
|
|
|
|
2006-05-07 11:14:41 +00:00
|
|
|
return STATUS_ACCESS_DENIED;
|
|
|
|
}
|
2001-05-05 15:21:05 +00:00
|
|
|
|
2006-05-07 11:14:41 +00:00
|
|
|
Length = IoStack->Parameters.Write.Length;
|
|
|
|
if (Irp->MdlAddress)
|
2015-09-15 09:40:30 +00:00
|
|
|
Buffer = MmGetSystemAddressForMdlSafe(Irp->MdlAddress, NormalPagePriority);
|
2006-05-07 11:14:41 +00:00
|
|
|
else
|
|
|
|
Buffer = Irp->UserBuffer;
|
2005-05-08 02:16:32 +00:00
|
|
|
|
2006-05-07 11:14:41 +00:00
|
|
|
DPRINT("Length: %lu Message: %s\n", Length, (PUCHAR)Buffer);
|
2005-05-08 02:16:32 +00:00
|
|
|
|
2006-05-07 11:14:41 +00:00
|
|
|
/* Allocate new message */
|
2015-03-27 18:03:39 +00:00
|
|
|
Message = ExAllocatePoolWithTag(NonPagedPool,
|
|
|
|
sizeof(MSFS_MESSAGE) + Length,
|
|
|
|
'rFsM');
|
2006-05-07 11:14:41 +00:00
|
|
|
if (Message == NULL)
|
|
|
|
{
|
|
|
|
Irp->IoStatus.Status = STATUS_NO_MEMORY;
|
|
|
|
Irp->IoStatus.Information = 0;
|
2005-05-08 02:16:32 +00:00
|
|
|
|
2006-05-07 11:14:41 +00:00
|
|
|
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
2005-05-08 02:16:32 +00:00
|
|
|
|
2006-05-07 11:14:41 +00:00
|
|
|
return STATUS_NO_MEMORY;
|
|
|
|
}
|
2005-05-08 02:16:32 +00:00
|
|
|
|
2006-05-07 11:14:41 +00:00
|
|
|
Message->Size = Length;
|
|
|
|
memcpy(&Message->Buffer, Buffer, Length);
|
2005-05-08 02:16:32 +00:00
|
|
|
|
2006-05-07 11:14:41 +00:00
|
|
|
KeAcquireSpinLock(&Fcb->MessageListLock, &oldIrql);
|
|
|
|
InsertTailList(&Fcb->MessageListHead, &Message->MessageListEntry);
|
|
|
|
Fcb->MessageCount++;
|
2015-10-10 12:33:22 +00:00
|
|
|
KeReleaseSpinLock(&Fcb->MessageListLock, oldIrql);
|
2005-05-08 02:16:32 +00:00
|
|
|
|
2015-10-10 12:33:22 +00:00
|
|
|
CsqIrp = IoCsqRemoveNextIrp(&Fcb->CancelSafeQueue, NULL);
|
|
|
|
if (CsqIrp != NULL)
|
2015-10-10 08:29:05 +00:00
|
|
|
{
|
2015-10-10 12:50:33 +00:00
|
|
|
/* Get the context */
|
|
|
|
Context = CsqIrp->Tail.Overlay.DriverContext[0];
|
|
|
|
/* DPC was queued, wait for it to fail (IRP is ours) */
|
|
|
|
if (Fcb->TimeOut.QuadPart != -1 && !KeCancelTimer(&Context->Timer))
|
|
|
|
{
|
|
|
|
KeWaitForSingleObject(&Context->Event, Executive, KernelMode, FALSE, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Free context & attempt read */
|
|
|
|
ExFreePoolWithTag(Context, 'NFsM');
|
2015-10-10 08:29:05 +00:00
|
|
|
MsfsRead(DeviceObject, CsqIrp);
|
|
|
|
}
|
|
|
|
|
2006-05-07 11:14:41 +00:00
|
|
|
Irp->IoStatus.Status = STATUS_SUCCESS;
|
|
|
|
Irp->IoStatus.Information = Length;
|
2005-05-08 02:16:32 +00:00
|
|
|
|
2006-05-07 11:14:41 +00:00
|
|
|
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
2005-05-08 02:16:32 +00:00
|
|
|
|
2006-05-07 11:14:41 +00:00
|
|
|
return STATUS_SUCCESS;
|
2001-05-05 15:21:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* EOF */
|