00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
#include "UdfProcs.h"
00023
00024
00025
00026
00027
00028 #define BugCheckFileId (UDFS_BUG_CHECK_PNP)
00029
00030
NTSTATUS
00031
UdfPnpQueryRemove (
00032
PIRP_CONTEXT IrpContext,
00033
PIRP Irp,
00034
PVCB Vcb
00035 );
00036
00037
NTSTATUS
00038
UdfPnpRemove (
00039
PIRP_CONTEXT IrpContext,
00040
PIRP Irp,
00041
PVCB Vcb
00042 );
00043
00044
NTSTATUS
00045
UdfPnpSurpriseRemove (
00046
PIRP_CONTEXT IrpContext,
00047
PIRP Irp,
00048
PVCB Vcb
00049 );
00050
00051
NTSTATUS
00052
UdfPnpCancelRemove (
00053
PIRP_CONTEXT IrpContext,
00054
PIRP Irp,
00055
PVCB Vcb
00056 );
00057
00058
NTSTATUS
00059
UdfPnpCompletionRoutine (
00060 IN
PDEVICE_OBJECT DeviceObject,
00061 IN
PIRP Irp,
00062 IN PVOID Contxt
00063 );
00064
00065
#ifdef ALLOC_PRAGMA
00066
#pragma alloc_text(PAGE, UdfCommonPnp)
00067
#pragma alloc_text(PAGE, UdfPnpCancelRemove)
00068
#pragma alloc_text(PAGE, UdfPnpQueryRemove)
00069
#pragma alloc_text(PAGE, UdfPnpRemove)
00070
#pragma alloc_text(PAGE, UdfPnpSurpriseRemove)
00071
#endif
00072
00073
00074
NTSTATUS
00075 UdfCommonPnp (
00076 IN
PIRP_CONTEXT IrpContext,
00077 IN
PIRP Irp
00078 )
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097 {
00098
NTSTATUS Status;
00099
00100
PIO_STACK_LOCATION IrpSp;
00101
00102
PVOLUME_DEVICE_OBJECT OurDeviceObject;
00103
PVCB Vcb;
00104
00105
00106
00107
00108
00109 IrpSp =
IoGetCurrentIrpStackLocation(
Irp );
00110
00111
00112
00113
00114
00115 OurDeviceObject = (
PVOLUME_DEVICE_OBJECT) IrpSp->
DeviceObject;
00116
00117
00118
00119
00120
00121
00122
00123
if (OurDeviceObject->
DeviceObject.
Size !=
sizeof(
VOLUME_DEVICE_OBJECT) ||
00124
NodeType( &OurDeviceObject->
Vcb ) !=
UDFS_NTC_VCB) {
00125
00126
00127
00128
00129
00130
Status = STATUS_INVALID_PARAMETER;
00131
UdfCompleteRequest( IrpContext,
Irp,
Status );
00132
return Status;
00133 }
00134
00135
00136
00137
00138
00139
SetFlag( IrpContext->Flags,
IRP_CONTEXT_FLAG_WAIT );
00140
00141 Vcb = &OurDeviceObject->
Vcb;
00142
00143
00144
00145
00146
00147
switch ( IrpSp->
MinorFunction ) {
00148
00149
case IRP_MN_QUERY_REMOVE_DEVICE:
00150
00151
Status =
UdfPnpQueryRemove( IrpContext,
Irp, Vcb );
00152
break;
00153
00154
case IRP_MN_SURPRISE_REMOVAL:
00155
00156
Status =
UdfPnpSurpriseRemove( IrpContext,
Irp, Vcb );
00157
break;
00158
00159
case IRP_MN_REMOVE_DEVICE:
00160
00161
Status =
UdfPnpRemove( IrpContext,
Irp, Vcb );
00162
break;
00163
00164
case IRP_MN_CANCEL_REMOVE_DEVICE:
00165
00166
Status =
UdfPnpCancelRemove( IrpContext,
Irp, Vcb );
00167
break;
00168
00169
default:
00170
00171
00172
00173
00174
00175
00176
IoSkipCurrentIrpStackLocation(
Irp );
00177
00178
Status =
IoCallDriver(Vcb->
TargetDeviceObject,
Irp);
00179
00180
00181
00182
00183
00184
UdfCompleteRequest( IrpContext,
NULL, STATUS_SUCCESS );
00185
00186
break;
00187 }
00188
00189
return Status;
00190 }
00191
00192
00193
NTSTATUS
00194 UdfPnpQueryRemove (
00195
PIRP_CONTEXT IrpContext,
00196
PIRP Irp,
00197
PVCB Vcb
00198 )
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223 {
00224
NTSTATUS Status;
00225
KEVENT Event;
00226 BOOLEAN VcbPresent =
TRUE;
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
UdfAcquireVcbExclusive( IrpContext, Vcb,
FALSE );
00240
00241
Status =
UdfLockVolumeInternal( IrpContext, Vcb,
NULL );
00242
00243
UdfReleaseVcb( IrpContext, Vcb );
00244
UdfAcquireUdfData( IrpContext );
00245
UdfAcquireVcbExclusive( IrpContext, Vcb,
FALSE );
00246
00247
if (
NT_SUCCESS(
Status )) {
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
IoCopyCurrentIrpStackLocationToNext(
Irp );
00259
00260
00261
00262
00263
00264
KeInitializeEvent( &
Event, NotificationEvent,
FALSE );
00265
IoSetCompletionRoutine(
Irp,
00266
UdfPnpCompletionRoutine,
00267 &
Event,
00268
TRUE,
00269
TRUE,
00270
TRUE );
00271
00272
00273
00274
00275
00276
Status =
IoCallDriver(Vcb->
TargetDeviceObject,
Irp);
00277
00278
if (
Status == STATUS_PENDING) {
00279
00280
KeWaitForSingleObject( &
Event,
00281
Executive,
00282
KernelMode,
00283
FALSE,
00284
NULL );
00285
00286
Status =
Irp->
IoStatus.Status;
00287 }
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
if (
NT_SUCCESS(
Status )) {
00306
00307 VcbPresent =
UdfCheckForDismount( IrpContext, Vcb,
TRUE );
00308
00309
ASSERT( !VcbPresent || Vcb->
VcbCondition ==
VcbDismountInProgress );
00310 }
00311 }
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
ASSERT( !(
NT_SUCCESS(
Status ) && VcbPresent && Vcb->
VcbReference != 0));
00331
00332
if (VcbPresent) {
00333
00334
UdfReleaseVcb( IrpContext, Vcb );
00335 }
00336
00337
UdfReleaseUdfData( IrpContext );
00338
00339
00340
00341
00342
00343
UdfCompleteRequest( IrpContext,
Irp,
Status );
00344
00345
return Status;
00346 }
00347
00348
00349
NTSTATUS
00350 UdfPnpRemove (
00351
PIRP_CONTEXT IrpContext,
00352
PIRP Irp,
00353
PVCB Vcb
00354 )
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371
00372
00373
00374
00375
00376
00377 {
00378
NTSTATUS Status;
00379
KEVENT Event;
00380 BOOLEAN VcbPresent =
TRUE;
00381
00382
00383
00384
00385
00386
00387
00388
00389
00390
00391
00392
00393
00394
00395
00396
00397
00398
UdfAcquireUdfData( IrpContext );
00399
UdfAcquireVcbExclusive( IrpContext, Vcb,
FALSE );
00400
00401
00402
00403
00404
00405
00406
Status =
UdfUnlockVolumeInternal( IrpContext, Vcb,
NULL );
00407
00408
00409
00410
00411
00412
00413
00414
if (!
NT_SUCCESS(
Status )) {
00415
00416
UdfLockVcb( IrpContext, Vcb );
00417
00418
if (Vcb->
VcbCondition !=
VcbDismountInProgress) {
00419 Vcb->
VcbCondition =
VcbInvalid;
00420 }
00421
00422
UdfUnlockVcb( IrpContext, Vcb );
00423
00424
Status = STATUS_SUCCESS;
00425 }
00426
00427
00428
00429
00430
00431
00432
00433
00434
00435
00436
IoCopyCurrentIrpStackLocationToNext(
Irp );
00437
00438
00439
00440
00441
00442
KeInitializeEvent( &
Event, NotificationEvent,
FALSE );
00443
IoSetCompletionRoutine(
Irp,
00444
UdfPnpCompletionRoutine,
00445 &
Event,
00446
TRUE,
00447
TRUE,
00448
TRUE );
00449
00450
00451
00452
00453
00454
Status =
IoCallDriver(Vcb->
TargetDeviceObject,
Irp);
00455
00456
if (
Status == STATUS_PENDING) {
00457
00458
KeWaitForSingleObject( &
Event,
00459
Executive,
00460
KernelMode,
00461
FALSE,
00462
NULL );
00463
00464
Status =
Irp->
IoStatus.Status;
00465 }
00466
00467
00468
00469
00470
00471
00472
00473
00474
00475
00476 VcbPresent =
UdfCheckForDismount( IrpContext, Vcb,
TRUE );
00477
00478
00479
00480
00481
00482
if (VcbPresent) {
00483
00484
UdfReleaseVcb( IrpContext, Vcb );
00485 }
00486
00487
UdfReleaseUdfData( IrpContext );
00488
00489
00490
00491
00492
00493
UdfCompleteRequest( IrpContext,
Irp,
Status );
00494
00495
return Status;
00496 }
00497
00498
00499
NTSTATUS
00500 UdfPnpSurpriseRemove (
00501
PIRP_CONTEXT IrpContext,
00502
PIRP Irp,
00503
PVCB Vcb
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
NTSTATUS Status;
00535
KEVENT Event;
00536 BOOLEAN VcbPresent =
TRUE;
00537
00538
00539
00540
00541
00542
00543
UdfAcquireUdfData( IrpContext );
00544
UdfAcquireVcbExclusive( IrpContext, Vcb,
FALSE );
00545
00546
00547
00548
00549
00550
00551
00552
00553
00554
UdfLockVcb( IrpContext, Vcb );
00555
00556
if (Vcb->
VcbCondition !=
VcbDismountInProgress) {
00557 Vcb->
VcbCondition =
VcbInvalid;
00558 }
00559
00560
UdfUnlockVcb( IrpContext, Vcb );
00561
00562
00563
00564
00565
00566
00567
00568
00569
00570
00571
IoCopyCurrentIrpStackLocationToNext(
Irp );
00572
00573
00574
00575
00576
00577
KeInitializeEvent( &
Event, NotificationEvent,
FALSE );
00578
IoSetCompletionRoutine(
Irp,
00579
UdfPnpCompletionRoutine,
00580 &
Event,
00581
TRUE,
00582
TRUE,
00583
TRUE );
00584
00585
00586
00587
00588
00589
Status =
IoCallDriver(Vcb->
TargetDeviceObject,
Irp);
00590
00591
if (
Status == STATUS_PENDING) {
00592
00593
KeWaitForSingleObject( &
Event,
00594
Executive,
00595
KernelMode,
00596
FALSE,
00597
NULL );
00598
00599
Status =
Irp->
IoStatus.Status;
00600 }
00601
00602
00603
00604
00605
00606
00607
00608 VcbPresent =
UdfCheckForDismount( IrpContext, Vcb,
TRUE );
00609
00610
00611
00612
00613
00614
if (VcbPresent) {
00615
00616
UdfReleaseVcb( IrpContext, Vcb );
00617 }
00618
00619
UdfReleaseUdfData( IrpContext );
00620
00621
00622
00623
00624
00625
UdfCompleteRequest( IrpContext,
Irp,
Status );
00626
00627
return Status;
00628 }
00629
00630
00631
NTSTATUS
00632 UdfPnpCancelRemove (
00633
PIRP_CONTEXT IrpContext,
00634
PIRP Irp,
00635
PVCB Vcb
00636 )
00637
00638
00639
00640
00641
00642
00643
00644
00645
00646
00647
00648
00649
00650
00651
00652
00653
00654
00655
00656
00657
00658
00659 {
00660
NTSTATUS Status;
00661
00662
00663
00664
00665
00666
00667
00668
00669
00670
00671
00672
00673
00674
00675
00676
00677
00678
UdfAcquireVcbExclusive( IrpContext, Vcb,
FALSE );
00679
00680
00681
00682
00683
00684
00685 (
VOID)
UdfUnlockVolumeInternal( IrpContext, Vcb,
NULL );
00686
00687
UdfReleaseVcb( IrpContext, Vcb );
00688
00689
00690
00691
00692
00693
00694
00695
IoSkipCurrentIrpStackLocation(
Irp );
00696
00697
Status =
IoCallDriver(Vcb->
TargetDeviceObject,
Irp);
00698
00699
UdfCompleteRequest( IrpContext,
NULL, STATUS_SUCCESS );
00700
00701
return Status;
00702 }
00703
00704
00705
00706
00707
00708
00709
NTSTATUS
00710 UdfPnpCompletionRoutine (
00711 IN
PDEVICE_OBJECT DeviceObject,
00712 IN
PIRP Irp,
00713 IN PVOID Contxt
00714 )
00715 {
00716
PKEVENT Event = (
PKEVENT) Contxt;
00717
00718
KeSetEvent(
Event, 0,
FALSE );
00719
00720
return STATUS_MORE_PROCESSING_REQUIRED;
00721
00722 UNREFERENCED_PARAMETER( DeviceObject );
00723 UNREFERENCED_PARAMETER( Contxt );
00724 }
00725