NTSTATUS CdPerformVerify ( IN PIRP_CONTEXT IrpContext, IN PIRP Irp, IN PDEVICE_OBJECT DeviceToVerify ) /*++ Routine Description: This routines performs an IoVerifyVolume operation and takes the appropriate action. If the verify is successful then we send the originating Irp off to an Ex Worker Thread. This routine is called from the exception handler. No file system resources are held when this routine is called. Arguments: Irp - The irp to send off after all is well and done. Device - The real device needing verification. Return Value: None. --*/ { PVCB Vcb; NTSTATUS Status = STATUS_SUCCESS; PIO_STACK_LOCATION IrpSp; ASSERT_IRP_CONTEXT( IrpContext ); ASSERT_IRP( Irp ); // // Check if this Irp has a status of Verify required and if it does // then call the I/O system to do a verify. // // Skip the IoVerifyVolume if this is a mount or verify request // itself. Trying a recursive mount will cause a deadlock with // the DeviceObject->DeviceLock. // if ((IrpContext->MajorFunction == IRP_MJ_FILE_SYSTEM_CONTROL) && ((IrpContext->MinorFunction == IRP_MN_MOUNT_VOLUME) || (IrpContext->MinorFunction == IRP_MN_VERIFY_VOLUME))) { return CdFsdPostRequest( IrpContext, Irp ); } // // Extract a pointer to the Vcb from the VolumeDeviceObject. // Note that since we have specifically excluded mount, // requests, we know that IrpSp->DeviceObject is indeed a // volume device object. // IrpSp = IoGetCurrentIrpStackLocation( Irp ); Vcb = &CONTAINING_RECORD( IrpSp->DeviceObject, VOLUME_DEVICE_OBJECT, DeviceObject )->Vcb; try { // // Send down the verify FSCTL. Note that this is sent to the // currently mounted volume, which may not be this one. // // We will allow Raw to mount this volume if we were doing a // an absolute DASD open. // Status = IoVerifyVolume( DeviceToVerify, CdOperationIsDasdOpen( IrpContext)); // // Acquire the Vcb so we're working with a stable VcbCondition. // CdAcquireVcbShared( IrpContext, Vcb, FALSE); // // If the verify operation completed it will return // either STATUS_SUCCESS or STATUS_WRONG_VOLUME, exactly. // // If CdVerifyVolume encountered an error during // processing, it will return that error. If we got // STATUS_WRONG_VOLUME from the verify, and our volume // is now mounted, commute the status to STATUS_SUCCESS. // if ((Status == STATUS_WRONG_VOLUME) && (Vcb->VcbCondition == VcbMounted)) { Status = STATUS_SUCCESS; } else if ((STATUS_SUCCESS == Status) && (Vcb->VcbCondition != VcbMounted)) { // // If the verify succeeded, but our volume is not mounted, // then some other volume is on the device. // Status = STATUS_WRONG_VOLUME; } // // Do a quick unprotected check here. The routine will do // a safe check. After here we can release the resource. // Note that if the volume really went away, we will be taking // the Reparse path. // // // If the device might need to go away then call our dismount routine. // if (((Vcb->VcbCondition == VcbNotMounted) || (Vcb->VcbCondition == VcbInvalid) || (Vcb->VcbCondition == VcbDismountInProgress)) && (Vcb->VcbReference <= CDFS_RESIDUAL_REFERENCE)) { CdReleaseVcb( IrpContext, Vcb); CdAcquireCdData( IrpContext ); CdCheckForDismount( IrpContext, Vcb, FALSE ); CdReleaseCdData( IrpContext ); } else { CdReleaseVcb( IrpContext, Vcb); } // // If this is a create and the verify succeeded then complete the // request with a REPARSE status. // if ((IrpContext->MajorFunction == IRP_MJ_CREATE) && (IrpSp->FileObject->RelatedFileObject == NULL) && ((Status == STATUS_SUCCESS) || (Status == STATUS_WRONG_VOLUME))) { Irp->IoStatus.Information = IO_REMOUNT; CdCompleteRequest( IrpContext, Irp, STATUS_REPARSE ); Status = STATUS_REPARSE; Irp = NULL; IrpContext = NULL; // // If there is still an error to process then call the Io system // for a popup. // } else if ((Irp != NULL) && !NT_SUCCESS( Status )) { // // Fill in the device object if required. // if (IoIsErrorUserInduced( Status ) ) { IoSetHardErrorOrVerifyDevice( Irp, DeviceToVerify ); } CdNormalizeAndRaiseStatus( IrpContext, Status ); } // // If there is still an Irp, send it off to an Ex Worker thread. // if (IrpContext != NULL) { Status = CdFsdPostRequest( IrpContext, Irp ); } } except(CdExceptionFilter( IrpContext, GetExceptionInformation() )) { // // We had some trouble trying to perform the verify or raised // an error ourselves. So we'll abort the I/O request with // the error status that we get back from the execption code. // Status = CdProcessException( IrpContext, Irp, GetExceptionCode() ); } return Status; }
VOID CdVerifyVcb ( 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)) { CdRaiseStatus( 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 = CdPerformDevIoCtrl( IrpContext, IOCTL_CDROM_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 && CdIsRawDevice( 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 )) { CdNormalizeAndRaiseStatus( 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 ); CdRaiseStatus( 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 ); CdRaiseStatus( IrpContext, STATUS_WRONG_VOLUME ); break; case VcbInvalid: case VcbDismountInProgress : CdRaiseStatus( IrpContext, STATUS_FILE_INVALID ); break; } return; }