📄 verfysup.c
字号:
if (Vcb->VatFcb != NULL) {
Vcb->VatFcb->FcbReference -= 1;
Vcb->VatFcb->FcbUserReference -= 1;
}
if (Vcb->VolumeDasdFcb != NULL) {
Vcb->VolumeDasdFcb->FcbReference -= 1;
Vcb->VolumeDasdFcb->FcbUserReference -= 1;
}
UdfUnlockVcb( IrpContext, Vcb );
//
// Purge the volume.
//
UdfPurgeVolume( IrpContext, Vcb, TRUE );
//
// Empty the delayed and async close queues.
//
UdfFspClose( Vcb );
//
// Allocate a new Vpb in case we will need it.
//
NewVpb = ExAllocatePoolWithTag( NonPagedPoolMustSucceed, sizeof( VPB ), TAG_VPB );
RtlZeroMemory( NewVpb, sizeof( VPB ) );
OldVpb = Vcb->Vpb;
//
// Remove the mount volume reference.
//
UdfLockVcb( IrpContext, Vcb );
Vcb->VcbReference -= 1;
//
// Acquire the Vpb spinlock to check for Vpb references.
//
IoAcquireVpbSpinLock( &SavedIrql );
//
// Remember if this is the last reference on this Vcb. We incremented
// the count on the Vpb earlier so we get one last crack it. If our
// reference has gone to zero but the vpb reference count is greater
// than zero then the Io system will be responsible for deleting the
// Vpb.
//
FinalReference = (BOOLEAN) ((Vcb->VcbReference == 0) &&
(OldVpb->ReferenceCount == 1));
//
// There is a reference count in the Vpb and in the Vcb. We have
// incremented the reference count in the Vpb to make sure that
// we have last crack at it. If this is a failed mount then we
// want to return the Vpb to the IO system to use for the next
// mount request.
//
if (OldVpb->RealDevice->Vpb == OldVpb) {
//
// If not the final reference then swap out the Vpb. We must
// preserve the REMOVE_PENDING flag so that the device is
// not remounted in the middle of a PnP remove operation.
//
if (!FinalReference) {
NewVpb->Type = IO_TYPE_VPB;
NewVpb->Size = sizeof( VPB );
NewVpb->RealDevice = OldVpb->RealDevice;
NewVpb->RealDevice->Vpb = NewVpb;
NewVpb->Flags = FlagOn( OldVpb->Flags, VPB_REMOVE_PENDING );
NewVpb = NULL;
IoReleaseVpbSpinLock( SavedIrql );
UdfUnlockVcb( IrpContext, Vcb );
//
// We want to leave the Vpb for the IO system. Mark it
// as being not mounted. Go ahead and delete the Vcb as
// well.
//
} else {
//
// Make sure to remove the last reference on the Vpb.
//
OldVpb->ReferenceCount -= 1;
OldVpb->DeviceObject = NULL;
ClearFlag( Vcb->Vpb->Flags, VPB_MOUNTED );
//
// Clear the Vpb flag so we know not to delete it.
//
Vcb->Vpb = NULL;
IoReleaseVpbSpinLock( SavedIrql );
UdfUnlockVcb( IrpContext, Vcb );
UdfDeleteVcb( IrpContext, Vcb );
VcbPresent = FALSE;
}
//
// Someone has already swapped in a new Vpb. If this is the final reference
// then the file system is responsible for deleting the Vpb.
//
} else if (FinalReference) {
//
// Make sure to remove the last reference on the Vpb.
//
OldVpb->ReferenceCount -= 1;
IoReleaseVpbSpinLock( SavedIrql );
UdfUnlockVcb( IrpContext, Vcb );
UdfDeleteVcb( IrpContext, Vcb );
VcbPresent = FALSE;
//
// The current Vpb is no longer the Vpb for the device (the IO system
// has already allocated a new one). We leave our reference in the
// Vpb and will be responsible for deleting it at a later time.
//
} else {
OldVpb->DeviceObject = NULL;
ClearFlag( Vcb->Vpb->Flags, VPB_MOUNTED );
IoReleaseVpbSpinLock( SavedIrql );
UdfUnlockVcb( IrpContext, Vcb );
}
//
// Deallocate the new Vpb if we don't need it.
//
if (NewVpb != NULL) {
UdfFreePool( &NewVpb );
}
//
// Let our caller know whether the Vcb is still present.
//
return VcbPresent;
}
VOID
UdfVerifyVcb (
IN PIRP_CONTEXT IrpContext,
IN PVCB Vcb
)
/*++
Routine Description:
This routine checks that the current Vcb is valid and currently mounted
on the device. It will raise on an error condition.
We check whether the volume needs verification and the current state
of the Vcb.
Arguments:
Vcb - This is the volume to verify.
Return Value:
None
--*/
{
NTSTATUS Status;
IO_STATUS_BLOCK Iosb;
ULONG MediaChangeCount = 0;
PAGED_CODE();
//
// Fail immediately if the volume is in the progress of being dismounted
// or has been marked invalid.
//
if ((Vcb->VcbCondition == VcbInvalid) ||
(Vcb->VcbCondition == VcbDismountInProgress)) {
UdfRaiseStatus( IrpContext, STATUS_FILE_INVALID );
}
//
// If the media is removable and the verify volume flag in the
// device object is not set then we want to ping the device
// to see if it needs to be verified
//
if ((Vcb->VcbCondition != VcbMountInProgress) &&
FlagOn( Vcb->VcbState, VCB_STATE_REMOVABLE_MEDIA ) &&
!FlagOn( Vcb->Vpb->RealDevice->Flags, DO_VERIFY_VOLUME )) {
Status = UdfPerformDevIoCtrl( IrpContext,
( Vcb->Vpb->RealDevice->DeviceType == FILE_DEVICE_CD_ROM ?
IOCTL_CDROM_CHECK_VERIFY :
IOCTL_DISK_CHECK_VERIFY ),
Vcb->TargetDeviceObject,
&MediaChangeCount,
sizeof(ULONG),
FALSE,
FALSE,
&Iosb );
if (Iosb.Information != sizeof(ULONG)) {
//
// Be safe about the count in case the driver didn't fill it in
//
MediaChangeCount = 0;
}
//
// If the volume is now an empty device, or we have receieved a
// bare STATUS_VERIFY_REQUIRED (various hardware conditions such
// as bus resets, etc., will trigger this in the drivers), or the
// media change count has moved since we last inspected the device,
// then mark the volume to be verified.
//
if ((Vcb->VcbCondition == VcbMounted &&
UdfIsRawDevice( IrpContext, Status )) ||
(Status == STATUS_VERIFY_REQUIRED) ||
(NT_SUCCESS(Status) &&
(Vcb->MediaChangeCount != MediaChangeCount))) {
SetFlag( Vcb->Vpb->RealDevice->Flags, DO_VERIFY_VOLUME );
//
// If the volume is not mounted and we got a media change count,
// update the Vcb so we do not trigger a verify again at this
// count value. If the verify->mount path detects that the media
// has actually changed and this Vcb is valid again, this will have
// done nothing. We are already synchronized since the caller has
// the Vcb.
//
if ((Vcb->VcbCondition == VcbNotMounted) &&
NT_SUCCESS(Status)) {
Vcb->MediaChangeCount = MediaChangeCount;
}
//
// Raise the error condition otherwise.
//
} else if (!NT_SUCCESS( Status )) {
UdfNormalizeAndRaiseStatus( IrpContext, Status );
}
}
//
// The Vcb may be mounted but the underlying real device may need to be verified.
// If it does then we'll set the Iosb in the irp to be our real device
// and raise Verify required
//
if (FlagOn( Vcb->Vpb->RealDevice->Flags, DO_VERIFY_VOLUME )) {
IoSetHardErrorOrVerifyDevice( IrpContext->Irp,
Vcb->Vpb->RealDevice );
UdfRaiseStatus( IrpContext, STATUS_VERIFY_REQUIRED );
}
//
// Based on the condition of the Vcb we'll either return to our
// caller or raise an error condition
//
switch (Vcb->VcbCondition) {
case VcbNotMounted:
SetFlag( Vcb->Vpb->RealDevice->Flags, DO_VERIFY_VOLUME );
IoSetHardErrorOrVerifyDevice( IrpContext->Irp, Vcb->Vpb->RealDevice );
UdfRaiseStatus( IrpContext, STATUS_WRONG_VOLUME );
break;
case VcbInvalid:
case VcbDismountInProgress :
UdfRaiseStatus( IrpContext, STATUS_FILE_INVALID );
break;
}
return;
}
BOOLEAN
UdfVerifyFcbOperation (
IN PIRP_CONTEXT IrpContext OPTIONAL,
IN PFCB Fcb
)
/*++
Routine Description:
This routine is called to verify that the state of the Fcb is valid
to allow the current operation to continue. We use the state of the
Vcb, target device and type of operation to determine this.
Arguments:
IrpContext - IrpContext for the request. If not present then we
were called from the fast IO path.
Fcb - Fcb to perform the request on.
Return Value:
BOOLEAN - TRUE if the request can continue, FALSE otherwise.
--*/
{
NTSTATUS Status = STATUS_SUCCESS;
PVCB Vcb = Fcb->Vcb;
PDEVICE_OBJECT RealDevice = Vcb->Vpb->RealDevice;
PAGED_CODE();
//
// Fail immediately if the volume is in the progress of being dismounted
// or has been marked invalid.
//
if ((Vcb->VcbCondition == VcbInvalid) ||
(Vcb->VcbCondition == VcbDismountInProgress)) {
if (ARGUMENT_PRESENT( IrpContext )) {
UdfRaiseStatus( IrpContext, STATUS_FILE_INVALID );
}
return FALSE;
}
//
// Always fail if the volume needs to be verified.
//
if (FlagOn( RealDevice->Flags, DO_VERIFY_VOLUME )) {
if (ARGUMENT_PRESENT( IrpContext )) {
IoSetHardErrorOrVerifyDevice( IrpContext->Irp,
RealDevice );
UdfRaiseStatus( IrpContext, STATUS_VERIFY_REQUIRED );
}
return FALSE;
//
// All operations are allowed on mounted volumes.
//
} else if ((Vcb->VcbCondition == VcbMounted) ||
(Vcb->VcbCondition == VcbMountInProgress)) {
return TRUE;
//
// Fail all requests for fast Io on other Vcb conditions.
//
} else if (!ARGUMENT_PRESENT( IrpContext )) {
return FALSE;
//
// The remaining case is VcbNotMounted.
// Mark the device to be verified and raise WRONG_VOLUME.
//
} else if (Vcb->VcbCondition == VcbNotMounted) {
if (ARGUMENT_PRESENT( IrpContext )) {
SetFlag(RealDevice->Flags, DO_VERIFY_VOLUME);
IoSetHardErrorOrVerifyDevice( IrpContext->Irp, RealDevice );
UdfRaiseStatus( IrpContext, STATUS_WRONG_VOLUME );
}
return FALSE;
}
return TRUE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -