mirror of
https://github.com/winfsp/winfsp.git
synced 2025-04-23 17:03:12 -05:00
sys: fsctl
This commit is contained in:
parent
e71ecd5fa1
commit
68eefd9e24
180
src/sys/fsctl.c
180
src/sys/fsctl.c
@ -394,24 +394,17 @@ static NTSTATUS FspFsctlTransact(
|
|||||||
PIRP ProcessIrp, PendingIrp;
|
PIRP ProcessIrp, PendingIrp;
|
||||||
LARGE_INTEGER Timeout;
|
LARGE_INTEGER Timeout;
|
||||||
|
|
||||||
|
Result = STATUS_SUCCESS;
|
||||||
FsContext2 = IrpSp->FileObject->FsContext2;
|
FsContext2 = IrpSp->FileObject->FsContext2;
|
||||||
ExAcquireFastMutex(&FsContext2->FastMutex);
|
ExAcquireFastMutex(&FsContext2->FastMutex);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
/* check to see if we already have a volume */
|
/* check to see if we already have a volume */
|
||||||
FsvolDeviceObject = FsContext2->FsvolDeviceObject;
|
FsvolDeviceObject = FsContext2->FsvolDeviceObject;
|
||||||
if (0 != FsvolDeviceObject)
|
if (0 == FsvolDeviceObject)
|
||||||
{
|
|
||||||
BOOLEAN Success; (VOID)Success;
|
|
||||||
|
|
||||||
/* this must succeed because our volume device exists until IRP_MJ_CLEANUP */
|
|
||||||
Success = FspDeviceRetain(FsvolDeviceObject);
|
|
||||||
ASSERT(Success);
|
|
||||||
|
|
||||||
Result = STATUS_SUCCESS;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
Result = STATUS_ACCESS_DENIED;
|
Result = STATUS_ACCESS_DENIED;
|
||||||
|
|
||||||
|
/* no need to FspDeviceRetain our volume device, because it exists until IRP_MJ_CLEANUP */
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
@ -420,109 +413,94 @@ static NTSTATUS FspFsctlTransact(
|
|||||||
if (!NT_SUCCESS(Result))
|
if (!NT_SUCCESS(Result))
|
||||||
return Result;
|
return Result;
|
||||||
|
|
||||||
try
|
FsvolDeviceExtension = FspFsvolDeviceExtension(FsvolDeviceObject);
|
||||||
|
|
||||||
|
/* process any user-mode file system responses */
|
||||||
|
Response = SystemBuffer;
|
||||||
|
BufferEnd = (PUINT8)SystemBuffer + InputBufferLength;
|
||||||
|
for (;;)
|
||||||
{
|
{
|
||||||
FsvolDeviceExtension = FspFsvolDeviceExtension(FsvolDeviceObject);
|
NextResponse = FspFsctlTransactConsumeResponse(Response, BufferEnd);
|
||||||
|
if (0 == NextResponse)
|
||||||
|
break;
|
||||||
|
|
||||||
/* process any user-mode file system responses */
|
ProcessIrp = FspIoqEndProcessingIrp(&FsvolDeviceExtension->Ioq, (UINT_PTR)Response->Hint);
|
||||||
Response = SystemBuffer;
|
if (0 == ProcessIrp)
|
||||||
BufferEnd = (PUINT8)SystemBuffer + InputBufferLength;
|
/* either IRP was canceled or a bogus Hint was provided */
|
||||||
for (;;)
|
continue;
|
||||||
|
|
||||||
|
FspIopDispatchComplete(ProcessIrp, Response);
|
||||||
|
|
||||||
|
Response = NextResponse;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* were we sent an output buffer? */
|
||||||
|
if (0 == Irp->MdlAddress)
|
||||||
|
{
|
||||||
|
Irp->IoStatus.Information = 0;
|
||||||
|
return STATUS_SUCCESS;
|
||||||
|
}
|
||||||
|
MdlBuffer = MmGetMdlVirtualAddress(Irp->MdlAddress);
|
||||||
|
ASSERT(0 != MdlBuffer);
|
||||||
|
|
||||||
|
/* wait for an IRP to arrive */
|
||||||
|
KeQuerySystemTime(&Timeout);
|
||||||
|
Timeout.QuadPart += FsvolDeviceExtension->VolumeParams.TransactTimeout * 10000;
|
||||||
|
/* convert millis to nanos and add to absolute time */
|
||||||
|
while (0 == (PendingIrp = FspIoqNextPendingIrp(&FsvolDeviceExtension->Ioq, &Timeout)))
|
||||||
|
{
|
||||||
|
if (FspIoqStopped(&FsvolDeviceExtension->Ioq))
|
||||||
|
return STATUS_CANCELLED;
|
||||||
|
}
|
||||||
|
if (FspIoqTimeout == PendingIrp)
|
||||||
|
{
|
||||||
|
Irp->IoStatus.Information = 0;
|
||||||
|
return STATUS_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* send any pending IRP's to the user-mode file system */
|
||||||
|
Request = MdlBuffer;
|
||||||
|
BufferEnd = (PUINT8)MdlBuffer + OutputBufferLength;
|
||||||
|
ASSERT(FspFsctlTransactCanProduceRequest(Request, BufferEnd));
|
||||||
|
for (;;)
|
||||||
|
{
|
||||||
|
PendingIrpRequest = FspIrpRequest(PendingIrp);
|
||||||
|
|
||||||
|
Result = FspIopDispatchPrepare(PendingIrp, PendingIrpRequest);
|
||||||
|
if (!NT_SUCCESS(Result))
|
||||||
|
FspIopCompleteIrp(PendingIrp, Result);
|
||||||
|
else
|
||||||
{
|
{
|
||||||
NextResponse = FspFsctlTransactConsumeResponse(Response, BufferEnd);
|
RtlCopyMemory(Request, PendingIrpRequest, PendingIrpRequest->Size);
|
||||||
if (0 == NextResponse)
|
Request = FspFsctlTransactProduceRequest(Request, PendingIrpRequest->Size);
|
||||||
break;
|
|
||||||
|
|
||||||
ProcessIrp = FspIoqEndProcessingIrp(&FsvolDeviceExtension->Ioq, (UINT_PTR)Response->Hint);
|
if (!FspIoqStartProcessingIrp(&FsvolDeviceExtension->Ioq, PendingIrp))
|
||||||
if (0 == ProcessIrp)
|
|
||||||
/* either IRP was canceled or a bogus Hint was provided */
|
|
||||||
continue;
|
|
||||||
|
|
||||||
FspIopDispatchComplete(ProcessIrp, Response);
|
|
||||||
|
|
||||||
Response = NextResponse;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* were we sent an output buffer? */
|
|
||||||
if (0 == Irp->MdlAddress)
|
|
||||||
{
|
|
||||||
Irp->IoStatus.Information = 0;
|
|
||||||
Result = STATUS_SUCCESS;
|
|
||||||
goto exit;
|
|
||||||
}
|
|
||||||
MdlBuffer = MmGetMdlVirtualAddress(Irp->MdlAddress);
|
|
||||||
ASSERT(0 != MdlBuffer);
|
|
||||||
|
|
||||||
/* wait for an IRP to arrive */
|
|
||||||
KeQuerySystemTime(&Timeout);
|
|
||||||
Timeout.QuadPart += FsvolDeviceExtension->VolumeParams.TransactTimeout * 10000;
|
|
||||||
/* convert millis to nanos and add to absolute time */
|
|
||||||
while (0 == (PendingIrp = FspIoqNextPendingIrp(&FsvolDeviceExtension->Ioq, &Timeout)))
|
|
||||||
{
|
|
||||||
if (FspIoqStopped(&FsvolDeviceExtension->Ioq))
|
|
||||||
{
|
{
|
||||||
Result = STATUS_CANCELLED;
|
/*
|
||||||
goto exit;
|
* This can only happen if the Ioq was stopped. Abandon everything
|
||||||
}
|
* and return STATUS_CANCELLED. Any IRP's in the Pending and Process
|
||||||
}
|
* queues of the Ioq will be cancelled during FspIoqStop(). We must
|
||||||
if (FspIoqTimeout == PendingIrp)
|
* also cancel the PendingIrp we have in our hands.
|
||||||
{
|
*/
|
||||||
Irp->IoStatus.Information = 0;
|
ASSERT(FspIoqStopped(&FsvolDeviceExtension->Ioq));
|
||||||
Result = STATUS_SUCCESS;
|
FspIopCompleteIrp(PendingIrp, STATUS_CANCELLED);
|
||||||
goto exit;
|
return STATUS_CANCELLED;
|
||||||
}
|
|
||||||
|
|
||||||
/* send any pending IRP's to the user-mode file system */
|
|
||||||
Request = MdlBuffer;
|
|
||||||
BufferEnd = (PUINT8)MdlBuffer + OutputBufferLength;
|
|
||||||
ASSERT(FspFsctlTransactCanProduceRequest(Request, BufferEnd));
|
|
||||||
for (;;)
|
|
||||||
{
|
|
||||||
PendingIrpRequest = FspIrpRequest(PendingIrp);
|
|
||||||
|
|
||||||
Result = FspIopDispatchPrepare(PendingIrp, PendingIrpRequest);
|
|
||||||
if (!NT_SUCCESS(Result))
|
|
||||||
FspIopCompleteIrp(PendingIrp, Result);
|
|
||||||
else
|
|
||||||
{
|
|
||||||
RtlCopyMemory(Request, PendingIrpRequest, PendingIrpRequest->Size);
|
|
||||||
Request = FspFsctlTransactProduceRequest(Request, PendingIrpRequest->Size);
|
|
||||||
|
|
||||||
if (!FspIoqStartProcessingIrp(&FsvolDeviceExtension->Ioq, PendingIrp))
|
|
||||||
{
|
|
||||||
/*
|
|
||||||
* This can only happen if the Ioq was stopped. Abandon everything
|
|
||||||
* and return STATUS_CANCELLED. Any IRP's in the Pending and Process
|
|
||||||
* queues of the Ioq will be cancelled during FspIoqStop(). We must
|
|
||||||
* also cancel the PendingIrp we have in our hands.
|
|
||||||
*/
|
|
||||||
ASSERT(FspIoqStopped(&FsvolDeviceExtension->Ioq));
|
|
||||||
FspIopCompleteIrp(PendingIrp, STATUS_CANCELLED);
|
|
||||||
Result = STATUS_CANCELLED;
|
|
||||||
goto exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* check that we have enough space before pulling the next pending IRP off the queue */
|
|
||||||
if (!FspFsctlTransactCanProduceRequest(Request, BufferEnd))
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PendingIrp = FspIoqNextPendingIrp(&FsvolDeviceExtension->Ioq, 0);
|
/* check that we have enough space before pulling the next pending IRP off the queue */
|
||||||
if (0 == PendingIrp)
|
if (!FspFsctlTransactCanProduceRequest(Request, BufferEnd))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Irp->IoStatus.Information = (PUINT8)Request - (PUINT8)MdlBuffer;
|
PendingIrp = FspIoqNextPendingIrp(&FsvolDeviceExtension->Ioq, 0);
|
||||||
Result = STATUS_SUCCESS;
|
if (0 == PendingIrp)
|
||||||
|
break;
|
||||||
|
|
||||||
exit:;
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
FspDeviceRelease(FsvolDeviceObject);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Irp->IoStatus.Information = (PUINT8)Request - (PUINT8)MdlBuffer;
|
||||||
|
Result = STATUS_SUCCESS;
|
||||||
|
|
||||||
return Result;
|
return Result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user