mirror of
https://github.com/reactos/reactos.git
synced 2025-07-31 15:51:49 +00:00
[USB-BRINGUP-TRUNK]
- Create a branch to do a proper merge of USB work from a trunk base instead of from cmake-bringup - In the future, DO NOT under any circumstances branch another branch. This leads to merge problems! svn path=/branches/usb-bringup-trunk/; revision=55018
This commit is contained in:
parent
f65034e760
commit
c2d0d784c7
20461 changed files with 0 additions and 1213965 deletions
17
drivers/filesystems/msfs/CMakeLists.txt
Normal file
17
drivers/filesystems/msfs/CMakeLists.txt
Normal file
|
@ -0,0 +1,17 @@
|
|||
|
||||
list(APPEND SOURCE
|
||||
create.c
|
||||
finfo.c
|
||||
fsctrl.c
|
||||
msfs.c
|
||||
rw.c
|
||||
msfs.rc)
|
||||
|
||||
add_library(msfs SHARED ${SOURCE})
|
||||
|
||||
set_module_type(msfs kernelmodedriver)
|
||||
add_importlibs(msfs ntoskrnl hal)
|
||||
|
||||
add_pch(msfs msfs.h)
|
||||
|
||||
add_cd_file(TARGET msfs DESTINATION reactos/system32/drivers FOR all)
|
323
drivers/filesystems/msfs/create.c
Normal file
323
drivers/filesystems/msfs/create.c
Normal file
|
@ -0,0 +1,323 @@
|
|||
/*
|
||||
* COPYRIGHT: See COPYING in the top level directory
|
||||
* PROJECT: ReactOS kernel
|
||||
* FILE: drivers/filesystems/msfs/create.c
|
||||
* PURPOSE: Mailslot filesystem
|
||||
* PROGRAMMER: Eric Kohl
|
||||
*/
|
||||
|
||||
/* INCLUDES ******************************************************************/
|
||||
|
||||
#include "msfs.h"
|
||||
|
||||
#define NDEBUG
|
||||
#include <debug.h>
|
||||
|
||||
|
||||
/* FUNCTIONS *****************************************************************/
|
||||
|
||||
/* Creates the client side */
|
||||
NTSTATUS DEFAULTAPI
|
||||
MsfsCreate(PDEVICE_OBJECT DeviceObject,
|
||||
PIRP Irp)
|
||||
{
|
||||
PIO_STACK_LOCATION IoStack;
|
||||
PFILE_OBJECT FileObject;
|
||||
PMSFS_DEVICE_EXTENSION DeviceExtension;
|
||||
PMSFS_FCB Fcb;
|
||||
PMSFS_CCB Ccb;
|
||||
PMSFS_FCB current = NULL;
|
||||
PLIST_ENTRY current_entry;
|
||||
KIRQL oldIrql;
|
||||
|
||||
DPRINT("MsfsCreate(DeviceObject %p Irp %p)\n", DeviceObject, Irp);
|
||||
|
||||
IoStack = IoGetCurrentIrpStackLocation(Irp);
|
||||
DeviceExtension = DeviceObject->DeviceExtension;
|
||||
FileObject = IoStack->FileObject;
|
||||
|
||||
DPRINT("Mailslot name: %wZ\n", &FileObject->FileName);
|
||||
|
||||
Ccb = ExAllocatePool(NonPagedPool, sizeof(MSFS_CCB));
|
||||
if (Ccb == NULL)
|
||||
{
|
||||
Irp->IoStatus.Status = STATUS_NO_MEMORY;
|
||||
Irp->IoStatus.Information = 0;
|
||||
|
||||
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
||||
return STATUS_NO_MEMORY;
|
||||
}
|
||||
|
||||
KeLockMutex(&DeviceExtension->FcbListLock);
|
||||
current_entry = DeviceExtension->FcbListHead.Flink;
|
||||
while (current_entry != &DeviceExtension->FcbListHead)
|
||||
{
|
||||
current = CONTAINING_RECORD(current_entry,
|
||||
MSFS_FCB,
|
||||
FcbListEntry);
|
||||
|
||||
if (!RtlCompareUnicodeString(&FileObject->FileName, ¤t->Name, TRUE))
|
||||
break;
|
||||
|
||||
current_entry = current_entry->Flink;
|
||||
}
|
||||
|
||||
if (current_entry == &DeviceExtension->FcbListHead)
|
||||
{
|
||||
ExFreePool(Ccb);
|
||||
KeUnlockMutex(&DeviceExtension->FcbListLock);
|
||||
|
||||
Irp->IoStatus.Status = STATUS_UNSUCCESSFUL;
|
||||
Irp->IoStatus.Information = 0;
|
||||
|
||||
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
||||
|
||||
return STATUS_UNSUCCESSFUL;
|
||||
}
|
||||
|
||||
Fcb = current;
|
||||
|
||||
KeAcquireSpinLock(&Fcb->CcbListLock, &oldIrql);
|
||||
InsertTailList(&Fcb->CcbListHead, &Ccb->CcbListEntry);
|
||||
KeReleaseSpinLock(&Fcb->CcbListLock, oldIrql);
|
||||
|
||||
Fcb->ReferenceCount++;
|
||||
|
||||
Ccb->Fcb = Fcb;
|
||||
|
||||
KeUnlockMutex(&DeviceExtension->FcbListLock);
|
||||
|
||||
FileObject->FsContext = Fcb;
|
||||
FileObject->FsContext2 = Ccb;
|
||||
FileObject->Flags |= FO_MAILSLOT;
|
||||
|
||||
Irp->IoStatus.Status = STATUS_SUCCESS;
|
||||
Irp->IoStatus.Information = 0;
|
||||
|
||||
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
||||
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
/* Creates the server side */
|
||||
NTSTATUS DEFAULTAPI
|
||||
MsfsCreateMailslot(PDEVICE_OBJECT DeviceObject,
|
||||
PIRP Irp)
|
||||
{
|
||||
PEXTENDED_IO_STACK_LOCATION IoStack;
|
||||
PFILE_OBJECT FileObject;
|
||||
PMSFS_DEVICE_EXTENSION DeviceExtension;
|
||||
PMSFS_FCB Fcb;
|
||||
PMSFS_CCB Ccb;
|
||||
KIRQL oldIrql;
|
||||
PLIST_ENTRY current_entry;
|
||||
PMSFS_FCB current = NULL;
|
||||
PMAILSLOT_CREATE_PARAMETERS Buffer;
|
||||
|
||||
DPRINT("MsfsCreateMailslot(DeviceObject %p Irp %p)\n", DeviceObject, Irp);
|
||||
|
||||
IoStack = (PEXTENDED_IO_STACK_LOCATION)IoGetCurrentIrpStackLocation(Irp);
|
||||
DeviceExtension = DeviceObject->DeviceExtension;
|
||||
FileObject = IoStack->FileObject;
|
||||
Buffer = IoStack->Parameters.CreateMailslot.Parameters;
|
||||
|
||||
DPRINT("Mailslot name: %wZ\n", &FileObject->FileName);
|
||||
|
||||
Fcb = ExAllocatePool(NonPagedPool, sizeof(MSFS_FCB));
|
||||
if (Fcb == NULL)
|
||||
{
|
||||
Irp->IoStatus.Status = STATUS_NO_MEMORY;
|
||||
Irp->IoStatus.Information = 0;
|
||||
|
||||
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
||||
|
||||
return STATUS_NO_MEMORY;
|
||||
}
|
||||
|
||||
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(Fcb);
|
||||
|
||||
Irp->IoStatus.Status = STATUS_NO_MEMORY;
|
||||
Irp->IoStatus.Information = 0;
|
||||
|
||||
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
||||
|
||||
return STATUS_NO_MEMORY;
|
||||
}
|
||||
|
||||
RtlCopyUnicodeString(&Fcb->Name, &FileObject->FileName);
|
||||
|
||||
Ccb = ExAllocatePool(NonPagedPool, sizeof(MSFS_CCB));
|
||||
if (Ccb == NULL)
|
||||
{
|
||||
ExFreePool(Fcb->Name.Buffer);
|
||||
ExFreePool(Fcb);
|
||||
|
||||
Irp->IoStatus.Status = STATUS_NO_MEMORY;
|
||||
Irp->IoStatus.Information = 0;
|
||||
|
||||
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
||||
|
||||
return STATUS_NO_MEMORY;
|
||||
}
|
||||
|
||||
Fcb->ReferenceCount = 0;
|
||||
InitializeListHead(&Fcb->CcbListHead);
|
||||
KeInitializeSpinLock(&Fcb->CcbListLock);
|
||||
|
||||
Fcb->MaxMessageSize = Buffer->MaximumMessageSize;
|
||||
Fcb->MessageCount = 0;
|
||||
Fcb->TimeOut = Buffer->ReadTimeout;
|
||||
KeInitializeEvent(&Fcb->MessageEvent,
|
||||
NotificationEvent,
|
||||
FALSE);
|
||||
|
||||
InitializeListHead(&Fcb->MessageListHead);
|
||||
KeInitializeSpinLock(&Fcb->MessageListLock);
|
||||
|
||||
KeLockMutex(&DeviceExtension->FcbListLock);
|
||||
current_entry = DeviceExtension->FcbListHead.Flink;
|
||||
while (current_entry != &DeviceExtension->FcbListHead)
|
||||
{
|
||||
current = CONTAINING_RECORD(current_entry,
|
||||
MSFS_FCB,
|
||||
FcbListEntry);
|
||||
|
||||
if (!RtlCompareUnicodeString(&Fcb->Name, ¤t->Name, TRUE))
|
||||
break;
|
||||
|
||||
current_entry = current_entry->Flink;
|
||||
}
|
||||
|
||||
if (current_entry != &DeviceExtension->FcbListHead)
|
||||
{
|
||||
ExFreePool(Fcb->Name.Buffer);
|
||||
ExFreePool(Fcb);
|
||||
ExFreePool(Ccb);
|
||||
|
||||
KeUnlockMutex(&DeviceExtension->FcbListLock);
|
||||
|
||||
Irp->IoStatus.Status = STATUS_UNSUCCESSFUL;
|
||||
Irp->IoStatus.Information = 0;
|
||||
|
||||
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
||||
|
||||
return STATUS_UNSUCCESSFUL;
|
||||
}
|
||||
else
|
||||
{
|
||||
InsertTailList(&DeviceExtension->FcbListHead,
|
||||
&Fcb->FcbListEntry);
|
||||
}
|
||||
|
||||
KeAcquireSpinLock(&Fcb->CcbListLock, &oldIrql);
|
||||
InsertTailList(&Fcb->CcbListHead, &Ccb->CcbListEntry);
|
||||
KeReleaseSpinLock(&Fcb->CcbListLock, oldIrql);
|
||||
|
||||
Fcb->ReferenceCount++;
|
||||
Fcb->ServerCcb = Ccb;
|
||||
Ccb->Fcb = Fcb;
|
||||
|
||||
KeUnlockMutex(&DeviceExtension->FcbListLock);
|
||||
|
||||
FileObject->FsContext = Fcb;
|
||||
FileObject->FsContext2 = Ccb;
|
||||
FileObject->Flags |= FO_MAILSLOT;
|
||||
|
||||
Irp->IoStatus.Status = STATUS_SUCCESS;
|
||||
Irp->IoStatus.Information = 0;
|
||||
|
||||
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
||||
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
NTSTATUS DEFAULTAPI
|
||||
MsfsClose(PDEVICE_OBJECT DeviceObject,
|
||||
PIRP Irp)
|
||||
{
|
||||
PIO_STACK_LOCATION IoStack;
|
||||
PFILE_OBJECT FileObject;
|
||||
PMSFS_DEVICE_EXTENSION DeviceExtension;
|
||||
PMSFS_FCB Fcb;
|
||||
PMSFS_CCB Ccb;
|
||||
PMSFS_MESSAGE Message;
|
||||
KIRQL oldIrql;
|
||||
|
||||
DPRINT("MsfsClose(DeviceObject %p Irp %p)\n", DeviceObject, Irp);
|
||||
|
||||
IoStack = IoGetCurrentIrpStackLocation(Irp);
|
||||
DeviceExtension = DeviceObject->DeviceExtension;
|
||||
FileObject = IoStack->FileObject;
|
||||
|
||||
KeLockMutex(&DeviceExtension->FcbListLock);
|
||||
|
||||
if (DeviceExtension->FcbListHead.Flink == &DeviceExtension->FcbListHead)
|
||||
{
|
||||
KeUnlockMutex(&DeviceExtension->FcbListLock);
|
||||
|
||||
Irp->IoStatus.Status = STATUS_SUCCESS;
|
||||
Irp->IoStatus.Information = 0;
|
||||
|
||||
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
||||
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
Fcb = FileObject->FsContext;
|
||||
Ccb = FileObject->FsContext2;
|
||||
|
||||
DPRINT("Mailslot name: %wZ\n", &Fcb->Name);
|
||||
|
||||
Fcb->ReferenceCount--;
|
||||
if (Fcb->ServerCcb == Ccb)
|
||||
{
|
||||
/* delete all messages from message-list */
|
||||
KeAcquireSpinLock(&Fcb->MessageListLock, &oldIrql);
|
||||
|
||||
while (Fcb->MessageListHead.Flink != &Fcb->MessageListHead)
|
||||
{
|
||||
Message = CONTAINING_RECORD(Fcb->MessageListHead.Flink,
|
||||
MSFS_MESSAGE,
|
||||
MessageListEntry);
|
||||
RemoveEntryList(Fcb->MessageListHead.Flink);
|
||||
ExFreePool(Message);
|
||||
}
|
||||
|
||||
Fcb->MessageCount = 0;
|
||||
|
||||
KeReleaseSpinLock(&Fcb->MessageListLock, oldIrql);
|
||||
Fcb->ServerCcb = NULL;
|
||||
}
|
||||
|
||||
KeAcquireSpinLock(&Fcb->CcbListLock, &oldIrql);
|
||||
RemoveEntryList(&Ccb->CcbListEntry);
|
||||
KeReleaseSpinLock(&Fcb->CcbListLock, oldIrql);
|
||||
ExFreePool(Ccb);
|
||||
FileObject->FsContext2 = NULL;
|
||||
|
||||
if (Fcb->ReferenceCount == 0)
|
||||
{
|
||||
DPRINT("ReferenceCount == 0: Deleting mailslot data\n");
|
||||
RemoveEntryList(&Fcb->FcbListEntry);
|
||||
ExFreePool(Fcb->Name.Buffer);
|
||||
ExFreePool(Fcb);
|
||||
}
|
||||
|
||||
KeUnlockMutex(&DeviceExtension->FcbListLock);
|
||||
|
||||
Irp->IoStatus.Status = STATUS_SUCCESS;
|
||||
Irp->IoStatus.Information = 0;
|
||||
|
||||
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
||||
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
/* EOF */
|
197
drivers/filesystems/msfs/finfo.c
Normal file
197
drivers/filesystems/msfs/finfo.c
Normal file
|
@ -0,0 +1,197 @@
|
|||
/*
|
||||
* COPYRIGHT: See COPYING in the top level directory
|
||||
* PROJECT: ReactOS kernel
|
||||
* FILE: drivers/filesystems/msfs/finfo.c
|
||||
* PURPOSE: Mailslot filesystem
|
||||
* PROGRAMMER: Eric Kohl
|
||||
*/
|
||||
|
||||
/* INCLUDES ******************************************************************/
|
||||
|
||||
#include "msfs.h"
|
||||
|
||||
#define NDEBUG
|
||||
#include <debug.h>
|
||||
|
||||
#undef MAILSLOT_NO_MESSAGE
|
||||
#undef MAILSLOT_WAIT_FOREVER
|
||||
#define MAILSLOT_NO_MESSAGE MAXULONG
|
||||
#define MAILSLOT_WAIT_FOREVER MAXULONG
|
||||
|
||||
|
||||
/* FUNCTIONS *****************************************************************/
|
||||
|
||||
static NTSTATUS
|
||||
MsfsQueryMailslotInformation(PMSFS_FCB Fcb,
|
||||
PFILE_MAILSLOT_QUERY_INFORMATION Buffer,
|
||||
PULONG BufferLength)
|
||||
{
|
||||
KIRQL oldIrql;
|
||||
|
||||
if (*BufferLength < sizeof(FILE_MAILSLOT_QUERY_INFORMATION))
|
||||
return STATUS_BUFFER_OVERFLOW;
|
||||
|
||||
Buffer->MaximumMessageSize = Fcb->MaxMessageSize;
|
||||
Buffer->ReadTimeout = Fcb->TimeOut;
|
||||
|
||||
KeAcquireSpinLock(&Fcb->MessageListLock, &oldIrql);
|
||||
Buffer->MessagesAvailable = Fcb->MessageCount;
|
||||
if (Fcb->MessageCount == 0)
|
||||
{
|
||||
Buffer->NextMessageSize = MAILSLOT_NO_MESSAGE;
|
||||
}
|
||||
else
|
||||
{
|
||||
PMSFS_MESSAGE Message = CONTAINING_RECORD(Fcb->MessageListHead.Flink,
|
||||
MSFS_MESSAGE,
|
||||
MessageListEntry);
|
||||
Buffer->NextMessageSize = Message->Size;
|
||||
}
|
||||
KeReleaseSpinLock(&Fcb->MessageListLock, oldIrql);
|
||||
|
||||
*BufferLength -= sizeof(FILE_MAILSLOT_QUERY_INFORMATION);
|
||||
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static NTSTATUS
|
||||
MsfsSetMailslotInformation(PMSFS_FCB Fcb,
|
||||
PFILE_MAILSLOT_SET_INFORMATION Buffer,
|
||||
PULONG BufferLength)
|
||||
{
|
||||
if (*BufferLength < sizeof(FILE_MAILSLOT_SET_INFORMATION))
|
||||
return STATUS_BUFFER_OVERFLOW;
|
||||
|
||||
Fcb->TimeOut = *Buffer->ReadTimeout;
|
||||
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
NTSTATUS DEFAULTAPI
|
||||
MsfsQueryInformation(PDEVICE_OBJECT DeviceObject,
|
||||
PIRP Irp)
|
||||
{
|
||||
PIO_STACK_LOCATION IoStack;
|
||||
FILE_INFORMATION_CLASS FileInformationClass;
|
||||
PFILE_OBJECT FileObject;
|
||||
PMSFS_FCB Fcb;
|
||||
PMSFS_CCB Ccb;
|
||||
PVOID SystemBuffer;
|
||||
ULONG BufferLength;
|
||||
NTSTATUS Status;
|
||||
|
||||
DPRINT("MsfsQueryInformation(DeviceObject %p Irp %p)\n",
|
||||
DeviceObject, Irp);
|
||||
|
||||
IoStack = IoGetCurrentIrpStackLocation (Irp);
|
||||
FileInformationClass = IoStack->Parameters.QueryFile.FileInformationClass;
|
||||
FileObject = IoStack->FileObject;
|
||||
Fcb = (PMSFS_FCB)FileObject->FsContext;
|
||||
Ccb = (PMSFS_CCB)FileObject->FsContext2;
|
||||
|
||||
DPRINT("Mailslot name: %wZ\n", &Fcb->Name);
|
||||
|
||||
/* querying information is not permitted on client side */
|
||||
if (Fcb->ServerCcb != Ccb)
|
||||
{
|
||||
Status = STATUS_ACCESS_DENIED;
|
||||
|
||||
Irp->IoStatus.Status = Status;
|
||||
Irp->IoStatus.Information = 0;
|
||||
|
||||
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
||||
|
||||
return Status;
|
||||
}
|
||||
|
||||
SystemBuffer = Irp->AssociatedIrp.SystemBuffer;
|
||||
BufferLength = IoStack->Parameters.QueryFile.Length;
|
||||
|
||||
switch (FileInformationClass)
|
||||
{
|
||||
case FileMailslotQueryInformation:
|
||||
Status = MsfsQueryMailslotInformation(Fcb,
|
||||
SystemBuffer,
|
||||
&BufferLength);
|
||||
break;
|
||||
|
||||
default:
|
||||
Status = STATUS_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
Irp->IoStatus.Status = Status;
|
||||
if (NT_SUCCESS(Status))
|
||||
Irp->IoStatus.Information =
|
||||
IoStack->Parameters.QueryFile.Length - BufferLength;
|
||||
else
|
||||
Irp->IoStatus.Information = 0;
|
||||
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
||||
|
||||
return Status;
|
||||
}
|
||||
|
||||
|
||||
NTSTATUS DEFAULTAPI
|
||||
MsfsSetInformation(PDEVICE_OBJECT DeviceObject,
|
||||
PIRP Irp)
|
||||
{
|
||||
PIO_STACK_LOCATION IoStack;
|
||||
FILE_INFORMATION_CLASS FileInformationClass;
|
||||
PFILE_OBJECT FileObject;
|
||||
PMSFS_FCB Fcb;
|
||||
PMSFS_CCB Ccb;
|
||||
PVOID SystemBuffer;
|
||||
ULONG BufferLength;
|
||||
NTSTATUS Status;
|
||||
|
||||
DPRINT("MsfsSetInformation(DeviceObject %p Irp %p)\n", DeviceObject, Irp);
|
||||
|
||||
IoStack = IoGetCurrentIrpStackLocation (Irp);
|
||||
FileInformationClass = IoStack->Parameters.QueryFile.FileInformationClass;
|
||||
FileObject = IoStack->FileObject;
|
||||
Fcb = (PMSFS_FCB)FileObject->FsContext;
|
||||
Ccb = (PMSFS_CCB)FileObject->FsContext2;
|
||||
|
||||
DPRINT("Mailslot name: %wZ\n", &Fcb->Name);
|
||||
|
||||
/* setting information is not permitted on client side */
|
||||
if (Fcb->ServerCcb != Ccb)
|
||||
{
|
||||
Status = STATUS_ACCESS_DENIED;
|
||||
|
||||
Irp->IoStatus.Status = Status;
|
||||
Irp->IoStatus.Information = 0;
|
||||
|
||||
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
||||
|
||||
return Status;
|
||||
}
|
||||
|
||||
SystemBuffer = Irp->AssociatedIrp.SystemBuffer;
|
||||
BufferLength = IoStack->Parameters.QueryFile.Length;
|
||||
|
||||
DPRINT("FileInformationClass %d\n", FileInformationClass);
|
||||
DPRINT("SystemBuffer %p\n", SystemBuffer);
|
||||
|
||||
switch (FileInformationClass)
|
||||
{
|
||||
case FileMailslotSetInformation:
|
||||
Status = MsfsSetMailslotInformation(Fcb,
|
||||
SystemBuffer,
|
||||
&BufferLength);
|
||||
break;
|
||||
|
||||
default:
|
||||
Status = STATUS_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
Irp->IoStatus.Status = Status;
|
||||
Irp->IoStatus.Information = 0;
|
||||
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
||||
|
||||
return Status;
|
||||
}
|
||||
|
||||
/* EOF */
|
49
drivers/filesystems/msfs/fsctrl.c
Normal file
49
drivers/filesystems/msfs/fsctrl.c
Normal file
|
@ -0,0 +1,49 @@
|
|||
/*
|
||||
* COPYRIGHT: See COPYING in the top level directory
|
||||
* PROJECT: ReactOS kernel
|
||||
* FILE: drivers/filesystems/msfs/fsctrl.c
|
||||
* PURPOSE: Mailslot filesystem
|
||||
* PROGRAMMER: Eric Kohl
|
||||
*/
|
||||
|
||||
/* INCLUDES ******************************************************************/
|
||||
|
||||
#include "msfs.h"
|
||||
|
||||
#define NDEBUG
|
||||
#include <debug.h>
|
||||
|
||||
|
||||
/* FUNCTIONS *****************************************************************/
|
||||
|
||||
NTSTATUS DEFAULTAPI
|
||||
MsfsFileSystemControl(PDEVICE_OBJECT DeviceObject,
|
||||
PIRP Irp)
|
||||
{
|
||||
PIO_STACK_LOCATION IoStack;
|
||||
PFILE_OBJECT FileObject;
|
||||
PMSFS_FCB Fcb;
|
||||
NTSTATUS Status;
|
||||
|
||||
DPRINT1("MsfsFileSystemControl(DeviceObject %p Irp %p)\n", DeviceObject, Irp);
|
||||
|
||||
IoStack = IoGetCurrentIrpStackLocation(Irp);
|
||||
FileObject = IoStack->FileObject;
|
||||
Fcb = FileObject->FsContext;
|
||||
|
||||
DPRINT1("Mailslot name: %wZ\n", &Fcb->Name);
|
||||
|
||||
switch (IoStack->Parameters.FileSystemControl.FsControlCode)
|
||||
{
|
||||
default:
|
||||
Status = STATUS_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
Irp->IoStatus.Status = Status;
|
||||
Irp->IoStatus.Information = 0;
|
||||
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
||||
|
||||
return Status;
|
||||
}
|
||||
|
||||
/* EOF */
|
80
drivers/filesystems/msfs/msfs.c
Normal file
80
drivers/filesystems/msfs/msfs.c
Normal file
|
@ -0,0 +1,80 @@
|
|||
/*
|
||||
* COPYRIGHT: See COPYING in the top level directory
|
||||
* PROJECT: ReactOS kernel
|
||||
* FILE: drivers/filesystems/msfs/msfs.c
|
||||
* PURPOSE: Mailslot filesystem
|
||||
* PROGRAMMER: Eric Kohl
|
||||
*/
|
||||
|
||||
/* INCLUDES ******************************************************************/
|
||||
|
||||
#include "msfs.h"
|
||||
|
||||
#define NDEBUG
|
||||
#include <debug.h>
|
||||
|
||||
|
||||
/* FUNCTIONS *****************************************************************/
|
||||
|
||||
NTSTATUS NTAPI
|
||||
DriverEntry(PDRIVER_OBJECT DriverObject,
|
||||
PUNICODE_STRING RegistryPath)
|
||||
{
|
||||
PMSFS_DEVICE_EXTENSION DeviceExtension;
|
||||
PDEVICE_OBJECT DeviceObject;
|
||||
UNICODE_STRING DeviceName;
|
||||
NTSTATUS Status;
|
||||
|
||||
DPRINT("Mailslot FSD 0.0.1\n");
|
||||
|
||||
DriverObject->Flags = 0;
|
||||
DriverObject->MajorFunction[IRP_MJ_CREATE] = MsfsCreate;
|
||||
DriverObject->MajorFunction[IRP_MJ_CREATE_MAILSLOT] =
|
||||
MsfsCreateMailslot;
|
||||
DriverObject->MajorFunction[IRP_MJ_CLOSE] = MsfsClose;
|
||||
DriverObject->MajorFunction[IRP_MJ_READ] = MsfsRead;
|
||||
DriverObject->MajorFunction[IRP_MJ_WRITE] = MsfsWrite;
|
||||
DriverObject->MajorFunction[IRP_MJ_QUERY_INFORMATION] =
|
||||
MsfsQueryInformation;
|
||||
DriverObject->MajorFunction[IRP_MJ_SET_INFORMATION] =
|
||||
MsfsSetInformation;
|
||||
// DriverObject->MajorFunction[IRP_MJ_DIRECTORY_CONTROL] =
|
||||
// MsfsDirectoryControl;
|
||||
// DriverObject->MajorFunction[IRP_MJ_FLUSH_BUFFERS] = MsfsFlushBuffers;
|
||||
// DriverObject->MajorFunction[IRP_MJ_SHUTDOWN] = MsfsShutdown;
|
||||
// DriverObject->MajorFunction[IRP_MJ_QUERY_SECURITY] =
|
||||
// MsfsQuerySecurity;
|
||||
// DriverObject->MajorFunction[IRP_MJ_SET_SECURITY] =
|
||||
// MsfsSetSecurity;
|
||||
DriverObject->MajorFunction[IRP_MJ_FILE_SYSTEM_CONTROL] =
|
||||
MsfsFileSystemControl;
|
||||
|
||||
DriverObject->DriverUnload = NULL;
|
||||
|
||||
RtlInitUnicodeString(&DeviceName,
|
||||
L"\\Device\\MailSlot");
|
||||
Status = IoCreateDevice(DriverObject,
|
||||
sizeof(MSFS_DEVICE_EXTENSION),
|
||||
&DeviceName,
|
||||
FILE_DEVICE_MAILSLOT,
|
||||
0,
|
||||
FALSE,
|
||||
&DeviceObject);
|
||||
if (!NT_SUCCESS(Status))
|
||||
{
|
||||
return Status;
|
||||
}
|
||||
|
||||
/* initialize the device object */
|
||||
DeviceObject->Flags |= DO_DIRECT_IO;
|
||||
|
||||
/* initialize device extension */
|
||||
DeviceExtension = DeviceObject->DeviceExtension;
|
||||
InitializeListHead(&DeviceExtension->FcbListHead);
|
||||
KeInitializeMutex(&DeviceExtension->FcbListLock,
|
||||
0);
|
||||
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
/* EOF */
|
93
drivers/filesystems/msfs/msfs.h
Normal file
93
drivers/filesystems/msfs/msfs.h
Normal file
|
@ -0,0 +1,93 @@
|
|||
/*
|
||||
* COPYRIGHT: See COPYING in the top level directory
|
||||
* PROJECT: ReactOS kernel
|
||||
* FILE: drivers/filesystems/msfs/msfs.h
|
||||
* PURPOSE: Mailslot filesystem
|
||||
* PROGRAMMER: Eric Kohl
|
||||
*/
|
||||
|
||||
#ifndef __DRIVERS_FS_MS_MSFS_H
|
||||
#define __DRIVERS_FS_MS_MSFS_H
|
||||
|
||||
#include <ntifs.h>
|
||||
#include <iotypes.h>
|
||||
|
||||
#define DEFAULTAPI NTAPI
|
||||
|
||||
typedef struct _MSFS_DEVICE_EXTENSION
|
||||
{
|
||||
LIST_ENTRY FcbListHead;
|
||||
KMUTEX FcbListLock;
|
||||
} MSFS_DEVICE_EXTENSION, *PMSFS_DEVICE_EXTENSION;
|
||||
|
||||
|
||||
typedef struct _MSFS_FCB
|
||||
{
|
||||
FSRTL_COMMON_FCB_HEADER RFCB;
|
||||
UNICODE_STRING Name;
|
||||
LIST_ENTRY FcbListEntry;
|
||||
KSPIN_LOCK CcbListLock;
|
||||
LIST_ENTRY CcbListHead;
|
||||
struct _MSFS_CCB *ServerCcb;
|
||||
ULONG ReferenceCount;
|
||||
LARGE_INTEGER TimeOut;
|
||||
KEVENT MessageEvent;
|
||||
ULONG MaxMessageSize;
|
||||
ULONG MessageCount;
|
||||
KSPIN_LOCK MessageListLock;
|
||||
LIST_ENTRY MessageListHead;
|
||||
} MSFS_FCB, *PMSFS_FCB;
|
||||
|
||||
|
||||
typedef struct _MSFS_CCB
|
||||
{
|
||||
LIST_ENTRY CcbListEntry;
|
||||
PMSFS_FCB Fcb;
|
||||
} MSFS_CCB, *PMSFS_CCB;
|
||||
|
||||
|
||||
typedef struct _MSFS_MESSAGE
|
||||
{
|
||||
LIST_ENTRY MessageListEntry;
|
||||
ULONG Size;
|
||||
UCHAR Buffer[1];
|
||||
} MSFS_MESSAGE, *PMSFS_MESSAGE;
|
||||
|
||||
|
||||
#define KeLockMutex(x) KeWaitForSingleObject(x, \
|
||||
UserRequest, \
|
||||
KernelMode, \
|
||||
FALSE, \
|
||||
NULL);
|
||||
|
||||
#define KeUnlockMutex(x) KeReleaseMutex(x, FALSE);
|
||||
|
||||
DRIVER_DISPATCH MsfsCreate;
|
||||
NTSTATUS DEFAULTAPI MsfsCreate(PDEVICE_OBJECT DeviceObject, PIRP Irp);
|
||||
|
||||
DRIVER_DISPATCH MsfsCreateMailslot;
|
||||
NTSTATUS DEFAULTAPI MsfsCreateMailslot(PDEVICE_OBJECT DeviceObject, PIRP Irp);
|
||||
|
||||
DRIVER_DISPATCH MsfsClose;
|
||||
NTSTATUS DEFAULTAPI MsfsClose(PDEVICE_OBJECT DeviceObject, PIRP Irp);
|
||||
|
||||
DRIVER_DISPATCH MsfsQueryInformation;
|
||||
NTSTATUS DEFAULTAPI MsfsQueryInformation(PDEVICE_OBJECT DeviceObject, PIRP Irp);
|
||||
|
||||
DRIVER_DISPATCH MsfsSetInformation;
|
||||
NTSTATUS DEFAULTAPI MsfsSetInformation(PDEVICE_OBJECT DeviceObject, PIRP Irp);
|
||||
|
||||
DRIVER_DISPATCH MsfsRead;
|
||||
NTSTATUS DEFAULTAPI MsfsRead(PDEVICE_OBJECT DeviceObject, PIRP Irp);
|
||||
|
||||
DRIVER_DISPATCH MsfsWrite;
|
||||
NTSTATUS DEFAULTAPI MsfsWrite(PDEVICE_OBJECT DeviceObject, PIRP Irp);
|
||||
|
||||
DRIVER_DISPATCH MsfsFileSystemControl;
|
||||
NTSTATUS DEFAULTAPI MsfsFileSystemControl(PDEVICE_OBJECT DeviceObject, PIRP Irp);
|
||||
|
||||
NTSTATUS NTAPI
|
||||
DriverEntry(PDRIVER_OBJECT DriverObject,
|
||||
PUNICODE_STRING RegistryPath);
|
||||
|
||||
#endif /* __DRIVERS_FS_MS_MSFS_H */
|
14
drivers/filesystems/msfs/msfs.rbuild
Normal file
14
drivers/filesystems/msfs/msfs.rbuild
Normal file
|
@ -0,0 +1,14 @@
|
|||
<?xml version="1.0"?>
|
||||
<!DOCTYPE module SYSTEM "../../../tools/rbuild/project.dtd">
|
||||
<module name="msfs" type="kernelmodedriver" installbase="system32/drivers" installname="msfs.sys">
|
||||
<include base="msfs">.</include>
|
||||
<library>ntoskrnl</library>
|
||||
<library>hal</library>
|
||||
<file>create.c</file>
|
||||
<file>finfo.c</file>
|
||||
<file>fsctrl.c</file>
|
||||
<file>msfs.c</file>
|
||||
<file>rw.c</file>
|
||||
<file>msfs.rc</file>
|
||||
<pch>msfs.h</pch>
|
||||
</module>
|
7
drivers/filesystems/msfs/msfs.rc
Normal file
7
drivers/filesystems/msfs/msfs.rc
Normal file
|
@ -0,0 +1,7 @@
|
|||
/* $Id$ */
|
||||
|
||||
#define REACTOS_VERSION_DLL
|
||||
#define REACTOS_STR_FILE_DESCRIPTION "Mailslot IFS Driver\0"
|
||||
#define REACTOS_STR_INTERNAL_NAME "msfs\0"
|
||||
#define REACTOS_STR_ORIGINAL_FILENAME "msfs.sys\0"
|
||||
#include <reactos/version.rc>
|
181
drivers/filesystems/msfs/rw.c
Normal file
181
drivers/filesystems/msfs/rw.c
Normal file
|
@ -0,0 +1,181 @@
|
|||
/*
|
||||
* COPYRIGHT: See COPYING in the top level directory
|
||||
* PROJECT: ReactOS kernel
|
||||
* FILE: drivers/filesystems/msfs/rw.c
|
||||
* PURPOSE: Mailslot filesystem
|
||||
* PROGRAMMER: Eric Kohl
|
||||
*/
|
||||
|
||||
/* INCLUDES ******************************************************************/
|
||||
|
||||
#include "msfs.h"
|
||||
|
||||
#define NDEBUG
|
||||
#include <debug.h>
|
||||
|
||||
|
||||
/* FUNCTIONS *****************************************************************/
|
||||
|
||||
NTSTATUS DEFAULTAPI
|
||||
MsfsRead(PDEVICE_OBJECT DeviceObject,
|
||||
PIRP Irp)
|
||||
{
|
||||
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;
|
||||
NTSTATUS Status;
|
||||
|
||||
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)
|
||||
Buffer = MmGetSystemAddressForMdl (Irp->MdlAddress);
|
||||
else
|
||||
Buffer = Irp->UserBuffer;
|
||||
|
||||
Status = KeWaitForSingleObject(&Fcb->MessageEvent,
|
||||
UserRequest,
|
||||
KernelMode,
|
||||
FALSE,
|
||||
&Fcb->TimeOut);
|
||||
if (NT_SUCCESS(Status))
|
||||
{
|
||||
if (Fcb->MessageCount > 0)
|
||||
{
|
||||
/* copy current message into buffer */
|
||||
Message = CONTAINING_RECORD(Fcb->MessageListHead.Flink,
|
||||
MSFS_MESSAGE,
|
||||
MessageListEntry);
|
||||
|
||||
memcpy(Buffer, &Message->Buffer, min(Message->Size,Length));
|
||||
LengthRead = Message->Size;
|
||||
|
||||
KeAcquireSpinLock(&Fcb->MessageListLock, &oldIrql);
|
||||
RemoveHeadList(&Fcb->MessageListHead);
|
||||
KeReleaseSpinLock(&Fcb->MessageListLock, oldIrql);
|
||||
|
||||
ExFreePool(Message);
|
||||
Fcb->MessageCount--;
|
||||
if (Fcb->MessageCount == 0)
|
||||
{
|
||||
KeClearEvent(&Fcb->MessageEvent);
|
||||
}
|
||||
}
|
||||
else if (Fcb->TimeOut.QuadPart != 0LL)
|
||||
{
|
||||
/* No message found after waiting */
|
||||
Status = STATUS_IO_TIMEOUT;
|
||||
}
|
||||
}
|
||||
|
||||
Irp->IoStatus.Status = Status;
|
||||
Irp->IoStatus.Information = LengthRead;
|
||||
|
||||
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
||||
|
||||
return Status;
|
||||
}
|
||||
|
||||
|
||||
NTSTATUS DEFAULTAPI
|
||||
MsfsWrite(PDEVICE_OBJECT DeviceObject,
|
||||
PIRP Irp)
|
||||
{
|
||||
PIO_STACK_LOCATION IoStack;
|
||||
PFILE_OBJECT FileObject;
|
||||
PMSFS_FCB Fcb;
|
||||
PMSFS_CCB Ccb;
|
||||
PMSFS_MESSAGE Message;
|
||||
KIRQL oldIrql;
|
||||
ULONG Length;
|
||||
PVOID Buffer;
|
||||
|
||||
DPRINT("MsfsWrite(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);
|
||||
|
||||
/* writing is not permitted on server 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.Write.Length;
|
||||
if (Irp->MdlAddress)
|
||||
Buffer = MmGetSystemAddressForMdl (Irp->MdlAddress);
|
||||
else
|
||||
Buffer = Irp->UserBuffer;
|
||||
|
||||
DPRINT("Length: %lu Message: %s\n", Length, (PUCHAR)Buffer);
|
||||
|
||||
/* Allocate new message */
|
||||
Message = ExAllocatePool(NonPagedPool,
|
||||
sizeof(MSFS_MESSAGE) + Length);
|
||||
if (Message == NULL)
|
||||
{
|
||||
Irp->IoStatus.Status = STATUS_NO_MEMORY;
|
||||
Irp->IoStatus.Information = 0;
|
||||
|
||||
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
||||
|
||||
return STATUS_NO_MEMORY;
|
||||
}
|
||||
|
||||
Message->Size = Length;
|
||||
memcpy(&Message->Buffer, Buffer, Length);
|
||||
|
||||
KeAcquireSpinLock(&Fcb->MessageListLock, &oldIrql);
|
||||
InsertTailList(&Fcb->MessageListHead, &Message->MessageListEntry);
|
||||
KeReleaseSpinLock(&Fcb->MessageListLock, oldIrql);
|
||||
|
||||
Fcb->MessageCount++;
|
||||
if (Fcb->MessageCount == 1)
|
||||
{
|
||||
KeSetEvent(&Fcb->MessageEvent,
|
||||
0,
|
||||
FALSE);
|
||||
}
|
||||
|
||||
Irp->IoStatus.Status = STATUS_SUCCESS;
|
||||
Irp->IoStatus.Information = Length;
|
||||
|
||||
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
||||
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
/* EOF */
|
Loading…
Add table
Add a link
Reference in a new issue