00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
#include "cc.h"
00023
00024
00025
00026
00027
00028 #define me 0x0000040
00029
00030
00031
VOID
00032 CcSetAdditionalCacheAttributes (
00033 IN
PFILE_OBJECT FileObject,
00034 IN BOOLEAN DisableReadAhead,
00035 IN BOOLEAN DisableWriteBehind
00036 )
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062 {
00063
PSHARED_CACHE_MAP SharedCacheMap;
00064 KIRQL OldIrql;
00065
00066
00067
00068
00069
00070 SharedCacheMap = FileObject->SectionObjectPointer->SharedCacheMap;
00071
00072
00073
00074
00075
00076
CcAcquireMasterLock( &OldIrql );
00077
if (DisableReadAhead) {
00078
SetFlag(SharedCacheMap->
Flags,
DISABLE_READ_AHEAD);
00079 }
else {
00080
ClearFlag(SharedCacheMap->
Flags,
DISABLE_READ_AHEAD);
00081 }
00082
if (DisableWriteBehind) {
00083
SetFlag(SharedCacheMap->
Flags,
DISABLE_WRITE_BEHIND |
MODIFIED_WRITE_DISABLED);
00084 }
else {
00085
ClearFlag(SharedCacheMap->
Flags,
DISABLE_WRITE_BEHIND);
00086 }
00087
CcReleaseMasterLock( OldIrql );
00088 }
00089
00090
00091
VOID
00092 CcSetLogHandleForFile (
00093 IN
PFILE_OBJECT FileObject,
00094 IN PVOID LogHandle,
00095 IN PFLUSH_TO_LSN FlushToLsnRoutine
00096 )
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123 {
00124
PSHARED_CACHE_MAP SharedCacheMap;
00125
00126
00127
00128
00129
00130 SharedCacheMap = FileObject->SectionObjectPointer->SharedCacheMap;
00131
00132
00133
00134
00135
00136 SharedCacheMap->
LogHandle = LogHandle;
00137 SharedCacheMap->
FlushToLsnRoutine = FlushToLsnRoutine;
00138 }
00139
00140
00141 LARGE_INTEGER
00142 CcGetDirtyPages (
00143 IN PVOID LogHandle,
00144 IN PDIRTY_PAGE_ROUTINE DirtyPageRoutine,
00145 IN PVOID Context1,
00146 IN PVOID Context2
00147 )
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176 {
00177
PSHARED_CACHE_MAP SharedCacheMap;
00178
PBCB Bcb, BcbToUnpin =
NULL;
00179 KIRQL OldIrql;
00180
NTSTATUS ExceptionStatus;
00181 LARGE_INTEGER SavedFileOffset, SavedOldestLsn, SavedNewestLsn;
00182 ULONG SavedByteLength;
00183 LARGE_INTEGER OldestLsn = {0,0};
00184
00185
00186
00187
00188
00189
CcAcquireMasterLock( &OldIrql );
00190
00191 SharedCacheMap = CONTAINING_RECORD(
CcDirtySharedCacheMapList.
SharedCacheMapLinks.Flink,
00192
SHARED_CACHE_MAP,
00193 SharedCacheMapLinks );
00194
00195
00196
00197
00198
00199
00200
00201
try {
00202
00203
while (&SharedCacheMap->
SharedCacheMapLinks != &
CcDirtySharedCacheMapList.
SharedCacheMapLinks) {
00204
00205
00206
00207
00208
00209
00210
if (!
FlagOn(SharedCacheMap->
Flags,
IS_CURSOR) && (SharedCacheMap->
LogHandle == LogHandle) &&
00211 (SharedCacheMap->
DirtyPages != 0)) {
00212
00213
00214
00215
00216
00217
CcIncrementOpenCount( SharedCacheMap, 'pdGS' );
00218 SharedCacheMap->
DirtyPages += 1;
00219
CcReleaseMasterLock( OldIrql );
00220
00221
00222
00223
00224
00225 ExAcquireFastLock( &SharedCacheMap->
BcbSpinLock, &OldIrql );
00226 Bcb = CONTAINING_RECORD( SharedCacheMap->
BcbList.Flink,
BCB, BcbLinks );
00227
00228
00229
00230
00231
00232
while (&Bcb->
BcbLinks != &SharedCacheMap->
BcbList) {
00233
00234
00235
00236
00237
00238
00239
if ((Bcb->
NodeTypeCode ==
CACHE_NTC_BCB) && Bcb->
Dirty) {
00240
00241 SavedFileOffset = Bcb->
FileOffset;
00242 SavedByteLength = Bcb->
ByteLength;
00243 SavedOldestLsn = Bcb->
OldestLsn;
00244 SavedNewestLsn = Bcb->
NewestLsn;
00245
00246
00247
00248
00249
00250 Bcb->
PinCount += 1;
00251
00252 ExReleaseFastLock( &SharedCacheMap->
BcbSpinLock, OldIrql );
00253
00254
00255
00256
00257
00258
if (BcbToUnpin !=
NULL) {
00259
CcUnpinFileData( BcbToUnpin,
TRUE,
UNREF );
00260 BcbToUnpin =
NULL;
00261 }
00262
00263
00264
00265
00266
00267 (*DirtyPageRoutine)( SharedCacheMap->
FileObject,
00268 &SavedFileOffset,
00269 SavedByteLength,
00270 &SavedOldestLsn,
00271 &SavedNewestLsn,
00272
Context1,
00273
Context2 );
00274
00275
00276
00277
00278
00279
if ((SavedOldestLsn.QuadPart != 0) &&
00280 ((OldestLsn.QuadPart == 0) || (SavedOldestLsn.QuadPart < OldestLsn.QuadPart ))) {
00281 OldestLsn = SavedOldestLsn;
00282 }
00283
00284
00285
00286
00287
00288
00289 ExAcquireFastLock( &SharedCacheMap->
BcbSpinLock, &OldIrql );
00290
00291
00292
00293
00294
00295
00296
00297
00298
if (Bcb->
PinCount > 1) {
00299 Bcb->
PinCount -= 1;
00300 }
else {
00301 BcbToUnpin = Bcb;
00302 }
00303 }
00304
00305 Bcb = CONTAINING_RECORD( Bcb->
BcbLinks.Flink,
BCB, BcbLinks );
00306 }
00307 ExReleaseFastLock( &SharedCacheMap->
BcbSpinLock, OldIrql );
00308
00309
00310
00311
00312
00313
00314
00315
if (BcbToUnpin !=
NULL) {
00316
00317
CcUnpinFileData( BcbToUnpin,
TRUE,
UNREF );
00318 BcbToUnpin =
NULL;
00319 }
00320
00321
CcAcquireMasterLock( &OldIrql );
00322
00323
00324
00325
00326
00327
CcDecrementOpenCount( SharedCacheMap, 'pdGF' );
00328 SharedCacheMap->
DirtyPages -= 1;
00329 }
00330
00331
00332
00333
00334
00335 SharedCacheMap =
00336 CONTAINING_RECORD( SharedCacheMap->
SharedCacheMapLinks.Flink,
00337
SHARED_CACHE_MAP,
00338 SharedCacheMapLinks );
00339 }
00340
00341
CcReleaseMasterLock( OldIrql );
00342
00343 } finally {
00344
00345
00346
00347
00348
00349
00350
00351
if (AbnormalTermination()) {
00352
00353
CcUnpinFileData( Bcb,
TRUE,
UNPIN );
00354 }
00355 }
00356
00357
return OldestLsn;
00358 }
00359
00360
00361 BOOLEAN
00362 CcIsThereDirtyData (
00363 IN
PVPB Vpb
00364 )
00365
00366
00367
00368
00369
00370
00371
00372
00373
00374
00375
00376
00377
00378
00379
00380
00381
00382
00383
00384 {
00385
PSHARED_CACHE_MAP SharedCacheMap;
00386 KIRQL OldIrql;
00387 ULONG LoopsWithLockHeld = 0;
00388
00389
00390
00391
00392
00393
CcAcquireMasterLock( &OldIrql );
00394
00395 SharedCacheMap = CONTAINING_RECORD(
CcDirtySharedCacheMapList.
SharedCacheMapLinks.Flink,
00396
SHARED_CACHE_MAP,
00397 SharedCacheMapLinks );
00398
00399
while (&SharedCacheMap->
SharedCacheMapLinks != &
CcDirtySharedCacheMapList.
SharedCacheMapLinks) {
00400
00401
00402
00403
00404
00405
00406
00407
if (!
FlagOn(SharedCacheMap->
Flags,
IS_CURSOR) &&
00408 (SharedCacheMap->
FileObject->
Vpb == Vpb) &&
00409 (SharedCacheMap->
DirtyPages != 0) &&
00410 !
FlagOn(SharedCacheMap->
FileObject->
Flags,
FO_TEMPORARY_FILE)) {
00411
00412
CcReleaseMasterLock( OldIrql );
00413
return TRUE;
00414 }
00415
00416
00417
00418
00419
00420
00421
00422
if ((++LoopsWithLockHeld >= 20) &&
00423 !
FlagOn(SharedCacheMap->
Flags,
WRITE_QUEUED |
IS_CURSOR)) {
00424
00425
SetFlag( (
volatile ULONG) SharedCacheMap->
Flags,
WRITE_QUEUED);
00426 (
volatile ULONG) SharedCacheMap->
DirtyPages += 1;
00427
CcReleaseMasterLock( OldIrql );
00428 LoopsWithLockHeld = 0;
00429
CcAcquireMasterLock( &OldIrql );
00430
ClearFlag( (
volatile ULONG) SharedCacheMap->
Flags,
WRITE_QUEUED);
00431 (
volatile ULONG) SharedCacheMap->
DirtyPages -= 1;
00432 }
00433
00434
00435
00436
00437
00438 SharedCacheMap =
00439 CONTAINING_RECORD( SharedCacheMap->
SharedCacheMapLinks.Flink,
00440
SHARED_CACHE_MAP,
00441 SharedCacheMapLinks );
00442 }
00443
00444
CcReleaseMasterLock( OldIrql );
00445
00446
return FALSE;
00447 }
00448
00449 LARGE_INTEGER
00450 CcGetLsnForFileObject(
00451 IN
PFILE_OBJECT FileObject,
00452 OUT PLARGE_INTEGER OldestLsn OPTIONAL
00453 )
00454
00455
00456
00457
00458
00459
00460
00461
00462
00463
00464
00465
00466
00467
00468
00469
00470
00471
00472
00473 {
00474
PBCB Bcb;
00475 KIRQL OldIrql;
00476 LARGE_INTEGER Oldest, Newest;
00477
PSHARED_CACHE_MAP SharedCacheMap = FileObject->SectionObjectPointer->SharedCacheMap;
00478
00479
00480
00481
00482
00483 Oldest.LowPart = 0;
00484 Oldest.HighPart = 0;
00485 Newest.LowPart = 0;
00486 Newest.HighPart = 0;
00487
00488
if(SharedCacheMap ==
NULL) {
00489
return Oldest;
00490 }
00491
00492 ExAcquireFastLock(&SharedCacheMap->
BcbSpinLock, &OldIrql);
00493
00494
00495
00496
00497
00498 Bcb = CONTAINING_RECORD( SharedCacheMap->
BcbList.Flink,
BCB, BcbLinks );
00499
00500
while (&Bcb->
BcbLinks != &SharedCacheMap->
BcbList) {
00501
00502
00503
00504
00505
00506
00507
if ((Bcb->
NodeTypeCode ==
CACHE_NTC_BCB) && Bcb->
Dirty) {
00508
00509 LARGE_INTEGER BcbLsn, BcbNewest;
00510
00511 BcbLsn = Bcb->
OldestLsn;
00512 BcbNewest = Bcb->
NewestLsn;
00513
00514
if ((BcbLsn.QuadPart != 0) &&
00515 ((Oldest.QuadPart == 0) ||
00516 (BcbLsn.QuadPart < Oldest.QuadPart))) {
00517
00518 Oldest = BcbLsn;
00519 }
00520
00521
if ((BcbLsn.QuadPart != 0) && (BcbNewest.QuadPart > Newest.QuadPart)) {
00522
00523 Newest = BcbNewest;
00524 }
00525 }
00526
00527
00528 Bcb = CONTAINING_RECORD( Bcb->
BcbLinks.Flink,
BCB, BcbLinks );
00529 }
00530
00531
00532
00533
00534
00535
00536 ExReleaseFastLock( &SharedCacheMap->
BcbSpinLock, OldIrql );
00537
00538
if (ARGUMENT_PRESENT(OldestLsn)) {
00539
00540 *OldestLsn = Oldest;
00541 }
00542
00543
return Newest;
00544 }