From 4ea62038a867952a46fa564f03575e62334b8701 Mon Sep 17 00:00:00 2001 From: Michael Martin Date: Sun, 29 Mar 2009 11:15:10 +0000 Subject: [PATCH] create.c: NpfsCleanup - Do not set the pipe's state to FILE_PIPE_DISCONNECTED_STATE, it is needed for determining broken pipes. Only set pipes otherside to NULL if it is not NULL already. fsctrl.c: NpfsDisconnectPipe - Set return status to STATUS_PIPE_DISCONNECTED if pipe is already disconnected. Add code to handle cases where PipeState is connected and pipes otherside has been set to NULL. rw.c: Set return status to STATUS_BROKEN_PIPE if the other side of pipe has been set to NULL, the data available in pipe is zero and pipe state is connected. Check that pipes otherside is valid before attempting to set the othersides read/write event. svn path=/trunk/; revision=40281 --- reactos/drivers/filesystems/npfs/create.c | 4 ++-- reactos/drivers/filesystems/npfs/fsctrl.c | 7 +++++++ reactos/drivers/filesystems/npfs/rw.c | 21 ++++++++++++--------- 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/reactos/drivers/filesystems/npfs/create.c b/reactos/drivers/filesystems/npfs/create.c index 866638b0436..5236e2035ee 100644 --- a/reactos/drivers/filesystems/npfs/create.c +++ b/reactos/drivers/filesystems/npfs/create.c @@ -605,7 +605,7 @@ NpfsCleanup(PDEVICE_OBJECT DeviceObject, { DPRINT("Client\n"); } - if (Ccb->PipeState == FILE_PIPE_CONNECTED_STATE) + if ((Ccb->PipeState == FILE_PIPE_CONNECTED_STATE) && (Ccb->OtherSide)) { OtherSide = Ccb->OtherSide; /* Lock the server first */ @@ -619,7 +619,7 @@ NpfsCleanup(PDEVICE_OBJECT DeviceObject, ExAcquireFastMutex(&OtherSide->DataListLock); ExAcquireFastMutex(&Ccb->DataListLock); } - OtherSide->PipeState = FILE_PIPE_DISCONNECTED_STATE; + //OtherSide->PipeState = FILE_PIPE_DISCONNECTED_STATE; OtherSide->OtherSide = NULL; /* * Signaling the write event. If is possible that an other diff --git a/reactos/drivers/filesystems/npfs/fsctrl.c b/reactos/drivers/filesystems/npfs/fsctrl.c index 75b6db5ecef..242102d0d75 100644 --- a/reactos/drivers/filesystems/npfs/fsctrl.c +++ b/reactos/drivers/filesystems/npfs/fsctrl.c @@ -196,6 +196,13 @@ NpfsDisconnectPipe(PNPFS_CCB Ccb) if (Ccb->PipeState == FILE_PIPE_DISCONNECTED_STATE) { DPRINT("Pipe is already disconnected\n"); + Status = STATUS_PIPE_DISCONNECTED; + } + else if ((!Ccb->OtherSide) && (Ccb->PipeState == FILE_PIPE_CONNECTED_STATE)) + { + ExAcquireFastMutex(&Ccb->DataListLock); + Ccb->PipeState = FILE_PIPE_DISCONNECTED_STATE; + ExReleaseFastMutex(&Ccb->DataListLock); Status = STATUS_SUCCESS; } else if (Ccb->PipeState == FILE_PIPE_CONNECTED_STATE) diff --git a/reactos/drivers/filesystems/npfs/rw.c b/reactos/drivers/filesystems/npfs/rw.c index 9a562a47418..aa6df9a0680 100644 --- a/reactos/drivers/filesystems/npfs/rw.c +++ b/reactos/drivers/filesystems/npfs/rw.c @@ -331,10 +331,12 @@ NpfsRead(IN PDEVICE_OBJECT DeviceObject, if ((Ccb->OtherSide == NULL) && (Ccb->ReadDataAvailable == 0)) { - /* Its ok if the other side has been Disconnect, but if we have data still in the buffer - , need to still be able to read it. Currently this is a HAXXXX */ - DPRINT("Pipe no longer connected and no data exist in buffer. Ok to close pipe\n"); - if (Ccb->PipeState == FILE_PIPE_LISTENING_STATE) + if (Ccb->PipeState == FILE_PIPE_CONNECTED_STATE) + { + DPRINT("File pipe broken\n"); + Status = STATUS_PIPE_BROKEN; + } + else if (Ccb->PipeState == FILE_PIPE_LISTENING_STATE) Status = STATUS_PIPE_LISTENING; else if (Ccb->PipeState == FILE_PIPE_DISCONNECTED_STATE) Status = STATUS_PIPE_DISCONNECTED; @@ -431,9 +433,8 @@ NpfsRead(IN PDEVICE_OBJECT DeviceObject, if (Ccb->PipeEnd == FILE_PIPE_CLIENT_END) ConnectionSideReadMode=Ccb->Fcb->ClientReadMode; else ConnectionSideReadMode = Ccb->Fcb->ServerReadMode; - if (Ccb->PipeState == FILE_PIPE_CONNECTED_STATE) + if ((Ccb->PipeState == FILE_PIPE_CONNECTED_STATE) && (Ccb->OtherSide)) { - ASSERT(Ccb->OtherSide != NULL); KeSetEvent(&Ccb->OtherSide->WriteEvent, IO_NO_INCREMENT, FALSE); } if (Information > 0 && @@ -526,7 +527,7 @@ NpfsRead(IN PDEVICE_OBJECT DeviceObject, if ((Length == 0) || (Ccb->ReadDataAvailable == 0)) { - if (Ccb->PipeState == FILE_PIPE_CONNECTED_STATE) + if ((Ccb->PipeState == FILE_PIPE_CONNECTED_STATE) && (Ccb->OtherSide)) { KeSetEvent(&Ccb->OtherSide->WriteEvent, IO_NO_INCREMENT, FALSE); } @@ -545,6 +546,8 @@ NpfsRead(IN PDEVICE_OBJECT DeviceObject, memcpy(Ccb->Data, Ccb->ReadPtr, (ULONG_PTR)Ccb->WritePtr - (ULONG_PTR)Ccb->ReadPtr); Ccb->WritePtr = (PVOID)((ULONG_PTR)Ccb->WritePtr - ((ULONG_PTR)Ccb->ReadPtr - (ULONG_PTR)Ccb->Data)); Ccb->ReadPtr = Ccb->Data; + ASSERT((ULONG_PTR)Ccb->WritePtr < ((ULONG_PTR)Ccb->Data + Ccb->MaxDataLength)); + ASSERT(Ccb->WritePtr >= Ccb->Data); } /* For Message mode, the Message length is stored in the buffer preceeding the Message. */ @@ -631,7 +634,7 @@ NpfsRead(IN PDEVICE_OBJECT DeviceObject, { KeResetEvent(&Ccb->ReadEvent); - if ((Ccb->PipeState == FILE_PIPE_CONNECTED_STATE) && (Ccb->WriteQuotaAvailable > 0)) + if ((Ccb->PipeState == FILE_PIPE_CONNECTED_STATE) && (Ccb->WriteQuotaAvailable > 0) && (Ccb->OtherSide)) { KeSetEvent(&Ccb->OtherSide->WriteEvent, IO_NO_INCREMENT, FALSE); } @@ -817,7 +820,7 @@ NpfsWrite(PDEVICE_OBJECT DeviceObject, if ((Status == STATUS_USER_APC) || (Status == STATUS_KERNEL_APC)) { Status = STATUS_CANCELLED; - break; + goto done; } if (!NT_SUCCESS(Status)) {