From 2dea5c279bafe85abdde6151b72fe8f445a4eaaf Mon Sep 17 00:00:00 2001 From: Eric Kohl Date: Mon, 11 Oct 2004 12:37:04 +0000 Subject: [PATCH] Minor simplifications. svn path=/trunk/; revision=11269 --- reactos/drivers/fs/np/create.c | 105 ++++++++++++--------- reactos/drivers/fs/np/fsctrl.c | 163 +++++++++++++++------------------ 2 files changed, 140 insertions(+), 128 deletions(-) diff --git a/reactos/drivers/fs/np/create.c b/reactos/drivers/fs/np/create.c index 75d70767c6c..54d2e91d076 100644 --- a/reactos/drivers/fs/np/create.c +++ b/reactos/drivers/fs/np/create.c @@ -1,4 +1,4 @@ -/* $Id: create.c,v 1.22 2004/07/03 17:40:20 navaraf Exp $ +/* $Id: create.c,v 1.23 2004/10/11 12:37:04 ekohl Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel @@ -18,13 +18,59 @@ /* FUNCTIONS *****************************************************************/ +static PNPFS_PIPE +NpfsFindPipe(PNPFS_DEVICE_EXTENSION DeviceExt, + PUNICODE_STRING PipeName) +{ + PLIST_ENTRY CurrentEntry; + PNPFS_PIPE Pipe; + + CurrentEntry = DeviceExt->PipeListHead.Flink; + while (CurrentEntry != &DeviceExt->PipeListHead) + { + Pipe = CONTAINING_RECORD(CurrentEntry, NPFS_PIPE, PipeListEntry); + if (RtlCompareUnicodeString(PipeName, + &Pipe->PipeName, + TRUE) == 0) + { + DPRINT1("<%wZ> = <%wZ>\n", PipeName, &Pipe->PipeName); + return Pipe; + } + + CurrentEntry = CurrentEntry->Flink; + } + + return NULL; +} + + +static PNPFS_FCB +NpfsFindListeningServerInstance(PNPFS_PIPE Pipe) +{ + PLIST_ENTRY CurrentEntry; + PNPFS_FCB ServerFcb; + + CurrentEntry = Pipe->ServerFcbListHead.Flink; + while (CurrentEntry != &Pipe->ServerFcbListHead) + { + ServerFcb = CONTAINING_RECORD(CurrentEntry, NPFS_FCB, FcbListEntry); + if (ServerFcb->PipeState == FILE_PIPE_LISTENING_STATE) + { + DPRINT("Server found! Fcb %p\n", ServerFcb); + return ServerFcb; + } + CurrentEntry = CurrentEntry->Flink; + } + + return NULL; +} + + NTSTATUS STDCALL NpfsCreate( PDEVICE_OBJECT DeviceObject, PIRP Irp) { - PLIST_ENTRY CurrentEntry; - PNPFS_PIPE Current; PIO_STACK_LOCATION IoStack; PFILE_OBJECT FileObject; PNPFS_PIPE Pipe; @@ -43,29 +89,17 @@ NpfsCreate( DPRINT("FileName %wZ\n", &FileObject->FileName); Irp->IoStatus.Information = 0; - + /* * Step 1. Find the pipe we're trying to open. */ KeLockMutex(&DeviceExt->PipeListLock); - CurrentEntry = DeviceExt->PipeListHead.Flink; - while (CurrentEntry != &DeviceExt->PipeListHead) - { - Current = CONTAINING_RECORD(CurrentEntry, NPFS_PIPE, PipeListEntry); - if (RtlCompareUnicodeString( - &FileObject->FileName, - &Current->PipeName, - TRUE) == 0) - { - break; - } - CurrentEntry = CurrentEntry->Flink; - } - - /* Not found, bail out with error. */ - if (CurrentEntry == &DeviceExt->PipeListHead) + Pipe = NpfsFindPipe(DeviceExt, + &FileObject->FileName); + if (Pipe == NULL) { + /* Not found, bail out with error. */ DPRINT("No pipe found!\n"); KeUnlockMutex(&DeviceExt->PipeListLock); Irp->IoStatus.Status = STATUS_OBJECT_NAME_NOT_FOUND; @@ -75,9 +109,6 @@ NpfsCreate( KeUnlockMutex(&DeviceExt->PipeListLock); - /* Save the pipe we found for later use. */ - Pipe = Current; - /* * Step 2. Search for listening server FCB. */ @@ -88,21 +119,10 @@ NpfsCreate( */ KeLockMutex(&Pipe->FcbListLock); - CurrentEntry = Pipe->ServerFcbListHead.Flink; - while (CurrentEntry != &Pipe->ServerFcbListHead) - { - ServerFcb = CONTAINING_RECORD(CurrentEntry, NPFS_FCB, FcbListEntry); - if (ServerFcb->PipeState == FILE_PIPE_LISTENING_STATE) - { - DPRINT("Server found! Fcb %p\n", ServerFcb); - break; - } - CurrentEntry = CurrentEntry->Flink; - } - - /* Not found, bail out with error for FILE_OPEN requests. */ - if (CurrentEntry == &Pipe->ServerFcbListHead) + ServerFcb = NpfsFindListeningServerInstance(Pipe); + if (ServerFcb == NULL) { + /* Not found, bail out with error for FILE_OPEN requests. */ DPRINT("No server fcb found!\n"); if (Disposition == FILE_OPEN) { @@ -111,7 +131,6 @@ NpfsCreate( IoCompleteRequest(Irp, IO_NO_INCREMENT); return STATUS_PIPE_BUSY; } - ServerFcb = NULL; } /* @@ -188,7 +207,7 @@ NpfsCreate( IoCompleteRequest(Irp, IO_NO_INCREMENT); DPRINT("Success!\n"); - + return STATUS_SUCCESS; } @@ -463,11 +482,12 @@ NpfsClose( /* FIXME: Clean up existing connections here ?? */ DPRINT("Server\n"); Pipe->CurrentInstances--; - } else + } + else { DPRINT("Client\n"); } - + if (Fcb->PipeState == FILE_PIPE_CONNECTED_STATE) { if (Fcb->OtherSide) @@ -482,6 +502,7 @@ NpfsClose( */ KeSetEvent(&Fcb->OtherSide->Event, IO_NO_INCREMENT, FALSE); } + #ifndef FIN_WORKAROUND_READCLOSE Fcb->PipeState = 0; #endif @@ -507,9 +528,11 @@ NpfsClose( ExFreePool(Fcb->OtherSide->Data); ExFreePool(Fcb->OtherSide); } + RemoveEntryList(&Fcb->FcbListEntry); if (Fcb->Data) ExFreePool(Fcb->Data); + ExFreePool(Fcb); } #endif diff --git a/reactos/drivers/fs/np/fsctrl.c b/reactos/drivers/fs/np/fsctrl.c index fcffbd9c73d..a65c11e0e78 100644 --- a/reactos/drivers/fs/np/fsctrl.c +++ b/reactos/drivers/fs/np/fsctrl.c @@ -1,4 +1,4 @@ -/* $Id: fsctrl.c,v 1.15 2004/05/05 18:30:16 navaraf Exp $ +/* $Id: fsctrl.c,v 1.16 2004/10/11 12:37:04 ekohl Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel @@ -21,94 +21,86 @@ static NTSTATUS NpfsConnectPipe(PNPFS_FCB Fcb) { - PNPFS_PIPE Pipe; - PLIST_ENTRY current_entry; - PNPFS_FCB ClientFcb; - NTSTATUS Status; + PNPFS_PIPE Pipe; + PLIST_ENTRY current_entry; + PNPFS_FCB ClientFcb; + NTSTATUS Status; - DPRINT("NpfsConnectPipe()\n"); + DPRINT("NpfsConnectPipe()\n"); - if (Fcb->PipeState == FILE_PIPE_CONNECTED_STATE) - { - KeResetEvent(&Fcb->ConnectEvent); - return STATUS_PIPE_CONNECTED; - } + if (Fcb->PipeState == FILE_PIPE_CONNECTED_STATE) + { + KeResetEvent(&Fcb->ConnectEvent); + return STATUS_PIPE_CONNECTED; + } - if (Fcb->PipeState == FILE_PIPE_CLOSING_STATE) - return STATUS_PIPE_CLOSING; + if (Fcb->PipeState == FILE_PIPE_CLOSING_STATE) + return STATUS_PIPE_CLOSING; - DPRINT("Waiting for connection...\n"); + DPRINT("Waiting for connection...\n"); - Pipe = Fcb->Pipe; + Pipe = Fcb->Pipe; - /* search for a listening client fcb */ + /* search for a listening client fcb */ + KeLockMutex(&Pipe->FcbListLock); - KeLockMutex(&Pipe->FcbListLock); - current_entry = Pipe->ClientFcbListHead.Flink; - while (current_entry != &Pipe->ClientFcbListHead) - { - ClientFcb = CONTAINING_RECORD(current_entry, - NPFS_FCB, - FcbListEntry); - - if (ClientFcb->PipeState == FILE_PIPE_LISTENING_STATE) - { - break; - } - - current_entry = current_entry->Flink; - } - - if (current_entry != &Pipe->ClientFcbListHead) - { - /* found a listening client fcb */ - DPRINT("Listening client fcb found -- connecting\n"); + current_entry = Pipe->ClientFcbListHead.Flink; + while (current_entry != &Pipe->ClientFcbListHead) + { + ClientFcb = CONTAINING_RECORD(current_entry, + NPFS_FCB, + FcbListEntry); - /* connect client and server fcb's */ - Fcb->OtherSide = ClientFcb; - ClientFcb->OtherSide = Fcb; + if (ClientFcb->PipeState == FILE_PIPE_LISTENING_STATE) + { + /* found a listening client fcb */ + DPRINT("Listening client fcb found -- connecting\n"); - /* set connected state */ - Fcb->PipeState = FILE_PIPE_CONNECTED_STATE; - ClientFcb->PipeState = FILE_PIPE_CONNECTED_STATE; + /* connect client and server fcb's */ + Fcb->OtherSide = ClientFcb; + ClientFcb->OtherSide = Fcb; - KeUnlockMutex(&Pipe->FcbListLock); + /* set connected state */ + Fcb->PipeState = FILE_PIPE_CONNECTED_STATE; + ClientFcb->PipeState = FILE_PIPE_CONNECTED_STATE; - /* FIXME: create and initialize data queues */ + KeUnlockMutex(&Pipe->FcbListLock); - /* signal client's connect event */ - DPRINT("Setting the ConnectEvent for %x\n", ClientFcb); - KeSetEvent(&ClientFcb->ConnectEvent, IO_NO_INCREMENT, FALSE); + /* FIXME: create and initialize data queues */ - Status = STATUS_PIPE_CONNECTED; - } - else - { - /* no listening client fcb found */ - DPRINT("No listening client fcb found -- waiting for client\n"); + /* signal client's connect event */ + DPRINT("Setting the ConnectEvent for %x\n", ClientFcb); + KeSetEvent(&ClientFcb->ConnectEvent, IO_NO_INCREMENT, FALSE); - KeUnlockMutex(&Pipe->FcbListLock); + return STATUS_PIPE_CONNECTED; + } - Fcb->PipeState = FILE_PIPE_LISTENING_STATE; + current_entry = current_entry->Flink; + } - Status = KeWaitForSingleObject(&Fcb->ConnectEvent, - UserRequest, - KernelMode, - FALSE, - NULL); + KeUnlockMutex(&Pipe->FcbListLock); - if (NT_SUCCESS(Status)) - { - Status = STATUS_PIPE_CONNECTED; - Fcb->PipeState = FILE_PIPE_CONNECTED_STATE; - } + /* no listening client fcb found */ + DPRINT("No listening client fcb found -- waiting for client\n"); - DPRINT("Finished waiting! Status: %x\n", Status); - } + Fcb->PipeState = FILE_PIPE_LISTENING_STATE; - DPRINT("Client Fcb: %p\n", Fcb->OtherSide); + Status = KeWaitForSingleObject(&Fcb->ConnectEvent, + UserRequest, + KernelMode, + FALSE, + NULL); + if (!NT_SUCCESS(Status)) + { + DPRINT("KeWaitForSingleObject() failed (Status %lx)\n", Status); + return Status; + } - return Status; + Fcb->PipeState = FILE_PIPE_CONNECTED_STATE; + + DPRINT("Client Fcb: %p\n", Fcb->OtherSide); + + return STATUS_PIPE_CONNECTED; } @@ -174,31 +166,28 @@ NpfsWaitPipe(PIRP Irp, FcbListEntry); if (ServerFcb->PipeState == FILE_PIPE_LISTENING_STATE) - break; + { + /* found a listening server fcb */ + DPRINT("Listening server fcb found -- connecting\n"); + + return STATUS_SUCCESS; + } current_entry = current_entry->Flink; } - if (current_entry != &Pipe->ServerFcbListHead) - { - /* found a listening server fcb */ - DPRINT("Listening server fcb found -- connecting\n"); + /* no listening server fcb found -- wait for one */ + Fcb->PipeState = FILE_PIPE_LISTENING_STATE; - Status = STATUS_SUCCESS; - } - else - { - /* no listening server fcb found -- wait for one */ - Fcb->PipeState = FILE_PIPE_LISTENING_STATE; + Status = KeWaitForSingleObject(&Fcb->ConnectEvent, + UserRequest, + KernelMode, + FALSE, + &WaitPipe->Timeout); - Status = KeWaitForSingleObject(&Fcb->ConnectEvent, - UserRequest, - KernelMode, - FALSE, - &WaitPipe->Timeout); - } + DPRINT("KeWaitForSingleObject() returned (Status %lx)\n", Status); - return(Status); + return Status; }