Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1014 lines
26 KiB

  1. /*++
  2. Copyright (c) 1989-2000 Microsoft Corporation
  3. Module Name:
  4. VerfySup.c
  5. Abstract:
  6. This module implements the Udfs Verification routines.
  7. // @@BEGIN_DDKSPLIT
  8. Author:
  9. Dan Lovinger [DanLo] 18-July-1996
  10. Revision History:
  11. // @@END_DDKSPLIT
  12. --*/
  13. #include "UdfProcs.h"
  14. //
  15. // The Bug check file id for this module
  16. //
  17. #define BugCheckFileId (UDFS_BUG_CHECK_VERFYSUP)
  18. //
  19. // The local debug trace level
  20. //
  21. #define Dbg (UDFS_DEBUG_LEVEL_VERFYSUP)
  22. #ifdef ALLOC_PRAGMA
  23. #pragma alloc_text(PAGE, UdfVerifyFcbOperation)
  24. #pragma alloc_text(PAGE, UdfVerifyVcb)
  25. #endif
  26. NTSTATUS
  27. UdfPerformVerify (
  28. IN PIRP_CONTEXT IrpContext,
  29. IN PIRP Irp,
  30. IN PDEVICE_OBJECT DeviceToVerify
  31. )
  32. /*++
  33. Routine Description:
  34. This routines performs an IoVerifyVolume operation and takes the
  35. appropriate action. If the verify is successful then we send the originating
  36. Irp off to an Ex Worker Thread. This routine is called from the exception handler.
  37. No file system resources are held when this routine is called.
  38. Arguments:
  39. Irp - The irp to send off after all is well and done.
  40. Device - The real device needing verification.
  41. Return Value:
  42. None.
  43. --*/
  44. {
  45. PVCB Vcb;
  46. NTSTATUS Status = STATUS_SUCCESS;
  47. PIO_STACK_LOCATION IrpSp;
  48. BOOLEAN AllowRawMount = FALSE;
  49. ASSERT_IRP_CONTEXT( IrpContext );
  50. ASSERT_IRP( Irp );
  51. //
  52. // Check if this Irp has a status of Verify required and if it does
  53. // then call the I/O system to do a verify.
  54. //
  55. // Skip the IoVerifyVolume if this is a mount or verify request
  56. // itself. Trying a recursive mount will cause a deadlock with
  57. // the DeviceObject->DeviceLock.
  58. //
  59. if ((IrpContext->MajorFunction == IRP_MJ_FILE_SYSTEM_CONTROL) &&
  60. ((IrpContext->MinorFunction == IRP_MN_MOUNT_VOLUME) ||
  61. (IrpContext->MinorFunction == IRP_MN_VERIFY_VOLUME))) {
  62. return UdfFsdPostRequest( IrpContext, Irp );
  63. }
  64. //
  65. // Extract a pointer to the Vcb from the VolumeDeviceObject.
  66. // Note that since we have specifically excluded mount,
  67. // requests, we know that IrpSp->DeviceObject is indeed a
  68. // volume device object.
  69. //
  70. IrpSp = IoGetCurrentIrpStackLocation( Irp );
  71. Vcb = &CONTAINING_RECORD( IrpSp->DeviceObject,
  72. VOLUME_DEVICE_OBJECT,
  73. DeviceObject )->Vcb;
  74. //
  75. // Check if the volume still thinks it needs to be verified,
  76. // if it doesn't then we can skip doing a verify because someone
  77. // else beat us to it. If this is a 'forced' verify then we
  78. // always go through the motions for mount sync. purposes.
  79. //
  80. try {
  81. //
  82. // We will allow Raw to mount this volume if we were doing a
  83. // an absolute DASD open.
  84. //
  85. if ((IrpContext->MajorFunction == IRP_MJ_CREATE) &&
  86. (IrpSp->FileObject->FileName.Length == 0) &&
  87. (IrpSp->FileObject->RelatedFileObject == NULL)) {
  88. AllowRawMount = TRUE;
  89. }
  90. //
  91. // Send down the verify FSCTL. Note that this is sent to the
  92. // currently mounted volume, which may not be this one.
  93. //
  94. Status = IoVerifyVolume( DeviceToVerify, AllowRawMount );
  95. //
  96. // Acquire the Vcb so we're working with a stable VcbCondition.
  97. //
  98. UdfAcquireVcbShared( IrpContext, Vcb, FALSE);
  99. //
  100. // If the verify operation completed it will return
  101. // either STATUS_SUCCESS or STATUS_WRONG_VOLUME, exactly.
  102. //
  103. // If UdfVerifyVolume encountered an error during
  104. // processing, it will return that error. If we got
  105. // STATUS_WRONG_VOLUME from the verify, and our volume
  106. // is now mounted, commute the status to STATUS_SUCCESS.
  107. //
  108. if ((Status == STATUS_WRONG_VOLUME) &&
  109. (Vcb->VcbCondition == VcbMounted)) {
  110. Status = STATUS_SUCCESS;
  111. }
  112. else if ((STATUS_SUCCESS == Status) && (Vcb->VcbCondition != VcbMounted)) {
  113. //
  114. // If the verify succeeded, but our volume is not mounted,
  115. // then some other volume is on the device.
  116. //
  117. Status = STATUS_WRONG_VOLUME;
  118. }
  119. //
  120. // Do a quick unprotected check here. The routine will do
  121. // a safe check. After here we can release the resource.
  122. // Note that if the volume really went away, we will be taking
  123. // the Reparse path.
  124. //
  125. //
  126. // If the device might need to go away then call our dismount routine.
  127. //
  128. if (((Vcb->VcbCondition == VcbNotMounted) ||
  129. (Vcb->VcbCondition == VcbInvalid) ||
  130. (Vcb->VcbCondition == VcbDismountInProgress)) &&
  131. (Vcb->VcbReference <= Vcb->VcbResidualReference)) {
  132. UdfReleaseVcb( IrpContext, Vcb);
  133. UdfAcquireUdfData( IrpContext );
  134. UdfCheckForDismount( IrpContext, Vcb, FALSE );
  135. UdfReleaseUdfData( IrpContext );
  136. }
  137. else {
  138. UdfReleaseVcb( IrpContext, Vcb);
  139. }
  140. //
  141. // If this is a create and the verify succeeded then complete the
  142. // request with a REPARSE status.
  143. //
  144. if ((IrpContext->MajorFunction == IRP_MJ_CREATE) &&
  145. (IrpSp->FileObject->RelatedFileObject == NULL) &&
  146. ((Status == STATUS_SUCCESS) || (Status == STATUS_WRONG_VOLUME))) {
  147. Irp->IoStatus.Information = IO_REMOUNT;
  148. UdfCompleteRequest( IrpContext, Irp, STATUS_REPARSE );
  149. Status = STATUS_REPARSE;
  150. Irp = NULL;
  151. IrpContext = NULL;
  152. DebugTrace(( 0, Dbg, "UdfPerformVerify, Reparsing create irp.\n"));
  153. //
  154. // If there is still an error to process then call the Io system
  155. // for a popup.
  156. //
  157. } else if ((Irp != NULL) && !NT_SUCCESS( Status )) {
  158. DebugTrace(( 0, Dbg, "UdfPerformVerify, Raising error %x (Op %x)\n", Status,
  159. IrpContext->MajorFunction));
  160. //
  161. // Fill in the device object if required.
  162. //
  163. if (IoIsErrorUserInduced( Status ) ) {
  164. IoSetHardErrorOrVerifyDevice( Irp, DeviceToVerify );
  165. }
  166. //
  167. // We should not be receiving this status from verify
  168. // volume - we'll end up recursing out of stack.
  169. //
  170. ASSERT( STATUS_VERIFY_REQUIRED != Status);
  171. UdfNormalizeAndRaiseStatus( IrpContext, Status );
  172. }
  173. //
  174. // If there is still an Irp, send it off to an Ex Worker thread.
  175. //
  176. if (IrpContext != NULL) {
  177. DebugTrace(( 0, Dbg, "UdfPerformVerify, Posting IRP (Op %x)\n", IrpContext->MajorFunction));
  178. Status = UdfFsdPostRequest( IrpContext, Irp );
  179. }
  180. } except(UdfExceptionFilter( IrpContext, GetExceptionInformation() )) {
  181. //
  182. // We had some trouble trying to perform the verify or raised
  183. // an error ourselves. So we'll abort the I/O request with
  184. // the error status that we get back from the execption code.
  185. //
  186. Status = UdfProcessException( IrpContext, Irp, GetExceptionCode() );
  187. }
  188. return Status;
  189. }
  190. BOOLEAN
  191. UdfCheckForDismount (
  192. IN PIRP_CONTEXT IrpContext,
  193. IN PVCB Vcb,
  194. IN BOOLEAN Force
  195. )
  196. /*++
  197. Routine Description:
  198. This routine is called to check if a volume is ready for dismount. This
  199. occurs when only file system references are left on the volume.
  200. If the dismount is not currently underway and the user reference count
  201. has gone to zero then we can begin the dismount.
  202. If the dismount is in progress and there are no references left on the
  203. volume (we check the Vpb for outstanding references as well to catch
  204. any create calls dispatched to the file system) then we can delete
  205. the Vcb.
  206. Arguments:
  207. Vcb - Vcb for the volume to try to dismount.
  208. Force - Whether we will force this volume to be dismounted.
  209. Return Value:
  210. BOOLEAN - True if the Vcb was not gone by the time this function finished,
  211. False if it was deleted.
  212. This is only a trustworthy indication to the caller if it had the vcb
  213. exclusive itself.
  214. --*/
  215. {
  216. BOOLEAN UnlockVcb = TRUE;
  217. BOOLEAN VcbPresent = TRUE;
  218. KIRQL SavedIrql;
  219. ASSERT_IRP_CONTEXT( IrpContext );
  220. ASSERT_VCB( Vcb );
  221. ASSERT_EXCLUSIVE_UDFDATA;
  222. //
  223. // Acquire and lock this Vcb to check the dismount state.
  224. //
  225. UdfAcquireVcbExclusive( IrpContext, Vcb, FALSE );
  226. //
  227. // Lets get rid of any pending closes for this volume.
  228. //
  229. UdfFspClose( Vcb );
  230. UdfLockVcb( IrpContext, Vcb );
  231. //
  232. // If the dismount is not already underway then check if the
  233. // user reference count has gone to zero or we are being forced
  234. // to disconnect. If so start the teardown on the Vcb.
  235. //
  236. if (Vcb->VcbCondition != VcbDismountInProgress) {
  237. if (Vcb->VcbUserReference <= Vcb->VcbResidualUserReference || Force) {
  238. UdfUnlockVcb( IrpContext, Vcb );
  239. UnlockVcb = FALSE;
  240. VcbPresent = UdfDismountVcb( IrpContext, Vcb );
  241. }
  242. //
  243. // If the teardown is underway and there are absolutely no references
  244. // remaining then delete the Vcb. References here include the
  245. // references in the Vcb and Vpb.
  246. //
  247. } else if (Vcb->VcbReference == 0) {
  248. IoAcquireVpbSpinLock( &SavedIrql );
  249. //
  250. // If there are no file objects and no reference counts in the
  251. // Vpb we can delete the Vcb. Don't forget that we have the
  252. // last reference in the Vpb.
  253. //
  254. if (Vcb->Vpb->ReferenceCount == 1) {
  255. IoReleaseVpbSpinLock( SavedIrql );
  256. UdfUnlockVcb( IrpContext, Vcb );
  257. UnlockVcb = FALSE;
  258. UdfDeleteVcb( IrpContext, Vcb );
  259. VcbPresent = FALSE;
  260. } else {
  261. IoReleaseVpbSpinLock( SavedIrql );
  262. }
  263. }
  264. //
  265. // Unlock the Vcb if still held.
  266. //
  267. if (UnlockVcb) {
  268. UdfUnlockVcb( IrpContext, Vcb );
  269. }
  270. //
  271. // Release any resources still acquired.
  272. //
  273. if (VcbPresent) {
  274. UdfReleaseVcb( IrpContext, Vcb );
  275. }
  276. return VcbPresent;
  277. }
  278. BOOLEAN
  279. UdfDismountVcb (
  280. IN PIRP_CONTEXT IrpContext,
  281. IN PVCB Vcb
  282. )
  283. /*++
  284. Routine Description:
  285. This routine is called when all of the user references to a volume are
  286. gone. We will initiate all of the teardown any system resources.
  287. If all of the references to this volume are gone at the end of this routine
  288. then we will complete the teardown of this Vcb and mark the current Vpb
  289. as not mounted. Otherwise we will allocated a new Vpb for this device
  290. and keep the current Vpb attached to the Vcb.
  291. Arguments:
  292. Vcb - Vcb for the volume to dismount.
  293. Return Value:
  294. BOOLEAN - TRUE if we didn't delete the Vcb, FALSE otherwise.
  295. --*/
  296. {
  297. PVPB OldVpb;
  298. BOOLEAN VcbPresent = TRUE;
  299. KIRQL SavedIrql;
  300. BOOLEAN FinalReference;
  301. ASSERT_EXCLUSIVE_UDFDATA;
  302. ASSERT_EXCLUSIVE_VCB( Vcb );
  303. UdfLockVcb( IrpContext, Vcb );
  304. //
  305. // We should only take this path once.
  306. //
  307. ASSERT( Vcb->VcbCondition != VcbDismountInProgress );
  308. //
  309. // Mark the Vcb as DismountInProgress.
  310. //
  311. UdfSetVcbCondition( Vcb, VcbDismountInProgress);
  312. //
  313. // Remove our reference to the internal Fcb's. The Fcb's will then
  314. // be removed in the purge path below.
  315. //
  316. if (Vcb->RootIndexFcb != NULL) {
  317. Vcb->RootIndexFcb->FcbReference -= 1;
  318. Vcb->RootIndexFcb->FcbUserReference -= 1;
  319. }
  320. if (Vcb->MetadataFcb != NULL) {
  321. Vcb->MetadataFcb->FcbReference -= 1;
  322. Vcb->MetadataFcb->FcbUserReference -= 1;
  323. }
  324. if (Vcb->VatFcb != NULL) {
  325. Vcb->VatFcb->FcbReference -= 1;
  326. Vcb->VatFcb->FcbUserReference -= 1;
  327. }
  328. if (Vcb->VolumeDasdFcb != NULL) {
  329. Vcb->VolumeDasdFcb->FcbReference -= 1;
  330. Vcb->VolumeDasdFcb->FcbUserReference -= 1;
  331. }
  332. UdfUnlockVcb( IrpContext, Vcb );
  333. //
  334. // Purge the volume.
  335. //
  336. UdfPurgeVolume( IrpContext, Vcb, TRUE );
  337. //
  338. // Empty the delayed and async close queues.
  339. //
  340. UdfFspClose( Vcb );
  341. OldVpb = Vcb->Vpb;
  342. //
  343. // Remove the mount volume reference.
  344. //
  345. UdfLockVcb( IrpContext, Vcb );
  346. Vcb->VcbReference -= 1;
  347. //
  348. // Acquire the Vpb spinlock to check for Vpb references.
  349. //
  350. IoAcquireVpbSpinLock( &SavedIrql );
  351. //
  352. // Remember if this is the last reference on this Vcb. We incremented
  353. // the count on the Vpb earlier so we get one last crack it. If our
  354. // reference has gone to zero but the vpb reference count is greater
  355. // than zero then the Io system will be responsible for deleting the
  356. // Vpb.
  357. //
  358. FinalReference = (BOOLEAN) ((Vcb->VcbReference == 0) &&
  359. (OldVpb->ReferenceCount == 1));
  360. //
  361. // There is a reference count in the Vpb and in the Vcb. We have
  362. // incremented the reference count in the Vpb to make sure that
  363. // we have last crack at it. If this is a failed mount then we
  364. // want to return the Vpb to the IO system to use for the next
  365. // mount request.
  366. //
  367. if (OldVpb->RealDevice->Vpb == OldVpb) {
  368. //
  369. // If not the final reference then swap out the Vpb. We must
  370. // preserve the REMOVE_PENDING flag so that the device is
  371. // not remounted in the middle of a PnP remove operation.
  372. //
  373. if (!FinalReference) {
  374. ASSERT( Vcb->SwapVpb != NULL );
  375. Vcb->SwapVpb->Type = IO_TYPE_VPB;
  376. Vcb->SwapVpb->Size = sizeof( VPB );
  377. Vcb->SwapVpb->RealDevice = OldVpb->RealDevice;
  378. Vcb->SwapVpb->RealDevice->Vpb = Vcb->SwapVpb;
  379. Vcb->SwapVpb->Flags = FlagOn( OldVpb->Flags, VPB_REMOVE_PENDING );
  380. IoReleaseVpbSpinLock( SavedIrql );
  381. //
  382. // Indicate we used up the swap.
  383. //
  384. Vcb->SwapVpb = NULL;
  385. UdfUnlockVcb( IrpContext, Vcb );
  386. //
  387. // We want to leave the Vpb for the IO system. Mark it
  388. // as being not mounted. Go ahead and delete the Vcb as
  389. // well.
  390. //
  391. } else {
  392. //
  393. // Make sure to remove the last reference on the Vpb.
  394. //
  395. OldVpb->ReferenceCount -= 1;
  396. OldVpb->DeviceObject = NULL;
  397. ClearFlag( Vcb->Vpb->Flags, VPB_MOUNTED );
  398. ClearFlag( Vcb->Vpb->Flags, VPB_LOCKED );
  399. //
  400. // Clear the Vpb flag so we know not to delete it.
  401. //
  402. Vcb->Vpb = NULL;
  403. IoReleaseVpbSpinLock( SavedIrql );
  404. UdfUnlockVcb( IrpContext, Vcb );
  405. UdfDeleteVcb( IrpContext, Vcb );
  406. VcbPresent = FALSE;
  407. }
  408. //
  409. // Someone has already swapped in a new Vpb. If this is the final reference
  410. // then the file system is responsible for deleting the Vpb.
  411. //
  412. } else if (FinalReference) {
  413. //
  414. // Make sure to remove the last reference on the Vpb.
  415. //
  416. OldVpb->ReferenceCount -= 1;
  417. IoReleaseVpbSpinLock( SavedIrql );
  418. UdfUnlockVcb( IrpContext, Vcb );
  419. UdfDeleteVcb( IrpContext, Vcb );
  420. VcbPresent = FALSE;
  421. //
  422. // The current Vpb is no longer the Vpb for the device (the IO system
  423. // has already allocated a new one). We leave our reference in the
  424. // Vpb and will be responsible for deleting it at a later time.
  425. //
  426. } else {
  427. IoReleaseVpbSpinLock( SavedIrql );
  428. UdfUnlockVcb( IrpContext, Vcb );
  429. }
  430. //
  431. // Let our caller know whether the Vcb is still present.
  432. //
  433. return VcbPresent;
  434. }
  435. BOOLEAN
  436. UdfMarkDevForVerifyIfVcbMounted(
  437. IN PVCB Vcb
  438. )
  439. /*++
  440. Routine Description:
  441. This routine checks to see if the specified Vcb is currently mounted on
  442. the device or not. If it is, it sets the verify flag on the device, if
  443. not then the state is noted in the Vcb.
  444. Arguments:
  445. Vcb - This is the volume to check.
  446. Return Value:
  447. TRUE if the device has been marked for verify here, FALSE otherwise.
  448. --*/
  449. {
  450. BOOLEAN Marked = FALSE;
  451. KIRQL SavedIrql;
  452. IoAcquireVpbSpinLock( &SavedIrql );
  453. if (Vcb->Vpb->RealDevice->Vpb == Vcb->Vpb) {
  454. UdfMarkRealDevForVerify( Vcb->Vpb->RealDevice);
  455. Marked = TRUE;
  456. }
  457. else {
  458. //
  459. // Flag this to avoid the VPB spinlock in future passes.
  460. //
  461. SetFlag( Vcb->VcbState, VCB_STATE_VPB_NOT_ON_DEVICE);
  462. }
  463. IoReleaseVpbSpinLock( SavedIrql );
  464. return Marked;
  465. }
  466. VOID
  467. UdfVerifyVcb (
  468. IN PIRP_CONTEXT IrpContext,
  469. IN PVCB Vcb
  470. )
  471. /*++
  472. Routine Description:
  473. This routine checks that the current Vcb is valid and currently mounted
  474. on the device. It will raise on an error condition.
  475. We check whether the volume needs verification and the current state
  476. of the Vcb.
  477. Arguments:
  478. Vcb - This is the volume to verify.
  479. Return Value:
  480. None
  481. --*/
  482. {
  483. NTSTATUS Status = STATUS_SUCCESS;
  484. IO_STATUS_BLOCK Iosb;
  485. ULONG MediaChangeCount = 0;
  486. BOOLEAN ForceVerify = FALSE;
  487. BOOLEAN DevMarkedForVerify;
  488. KIRQL SavedIrql;
  489. PAGED_CODE();
  490. DebugTrace((0, Dbg, "UdfVerifyVcb %x (condition %d)\n", IrpContext->MajorFunction,
  491. Vcb->VcbCondition));
  492. //
  493. // Fail immediately if the volume is in the progress of being dismounted
  494. // or has been marked invalid.
  495. //
  496. if ((Vcb->VcbCondition == VcbInvalid) ||
  497. ((Vcb->VcbCondition == VcbDismountInProgress) &&
  498. (IrpContext->MajorFunction != IRP_MJ_CREATE))) {
  499. UdfRaiseStatus( IrpContext, STATUS_FILE_INVALID );
  500. }
  501. if (FlagOn( Vcb->VcbState, VCB_STATE_REMOVABLE_MEDIA )) {
  502. //
  503. // Capture the real device verify state.
  504. //
  505. DevMarkedForVerify = UdfRealDevNeedsVerify( Vcb->Vpb->RealDevice);
  506. //
  507. // If the verify volume flag in the device object is not set then we
  508. // want to ping the device to see if it needs to be verified.
  509. //
  510. if (Vcb->VcbCondition != VcbMountInProgress) {
  511. Status = UdfPerformDevIoCtrl( IrpContext,
  512. ( Vcb->Vpb->RealDevice->DeviceType == FILE_DEVICE_CD_ROM ?
  513. IOCTL_CDROM_CHECK_VERIFY :
  514. IOCTL_DISK_CHECK_VERIFY ),
  515. Vcb->TargetDeviceObject,
  516. NULL,
  517. 0,
  518. &MediaChangeCount,
  519. sizeof(ULONG),
  520. FALSE,
  521. FALSE,
  522. &Iosb );
  523. if (Iosb.Information != sizeof(ULONG)) {
  524. //
  525. // Be safe about the count in case the driver didn't fill it in
  526. //
  527. MediaChangeCount = 0;
  528. }
  529. //
  530. // There are four cases when we want to do a verify. These are the
  531. // first three.
  532. //
  533. // 1. We are mounted, and the device has become empty
  534. // 2. The device has returned verify required (=> DO_VERIFY_VOL flag is
  535. // set, but could be due to hardware condition)
  536. // 3. Media change count doesn't match the one in the Vcb
  537. //
  538. if (((Vcb->VcbCondition == VcbMounted) &&
  539. UdfIsRawDevice( IrpContext, Status ))
  540. ||
  541. (Status == STATUS_VERIFY_REQUIRED)
  542. ||
  543. (NT_SUCCESS(Status) &&
  544. (Vcb->MediaChangeCount != MediaChangeCount))) {
  545. //
  546. // If we are currently the volume on the device then it is our
  547. // responsibility to set the verify flag. If we're not on the device,
  548. // then we shouldn't touch the flag.
  549. //
  550. if (!FlagOn( Vcb->VcbState, VCB_STATE_VPB_NOT_ON_DEVICE) &&
  551. !DevMarkedForVerify) {
  552. DevMarkedForVerify = UdfMarkDevForVerifyIfVcbMounted( Vcb);
  553. }
  554. ForceVerify = TRUE;
  555. DebugTrace((0, Dbg, "Force verify due to dev state. CV %x Vcb->Mc %d Device->Mc %d\n",
  556. Status, Vcb->MediaChangeCount, MediaChangeCount));
  557. //
  558. // Note that we no longer update the media change count here. We
  559. // do so only when we've actually completed a verify at a
  560. // particular change count value.
  561. //
  562. }
  563. }
  564. //
  565. // This is the 4th verify case.
  566. //
  567. // We ALWAYS force CREATE requests on unmounted volumes through the
  568. // verify path. These requests could have been in limbo between
  569. // IoCheckMountedVpb and us when a verify/mount took place and caused
  570. // a completely different fs/volume to be mounted. In this case the
  571. // checks above may not have caught the condition, since we may already
  572. // have verified (wrong volume) and decided that we have nothing to do.
  573. // We want the requests to be re routed to the currently mounted volume,
  574. // since they were directed at the 'drive', not our volume.
  575. //
  576. if (NT_SUCCESS( Status) && !ForceVerify &&
  577. (IrpContext->MajorFunction == IRP_MJ_CREATE)) {
  578. PIO_STACK_LOCATION IrpSp = IoGetCurrentIrpStackLocation( IrpContext->Irp);
  579. ForceVerify = (IrpSp->FileObject->RelatedFileObject == NULL) &&
  580. ((Vcb->VcbCondition == VcbDismountInProgress) ||
  581. (Vcb->VcbCondition == VcbNotMounted));
  582. //
  583. // Note that we don't touch the device verify flag here. It required
  584. // it would have been caught and set by the first set of checks.
  585. //
  586. if (ForceVerify) {
  587. DebugTrace((0, Dbg, "Forcing verify on Create request\n"));
  588. }
  589. }
  590. //
  591. // Raise any verify / error if neccessary.
  592. //
  593. if (ForceVerify || !NT_SUCCESS( Status)) {
  594. DebugTrace((0, Dbg, "Raising verify / status %x\n", Status));
  595. IoSetHardErrorOrVerifyDevice( IrpContext->Irp,
  596. Vcb->Vpb->RealDevice );
  597. UdfRaiseStatus( IrpContext, ForceVerify ? STATUS_VERIFY_REQUIRED : Status);
  598. }
  599. }
  600. //
  601. // Based on the condition of the Vcb we'll either return to our
  602. // caller or raise an error condition
  603. //
  604. switch (Vcb->VcbCondition) {
  605. case VcbNotMounted:
  606. DebugTrace(( 0, Dbg, "Raising WRONG VOLUME\n"));
  607. IoSetHardErrorOrVerifyDevice( IrpContext->Irp, Vcb->Vpb->RealDevice );
  608. UdfRaiseStatus( IrpContext, STATUS_WRONG_VOLUME );
  609. break;
  610. case VcbInvalid:
  611. case VcbDismountInProgress :
  612. UdfRaiseStatus( IrpContext, STATUS_FILE_INVALID );
  613. break;
  614. }
  615. }
  616. BOOLEAN
  617. UdfVerifyFcbOperation (
  618. IN PIRP_CONTEXT IrpContext OPTIONAL,
  619. IN PFCB Fcb
  620. )
  621. /*++
  622. Routine Description:
  623. This routine is called to verify that the state of the Fcb is valid
  624. to allow the current operation to continue. We use the state of the
  625. Vcb, target device and type of operation to determine this.
  626. Arguments:
  627. IrpContext - IrpContext for the request. If not present then we
  628. were called from the fast IO path.
  629. Fcb - Fcb to perform the request on.
  630. Return Value:
  631. BOOLEAN - TRUE if the request can continue, FALSE otherwise.
  632. --*/
  633. {
  634. NTSTATUS Status = STATUS_SUCCESS;
  635. PVCB Vcb = Fcb->Vcb;
  636. PDEVICE_OBJECT RealDevice = Vcb->Vpb->RealDevice;
  637. PIRP Irp;
  638. PAGED_CODE();
  639. //
  640. // Check that the fileobject has not been cleaned up.
  641. //
  642. if ( ARGUMENT_PRESENT( IrpContext )) {
  643. PFILE_OBJECT FileObject;
  644. Irp = IrpContext->Irp;
  645. FileObject = IoGetCurrentIrpStackLocation( Irp)->FileObject;
  646. if ( FileObject && FlagOn( FileObject->Flags, FO_CLEANUP_COMPLETE)) {
  647. PIO_STACK_LOCATION IrpSp = IoGetCurrentIrpStackLocation( Irp );
  648. //
  649. // Following FAT, we allow certain operations even on cleaned up
  650. // file objects. Everything else, we fail.
  651. //
  652. if ( (FlagOn(Irp->Flags, IRP_PAGING_IO)) ||
  653. (IrpSp->MajorFunction == IRP_MJ_CLOSE ) ||
  654. (IrpSp->MajorFunction == IRP_MJ_QUERY_INFORMATION) ||
  655. ( (IrpSp->MajorFunction == IRP_MJ_READ) &&
  656. FlagOn(IrpSp->MinorFunction, IRP_MN_COMPLETE) ) ) {
  657. NOTHING;
  658. } else {
  659. UdfRaiseStatus( IrpContext, STATUS_FILE_CLOSED );
  660. }
  661. }
  662. }
  663. //
  664. // Fail immediately if the volume is in the progress of being dismounted
  665. // or has been marked invalid.
  666. //
  667. if ((Vcb->VcbCondition == VcbInvalid) ||
  668. (Vcb->VcbCondition == VcbDismountInProgress)) {
  669. if (ARGUMENT_PRESENT( IrpContext )) {
  670. UdfRaiseStatus( IrpContext, STATUS_FILE_INVALID );
  671. }
  672. return FALSE;
  673. }
  674. //
  675. // Always fail if the volume needs to be verified.
  676. //
  677. if (UdfRealDevNeedsVerify( RealDevice)) {
  678. if (ARGUMENT_PRESENT( IrpContext )) {
  679. IoSetHardErrorOrVerifyDevice( IrpContext->Irp,
  680. RealDevice );
  681. UdfRaiseStatus( IrpContext, STATUS_VERIFY_REQUIRED );
  682. }
  683. return FALSE;
  684. //
  685. // All operations are allowed on mounted volumes.
  686. //
  687. } else if ((Vcb->VcbCondition == VcbMounted) ||
  688. (Vcb->VcbCondition == VcbMountInProgress)) {
  689. return TRUE;
  690. //
  691. // Fail all requests for fast Io on other Vcb conditions.
  692. //
  693. } else if (!ARGUMENT_PRESENT( IrpContext )) {
  694. return FALSE;
  695. //
  696. // The remaining case is VcbNotMounted - raise WRONG_VOLUME.
  697. //
  698. } else if (Vcb->VcbCondition == VcbNotMounted) {
  699. if (ARGUMENT_PRESENT( IrpContext )) {
  700. IoSetHardErrorOrVerifyDevice( IrpContext->Irp, RealDevice );
  701. UdfRaiseStatus( IrpContext, STATUS_WRONG_VOLUME );
  702. }
  703. return FALSE;
  704. }
  705. return TRUE;
  706. }