00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
#include "UdfProcs.h"
00051
00052
00053
00054
00055
00056 #define BugCheckFileId (UDFS_BUG_CHECK_CLOSE)
00057
00058
00059
00060
00061
00062 #define Dbg (UDFS_DEBUG_LEVEL_CLOSE)
00063
00064
00065
00066
00067
00068 BOOLEAN
00069
UdfCommonClosePrivate (
00070 IN
PIRP_CONTEXT IrpContext,
00071 IN
PVCB Vcb,
00072 IN
PFCB Fcb,
00073 IN ULONG UserReference,
00074 IN BOOLEAN FromFsd
00075 );
00076
00077
VOID
00078
UdfQueueClose (
00079 IN
PIRP_CONTEXT IrpContext,
00080 IN
PFCB Fcb,
00081 IN ULONG UserReference,
00082 IN BOOLEAN DelayedClose
00083 );
00084
00085
PIRP_CONTEXT
00086
UdfRemoveClose (
00087 IN
PVCB Vcb OPTIONAL
00088 );
00089
00090
#ifdef ALLOC_PRAGMA
00091
#pragma alloc_text(PAGE, UdfCommonClose)
00092
#pragma alloc_text(PAGE, UdfCommonClosePrivate)
00093
#pragma alloc_text(PAGE, UdfQueueClose)
00094
#pragma alloc_text(PAGE, UdfRemoveClose)
00095
#endif
00096
00097
00098
VOID
00099 UdfFspClose (
00100 IN
PVCB Vcb OPTIONAL
00101 )
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122 {
00123
PIRP_CONTEXT IrpContext;
00124
IRP_CONTEXT StackIrpContext;
00125
00126
THREAD_CONTEXT ThreadContext;
00127
00128
PFCB Fcb;
00129 ULONG UserReference;
00130
00131 ULONG VcbHoldCount = 0;
00132
PVCB CurrentVcb =
NULL;
00133
00134 BOOLEAN ReleaseUdfData =
FALSE;
00135
00136
PAGED_CODE();
00137
00138
00139
00140
00141
00142
ASSERT_OPTIONAL_VCB( Vcb );
00143
00144
FsRtlEnterFileSystem();
00145
00146
00147
00148
00149
00150
while (IrpContext =
UdfRemoveClose( Vcb )) {
00151
00152
00153
00154
00155
00156
00157
if (
SafeNodeType( IrpContext ) !=
UDFS_NTC_IRP_CONTEXT ) {
00158
00159
00160
00161
00162
00163 Fcb = ((
PIRP_CONTEXT_LITE) IrpContext)->Fcb;
00164 UserReference = ((
PIRP_CONTEXT_LITE) IrpContext)->UserReference;
00165
00166
00167
00168
00169
00170
00171
UdfInitializeStackIrpContext( &StackIrpContext,
00172 (
PIRP_CONTEXT_LITE) IrpContext );
00173
00174
00175
00176
00177
00178
UdfFreeIrpContextLite( (
PIRP_CONTEXT_LITE) IrpContext );
00179
00180
00181
00182
00183
00184 IrpContext = &StackIrpContext;
00185
00186
00187
00188
00189
00190 }
else {
00191
00192
00193
00194
00195
00196 Fcb = (
PFCB) IrpContext->
Irp;
00197 IrpContext->
Irp =
NULL;
00198
00199 UserReference = (ULONG) IrpContext->
ExceptionStatus;
00200 IrpContext->
ExceptionStatus = STATUS_SUCCESS;
00201 }
00202
00203
00204
00205
00206
00207
00208
SetFlag( IrpContext->
Flags,
IRP_CONTEXT_FSP_FLAGS );
00209
00210
00211
00212
00213
00214
if (ARGUMENT_PRESENT( Vcb )) {
00215
00216
ClearFlag( IrpContext->
Flags,
00217
IRP_CONTEXT_FLAG_TOP_LEVEL |
IRP_CONTEXT_FLAG_TOP_LEVEL_UDFS );
00218 }
00219
00220
UdfSetThreadContext( IrpContext, &
ThreadContext );
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235 ReleaseUdfData = !ARGUMENT_PRESENT( Vcb ) &&
00236 (Fcb->
Vcb->
VcbCondition !=
VcbMounted) &&
00237 (Fcb->
Vcb->
VcbCondition !=
VcbMountInProgress) &&
00238 (Fcb->
Vcb->
VcbCleanup == 0);
00239
00240
if (ReleaseUdfData ||
00241 (VcbHoldCount >
UdfData.
MinDelayedCloseCount) ||
00242 (Fcb->
Vcb != CurrentVcb)) {
00243
00244
if (CurrentVcb !=
NULL) {
00245
00246
UdfReleaseVcb( IrpContext, CurrentVcb );
00247 }
00248
00249
if (ReleaseUdfData) {
00250
00251
UdfAcquireUdfData( IrpContext );
00252 }
00253
00254 CurrentVcb = Fcb->
Vcb;
00255
UdfAcquireVcbShared( IrpContext, CurrentVcb,
FALSE );
00256
00257 VcbHoldCount = 0;
00258
00259 }
else {
00260
00261 VcbHoldCount += 1;
00262 }
00263
00264
DebugTrace(( +1,
Dbg,
00265
"UdfFspClose, Fcb %08x %4s Vcb %d/%d Fcb %d/%d\n",
00266 Fcb,
00267 ( UserReference?
"USER" :
"SYS" ),
00268 CurrentVcb->
VcbReference,
00269 CurrentVcb->
VcbUserReference,
00270 Fcb->
FcbReference,
00271 Fcb->
FcbUserReference ));
00272
00273
00274
00275
00276
00277
UdfCommonClosePrivate( IrpContext, CurrentVcb, Fcb, UserReference,
FALSE );
00278
00279
00280
00281
00282
00283
00284
if (ReleaseUdfData) {
00285
00286
UdfReleaseVcb( IrpContext, CurrentVcb );
00287
UdfCheckForDismount( IrpContext, CurrentVcb,
FALSE );
00288
00289 CurrentVcb =
NULL;
00290
00291
UdfReleaseUdfData( IrpContext );
00292 ReleaseUdfData =
FALSE;
00293 }
00294
00295
00296
00297
00298
00299
UdfCompleteRequest( IrpContext,
NULL, STATUS_SUCCESS );
00300
00301
DebugTrace(( -1,
Dbg,
"UdfFspClose -> VOID\n" ));
00302 }
00303
00304
00305
00306
00307
00308
if (CurrentVcb !=
NULL) {
00309
00310
UdfReleaseVcb( IrpContext, CurrentVcb );
00311 }
00312
00313
FsRtlExitFileSystem();
00314
return;
00315 }
00316
00317
00318
NTSTATUS
00319 UdfCommonClose (
00320 IN
PIRP_CONTEXT IrpContext,
00321 IN
PIRP Irp
00322 )
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344
00345 {
00346
TYPE_OF_OPEN TypeOfOpen;
00347
00348
PVCB Vcb;
00349
PFCB Fcb;
00350
PCCB Ccb;
00351 ULONG UserReference = 0;
00352
00353 BOOLEAN DelayedClose;
00354 BOOLEAN ReleaseUdfData =
FALSE;
00355
00356
PAGED_CODE();
00357
00358
00359
00360
00361
00362
ASSERT_IRP_CONTEXT( IrpContext );
00363
ASSERT_IRP(
Irp );
00364
00365
00366
00367
00368
00369
00370
if (IrpContext->Vcb ==
NULL) {
00371
00372
UdfCompleteRequest( IrpContext,
Irp, STATUS_SUCCESS );
00373
return STATUS_SUCCESS;
00374 }
00375
00376
00377
00378
00379
00380 TypeOfOpen =
UdfDecodeFileObject(
IoGetCurrentIrpStackLocation(
Irp )->FileObject,
00381 &Fcb,
00382 &Ccb );
00383
00384
00385
00386
00387
00388
if (TypeOfOpen ==
UnopenedFileObject) {
00389
00390
UdfCompleteRequest( IrpContext,
Irp, STATUS_SUCCESS );
00391
00392
return STATUS_SUCCESS;
00393 }
00394
00395 Vcb = Fcb->
Vcb;
00396
00397
00398
00399
00400
00401
00402
if (Ccb !=
NULL) {
00403
00404 UserReference = 1;
00405
00406
00407
00408
00409
00410
UdfDeleteCcb( IrpContext, Ccb );
00411 }
00412
00413
00414
00415
00416
00417
00418
00419
if ((Vcb->
VcbCondition ==
VcbMounted) &&
00420 (Fcb->
FcbReference == 1) &&
00421 ((TypeOfOpen ==
UserFileOpen) ||
00422 (TypeOfOpen ==
UserDirectoryOpen))) {
00423
00424
UdfQueueClose( IrpContext, Fcb, UserReference,
TRUE );
00425 IrpContext =
NULL;
00426
00427
00428
00429
00430
00431
00432 }
else {
00433
00434
00435
00436
00437
00438
00439
00440
00441
00442
00443
00444
00445
if ((Vcb->
VcbCleanup == 0) &&
00446 (Vcb->
VcbCondition !=
VcbMounted) &&
00447 (Vcb->
VcbCondition !=
VcbMountInProgress) &&
00448
FlagOn( IrpContext->Flags,
IRP_CONTEXT_FLAG_TOP_LEVEL_UDFS )) {
00449
00450
UdfAcquireUdfData( IrpContext );
00451 ReleaseUdfData =
TRUE;
00452 }
00453
00454
if (!
UdfCommonClosePrivate( IrpContext, Vcb, Fcb, UserReference,
TRUE )) {
00455
00456
00457
00458
00459
00460
UdfQueueClose( IrpContext, Fcb, UserReference,
FALSE );
00461 IrpContext =
NULL;
00462
00463
00464
00465
00466
00467
00468 }
else if (ReleaseUdfData) {
00469
00470
UdfCheckForDismount( IrpContext, Vcb,
FALSE );
00471 }
00472 }
00473
00474
00475
00476
00477
00478
UdfCompleteRequest( IrpContext,
Irp, STATUS_SUCCESS );
00479
00480
if (ReleaseUdfData) {
00481
00482
UdfReleaseUdfData( IrpContext );
00483 }
00484
00485
00486
00487
00488
00489
return STATUS_SUCCESS;
00490 }
00491
00492
00493
00494
00495
00496
00497 BOOLEAN
00498 UdfCommonClosePrivate (
00499 IN
PIRP_CONTEXT IrpContext,
00500 IN
PVCB Vcb,
00501 IN
PFCB Fcb,
00502 IN ULONG UserReference,
00503 IN BOOLEAN FromFsd
00504 )
00505
00506
00507
00508
00509
00510
00511
00512
00513
00514
00515
00516
00517
00518
00519
00520
00521
00522
00523
00524
00525
00526
00527
00528
00529
00530
00531
00532
00533
00534
00535
00536
00537
00538 {
00539 BOOLEAN CompletedClose;
00540 BOOLEAN RemovedFcb;
00541
00542
PAGED_CODE();
00543
00544
00545
00546
00547
00548
ASSERT_IRP_CONTEXT( IrpContext );
00549
ASSERT_VCB( Vcb );
00550
ASSERT_FCB( Fcb );
00551
00552
00553
00554
00555
00556
00557
00558
if (
UdfAcquireVcbShared( IrpContext, Vcb, FromFsd )) {
00559
00560
if (!
UdfAcquireFcbExclusive( IrpContext, Fcb, FromFsd )) {
00561
00562
00563
00564
00565
00566
00567
UdfReleaseVcb( IrpContext, Vcb );
00568
return FALSE;
00569 }
00570
00571
00572
00573
00574
00575 }
else {
00576
00577
return FALSE;
00578 }
00579
00580
00581
00582
00583
00584
UdfLockVcb( IrpContext, Vcb );
00585
00586
DebugTrace(( +1,
Dbg,
00587
"UdfCommonClosePrivate, Fcb %08x %4s Vcb %d/%d Fcb %d/%d\n", Fcb,
00588 ( UserReference?
"USER" :
"SYS" ),
00589 Vcb->VcbReference,
00590 Vcb->VcbUserReference,
00591 Fcb->FcbReference,
00592 Fcb->FcbUserReference ));
00593
00594
UdfDecrementReferenceCounts( IrpContext, Fcb, 1, UserReference );
00595
00596
DebugTrace(( +0,
Dbg,
00597
"UdfCommonClosePrivate, Vcb %d/%d Fcb %d/%d\n",
00598 Vcb->VcbReference,
00599 Vcb->VcbUserReference,
00600 Fcb->FcbReference,
00601 Fcb->FcbUserReference ));
00602
00603
UdfUnlockVcb( IrpContext, Vcb );
00604
00605
00606
00607
00608
00609
00610
UdfTeardownStructures( IrpContext, Fcb,
FALSE, &RemovedFcb );
00611
00612
if (!RemovedFcb) {
00613
00614
UdfReleaseFcb( IrpContext, Fcb );
00615 }
00616
00617
DebugTrace(( -1,
Dbg,
00618
"UdfCommonClosePrivate, RemovedFcb %08x -> %c\n",
00619 Fcb,
00620 ( RemovedFcb?
'T' :
'F' )));
00621
00622
00623
00624
00625
00626
00627
UdfReleaseVcb( IrpContext, Vcb );
00628
00629
return TRUE;
00630 }
00631
00632
00633
VOID
00634 UdfQueueClose (
00635 IN
PIRP_CONTEXT IrpContext,
00636 IN
PFCB Fcb,
00637 IN ULONG UserReference,
00638 IN BOOLEAN DelayedClose
00639 )
00640
00641
00642
00643
00644
00645
00646
00647
00648
00649
00650
00651
00652
00653
00654
00655
00656
00657
00658
00659
00660
00661
00662
00663
00664
00665
00666
00667
00668 {
00669
PIRP_CONTEXT_LITE IrpContextLite =
NULL;
00670 BOOLEAN StartWorker =
FALSE;
00671
00672
PAGED_CODE();
00673
00674
00675
00676
00677
00678
ASSERT_IRP_CONTEXT( IrpContext );
00679
ASSERT_FCB( Fcb );
00680
00681
00682
00683
00684
00685
00686
if (DelayedClose) {
00687
00688
00689
00690
00691
00692 IrpContextLite =
UdfCreateIrpContextLite( IrpContext );
00693 }
00694
00695
00696
00697
00698
00699
00700
SetFlag( IrpContext->Flags,
IRP_CONTEXT_FLAG_MORE_PROCESSING );
00701
UdfCleanupIrpContext( IrpContext,
TRUE );
00702
00703
00704
00705
00706
00707
UdfLockUdfData();
00708
00709
DebugTrace(( +1,
Dbg,
00710
"UdfQueueClose, Fcb %08x %4s %5s\n",
00711 Fcb,
00712 ( UserReference?
"USER" :
"SYS" ),
00713 ( IrpContextLite?
"DELAY" :
"ASYNC" )));
00714
00715
00716
00717
00718
00719
00720
if (IrpContextLite !=
NULL) {
00721
00722
00723
00724
00725
00726 IrpContextLite->
NodeTypeCode =
UDFS_NTC_IRP_CONTEXT_LITE;
00727 IrpContextLite->
NodeByteSize =
sizeof(
IRP_CONTEXT_LITE );
00728 IrpContextLite->
Fcb = Fcb;
00729 IrpContextLite->
UserReference = UserReference;
00730 IrpContextLite->
RealDevice = IrpContext->RealDevice;
00731
00732
00733
00734
00735
00736
00737 InsertTailList( &
UdfData.
DelayedCloseQueue,
00738 &IrpContextLite->
DelayedCloseLinks );
00739
00740
UdfData.
DelayedCloseCount += 1;
00741
00742
00743
00744
00745
00746
00747
if (
UdfData.
DelayedCloseCount >
UdfData.
MaxDelayedCloseCount) {
00748
00749
UdfData.
ReduceDelayedClose =
TRUE;
00750
00751
if (!
UdfData.
FspCloseActive) {
00752
00753
UdfData.
FspCloseActive =
TRUE;
00754 StartWorker =
TRUE;
00755 }
00756 }
00757
00758
00759
00760
00761
00762
UdfUnlockUdfData();
00763
00764
00765
00766
00767
00768
UdfCompleteRequest( IrpContext,
NULL, STATUS_SUCCESS );
00769
00770
00771
00772
00773
00774 }
else {
00775
00776
00777
00778
00779
00780 IrpContext->Irp = (
PIRP) Fcb;
00781 IrpContext->ExceptionStatus = (
NTSTATUS) UserReference;
00782
00783
00784
00785
00786
00787 InsertTailList( &
UdfData.
AsyncCloseQueue,
00788 &IrpContext->WorkQueueItem.List );
00789
00790
UdfData.
AsyncCloseCount += 1;
00791
00792
00793
00794
00795
00796
if (!
UdfData.
FspCloseActive) {
00797
00798
UdfData.
FspCloseActive =
TRUE;
00799 StartWorker =
TRUE;
00800 }
00801
00802
00803
00804
00805
00806
UdfUnlockUdfData();
00807 }
00808
00809
00810
00811
00812
00813
if (StartWorker) {
00814
00815
ExQueueWorkItem( &
UdfData.
CloseItem,
CriticalWorkQueue );
00816 }
00817
00818
DebugTrace(( -1,
Dbg,
"UdfQueueClose -> VOID\n" ));
00819
00820
00821
00822
00823
00824
return;
00825 }
00826
00827
00828
00829
00830
00831
00832
PIRP_CONTEXT
00833 UdfRemoveClose (
00834 IN
PVCB Vcb OPTIONAL
00835 )
00836
00837
00838
00839
00840
00841
00842
00843
00844
00845
00846
00847
00848
00849
00850
00851
00852
00853
00854
00855
00856
00857 {
00858
PIRP_CONTEXT IrpContext =
NULL;
00859
PIRP_CONTEXT NextIrpContext;
00860
PIRP_CONTEXT_LITE NextIrpContextLite;
00861
00862 PLIST_ENTRY Entry;
00863
00864
PAGED_CODE();
00865
00866
ASSERT_OPTIONAL_VCB( Vcb );
00867
00868
00869
00870
00871
00872
UdfLockUdfData();
00873
00874
00875
00876
00877
00878 Entry =
UdfData.
AsyncCloseQueue.Flink;
00879
00880
while (Entry != &
UdfData.
AsyncCloseQueue) {
00881
00882
00883
00884
00885
00886 NextIrpContext = CONTAINING_RECORD( Entry,
00887
IRP_CONTEXT,
00888 WorkQueueItem.List );
00889
00890
00891
00892
00893
00894
00895
if (!ARGUMENT_PRESENT( Vcb ) || (NextIrpContext->
Vcb == Vcb)) {
00896
00897 RemoveEntryList( Entry );
00898
UdfData.
AsyncCloseCount -= 1;
00899
00900 IrpContext = NextIrpContext;
00901
break;
00902 }
00903
00904
00905
00906
00907
00908 Entry = Entry->Flink;
00909 }
00910
00911
00912
00913
00914
00915
00916
00917
00918
00919
if ((IrpContext ==
NULL) &&
00920 (ARGUMENT_PRESENT( Vcb ) ||
00921 (
UdfData.
ReduceDelayedClose &&
00922 (
UdfData.
DelayedCloseCount >
UdfData.
MinDelayedCloseCount)))) {
00923
00924 Entry =
UdfData.
DelayedCloseQueue.Flink;
00925
00926
while (Entry != &
UdfData.
DelayedCloseQueue) {
00927
00928
00929
00930
00931
00932 NextIrpContextLite = CONTAINING_RECORD( Entry,
00933
IRP_CONTEXT_LITE,
00934 DelayedCloseLinks );
00935
00936
00937
00938
00939
00940
00941
if (!ARGUMENT_PRESENT( Vcb ) || (NextIrpContextLite->
Fcb->
Vcb == Vcb)) {
00942
00943 RemoveEntryList( Entry );
00944
UdfData.
DelayedCloseCount -= 1;
00945
00946 IrpContext = (
PIRP_CONTEXT) NextIrpContextLite;
00947
break;
00948 }
00949
00950
00951
00952
00953
00954 Entry = Entry->Flink;
00955 }
00956 }
00957
00958
00959
00960
00961
00962
00963
if (!ARGUMENT_PRESENT( Vcb ) && (IrpContext ==
NULL)) {
00964
00965
UdfData.
FspCloseActive =
FALSE;
00966
UdfData.
ReduceDelayedClose =
FALSE;
00967 }
00968
00969
00970
00971
00972
00973
UdfUnlockUdfData();
00974
00975
return IrpContext;
00976 }
00977
00978