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_LOCKCTRL)
00029
00030
00031
00032
00033
00034 #define Dbg (UDFS_DEBUG_LEVEL_LOCKCTRL)
00035
00036
#ifdef ALLOC_PRAGMA
00037
#pragma alloc_text(PAGE, UdfCommonLockControl)
00038
#pragma alloc_text(PAGE, UdfFastLock)
00039
#pragma alloc_text(PAGE, UdfFastUnlockAll)
00040
#pragma alloc_text(PAGE, UdfFastUnlockAllByKey)
00041
#pragma alloc_text(PAGE, UdfFastUnlockSingle)
00042
#endif
00043
00044
00045
NTSTATUS
00046 UdfCommonLockControl (
00047 IN
PIRP_CONTEXT IrpContext,
00048 IN
PIRP Irp
00049 )
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068 {
00069
NTSTATUS Status;
00070
PIO_STACK_LOCATION IrpSp =
IoGetCurrentIrpStackLocation(
Irp );
00071
00072
TYPE_OF_OPEN TypeOfOpen;
00073
PFCB Fcb;
00074
PCCB Ccb;
00075
00076
PAGED_CODE();
00077
00078
00079
00080
00081
00082 TypeOfOpen =
UdfDecodeFileObject( IrpSp->
FileObject, &Fcb, &Ccb );
00083
00084
00085
00086
00087
00088
00089
if (TypeOfOpen !=
UserFileOpen) {
00090
00091
UdfCompleteRequest( IrpContext,
Irp, STATUS_INVALID_PARAMETER );
00092
return STATUS_INVALID_PARAMETER;
00093 }
00094
00095
00096
00097
00098
00099
00100
Status =
FsRtlCheckOplock( &Fcb->Oplock,
00101
Irp,
00102 IrpContext,
00103
UdfOplockComplete,
00104
NULL );
00105
00106
00107
00108
00109
00110
if (
Status != STATUS_SUCCESS) {
00111
00112
return Status;
00113 }
00114
00115
00116
00117
00118
00119
UdfVerifyFcbOperation( IrpContext, Fcb );
00120
00121
00122
00123
00124
00125
if (Fcb->FileLock ==
NULL) {
UdfCreateFileLock( IrpContext, Fcb,
TRUE ); }
00126
00127
00128
00129
00130
00131
00132
Status =
FsRtlProcessFileLock( Fcb->FileLock,
Irp,
NULL );
00133
00134
00135
00136
00137
00138
UdfLockFcb( IrpContext, Fcb );
00139 Fcb->IsFastIoPossible =
UdfIsFastIoPossible( Fcb );
00140
UdfUnlockFcb( IrpContext, Fcb );
00141
00142
00143
00144
00145
00146
UdfCompleteRequest( IrpContext,
NULL,
Status );
00147
return Status;
00148 }
00149
00150
00151 BOOLEAN
00152 UdfFastLock (
00153 IN
PFILE_OBJECT FileObject,
00154 IN PLARGE_INTEGER FileOffset,
00155 IN PLARGE_INTEGER Length,
00156
PEPROCESS ProcessId,
00157 ULONG Key,
00158 BOOLEAN FailImmediately,
00159 BOOLEAN ExclusiveLock,
00160 OUT PIO_STATUS_BLOCK IoStatus,
00161 IN
PDEVICE_OBJECT DeviceObject
00162 )
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197 {
00198 BOOLEAN Results =
FALSE;
00199
00200
PFCB Fcb;
00201
TYPE_OF_OPEN TypeOfOpen;
00202
00203
PAGED_CODE();
00204
00205
ASSERT_FILE_OBJECT( FileObject );
00206
00207 IoStatus->Information = 0;
00208
00209
00210
00211
00212
00213
00214 TypeOfOpen =
UdfFastDecodeFileObject( FileObject, &Fcb );
00215
00216
if (TypeOfOpen !=
UserFileOpen) {
00217
00218 IoStatus->Status = STATUS_INVALID_PARAMETER;
00219
return TRUE;
00220 }
00221
00222
00223
00224
00225
00226
if (!
UdfVerifyFcbOperation(
NULL, Fcb )) {
00227
00228
return FALSE;
00229 }
00230
00231
FsRtlEnterFileSystem();
00232
00233
00234
00235
00236
00237
try {
00238
00239
00240
00241
00242
00243
if ((Fcb->Oplock !=
NULL) && !
FsRtlOplockIsFastIoPossible( &Fcb->Oplock )) {
00244
00245
try_leave( NOTHING );
00246 }
00247
00248
00249
00250
00251
00252
if ((Fcb->FileLock ==
NULL) && !
UdfCreateFileLock(
NULL, Fcb,
FALSE )) {
00253
00254
try_leave( NOTHING );
00255 }
00256
00257
00258
00259
00260
00261
if (Results =
FsRtlFastLock( Fcb->FileLock,
00262 FileObject,
00263 FileOffset,
00264 Length,
00265 ProcessId,
00266
Key,
00267 FailImmediately,
00268 ExclusiveLock,
00269 IoStatus,
00270
NULL,
00271
FALSE )) {
00272
00273
00274
00275
00276
00277
00278
00279
if (Fcb->IsFastIoPossible ==
FastIoIsPossible) {
00280
00281
UdfLockFcb(
NULL, Fcb );
00282 Fcb->IsFastIoPossible =
UdfIsFastIoPossible( Fcb );
00283
UdfUnlockFcb(
NULL, Fcb );
00284 }
00285 }
00286
00287 } finally {
00288
00289
FsRtlExitFileSystem();
00290 }
00291
00292
return Results;
00293 }
00294
00295
00296 BOOLEAN
00297 UdfFastUnlockSingle (
00298 IN
PFILE_OBJECT FileObject,
00299 IN PLARGE_INTEGER FileOffset,
00300 IN PLARGE_INTEGER Length,
00301
PEPROCESS ProcessId,
00302 ULONG Key,
00303 OUT PIO_STATUS_BLOCK IoStatus,
00304 IN
PDEVICE_OBJECT DeviceObject
00305 )
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334 {
00335 BOOLEAN Results =
FALSE;
00336
TYPE_OF_OPEN TypeOfOpen;
00337
PFCB Fcb;
00338
00339
PAGED_CODE();
00340
00341 IoStatus->Information = 0;
00342
00343
00344
00345
00346
00347
00348 TypeOfOpen =
UdfFastDecodeFileObject( FileObject, &Fcb );
00349
00350
if (TypeOfOpen !=
UserFileOpen) {
00351
00352 IoStatus->Status = STATUS_INVALID_PARAMETER;
00353
return TRUE;
00354 }
00355
00356
00357
00358
00359
00360
if (!
UdfVerifyFcbOperation(
NULL, Fcb )) {
00361
00362
return FALSE;
00363 }
00364
00365
00366
00367
00368
00369
if (Fcb->FileLock ==
NULL) {
00370
00371 IoStatus->Status = STATUS_RANGE_NOT_LOCKED;
00372
return TRUE;
00373 }
00374
00375
FsRtlEnterFileSystem();
00376
00377
try {
00378
00379
00380
00381
00382
00383
if ((Fcb->Oplock !=
NULL) && !
FsRtlOplockIsFastIoPossible( &Fcb->Oplock )) {
00384
00385
try_leave( NOTHING );
00386 }
00387
00388
00389
00390
00391
00392
if ((Fcb->FileLock ==
NULL) && !
UdfCreateFileLock(
NULL, Fcb,
FALSE )) {
00393
00394
try_leave( NOTHING );
00395 }
00396
00397
00398
00399
00400
00401
00402 Results =
TRUE;
00403 IoStatus->Status =
FsRtlFastUnlockSingle( Fcb->FileLock,
00404 FileObject,
00405 FileOffset,
00406 Length,
00407 ProcessId,
00408
Key,
00409
NULL,
00410
FALSE );
00411
00412
00413
00414
00415
00416
00417
00418
if (!
FsRtlAreThereCurrentFileLocks( Fcb->FileLock ) &&
00419 (Fcb->IsFastIoPossible !=
FastIoIsPossible)) {
00420
00421
UdfLockFcb( IrpContext, Fcb );
00422 Fcb->IsFastIoPossible =
UdfIsFastIoPossible( Fcb );
00423
UdfUnlockFcb( IrpContext, Fcb );
00424 }
00425
00426 } finally {
00427
00428
FsRtlExitFileSystem();
00429 }
00430
00431
return Results;
00432 }
00433
00434
00435 BOOLEAN
00436 UdfFastUnlockAll (
00437 IN
PFILE_OBJECT FileObject,
00438
PEPROCESS ProcessId,
00439 OUT PIO_STATUS_BLOCK IoStatus,
00440 IN
PDEVICE_OBJECT DeviceObject
00441 )
00442
00443
00444
00445
00446
00447
00448
00449
00450
00451
00452
00453
00454
00455
00456
00457
00458
00459
00460
00461
00462
00463
00464 {
00465 BOOLEAN Results =
FALSE;
00466
TYPE_OF_OPEN TypeOfOpen;
00467
PFCB Fcb;
00468
00469
PAGED_CODE();
00470
00471 IoStatus->Information = 0;
00472
00473
00474
00475
00476
00477
00478 TypeOfOpen =
UdfFastDecodeFileObject( FileObject, &Fcb );
00479
00480
if (TypeOfOpen !=
UserFileOpen) {
00481
00482 IoStatus->Status = STATUS_INVALID_PARAMETER;
00483
return TRUE;
00484 }
00485
00486
00487
00488
00489
00490
if (!
UdfVerifyFcbOperation(
NULL, Fcb )) {
00491
00492
return FALSE;
00493 }
00494
00495
00496
00497
00498
00499
if (Fcb->FileLock ==
NULL) {
00500
00501 IoStatus->Status = STATUS_RANGE_NOT_LOCKED;
00502
return TRUE;
00503 }
00504
00505
FsRtlEnterFileSystem();
00506
00507
try {
00508
00509
00510
00511
00512
00513
if ((Fcb->Oplock !=
NULL) && !
FsRtlOplockIsFastIoPossible( &Fcb->Oplock )) {
00514
00515
try_leave( NOTHING );
00516 }
00517
00518
00519
00520
00521
00522
if ((Fcb->FileLock ==
NULL) && !
UdfCreateFileLock(
NULL, Fcb,
FALSE )) {
00523
00524
try_leave( NOTHING );
00525 }
00526
00527
00528
00529
00530
00531
00532 Results =
TRUE;
00533 IoStatus->Status =
FsRtlFastUnlockAll( Fcb->FileLock,
00534 FileObject,
00535 ProcessId,
00536
NULL );
00537
00538
00539
00540
00541
00542
00543
UdfLockFcb( IrpContext, Fcb );
00544 Fcb->IsFastIoPossible =
UdfIsFastIoPossible( Fcb );
00545
UdfUnlockFcb( IrpContext, Fcb );
00546
00547 } finally {
00548
00549
FsRtlExitFileSystem();
00550 }
00551
00552
return Results;
00553 }
00554
00555
00556 BOOLEAN
00557 UdfFastUnlockAllByKey (
00558 IN
PFILE_OBJECT FileObject,
00559 PVOID ProcessId,
00560 ULONG Key,
00561 OUT PIO_STATUS_BLOCK IoStatus,
00562 IN
PDEVICE_OBJECT DeviceObject
00563 )
00564
00565
00566
00567
00568
00569
00570
00571
00572
00573
00574
00575
00576
00577
00578
00579
00580
00581
00582
00583
00584
00585
00586
00587
00588 {
00589 BOOLEAN Results =
FALSE;
00590
TYPE_OF_OPEN TypeOfOpen;
00591
PFCB Fcb;
00592
00593
PAGED_CODE();
00594
00595 IoStatus->Information = 0;
00596
00597
00598
00599
00600
00601
00602 TypeOfOpen =
UdfFastDecodeFileObject( FileObject, &Fcb );
00603
00604
if (TypeOfOpen !=
UserFileOpen) {
00605
00606 IoStatus->Status = STATUS_INVALID_PARAMETER;
00607
return TRUE;
00608 }
00609
00610
00611
00612
00613
00614
if (!
UdfVerifyFcbOperation(
NULL, Fcb )) {
00615
00616
return FALSE;
00617 }
00618
00619
00620
00621
00622
00623
if (Fcb->FileLock ==
NULL) {
00624
00625 IoStatus->Status = STATUS_RANGE_NOT_LOCKED;
00626
return TRUE;
00627 }
00628
00629
FsRtlEnterFileSystem();
00630
00631
try {
00632
00633
00634
00635
00636
00637
if ((Fcb->Oplock !=
NULL) && !
FsRtlOplockIsFastIoPossible( &Fcb->Oplock )) {
00638
00639
try_leave( NOTHING );
00640 }
00641
00642
00643
00644
00645
00646
if ((Fcb->FileLock ==
NULL) && !
UdfCreateFileLock(
NULL, Fcb,
FALSE )) {
00647
00648
try_leave( NOTHING );
00649 }
00650
00651
00652
00653
00654
00655
00656 Results =
TRUE;
00657 IoStatus->Status =
FsRtlFastUnlockAllByKey( Fcb->FileLock,
00658 FileObject,
00659 ProcessId,
00660
Key,
00661
NULL );
00662
00663
00664
00665
00666
00667
00668
UdfLockFcb( IrpContext, Fcb );
00669 Fcb->IsFastIoPossible =
UdfIsFastIoPossible( Fcb );
00670
UdfUnlockFcb( IrpContext, Fcb );
00671
00672 } finally {
00673
00674
FsRtlExitFileSystem();
00675 }
00676
00677
return Results;
00678 }
00679
00680