NTSTATUS NpfsClientCloseHandle( PNPFS_CCB pCCB ) { NTSTATUS ntStatus = 0; PNPFS_PIPE pPipe = NULL; PNPFS_CCB pSCB = NULL; PLW_LIST_LINKS pLink = NULL; PNPFS_IRP_CONTEXT pReadContext = NULL; pPipe = pCCB->pPipe; ENTER_MUTEX(&pPipe->PipeMutex); pSCB = pPipe->pSCB; pPipe->PipeClientState = PIPE_CLIENT_CLOSED; while (pSCB && !LwListIsEmpty(&pSCB->ReadIrpList)) { pLink = pSCB->ReadIrpList.Next; LwListRemove(pLink); pReadContext = LW_STRUCT_FROM_FIELD(pLink, NPFS_IRP_CONTEXT, Link); NpfsServerCompleteReadFile(pSCB, pReadContext); } pthread_cond_signal(&pPipe->PipeCondition); if (pPipe->PipeServerState == PIPE_SERVER_CLOSED) { ntStatus = NpfsFreePipeContext(pPipe); BAIL_ON_NT_STATUS(ntStatus); } error: pPipe->pCCB = NULL; LEAVE_MUTEX(&pPipe->PipeMutex); NpfsReleaseCCB(pCCB); return(ntStatus); }
NTSTATUS NpfsClientWriteFile_Connected( PNPFS_CCB pCCB, PNPFS_IRP_CONTEXT pIrpContext ) { NTSTATUS ntStatus = 0; PNPFS_PIPE pPipe = NULL; PNPFS_CCB pSCB = NULL; PVOID pBuffer = NULL; ULONG Length = 0; ULONG ulBytesTransferred = 0; PLW_LIST_LINKS pLink = NULL; PNPFS_IRP_CONTEXT pReadContext = NULL; switch (pIrpContext->pIrp->Type) { case IRP_TYPE_FS_CONTROL: pBuffer = pIrpContext->pIrp->Args.IoFsControl.InputBuffer; Length = pIrpContext->pIrp->Args.IoFsControl.InputBufferLength; break; default: pBuffer = pIrpContext->pIrp->Args.ReadWrite.Buffer; Length = pIrpContext->pIrp->Args.ReadWrite.Length; break; } pPipe = pCCB->pPipe; pSCB = pPipe->pSCB; ntStatus = NpfsEnqueueBuffer( &pSCB->mdlList, pBuffer, Length, &ulBytesTransferred); BAIL_ON_NT_STATUS(ntStatus); while (!LwListIsEmpty(&pSCB->ReadIrpList) && !NpfsMdlListIsEmpty(&pSCB->mdlList)) { pLink = pSCB->ReadIrpList.Next; LwListRemove(pLink); pReadContext = LW_STRUCT_FROM_FIELD(pLink, NPFS_IRP_CONTEXT, Link); NpfsServerCompleteReadFile(pSCB, pReadContext); } pthread_cond_signal(&pPipe->PipeCondition); pIrpContext->pIrp->IoStatusBlock.BytesTransferred = ulBytesTransferred; error: pIrpContext->pIrp->IoStatusBlock.Status = ntStatus; return(ntStatus); }