Leaked source code of windows server 2003
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.

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