diff --git a/reactos/drivers/filesystems/npfs/create.c b/reactos/drivers/filesystems/npfs/create.c index 8d7a342fcc1..ea6e52cf743 100644 --- a/reactos/drivers/filesystems/npfs/create.c +++ b/reactos/drivers/filesystems/npfs/create.c @@ -1,7 +1,7 @@ /* * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel -* FILE: drivers/fs/np/create.c +* FILE: drivers/filesystems/npfs/create.c * PURPOSE: Named pipe filesystem * PROGRAMMER: David Welch */ @@ -49,6 +49,7 @@ NpfsAllocateCcb(CCB_TYPE Type, PNPFS_FCB Fcb) Ccb->RefCount = 1; Ccb->Type = Type; + // FIXME: why does this function not reference Fcb? Ccb->Fcb = Fcb; Ccb->OtherSide = NULL; @@ -60,7 +61,7 @@ VOID NpfsReferenceCcb(PNPFS_CCB Ccb) { ASSERT(Ccb->RefCount > 0); - InterlockedIncrement((PLONG)&Ccb->RefCount); + InterlockedIncrement(&Ccb->RefCount); } static @@ -69,7 +70,7 @@ NpfsDereferenceCcb(PNPFS_CCB Ccb) { /* Decrement reference count */ ASSERT(Ccb->RefCount > 0); - if (InterlockedDecrement((PLONG)&Ccb->RefCount) == 0) + if (InterlockedDecrement(&Ccb->RefCount) == 0) { /* Its zero, delete CCB */ ExFreePoolWithTag(Ccb, TAG_NPFS_CCB); @@ -249,9 +250,9 @@ NpfsCreate(PDEVICE_OBJECT DeviceObject, PNPFS_CCB ClientCcb; PNPFS_CCB ServerCcb = NULL; PNPFS_VCB Vcb; - ACCESS_MASK DesiredAccess; NTSTATUS Status; #ifndef USING_PROPER_NPFS_WAIT_SEMANTICS + ACCESS_MASK DesiredAccess; BOOLEAN SpecialAccess; #endif @@ -262,7 +263,9 @@ NpfsCreate(PDEVICE_OBJECT DeviceObject, FileObject = IoStack->FileObject; RelatedFileObject = FileObject->RelatedFileObject; FileName = &FileObject->FileName; +#ifndef USING_PROPER_NPFS_WAIT_SEMANTICS DesiredAccess = IoStack->Parameters.CreatePipe.SecurityContext->DesiredAccess; +#endif DPRINT("FileObject %p\n", FileObject); DPRINT("FileName %wZ\n", &FileObject->FileName); @@ -444,9 +447,9 @@ NpfsCreate(PDEVICE_OBJECT DeviceObject, NpfsDereferenceCcb(ClientCcb); KeUnlockMutex(&Fcb->CcbListLock); NpfsDereferenceFcb(Fcb); - Irp->IoStatus.Status = STATUS_OBJECT_PATH_NOT_FOUND; + Irp->IoStatus.Status = STATUS_OBJECT_NAME_NOT_FOUND; IoCompleteRequest(Irp, IO_NO_INCREMENT); - return STATUS_OBJECT_PATH_NOT_FOUND; + return STATUS_OBJECT_NAME_NOT_FOUND; } } else diff --git a/reactos/drivers/filesystems/npfs/dirctl.c b/reactos/drivers/filesystems/npfs/dirctl.c index 17039b20faa..708320f7451 100644 --- a/reactos/drivers/filesystems/npfs/dirctl.c +++ b/reactos/drivers/filesystems/npfs/dirctl.c @@ -1,7 +1,7 @@ /* * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel - * FILE: drivers/filesastems/npfs/dirctl.c + * FILE: drivers/filesystems/npfs/dirctl.c * PURPOSE: Named pipe filesystem * PROGRAMMER: Eric Kohl */ @@ -55,7 +55,8 @@ NpfsQueryDirectory(PNPFS_CCB Ccb, /* Determine Buffer for result */ if (Irp->MdlAddress) { - Buffer = MmGetSystemAddressForMdl(Irp->MdlAddress); + Buffer = MmGetSystemAddressForMdlSafe(Irp->MdlAddress, + NormalPagePriority); } else { @@ -298,6 +299,8 @@ NpfsDirectoryControl(PDEVICE_OBJECT DeviceObject, NTSTATUS Status; ULONG Size = 0; + UNREFERENCED_PARAMETER(DeviceObject); + DPRINT("NpfsDirectoryControl() called\n"); IoStack = IoGetCurrentIrpStackLocation(Irp); diff --git a/reactos/drivers/filesystems/npfs/finfo.c b/reactos/drivers/filesystems/npfs/finfo.c index 7a7be5a0232..03c9a60a1fe 100644 --- a/reactos/drivers/filesystems/npfs/finfo.c +++ b/reactos/drivers/filesystems/npfs/finfo.c @@ -1,7 +1,7 @@ /* * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel -* FILE: drivers/fs/np/finfo.c +* FILE: drivers/filesystems/npfs/finfo.c * PURPOSE: Named pipe filesystem * PROGRAMMER: Eric Kohl */ @@ -24,6 +24,9 @@ NpfsSetPipeInformation(PDEVICE_OBJECT DeviceObject, { PNPFS_FCB Fcb; PFILE_PIPE_INFORMATION Request; + + UNREFERENCED_PARAMETER(DeviceObject); + DPRINT("NpfsSetPipeInformation()\n"); if (*BufferLength < sizeof(FILE_PIPE_INFORMATION)) @@ -48,7 +51,7 @@ NpfsSetPipeInformation(PDEVICE_OBJECT DeviceObject, { Fcb->ClientReadMode = Request->ReadMode; } - else + else { Fcb->ServerReadMode = Request->ReadMode; } @@ -68,6 +71,9 @@ NpfsSetPipeRemoteInformation(PDEVICE_OBJECT DeviceObject, { PNPFS_FCB Fcb; PFILE_PIPE_REMOTE_INFORMATION Request; + + UNREFERENCED_PARAMETER(DeviceObject); + DPRINT("NpfsSetPipeRemoteInformation()\n"); if (*BufferLength < sizeof(FILE_PIPE_REMOTE_INFORMATION)) @@ -97,6 +103,9 @@ NpfsQueryPipeInformation(PDEVICE_OBJECT DeviceObject, { PNPFS_FCB Fcb; ULONG ConnectionSideReadMode; + + UNREFERENCED_PARAMETER(DeviceObject); + DPRINT("NpfsQueryPipeInformation()\n"); if (*BufferLength < sizeof(FILE_PIPE_INFORMATION)) @@ -132,6 +141,9 @@ NpfsQueryPipeRemoteInformation(PDEVICE_OBJECT DeviceObject, PULONG BufferLength) { PNPFS_FCB Fcb; + + UNREFERENCED_PARAMETER(DeviceObject); + DPRINT("NpfsQueryPipeRemoteInformation()\n"); if (*BufferLength < sizeof(FILE_PIPE_REMOTE_INFORMATION)) @@ -165,6 +177,8 @@ NpfsQueryLocalPipeInformation(PDEVICE_OBJECT DeviceObject, { PNPFS_FCB Fcb; + UNREFERENCED_PARAMETER(DeviceObject); + DPRINT("NpfsQueryLocalPipeInformation()\n"); if (*BufferLength < sizeof(FILE_PIPE_REMOTE_INFORMATION)) diff --git a/reactos/drivers/filesystems/npfs/fsctrl.c b/reactos/drivers/filesystems/npfs/fsctrl.c index a7eca3f1c36..c6ebd5efcaf 100644 --- a/reactos/drivers/filesystems/npfs/fsctrl.c +++ b/reactos/drivers/filesystems/npfs/fsctrl.c @@ -1,7 +1,7 @@ /* * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel -* FILE: drivers/fs/np/fsctrl.c +* FILE: drivers/filesystems/npfs/fsctrl.c * PURPOSE: Named pipe filesystem * PROGRAMMER: David Welch * Eric Kohl @@ -26,6 +26,8 @@ NpfsListeningCancelRoutine(IN PDEVICE_OBJECT DeviceObject, { PNPFS_WAITER_ENTRY Waiter; + UNREFERENCED_PARAMETER(DeviceObject); + Waiter = (PNPFS_WAITER_ENTRY)&Irp->Tail.Overlay.DriverContext; DPRINT("NpfsListeningCancelRoutine() called for <%wZ>\n", @@ -795,6 +797,7 @@ NpfsFlushBuffers(PDEVICE_OBJECT DeviceObject, PIRP Irp) { /* FIXME: Implement */ + UNREFERENCED_PARAMETER(DeviceObject); Irp->IoStatus.Status = STATUS_SUCCESS; Irp->IoStatus.Information = 0; diff --git a/reactos/drivers/filesystems/npfs/npfs.c b/reactos/drivers/filesystems/npfs/npfs.c index 13f92ab7554..f794964a497 100644 --- a/reactos/drivers/filesystems/npfs/npfs.c +++ b/reactos/drivers/filesystems/npfs/npfs.c @@ -1,7 +1,7 @@ /* * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel -* FILE: drivers/fs/np/mount.c +* FILE: drivers/filesystems/npfs/npfs.c * PURPOSE: Named pipe filesystem * PROGRAMMER: David Welch */ @@ -25,6 +25,8 @@ DriverEntry(PDRIVER_OBJECT DriverObject, PNPFS_FCB Fcb; NTSTATUS Status; + UNREFERENCED_PARAMETER(RegistryPath); + DPRINT("Named Pipe FSD 0.0.2\n"); ASSERT (sizeof(NPFS_CONTEXT) <= FIELD_OFFSET(IRP, Tail.Overlay.DriverContext)); @@ -87,6 +89,12 @@ DriverEntry(PDRIVER_OBJECT DriverObject, /* Create the device FCB */ Fcb = ExAllocatePoolWithTag(NonPagedPool, sizeof(NPFS_FCB), TAG_NPFS_FCB); + if (!Fcb) + { + DPRINT1("Out of memory for device FCB!\n"); + IoDeleteDevice(DeviceObject); + return STATUS_INSUFFICIENT_RESOURCES; + } Fcb->Type = FCB_DEVICE; Fcb->Vcb = Vcb; Fcb->RefCount = 1; @@ -94,6 +102,13 @@ DriverEntry(PDRIVER_OBJECT DriverObject, /* Create the root directory FCB */ Fcb = ExAllocatePoolWithTag(NonPagedPool, sizeof(NPFS_FCB), TAG_NPFS_FCB); + if (!Fcb) + { + DPRINT1("Out of memory for root FCB!\n"); + IoDeleteDevice(DeviceObject); + ExFreePoolWithTag(Vcb->DeviceFcb, TAG_NPFS_FCB); + return STATUS_INSUFFICIENT_RESOURCES; + } Fcb->Type = FCB_DIRECTORY; Fcb->Vcb = Vcb; Fcb->RefCount = 1; diff --git a/reactos/drivers/filesystems/npfs/npfs.h b/reactos/drivers/filesystems/npfs/npfs.h index 31589e2bf39..8cf4651b887 100644 --- a/reactos/drivers/filesystems/npfs/npfs.h +++ b/reactos/drivers/filesystems/npfs/npfs.h @@ -95,7 +95,7 @@ typedef struct _NPFS_CCB ULONG PipeState; ULONG ReadDataAvailable; ULONG WriteQuotaAvailable; - ULONG RefCount; + volatile LONG RefCount; LIST_ENTRY ReadRequestListHead; diff --git a/reactos/drivers/filesystems/npfs/rw.c b/reactos/drivers/filesystems/npfs/rw.c index 3c535ec9701..20dcd94c0dc 100644 --- a/reactos/drivers/filesystems/npfs/rw.c +++ b/reactos/drivers/filesystems/npfs/rw.c @@ -1,7 +1,7 @@ /* * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel -* FILE: drivers/fs/np/rw.c +* FILE: drivers/filesystems/npfs/rw.c * PURPOSE: Named pipe filesystem * PROGRAMMER: David Welch * Michael Martin @@ -115,6 +115,7 @@ NpfsReadWriteCancelRoutine(IN PDEVICE_OBJECT DeviceObject, } } +static KSTART_ROUTINE NpfsWaiterThread; static VOID NTAPI NpfsWaiterThread(PVOID InitContext) { @@ -175,7 +176,7 @@ NpfsWaiterThread(PVOID InitContext) } else { - /* someone has add a new wait request or cancelled an old one */ + /* someone has added a new wait request or cancelled an old one */ Irp = NULL; /* Look for cancelled requests */ @@ -183,16 +184,16 @@ NpfsWaiterThread(PVOID InitContext) { if (ThreadContext->WaitIrpArray[i] == NULL) { - ThreadContext->Count--; - ThreadContext->Vcb->EmptyWaiterCount++; - ThreadContext->WaitObjectArray[i] = ThreadContext->WaitObjectArray[ThreadContext->Count]; - ThreadContext->WaitIrpArray[i] = ThreadContext->WaitIrpArray[ThreadContext->Count]; + ThreadContext->Count--; + ThreadContext->Vcb->EmptyWaiterCount++; + ThreadContext->WaitObjectArray[i] = ThreadContext->WaitObjectArray[ThreadContext->Count]; + ThreadContext->WaitIrpArray[i] = ThreadContext->WaitIrpArray[ThreadContext->Count]; } } } if (ThreadContext->Count == 1 && ThreadContext->Vcb->EmptyWaiterCount >= MAXIMUM_WAIT_OBJECTS) { - /* it exist an other thread with empty wait slots, we can remove our thread from the list */ + /* there is another thread with empty wait slots, we can remove our thread from the list */ RemoveEntryList(&ThreadContext->ListEntry); ExFreePoolWithTag(ThreadContext, TAG_NPFS_THREAD_CONTEXT); KeUnlockMutex(&ThreadContext->Vcb->PipeListLock); @@ -416,10 +417,11 @@ NpfsRead(IN PDEVICE_OBJECT DeviceObject, while (1) { - Buffer = MmGetSystemAddressForMdl(Irp->MdlAddress); + Buffer = MmGetSystemAddressForMdlSafe(Irp->MdlAddress, + NormalPagePriority); Information = Irp->IoStatus.Information; Length = IoGetCurrentIrpStackLocation(Irp)->Parameters.Read.Length; - ASSERT (Information <= Length); + ASSERT(Information <= Length); Buffer = (PVOID)((ULONG_PTR)Buffer + Information); Length -= Information; Status = STATUS_SUCCESS; @@ -443,7 +445,8 @@ NpfsRead(IN PDEVICE_OBJECT DeviceObject, { break; } - if (((Ccb->PipeState != FILE_PIPE_CONNECTED_STATE) || (!Ccb->OtherSide)) && (Ccb->ReadDataAvailable == 0)) + ASSERT(Ccb->ReadDataAvailable == 0); + if ((Ccb->PipeState != FILE_PIPE_CONNECTED_STATE) || (!Ccb->OtherSide)) { DPRINT("PipeState: %x\n", Ccb->PipeState); Status = STATUS_PIPE_BROKEN; @@ -556,7 +559,7 @@ NpfsRead(IN PDEVICE_OBJECT DeviceObject, { ULONG NextMessageLength = 0; - /*First get the size of the message */ + /* First get the size of the message */ memcpy(&NextMessageLength, Ccb->ReadPtr, sizeof(NextMessageLength)); if ((NextMessageLength == 0) || (NextMessageLength > Ccb->ReadDataAvailable)) @@ -579,7 +582,7 @@ NpfsRead(IN PDEVICE_OBJECT DeviceObject, /* Client only requested part of the message */ { /* Calculate the remaining message new size */ - ULONG NewMessageSize = NextMessageLength-CopyLength; + ULONG NewMessageSize = NextMessageLength - CopyLength; /* Update ReadPtr to point to new Message size location */ Ccb->ReadPtr = (PVOID)((ULONG_PTR)Ccb->ReadPtr + CopyLength); @@ -616,7 +619,7 @@ NpfsRead(IN PDEVICE_OBJECT DeviceObject, Ccb->ReadDataAvailable -= CopyLength; - if ((ULONG)Ccb->WriteQuotaAvailable > (ULONG)Ccb->MaxDataLength) ASSERT(FALSE); + ASSERT(Ccb->WriteQuotaAvailable <= Ccb->MaxDataLength); } if (Information > 0) @@ -740,6 +743,8 @@ NpfsWrite(PDEVICE_OBJECT DeviceObject, ULONG CopyLength; ULONG TempLength; + UNREFERENCED_PARAMETER(DeviceObject); + DPRINT("NpfsWrite()\n"); IoStack = IoGetCurrentIrpStackLocation(Irp); @@ -794,7 +799,7 @@ NpfsWrite(PDEVICE_OBJECT DeviceObject, } Status = STATUS_SUCCESS; - Buffer = MmGetSystemAddressForMdlSafe (Irp->MdlAddress, NormalPagePriority); + Buffer = MmGetSystemAddressForMdlSafe(Irp->MdlAddress, NormalPagePriority); if (!Buffer) { @@ -813,7 +818,7 @@ NpfsWrite(PDEVICE_OBJECT DeviceObject, HexDump(Buffer, Length); #endif - while(1) + while (1) { if (ReaderCcb->WriteQuotaAvailable == 0) { diff --git a/reactos/drivers/filesystems/npfs/volume.c b/reactos/drivers/filesystems/npfs/volume.c index 63eb0773b91..50050da7da3 100644 --- a/reactos/drivers/filesystems/npfs/volume.c +++ b/reactos/drivers/filesystems/npfs/volume.c @@ -1,7 +1,7 @@ /* * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel -* FILE: drivers/fs/npfs/volume.c +* FILE: drivers/filesystems/npfs/volume.c * PURPOSE: Named pipe filesystem * PROGRAMMER: Eric Kohl */