00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
#include "UdfProcs.h"
00022
00023
00024
00025
00026
00027 #define BugCheckFileId (UDFS_BUG_CHECK_VERFYSUP)
00028
00029
00030
00031
00032
00033 #define Dbg (UDFS_DEBUG_LEVEL_VERFYSUP)
00034
00035
#ifdef ALLOC_PRAGMA
00036
#pragma alloc_text(PAGE, UdfVerifyFcbOperation)
00037
#pragma alloc_text(PAGE, UdfVerifyVcb)
00038
#endif
00039
00040
00041
NTSTATUS
00042 UdfPerformVerify (
00043 IN
PIRP_CONTEXT IrpContext,
00044 IN
PIRP Irp,
00045 IN
PDEVICE_OBJECT DeviceToVerify
00046 )
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070 {
00071
PVCB Vcb;
00072
NTSTATUS Status = STATUS_SUCCESS;
00073
PIO_STACK_LOCATION IrpSp;
00074
00075
ASSERT_IRP_CONTEXT( IrpContext );
00076
ASSERT_IRP(
Irp );
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
if ((IrpContext->MajorFunction ==
IRP_MJ_FILE_SYSTEM_CONTROL) &&
00088 ((IrpContext->MinorFunction ==
IRP_MN_MOUNT_VOLUME) ||
00089 (IrpContext->MinorFunction ==
IRP_MN_VERIFY_VOLUME))) {
00090
00091
return UdfFsdPostRequest( IrpContext,
Irp );
00092 }
00093
00094
00095
00096
00097
00098
00099
00100
00101 IrpSp =
IoGetCurrentIrpStackLocation(
Irp );
00102
00103 Vcb = &CONTAINING_RECORD( IrpSp->
DeviceObject,
00104
VOLUME_DEVICE_OBJECT,
00105 DeviceObject )->Vcb;
00106
00107
00108
00109
00110
00111
00112
00113
try {
00114
00115
if (
FlagOn( DeviceToVerify->Flags,
DO_VERIFY_VOLUME )) {
00116
00117 BOOLEAN AllowRawMount =
FALSE;
00118
00119
00120
00121
00122
00123
00124
if ((IrpContext->MajorFunction ==
IRP_MJ_CREATE) &&
00125 (IrpSp->
FileObject->
FileName.Length == 0) &&
00126 (IrpSp->
FileObject->
RelatedFileObject ==
NULL)) {
00127
00128 AllowRawMount =
TRUE;
00129 }
00130
00131
00132
00133
00134
00135
00136
Status =
IoVerifyVolume( DeviceToVerify, AllowRawMount );
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
if ((
Status == STATUS_WRONG_VOLUME) &&
00149 (Vcb->
VcbCondition ==
VcbMounted)) {
00150
00151
Status = STATUS_SUCCESS;
00152 }
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
if (((Vcb->
VcbCondition ==
VcbNotMounted) ||
00166 (Vcb->
VcbCondition ==
VcbInvalid) ||
00167 (Vcb->
VcbCondition ==
VcbDismountInProgress)) &&
00168 (Vcb->
VcbReference <= Vcb->
VcbResidualReference)) {
00169
00170
UdfAcquireUdfData( IrpContext );
00171
UdfCheckForDismount( IrpContext, Vcb,
FALSE );
00172
UdfReleaseUdfData( IrpContext );
00173 }
00174
00175
00176
00177
00178
00179
00180
if ((IrpContext->MajorFunction ==
IRP_MJ_CREATE) &&
00181 (IrpSp->
FileObject->
RelatedFileObject ==
NULL) &&
00182 ((
Status == STATUS_SUCCESS) || (
Status == STATUS_WRONG_VOLUME))) {
00183
00184
Irp->
IoStatus.Information =
IO_REMOUNT;
00185
00186
UdfCompleteRequest( IrpContext,
Irp, STATUS_REPARSE );
00187
Status = STATUS_REPARSE;
00188
Irp =
NULL;
00189 IrpContext =
NULL;
00190
00191
00192
00193
00194
00195
00196 }
else if ((
Irp !=
NULL) && !
NT_SUCCESS(
Status )) {
00197
00198
00199
00200
00201
00202
if (
IoIsErrorUserInduced(
Status ) ) {
00203
00204
IoSetHardErrorOrVerifyDevice(
Irp, DeviceToVerify );
00205 }
00206
00207
UdfNormalizeAndRaiseStatus( IrpContext,
Status );
00208 }
00209 }
00210
00211
00212
00213
00214
00215
if (IrpContext !=
NULL) {
00216
00217
Status =
UdfFsdPostRequest( IrpContext,
Irp );
00218 }
00219
00220 } except(
UdfExceptionFilter( IrpContext, GetExceptionInformation() )) {
00221
00222
00223
00224
00225
00226
00227
00228
Status =
UdfProcessException( IrpContext,
Irp, GetExceptionCode() );
00229 }
00230
00231
return Status;
00232 }
00233
00234
00235 BOOLEAN
00236 UdfCheckForDismount (
00237 IN
PIRP_CONTEXT IrpContext,
00238 IN
PVCB Vcb,
00239 IN BOOLEAN Force
00240 )
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273 {
00274 BOOLEAN UnlockVcb =
TRUE;
00275 BOOLEAN VcbPresent =
TRUE;
00276 KIRQL SavedIrql;
00277
00278
ASSERT_IRP_CONTEXT( IrpContext );
00279
ASSERT_VCB( Vcb );
00280
00281
ASSERT_EXCLUSIVE_UDFDATA;
00282
00283
00284
00285
00286
00287
UdfAcquireVcbExclusive( IrpContext, Vcb,
FALSE );
00288
00289
00290
00291
00292
00293
UdfFspClose( Vcb );
00294
00295
UdfLockVcb( IrpContext, Vcb );
00296
00297
00298
00299
00300
00301
00302
00303
if (Vcb->VcbCondition !=
VcbDismountInProgress) {
00304
00305
if (Vcb->VcbUserReference <= Vcb->VcbResidualUserReference || Force) {
00306
00307
UdfUnlockVcb( IrpContext, Vcb );
00308 UnlockVcb =
FALSE;
00309 VcbPresent =
UdfDismountVcb( IrpContext, Vcb );
00310 }
00311
00312
00313
00314
00315
00316
00317
00318 }
else if (Vcb->VcbReference == 0) {
00319
00320
IoAcquireVpbSpinLock( &SavedIrql );
00321
00322
00323
00324
00325
00326
00327
00328
if (Vcb->Vpb->ReferenceCount == 1) {
00329
00330
IoReleaseVpbSpinLock( SavedIrql );
00331
UdfUnlockVcb( IrpContext, Vcb );
00332 UnlockVcb =
FALSE;
00333
UdfDeleteVcb( IrpContext, Vcb );
00334 VcbPresent =
FALSE;
00335
00336 }
else {
00337
00338
IoReleaseVpbSpinLock( SavedIrql );
00339 }
00340 }
00341
00342
00343
00344
00345
00346
if (UnlockVcb) {
00347
00348
UdfUnlockVcb( IrpContext, Vcb );
00349 }
00350
00351
00352
00353
00354
00355
if (VcbPresent) {
00356
00357
UdfReleaseVcb( IrpContext, Vcb );
00358 }
00359
00360
return VcbPresent;
00361 }
00362
00363
00364 BOOLEAN
00365 UdfDismountVcb (
00366 IN
PIRP_CONTEXT IrpContext,
00367 IN
PVCB Vcb
00368 )
00369
00370
00371
00372
00373
00374
00375
00376
00377
00378
00379
00380
00381
00382
00383
00384
00385
00386
00387
00388
00389
00390
00391
00392 {
00393
PVPB OldVpb;
00394
PVPB NewVpb;
00395 BOOLEAN VcbPresent =
TRUE;
00396 KIRQL SavedIrql;
00397
00398 BOOLEAN FinalReference;
00399
00400
ASSERT_EXCLUSIVE_UDFDATA;
00401
ASSERT_EXCLUSIVE_VCB( Vcb );
00402
00403
UdfLockVcb( IrpContext, Vcb );
00404
00405
00406
00407
00408
00409
ASSERT( Vcb->VcbCondition !=
VcbDismountInProgress );
00410
00411
00412
00413
00414
00415 Vcb->VcbCondition =
VcbDismountInProgress;
00416
00417
00418
00419
00420
00421
00422
if (Vcb->RootIndexFcb !=
NULL) {
00423
00424 Vcb->RootIndexFcb->FcbReference -= 1;
00425 Vcb->RootIndexFcb->FcbUserReference -= 1;
00426 }
00427
00428
if (Vcb->MetadataFcb !=
NULL) {
00429
00430 Vcb->MetadataFcb->FcbReference -= 1;
00431 Vcb->MetadataFcb->FcbUserReference -= 1;
00432 }
00433
00434
if (Vcb->VatFcb !=
NULL) {
00435
00436 Vcb->VatFcb->FcbReference -= 1;
00437 Vcb->VatFcb->FcbUserReference -= 1;
00438 }
00439
00440
if (Vcb->VolumeDasdFcb !=
NULL) {
00441
00442 Vcb->VolumeDasdFcb->FcbReference -= 1;
00443 Vcb->VolumeDasdFcb->FcbUserReference -= 1;
00444 }
00445
00446
UdfUnlockVcb( IrpContext, Vcb );
00447
00448
00449
00450
00451
00452
UdfPurgeVolume( IrpContext, Vcb,
TRUE );
00453
00454
00455
00456
00457
00458
UdfFspClose( Vcb );
00459
00460
00461
00462
00463
00464 NewVpb =
ExAllocatePoolWithTag(
NonPagedPoolMustSucceed,
sizeof(
VPB ),
TAG_VPB );
00465 RtlZeroMemory( NewVpb,
sizeof(
VPB ) );
00466
00467 OldVpb = Vcb->Vpb;
00468
00469
00470
00471
00472
00473
UdfLockVcb( IrpContext, Vcb );
00474 Vcb->VcbReference -= 1;
00475
00476
00477
00478
00479
00480
IoAcquireVpbSpinLock( &SavedIrql );
00481
00482
00483
00484
00485
00486
00487
00488
00489
00490 FinalReference = (BOOLEAN) ((Vcb->VcbReference == 0) &&
00491 (OldVpb->
ReferenceCount == 1));
00492
00493
00494
00495
00496
00497
00498
00499
00500
00501
if (OldVpb->
RealDevice->
Vpb == OldVpb) {
00502
00503
00504
00505
00506
00507
00508
00509
if (!FinalReference) {
00510
00511 NewVpb->
Type =
IO_TYPE_VPB;
00512 NewVpb->
Size =
sizeof(
VPB );
00513 NewVpb->
RealDevice = OldVpb->
RealDevice;
00514
00515 NewVpb->
RealDevice->
Vpb = NewVpb;
00516
00517 NewVpb->
Flags =
FlagOn( OldVpb->
Flags,
VPB_REMOVE_PENDING );
00518
00519 NewVpb =
NULL;
00520
IoReleaseVpbSpinLock( SavedIrql );
00521
UdfUnlockVcb( IrpContext, Vcb );
00522
00523
00524
00525
00526
00527
00528
00529 }
else {
00530
00531
00532
00533
00534
00535 OldVpb->
ReferenceCount -= 1;
00536
00537 OldVpb->
DeviceObject =
NULL;
00538
ClearFlag( Vcb->Vpb->Flags,
VPB_MOUNTED );
00539
00540
00541
00542
00543
00544 Vcb->Vpb =
NULL;
00545
00546
IoReleaseVpbSpinLock( SavedIrql );
00547
UdfUnlockVcb( IrpContext, Vcb );
00548
UdfDeleteVcb( IrpContext, Vcb );
00549 VcbPresent =
FALSE;
00550 }
00551
00552
00553
00554
00555
00556
00557 }
else if (FinalReference) {
00558
00559
00560
00561
00562
00563 OldVpb->
ReferenceCount -= 1;
00564
00565
IoReleaseVpbSpinLock( SavedIrql );
00566
UdfUnlockVcb( IrpContext, Vcb );
00567
UdfDeleteVcb( IrpContext, Vcb );
00568 VcbPresent =
FALSE;
00569
00570
00571
00572
00573
00574
00575
00576 }
else {
00577
00578 OldVpb->
DeviceObject =
NULL;
00579
ClearFlag( Vcb->Vpb->Flags,
VPB_MOUNTED );
00580
00581
IoReleaseVpbSpinLock( SavedIrql );
00582
UdfUnlockVcb( IrpContext, Vcb );
00583 }
00584
00585
00586
00587
00588
00589
if (NewVpb !=
NULL) {
00590
00591
UdfFreePool( &NewVpb );
00592 }
00593
00594
00595
00596
00597
00598
return VcbPresent;
00599 }
00600
00601
00602
00603 VOID
00604
UdfVerifyVcb (
00605 IN
PIRP_CONTEXT IrpContext,
00606 IN
PVCB Vcb
00607 )
00608
00609
00610
00611
00612
00613
00614
00615
00616
00617
00618
00619
00620
00621
00622
00623
00624
00625
00626
00627
00628
00629 {
00630
NTSTATUS Status;
00631 IO_STATUS_BLOCK Iosb;
00632 ULONG MediaChangeCount = 0;
00633
00634
PAGED_CODE();
00635
00636
00637
00638
00639
00640
00641
if ((Vcb->VcbCondition ==
VcbInvalid) ||
00642 (Vcb->VcbCondition ==
VcbDismountInProgress)) {
00643
00644
UdfRaiseStatus( IrpContext, STATUS_FILE_INVALID );
00645 }
00646
00647
00648
00649
00650
00651
00652
00653
if ((Vcb->VcbCondition !=
VcbMountInProgress) &&
00654
FlagOn( Vcb->VcbState,
VCB_STATE_REMOVABLE_MEDIA ) &&
00655 !
FlagOn( Vcb->Vpb->RealDevice->Flags,
DO_VERIFY_VOLUME )) {
00656
00657
Status =
UdfPerformDevIoCtrl( IrpContext,
00658 ( Vcb->Vpb->RealDevice->DeviceType == FILE_DEVICE_CD_ROM ?
00659 IOCTL_CDROM_CHECK_VERIFY :
00660 IOCTL_DISK_CHECK_VERIFY ),
00661 Vcb->TargetDeviceObject,
00662 &MediaChangeCount,
00663
sizeof(ULONG),
00664
FALSE,
00665
FALSE,
00666 &Iosb );
00667
00668
if (Iosb.Information !=
sizeof(ULONG)) {
00669
00670
00671
00672
00673
00674 MediaChangeCount = 0;
00675 }
00676
00677
00678
00679
00680
00681
00682
00683
00684
00685
if ((Vcb->VcbCondition ==
VcbMounted &&
00686
UdfIsRawDevice( IrpContext,
Status )) ||
00687 (
Status == STATUS_VERIFY_REQUIRED) ||
00688 (
NT_SUCCESS(
Status) &&
00689 (Vcb->MediaChangeCount != MediaChangeCount))) {
00690
00691
SetFlag( Vcb->Vpb->RealDevice->Flags,
DO_VERIFY_VOLUME );
00692
00693
00694
00695
00696
00697
00698
00699
00700
00701
00702
if ((Vcb->VcbCondition ==
VcbNotMounted) &&
00703
NT_SUCCESS(
Status)) {
00704
00705 Vcb->MediaChangeCount = MediaChangeCount;
00706 }
00707
00708
00709
00710
00711
00712 }
else if (!
NT_SUCCESS(
Status )) {
00713
00714
UdfNormalizeAndRaiseStatus( IrpContext,
Status );
00715 }
00716
00717 }
00718
00719
00720
00721
00722
00723
00724
00725
if (
FlagOn( Vcb->Vpb->RealDevice->Flags,
DO_VERIFY_VOLUME )) {
00726
00727
IoSetHardErrorOrVerifyDevice( IrpContext->Irp,
00728 Vcb->Vpb->RealDevice );
00729
00730
UdfRaiseStatus( IrpContext, STATUS_VERIFY_REQUIRED );
00731 }
00732
00733
00734
00735
00736
00737
00738
switch (Vcb->VcbCondition) {
00739
00740
case VcbNotMounted:
00741
00742
SetFlag( Vcb->Vpb->RealDevice->Flags,
DO_VERIFY_VOLUME );
00743
00744
IoSetHardErrorOrVerifyDevice( IrpContext->Irp, Vcb->Vpb->RealDevice );
00745
00746
UdfRaiseStatus( IrpContext, STATUS_WRONG_VOLUME );
00747
break;
00748
00749
case VcbInvalid:
00750
case VcbDismountInProgress :
00751
00752
UdfRaiseStatus( IrpContext, STATUS_FILE_INVALID );
00753
break;
00754 }
00755
00756
return;
00757 }
00758
00759
00760
00761 BOOLEAN
00762
UdfVerifyFcbOperation (
00763 IN
PIRP_CONTEXT IrpContext OPTIONAL,
00764 IN
PFCB Fcb
00765 )
00766
00767
00768
00769
00770
00771
00772
00773
00774
00775
00776
00777
00778
00779
00780
00781
00782
00783
00784
00785
00786
00787
00788 {
00789
NTSTATUS Status = STATUS_SUCCESS;
00790
PVCB Vcb = Fcb->Vcb;
00791
PDEVICE_OBJECT RealDevice = Vcb->
Vpb->
RealDevice;
00792
00793
PAGED_CODE();
00794
00795
00796
00797
00798
00799
00800
if ((Vcb->
VcbCondition ==
VcbInvalid) ||
00801 (Vcb->
VcbCondition ==
VcbDismountInProgress)) {
00802
00803
if (ARGUMENT_PRESENT( IrpContext )) {
00804
00805
UdfRaiseStatus( IrpContext, STATUS_FILE_INVALID );
00806 }
00807
00808
return FALSE;
00809 }
00810
00811
00812
00813
00814
00815
if (
FlagOn( RealDevice->
Flags,
DO_VERIFY_VOLUME )) {
00816
00817
if (ARGUMENT_PRESENT( IrpContext )) {
00818
00819
IoSetHardErrorOrVerifyDevice( IrpContext->Irp,
00820 RealDevice );
00821
00822
UdfRaiseStatus( IrpContext, STATUS_VERIFY_REQUIRED );
00823 }
00824
00825
return FALSE;
00826
00827
00828
00829
00830
00831 }
else if ((Vcb->
VcbCondition ==
VcbMounted) ||
00832 (Vcb->
VcbCondition ==
VcbMountInProgress)) {
00833
00834
return TRUE;
00835
00836
00837
00838
00839
00840 }
else if (!ARGUMENT_PRESENT( IrpContext )) {
00841
00842
return FALSE;
00843
00844
00845
00846
00847
00848
00849 }
else if (Vcb->
VcbCondition ==
VcbNotMounted) {
00850
00851
if (ARGUMENT_PRESENT( IrpContext )) {
00852
00853
SetFlag(RealDevice->
Flags,
DO_VERIFY_VOLUME);
00854
00855
IoSetHardErrorOrVerifyDevice( IrpContext->Irp, RealDevice );
00856
UdfRaiseStatus( IrpContext, STATUS_WRONG_VOLUME );
00857 }
00858
00859
return FALSE;
00860 }
00861
00862
return TRUE;
00863 }
00864
00865