4 # Checks assumptions on Cc* (Cache Manager) behaviour by reading TraceFS log
5 # Copyright (C) 2003 Jan Kratochvil <project-captive@jankratochvil.net>
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; exactly version 2 of June 1991 is required
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 use Carp qw(cluck confess);
28 $Data::Dumper::Sortkeys=1;
29 my $ntfs_blocksize=0x200;
31 # $Object->{"by"}="CcSomeFunction";
32 # $Object->{"line_enter"}=123;
33 # $Object->{"line_leave"}=124;
34 # $Object->{"ProcessThread"}="0x12345678/0x12345678";
35 # $Object->{"data"}[dataline]{"FileObject"}="0x12345678";
36 # $Object->{"data"}[dataline]{"FileName"}="\filename" or undef() if NULL;
37 # $Object->{"data"}[dataline]{"Flags"}="0x40100";
38 # $Object->{"data"}[dataline]{"SectionObjectPointer"}="0x12345678";
39 # $Object->{"data"}[dataline]{"SharedCacheMap"}="0x12345678";
40 # $FileObject{$FileObject}{"FileObject"}="0x12345678";
41 # $FileObject{$FileObject}{"SectionObjectPointer"}="0x12345678";
42 # $SectionObjectPointer{$SectionObjectPointer}{"SectionObjectPointer"}="0x12345678";
43 # $SectionObjectPointer{$SectionObjectPointer}{"SharedCacheMap"}="0x12345678";
44 # $SharedCacheMap{$SharedCacheMap}{"SharedCacheMap"}="0x12345678";
45 # $SharedCacheMap{$SharedCacheMap}{"SectionObjectPointer"}="0x12345678";
46 # $SharedCacheMap{$SharedCacheMap}{"AllocationSize"}="0x12345";
47 # $SharedCacheMap{$SharedCacheMap}{"FileSize"}="0x12345";
48 # $SharedCacheMap{$SharedCacheMap}{"ref_count"}=1;
49 # $SharedCacheMap{$SharedCacheMap}{"map"}="0x12345678" (Bcb);
50 # $SharedCacheMap{$SharedCacheMap}{"pin"}{"0x1000"}="0x12345678" (Bcb) if !Bcb->{"OwnerPointer"};
51 # $SharedCacheMap{$SharedCacheMap}{"PinAccess"}=0 or 1;
52 # $SharedCacheMap{$SharedCacheMap}{"LogHandle"}="0x12345678" optional;
53 # $SharedCacheMap{$SharedCacheMap}{"AcquireForLazyWrite"}=0; # count
54 # $SharedCacheMap{$SharedCacheMap}{"in_memory"}{"0x4000"}=1; # mapped page?
55 # $LogHandle{$LogHandle}{"LogHandle"}="0x12345678";
56 # $Bcb{$Bcb}{"Bcb"}="0x12345678";
57 # $Bcb{$Bcb}{"SharedCacheMap"}="0x12345678";
58 # $Bcb{$Bcb}{"type"}="pin" or "map";
59 # $Bcb{$Bcb}{"ref_count"}=1;
60 # $Bcb{$Bcb}{"FileOffset"}="0x1000" if {"type"} eq "pin";
61 # $Bcb{$Bcb}{"Buffer"}="0x12345678"; # PAGE_SIZE-aligned for "pin", FileOffset_0-aligned for "map"
62 # $Bcb{$Bcb}{"OwnerPointer"}="0x12345678" optional;
63 # $Bcb{$Bcb}{"Lsn"}="0x12345678" optional;
64 # $Bcb{$Bcb}{"dirty"}=1 optional;
65 # $MdlChain{$MdlChain}{"MdlChain"}="0x12345678";
66 # $MdlChain{$MdlChain}{"FileObject"}="0x12345678";
67 # $MdlChain{$MdlChain}{"FileOffset"}="0x5000";
68 # $MdlChain{$MdlChain}{"Length"}="0x9000";
72 my %SectionObjectPointer;
76 my %LastLeave; # $ProcessThread=>[$Object,$Object,...]
77 my $LastLeave; # ref copy of the last item for the current $ProcessThread
80 my $EnterLeave; # ref copy of the list for the current $ProcessThread
83 print Data::Dumper->Dump([\%FileObject,\%SectionObjectPointer,\%SharedCacheMap,\%Bcb],
84 [qw(%FileObject %SectionObjectPointer %SharedCacheMap %Bcb)]) if !$filter;
93 return sprintf("0x%X",$num);
100 my $FObject=$FileObject{$FileObject};
102 my($package,$filename,$line,$subroutine)=caller 0;
103 warn "Non-existent FileObject $FileObject by line $line";
108 sub delete_FObject($)
112 my $FileObject=$FObject->{"FileObject"};
113 delete $FileObject{$FileObject};
118 my($SectionObjectPointer)=@_;
120 my $SObject=$SectionObjectPointer{$SectionObjectPointer};
122 my($package,$filename,$line,$subroutine)=caller 0;
123 warn "Non-existent SectionObjectPointer $SectionObjectPointer by line $line"
128 sub SObject_from_FileObject($)
132 return if !(my $FObject=FObject $FileObject);
133 my $SObject=SObject $FObject->{"SectionObjectPointer"};
135 my($package,$filename,$line,$subroutine)=caller 0;
136 warn "by line $line";
141 sub delete_CObject($)
145 my $SharedCacheMap=$CObject->{"SharedCacheMap"};
146 do { warn "Trailing map $_ of SharedCacheMap $SharedCacheMap during its deletion" if $_; } for ($CObject->{"map"});
147 do { warn "Trailing pin $_ of SharedCacheMap $SharedCacheMap during its deletion" if $_; } for (values(%{$CObject->{"pin"}}));
148 if (my $LogHandle=$CObject->{"LogHandle"}) {
149 do { warn "INTERNAL: Missing LogHandle $LogHandle for SharedCacheMap $SharedCacheMap"; return; }
150 if !(my $LObject=$LogHandle{$LogHandle});
151 # Do not delete $LogHandle as it may be used by many SharedCacheMap-s
153 delete $SharedCacheMap{$SharedCacheMap};
158 my($SharedCacheMap)=@_;
160 my $CObject=$SharedCacheMap{$SharedCacheMap};
162 my($package,$filename,$line,$subroutine)=caller 0;
163 warn "Non-existent SharedCacheMap $SharedCacheMap by line $line";
168 sub CObject_from_FileObject($)
172 return if !(my $SObject=SObject_from_FileObject $FileObject);
173 return if !(my $CObject=CObject $SObject->{"SharedCacheMap"});
177 sub SharedCacheMap_valid($)
179 my($SharedCacheMap)=@_;
181 cluck if !defined $SharedCacheMap;
182 return 0 if "0x".("F"x8) eq $SharedCacheMap;
183 return 0 if !eval $SharedCacheMap;
191 if (!eval $data->{"SectionObjectPointer"}) {
192 return if $Object->{"by"} eq "IRP_MJ_CREATE"; # SectionObjectPointer is not yet initialized
193 warn "Existing FileObject ".$data->{"FileObject"}." but no SectionObjectPointer found"
194 if $FileObject{$data->{"FileObject"}} && eval($FileObject{$data->{"FileObject"}}{"SectionObjectPointer"});
197 my $SectionObjectPointer=$data->{"SectionObjectPointer"};
198 if (!SharedCacheMap_valid $data->{"SharedCacheMap"} && $SectionObjectPointer{$SectionObjectPointer}) {
199 return if !(my $SObject=SObject $SectionObjectPointer);
200 my $SharedCacheMap=$SObject->{"SharedCacheMap"};
201 return if !eval $SharedCacheMap;
202 my $CObject=CObject $SharedCacheMap;
203 warn "Existing SectionObjectPointer ".$data->{"SectionObjectPointer"}." but no SharedCacheMap found,"
204 ." ref_count of SharedCacheMap is ".$CObject->{"ref_count"}
205 if $CObject->{"ref_count"};
206 # if $SectionObjectPointer{$data->{"SectionObjectPointer"}};
207 # SharedCacheMap was droppped by async task as it had ref_count==0.
208 delete_CObject $CObject;
209 $SObject->{"SharedCacheMap"}=tohex(0);
210 # FileObject is still valid!
213 return if !$FileObject{$data->{"FileObject"}};
214 return if !(my $FObject=FObject $data->{"FileObject"});
215 return if !(my $SObject=SObject $FObject->{"SectionObjectPointer"});
216 my $SharedCacheMap=$SObject->{"SharedCacheMap"};
217 warn "FileObject ".$FObject->{"FileObject"}." SectionObjectPointer ".$SObject->{"SectionObjectPointer"}
218 ." expected SharedCacheMap $SharedCacheMap"
219 ." but found SharedCacheMap ".$data->{"SharedCacheMap"}
220 if $SharedCacheMap ne $data->{"SharedCacheMap"};
221 warn "INTERNAL: SharedCacheMap $SharedCacheMap of FileObject ".$FObject->{"FileObject"}." got destroyed"
222 if !$SharedCacheMap{$SharedCacheMap};
225 sub CcInitializeCacheMap($$$$$)
227 my($FileObject,$AllocationSize,$FileSize,$ValidDataLength,$PinAccess)=@_;
229 $ValidDataLength=$FileSize if $ValidDataLength==eval("0x".("F"x8));
230 $Object->{"ref_count"}=1;
231 $Object->{"AllocationSize"}=tohex($AllocationSize);
232 $Object->{"FileSize"}=tohex($FileSize);
233 $Object->{"ValidDataLength"}=tohex($ValidDataLength);
234 $Object->{"map"}=undef();
236 $Object->{"PinAccess"}=$PinAccess;
237 $Object->{"FileObject"}=$FileObject;
240 sub CcInitializeCacheMap_leave()
242 my $SharedCacheMap=$Object->{"data"}[1]{"SharedCacheMap"};
243 $Object->{"SharedCacheMap"}=$SharedCacheMap;
244 my $old=$SharedCacheMap{$SharedCacheMap};
245 if (!SharedCacheMap_valid $Object->{"data"}[0]{"SharedCacheMap"} && $old) {
246 # SharedCacheMap got deleted in the meantime
247 delete_CObject CObject $SharedCacheMap;
248 my $SObject=SObject $Object->{"data"}[0]{"SectionObjectPointer"};
249 $SObject->{"SharedCacheMap"}=tohex(0);
252 if (!$old != !SharedCacheMap_valid $Object->{"data"}[0]{"SharedCacheMap"}) {
253 warn "Expecting old SharedCacheMap validity ".(!!$old)
254 ." but found old SharedCacheMap ".$Object->{"data"}[0]{"SharedCacheMap"};
256 warn "New SharedCacheMap ".$Object->{"data"}[1]{"SharedCacheMap"}." is not valid"
257 if !SharedCacheMap_valid $Object->{"data"}[1]{"SharedCacheMap"};
258 if (SharedCacheMap_valid $Object->{"data"}[0]{"SharedCacheMap"}) {
259 warn "Existing SharedCacheMap changed"
260 ." from ".$Object->{"data"}[0]{"SharedCacheMap"}." to ".$Object->{"data"}[1]{"SharedCacheMap"}
261 if $Object->{"data"}[0]{"SharedCacheMap"} ne $Object->{"data"}[1]{"SharedCacheMap"};
264 for my $field (qw(AllocationSize FileSize PinAccess)) {
265 warn "SharedCacheMap $SharedCacheMap old instance $field ".$old->{$field}
266 ." != new instance $field ".$Object->{$field}
267 if $old->{$field} ne $Object->{$field};
269 do { warn "Existing map Bcb $_ during CcInitializeCacheMap()" if $_; } for ($old->{"map"});
270 do { warn "Existing pin Bcb $_ during CcInitializeCacheMap()" if $_; } for (values(%{$old->{"pin"}}));
271 $Object->{"ref_count"}+=$old->{"ref_count"};
273 $SharedCacheMap{$SharedCacheMap}=$Object;
275 warn "Changed SectionObjectPointer inside CcInitializeCacheMap()"
276 ." from ".$Object->{"data"}[0]{"SectionObjectPointer"}." to ".$Object->{"data"}[1]{"SectionObjectPointer"}
277 if $Object->{"data"}[0]{"SectionObjectPointer"} ne $Object->{"data"}[1]{"SectionObjectPointer"};
278 my $SectionObjectPointer=$Object->{"data"}[1]{"SectionObjectPointer"};
280 my $FileObject=$Object->{"FileObject"};
281 if (my $FObject=$FileObject{$FileObject}) {
282 if (my $SObject=$SectionObjectPointer{$FObject->{"SectionObjectPointer"}}) {
283 warn "Changed SectionObjectPointer of FileObject $FileObject"
284 ." from ".$FObject->{"SectionObjectPointer"}." to ".$SectionObjectPointer
285 if $FObject->{"SectionObjectPointer"} ne $SectionObjectPointer;
287 # Otherwise SectionObjectPointer could be deleted and rebuilt async in the meantime.
289 $FileObject{$FileObject}={
290 "FileObject"=>$FileObject,
291 "SectionObjectPointer"=>$SectionObjectPointer,
294 if (my $SObject=$SectionObjectPointer{$SectionObjectPointer}) {
295 warn "Changed SharedCacheMap of SectionObjectPointer $SectionObjectPointer"
296 ." from ".$SObject->{"SharedCacheMap"}." to ".$SharedCacheMap
297 if $SObject->{"SharedCacheMap"} ne $SharedCacheMap && eval($SObject->{"SharedCacheMap"});
299 $SectionObjectPointer{$SectionObjectPointer}={
300 "SectionObjectPointer"=>$SectionObjectPointer,
301 "SharedCacheMap"=>$SharedCacheMap,
304 CcSetFileSizes($FileObject,map({ eval($Object->{$_}); } qw(AllocationSize FileSize ValidDataLength)));
305 delete $Object->{$_} for (qw(FileObject ValidDataLength));
308 sub CcUninitializeCacheMap($$)
310 my($FileObject,$TruncateSize)=@_;
312 $Object->{"FileObject"}=$FileObject;
315 sub CcUninitializeCacheMap_leave($)
319 my $FileObject=$Object->{"FileObject"};
320 # 'r' means function success.
321 # r=0 either if no CcInitializeCacheMap() was called at all
322 # or if Cc was unable to detach SharedCacheMap and it remains valid
323 # (FIXME: Do we SharedCacheMap->ref_count-- on in such case?).
324 my $SectionObjectPointer=$FileObject{$FileObject}->{"SectionObjectPointer"} if $FileObject{$FileObject};
325 my $SharedCacheMap=$SectionObjectPointer{$SectionObjectPointer}->{"SharedCacheMap"}
326 if $SectionObjectPointer && $SectionObjectPointer{$SectionObjectPointer};
327 warn "Unexpected 'r' result $r for CcUninitializeCacheMap of FileObject $FileObject"
328 if !(eval($SharedCacheMap) && !SharedCacheMap_valid($Object->{"data"}[1]{"SharedCacheMap"})) != !$r;
329 if (!eval $SharedCacheMap) {
330 for my $SharedCacheMap ($Object->{"data"}[0]{"SharedCacheMap"},$Object->{"data"}[1]{"SharedCacheMap"}) {
331 warn "Not expecting valid SharedCacheMap $SharedCacheMap"
332 if SharedCacheMap_valid $SharedCacheMap;
336 for my $SharedCacheMap ($Object->{"data"}[0]{"SharedCacheMap"}) {
337 warn "Expecting valid SharedCacheMap $SharedCacheMap"
338 if !SharedCacheMap_valid $SharedCacheMap;
340 return if !(my $FObject=FObject $FileObject);
341 return if !(my $SObject=SObject $FObject->{"SectionObjectPointer"});
342 return if !(my $CObject=CObject $SObject->{"SharedCacheMap"});
343 if (--$CObject->{"ref_count"}) {
344 for my $SharedCacheMap ($Object->{"data"}[1]{"SharedCacheMap"}) {
345 warn "Expecting still valid SharedCacheMap $SharedCacheMap after CcUninitializeCacheMap()"
346 ." with ref_count=".$CObject->{"ref_count"}
347 if !SharedCacheMap_valid $SharedCacheMap;
351 if (!SharedCacheMap_valid $Object->{"data"}[1]{"SharedCacheMap"}) {
352 delete_CObject $CObject;
353 $SObject->{"SharedCacheMap"}=tohex(0);
354 # FileObject is still valid!
357 # FIXME: Do we SharedCacheMap->ref_count-- on in such case?
361 sub CcSetFileSizes($$$$)
363 my($FileObject,$AllocationSize,$FileSize,$ValidDataLength)=@_;
365 return if !(my $CObject=CObject_from_FileObject $FileObject);
366 my $SharedCacheMap=$CObject->{"SharedCacheMap"};
367 if ($AllocationSize!=eval($CObject->{"AllocationSize"})) {
368 do { warn "Existing map $_ of FileObject $FileObject SharedCacheMap $SharedCacheMap during CcSetAllocationSizes(),"
369 ." AllocationSize=".$CObject->{"AllocationSize"} if $_; }
370 for ($CObject->{"map"});
371 do { warn "Existing pin $_ of FileObject $FileObject SharedCacheMap $SharedCacheMap during CcSetAllocationSizes(),"
372 ." AllocationSize=".$CObject->{"AllocationSize"} if $_; }
373 for (values(%{$CObject->{"pin"}}));
375 # $ValidDataLength can be > $CObject->{"FileSize"};
376 warn "ValidDataLength ".tohex($ValidDataLength)." > FileSize ".tohex($FileSize)
377 if $ValidDataLength>$FileSize;
378 warn "0 != AllocationSize ".tohex($AllocationSize)." % ntfs_blocksize ".tohex($ntfs_blocksize)
379 if 0!=($AllocationSize%$ntfs_blocksize);
380 # $AllocationSize can be higher
381 warn "FileSize ".tohex($FileSize)." > AllocationSize ".tohex($AllocationSize)
382 if $FileSize>$AllocationSize;
383 $CObject->{"FileSize"}=tohex($FileSize);
384 $CObject->{"AllocationSize"}=tohex($AllocationSize);
387 sub IRP_MJ_CREATE_leave()
389 do { warn "Non-NULL SectionObjectPointer $_ not expected" if eval($_); } for ($Object->{"data"}[0]{"SectionObjectPointer"});
390 my $FileObject=$Object->{"data"}[0]{"FileObject"};
391 warn "Existing FileObject $FileObject not expected" if $FileObject{$FileObject};
392 my $SectionObjectPointer=$Object->{"data"}[1]{"SectionObjectPointer"};
393 # We want to track even FileObject without SectionObjectPointer yet.
394 # if ($SectionObjectPointer && $SectionObjectPointer{$SectionObjectPointer})
396 $FileObject{$FileObject}={
397 "FileObject"=>$FileObject,
398 "SectionObjectPointer"=>$SectionObjectPointer,
401 if (eval $SectionObjectPointer) {
402 my $SharedCacheMap=$Object->{"data"}[1]{"SharedCacheMap"};
403 if (my $SObject=$SectionObjectPointer{$SectionObjectPointer}) {
404 warn "Changed SharedCacheMap from stored ".$SObject->{"SharedCacheMap"}." to ".$SharedCacheMap
405 if $SObject->{"SharedCacheMap"} ne $SharedCacheMap && $Object->{"by"} ne "IRP_MJ_CREATE";
407 $SectionObjectPointer{$SectionObjectPointer}={
408 "SectionObjectPointer"=>$SectionObjectPointer,
409 "SharedCacheMap"=>$SharedCacheMap,
418 cluck if !defined $Bcb;
419 my $BObject=$Bcb{$Bcb};
420 warn "Non-existent Bcb $Bcb" if !$BObject;
424 sub delete_BObject($)
428 my $Bcb=$BObject->{"Bcb"};
429 warn "Deleting ref_count=".$BObject->{"ref_count"}." Bcb $Bcb" if $BObject->{"ref_count"};
430 # Do not: warn "Deleting dirty Bcb $Bcb" if $BObject->{"dirty"};
431 # as it is valid to allow sanity check below.
432 warn "Deleting dirty Bcb $Bcb" if $BObject->{"dirty"} && $BObject->{"ref_count"};
433 return if !(my $CObject=CObject $BObject->{"SharedCacheMap"});
434 if ($BObject->{"type"} eq "map") {
435 for my $pin (values(%{$CObject->{"pin"}})) {
436 next if !defined $pin;
437 warn "unpin map but CcPinMappedData pin $pin still exists"
438 if $Bcb{$pin}->{"by"} eq "CcPinMappedData";
442 warn "unpin of pin Bcb $Bcb of SharedCacheMap ".$CObject->{"SharedCacheMap"}
443 ." although FileOffset ".$BObject->{"FileOffset"}." not in_memory"
444 if !($CObject->{"in_memory"}{$BObject->{"FileOffset"}});
445 # Do not: delete $CObject->{"in_memory"}{$BObject->{"FileOffset"}};
446 # as Cache Manager is not forced to drop it.
447 # warn "UNMARK: SharedCacheMap ".$CObject->{"SharedCacheMap"}." FileOffset ".$BObject->{"FileOffset"};
449 for my $ref ($BObject->{"type"} eq "map" ? \$CObject->{"map"} : \$CObject->{"pin"}{$BObject->{"FileOffset"}}) {
450 warn "Final unpin but ".$BObject->{"type"}." Bcb $Bcb not registered"
451 ." in SharedCacheMap ".$CObject->{"SharedCacheMap"}." ref ".($$ref || "<undef>")
452 if !defined($BObject->{"OwnerPointer"}) && !($$ref && $$ref eq $Bcb)
453 && !($BObject->{"ref_count"}==0 && $BObject->{"dirty"});
454 if ($$ref && $$ref eq $Bcb) {
456 # Do not: delete $CObject->{"pin"}{$BObject->{"FileOffset"}} if $BObject->{"type"} eq "pin";
457 # as it would destroy $$ref slot in &Bcb_checkref '($$ref && $Bcb ne $$ref)' codepath.
467 cluck if !defined $MdlChain;
468 my $MObject=$MdlChain{$MdlChain};
469 warn "Non-existent MdlChain $MdlChain" if !$MObject;
473 sub Bcb_conflict($;@)
475 my($CObject,@Bcb_list)=@_;
479 "map"=>$CObject->{"map"},
480 map(("arg".($arg++)=>$_),@Bcb_list),
481 %{$CObject->{"pin"}},
484 my $BufferBase; # relativized to FileOffset 0
486 while (my($key,$val)=each(%check)) {
487 next if !defined $val;
488 warn "Conflicting Bcb $val of keys $key and ".$reversed{$val}." of SharedCacheMap ".$CObject->{"SharedCacheMap"}
490 # Buffer base should match even between 'map's and 'pin's
491 # as the data are always mapped only once.
492 if (my $BObject=BObject $val) {
493 my $Buffer=eval $BObject->{"Buffer"};
494 $Buffer-=eval($BObject->{"FileOffset"}) if exists $BObject->{"FileOffset"};
495 warn "Non-matching Bcb ".$BObject->{"type"}." $val Buffer base ".tohex($Buffer)
496 ." with Bcb ".$Bcb{$BufferBase_val}->{"type"}." $BufferBase_val BufferBase ".tohex($BufferBase)
497 if defined($BufferBase) && $Buffer!=$BufferBase;
499 $BufferBase_val=$val;
501 $reversed{$val}=$key;
505 # New $BObject will always be forced as the last stored reference.
508 my($BObject,$ref)=@_;
510 return if !(my $CObject=CObject $BObject->{"SharedCacheMap"});
511 my $type=$BObject->{"type"};
512 my $Bcb=$BObject->{"Bcb"};
513 if ($$ref && $Bcb ne $$ref) {
514 my $BObject2=$Bcb{$$ref};
515 warn "new $type Bcb $Bcb != old ".$BObject2->{"type"}." Bcb $$ref";
516 delete_BObject $BObject2;
517 warn "INTERNAL: Trailing ref to Bcb $$ref" if $$ref;
520 my $BObject2=$Bcb{$$ref};
521 warn "new $type $Bcb type ".$BObject->{"type"}." != old type $type $$ref type ".$BObject2->{"type"}
522 if $BObject->{"type"} ne $BObject2->{"type"};
523 warn "new $type $Bcb Buffer ".$BObject->{"Buffer"}." != old $type $$ref Buffer ".$BObject2->{"Buffer"}
524 if $BObject->{"Buffer"} ne $BObject2->{"Buffer"};
526 if ($$ref && $$ref eq $Bcb) {
527 $BObject->{"ref_count"}+=$Bcb{$$ref}->{"ref_count"};
530 $Bcb{$Bcb}=$BObject; # &Bcb_conflict needs this reference
531 Bcb_conflict $CObject,$Bcb;
537 my($SharedCacheMap,$FileOffset,$Length)=@_;
539 return if !(my $CObject=CObject $SharedCacheMap);
540 if (defined($FileOffset) && defined($Length)) {
541 warn "Mapping data (end ".tohex($FileOffset+$Length).") out of FileSize ".$CObject->{"FileSize"}
542 if $FileOffset+$Length>eval($CObject->{"FileSize"});
544 $Object->{"SharedCacheMap"}=$CObject->{"SharedCacheMap"};
545 if (defined $FileOffset) {
546 $Object->{"FileOffset"}=tohex($FileOffset);
548 $Object->{"type"}="map";
549 $Object->{"ref_count"}=1;
552 sub map_new_from_FileObject($;$$)
554 my($FileObject,$FileOffset,$Length)=@_;
556 return if !(my $CObject=CObject_from_FileObject $FileObject);
557 map_new $CObject->{"SharedCacheMap"},$FileOffset,$Length;
560 sub map_new_leave($;$)
564 $Object->{"Bcb"}=$Bcb;
565 return if !(my $CObject=CObject $Object->{"SharedCacheMap"});
567 if (defined $Buffer) {
568 $Object->{"Buffer"}=tohex(eval($Buffer)-(eval($Object->{"FileOffset"}) || 0));
570 delete $Object->{"FileOffset"};
572 my $ref=\$CObject->{"map"};
573 # There may exist some pin bcbs even if we are creating the new map bcb.
574 Bcb_checkref $Object,$ref;
579 my($FileObject,$FileOffset,$Length)=@_;
581 map_new_from_FileObject $FileObject,$FileOffset,$Length;
584 sub CcMapData_leave($$)
588 map_new_leave $Bcb,$Buffer;
593 my($FileObject,$FileOffset,$Length)=@_;
595 return if !(my $CObject=CObject_from_FileObject $FileObject);
596 warn "Pinning of non-PinAccess FileObject $FileObject" if !$CObject->{"PinAccess"};
597 warn "Mapping data (end ".tohex($FileOffset+$Length).") out of FileSize ".$CObject->{"FileSize"}
598 if $FileOffset+$Length>eval($CObject->{"FileSize"});
599 warn "Pinning Length ".tohex($Length)." > 0x1000" if $Length>0x1000;
600 warn "Pinning across file page (start=".tohex($FileOffset).",end-1=".tohex($FileOffset+$Length-1).")"
601 if ($FileOffset&~0xFFF)!=(($FileOffset+$Length-1)&~0xFFF);
602 $Object->{"SharedCacheMap"}=$CObject->{"SharedCacheMap"};
603 $Object->{"FileOffset"}=tohex($FileOffset);
604 $Object->{"type"}="pin";
605 $Object->{"ref_count"}=1;
608 sub pin_new_leave($$)
612 $Object->{"Bcb"}=$Bcb;
613 return if !(my $CObject=CObject $Object->{"SharedCacheMap"});
614 $Object->{"Buffer"}=tohex(eval($Buffer)-(eval($Object->{"FileOffset"})&0xFFF));
615 my $shift=eval($Object->{"FileOffset"})&0xFFF;
616 $Object->{"FileOffset"}=tohex(eval($Object->{"FileOffset"})-$shift);
617 $Object->{"Buffer"}=tohex(eval($Buffer)-$shift);
619 warn "pin_new_leave() while FileOffset ".$Object->{"FileOffset"}." not in_memory"
620 ." of SharedCacheMap ".$CObject->{"SharedCacheMap"}
621 if !$CObject->{"in_memory"}{$Object->{"FileOffset"}};
623 my $ref=\$CObject->{"pin"}{$Object->{"FileOffset"}};
624 # There may not exist map bcb even if we are creating the new pin bcb.
625 Bcb_checkref $Object,$ref;
630 my($FileObject,$FileOffset,$Length)=@_;
632 pin_new $FileObject,$FileOffset,$Length;
635 sub CcPinRead_leave($$)
639 pin_new_leave $Bcb,$Buffer;
642 sub CcPreparePinWrite($$$)
644 my($FileObject,$FileOffset,$Length)=@_;
646 return if !(my $CObject=CObject_from_FileObject $FileObject);
647 # Full pages do not need to be read:
648 if (!($FileOffset&0xFFF)) {
649 $CObject->{"in_memory"}{tohex $FileOffset}=1;
652 pin_new $FileObject,$FileOffset,$Length;
655 sub CcPreparePinWrite_leave($$)
659 pin_new_leave $Bcb,$Buffer;
660 my $BObject=BObject $Bcb;
661 $BObject->{"dirty"}=1;
664 sub CcPinMappedData($$$)
666 my($FileObject,$FileOffset,$Length)=@_;
668 pin_new $FileObject,$FileOffset,$Length;
671 sub CcPinMappedData_leave($)
675 return if !(my $CObject=CObject $Object->{"SharedCacheMap"});
676 do { warn "CcPinMappedData() with Bcb $Bcb on non-CcMapData()ed SharedCacheMap ".$CObject->{"SharedCacheMap"}; return; }
677 if !(my $mapBcb=$CObject->{"map"});
678 return if !(my $BmapObject=BObject $mapBcb);
679 my $Buffer=tohex(eval($BmapObject->{"Buffer"})+eval($Object->{"FileOffset"}));
681 my $Bcb2=$CObject->{"pin"}{tohex(eval($Object->{"FileOffset"})&~0xFFF)};
682 my $BObject2=BObject $Bcb2 if $Bcb2;
684 pin_new_leave $Bcb,$Buffer;
687 sub CcSetDirtyPinnedData($$)
691 return if !(my $BObject=BObject $Bcb);
692 # Do not: warn "Lsn already set for Bcb $Bcb as ".$BObject->{"Lsn"}." while current Lsn=$Lsn" if $BObject->{"Lsn"};
693 # as it is permitted.
694 warn "Lsn goes backward for Bcb $Bcb old Lsn ".$BObject->{"Lsn"}." to a new Lsn=$Lsn"
695 if $BObject->{"Lsn"} && eval($BObject->{"Lsn"})>eval($Lsn);
696 $BObject->{"Lsn"}=$Lsn if $Lsn ne "0x".("F"x8);
697 $BObject->{"dirty"}=1;
698 return if !(my $CObject=CObject $BObject->{"SharedCacheMap"});
701 sub FlushToLsnRoutine($$)
703 my($LogHandle,$Lsn)=@_;
705 $Object->{"LogHandle"}=$LogHandle;
706 $Object->{"Lsn"}=$Lsn;
709 my $LogHandle_static;
710 sub CcSetLogHandleForFile($$$)
712 my($FileObject,$LogHandle,$FlushToLsnRoutine)=@_;
714 return if !(my $CObject=CObject_from_FileObject $FileObject);
715 warn "LogHandle ".$CObject->{"LogHandle"}." already exists for SharedCacheMap ".$CObject->{"SharedCacheMap"}
716 if $CObject->{"LogHandle"};
717 return if !eval $LogHandle; # $LogHandle may be "0x0"
718 # ntfs.sys uses single LogHandle for its whole session:
719 warn "Non-unique LogHandle $LogHandle while last LogHandle was $LogHandle_static"
720 if $LogHandle_static && $LogHandle ne $LogHandle_static;
721 $CObject->{"LogHandle"}=$LogHandle;
722 if (!$LogHandle{$LogHandle}) {
723 $LogHandle{$LogHandle}={
724 "LogHandle"=>$LogHandle,
729 sub IRP_MJ_WRITE_leave_page($$)
731 my($ByteOffset,$Lsn_check)=@_;
733 my $SharedCacheMap=$Object->{"data"}[0]{"SharedCacheMap"};
734 return if !(my $CObject=CObject $SharedCacheMap);
735 my $FlushToLsnRoutine=$LastLeave if $LastLeave->{"by"} eq "FlushToLsnRoutine";
736 # Do not: my $Bcb=$CObject->{"pin"}{$ByteOffset};
737 # as Bcbs with $BObject->{"OwnerPointer"} are no longer stored in $CObject->{"pin"}.
739 for my $Bcb (keys(%Bcb)) {
740 my $BObject=BObject $Bcb;
742 && $BObject->{"type"} eq "pin"
743 && $BObject->{"SharedCacheMap"} eq $SharedCacheMap
744 && $BObject->{"FileOffset"} eq $ByteOffset) {
750 warn "Non-Bcb IRP_MJ_WRITE ByteOffset=$ByteOffset as non-toplevel function"
751 ." (".join(",",map({ $_->{"line_enter"}.":".$_->{"by"}; } @$EnterLeave)).")";
752 # warn Dumper $CObject;
753 # Direct IRP_MJ_WRITE can be from callbacked 'FlushToLsnRoutine'.
754 # It can occur even from other callbacks ('DirtyPageRoutine' etc.)
755 # but it was not needed here yet.
756 } if @$EnterLeave && !(${$EnterLeave}[$#$EnterLeave]->{"by"} eq "FlushToLsnRoutine");
757 warn "Non-Bcb IRP_MJ_WRITE ByteOffset=$ByteOffset but FlushToLsnRoutine was preceding"
758 if $FlushToLsnRoutine;
761 $CObject->{"in_memory"}{$ByteOffset}=1;
762 warn "Ambiguous matching Bcbs ".join(",",@Bcbs)
763 ." to SharedCacheMap $SharedCacheMap WRITE ByteOffset $ByteOffset"
766 return if !(my $BObject=BObject $Bcb);
767 warn "IRP_MJ_WRITE on non-dirty Bcb $Bcb" if !$BObject->{"dirty"};
768 if ($FlushToLsnRoutine) {
771 "Bcb_Lsn",$BObject->{"Lsn"},
775 warn "Missing preceding FlushToLsnRoutine during IRP_MJ_WRITE of Bcb $Bcb with Lsn ".$BObject->{"Lsn"}
776 if $BObject->{"Lsn"};
778 warn "IRP_MJ_WRITE with FlushToLsnRoutine although not in AcquireForLazyWrite"
779 if $FlushToLsnRoutine && !($CObject->{"AcquireForLazyWrite"}>=1);
780 warn "IRP_MJ_WRITE not the toplevel function"
781 ." (".join(",",map({ $_->{"line_enter"}.":".$_->{"by"}; } @$EnterLeave)).")"
783 || (1==@$EnterLeave && ${$EnterLeave}[0]->{"by"} eq "CcFlushCache")
784 || (2==@$EnterLeave && ${$EnterLeave}[0]->{"by"} eq "IRP_MJ_FILE_SYSTEM_CONTROL"
785 && ${$EnterLeave}[1]->{"by"} eq "CcFlushCache"));
786 my $CcFlushCache=${$EnterLeave}[$#$EnterLeave];
787 if ($CcFlushCache && $CcFlushCache->{"by"} eq "CcFlushCache") {
788 $CcFlushCache->{"CcFlushCached"}++;
789 if ($CcFlushCache->{"FileOffset"} ne "0x".("F"x8) || $CcFlushCache->{"Length"} ne "0x0") {
790 warn "IRP_MJ_WRITE outside of range of active CcFlushCache()"
791 if eval($ByteOffset)< eval($CcFlushCache->{"FileOffset"})
792 || eval($ByteOffset)>=eval($CcFlushCache->{"FileOffset"})+eval($CcFlushCache->{"Length"});
795 # Keep $BObject->{"dirty"} there for &delete_BObject sanity checks.
796 delete_BObject $BObject if $BObject->{"dirty"} && !$BObject->{"ref_count"};
799 sub IRP_MJ_WRITE_leave()
801 do { warn "Length $_ not divisible by 0x1000" if eval($_)%0x1000; } for ($Object->{"WRITE"}{"Length"});
803 for my $reloffs (0..(eval($Object->{"WRITE"}{"Length"})/0x1000)-1) {
804 IRP_MJ_WRITE_leave_page tohex(eval($Object->{"WRITE"}{"ByteOffset"})+0x1000*$reloffs),\@Lsn_check;
807 if ($LastLeave->{"by"} eq "FlushToLsnRoutine" && (my $FlushToLsnRoutine=$LastLeave)) {
810 my $Lsn=eval $_->{"Bcb_Lsn"};
811 $Lsn_max=$Lsn if !defined($Lsn_max) || $Lsn_max<$Lsn;
813 warn "FlushToLsnRoutine of line_enter ".$FlushToLsnRoutine->{"line_enter"}
814 ." got Lsn ".$FlushToLsnRoutine->{"Lsn"}." although Bcbs have "
815 .join(",",map({ "(".$_->{"Bcb"}.":".$_->{"Bcb_Lsn"}.")"; } @Lsn_check))
816 if tohex($Lsn_max) ne $FlushToLsnRoutine->{"Lsn"};
820 sub IRP_MJ_READ_leave()
822 # toplevel IRP_MJ_READ has no requirements
823 return if (0==@$EnterLeave);
824 my @stack=map({ $_->{"by"}=~/^IRP_MJ_/ ? () : $_ } @$EnterLeave);
825 my $opObject=$stack[0] if 1==@stack;
826 warn "IRP_MJ_READ not the expected function stack"
827 ." (".join(",",map({ $_->{"line_enter"}.":".$_->{"by"}; } @$EnterLeave)).")"
828 if !($opObject->{"by"} eq "CcMapData"
829 || $opObject->{"by"} eq "CcCopyRead"
830 || $opObject->{"by"} eq "CcMdlRead"
831 || $opObject->{"by"} eq "CcPinRead");
832 if ($opObject->{"by"} eq "CcMdlRead") {
833 do { warn "Length $_ not divisible by 0x1000" if eval($_)%0x1000; } for ($Object->{"READ"}{"Length"});
836 do { warn "Length $_ not 0x1000" if eval($_)!=0x1000; } for ($Object->{"READ"}{"Length"});
838 my $SharedCacheMap=$Object->{"data"}[0]{"SharedCacheMap"};
839 return if !(my $CObject=CObject $SharedCacheMap);
840 for my $reloffs (0..eval($Object->{"READ"}{"Length"})/0x1000-1) {
841 my $ByteOffset=tohex(eval($Object->{"READ"}{"ByteOffset"})+$reloffs*0x1000);
842 # Do not: warn "Reading ByteOffset $ByteOffset into SharedCacheMap $SharedCacheMap twice"
843 # if $CObject->{"in_memory"}{$ByteOffset};
844 # as it may be still cached there as Cache Manager is not forced to drop it.
845 $CObject->{"in_memory"}{$ByteOffset}=1;
846 # warn "MARK: SharedCacheMap ".$CObject->{"SharedCacheMap"}." FileOffset $ByteOffset";
850 sub CcPurgeCacheSection($$$$$)
852 my($SectionObjectPointer,$SharedCacheMap,$FileOffset,$Length,$UninitializeCacheMaps)=@_;
854 return if !(my $CObject=CObject $SharedCacheMap);
855 warn "Unexpected UninitializeCacheMaps $UninitializeCacheMaps" if $UninitializeCacheMaps ne "0";
856 my $all=($FileOffset eq "0x".("F"x8) && !eval $Length);
857 warn "Not yet implemented ranged CcPurgeCacheSection()" if !$all;
858 do { warn "Existing map Bcb $_ during CcPurgeCacheSection()" if $_; } for ($CObject->{"map"});
859 do { warn "Existing pin Bcb $_ during CcPurgeCacheSection()" if $_; } for (values(%{$CObject->{"pin"}}));
860 delete $CObject->{"in_memory"};
863 sub CcFlushCache($$$$)
865 my($SectionObjectPointer,$SharedCacheMap,$FileOffset,$Length)=@_;
867 $Object->{"CcFlushCached"}=0;
868 $Object->{"FileOffset"}=$FileOffset;
869 $Object->{"Length"}=$Length;
872 sub CcFlushCache_leave($$)
874 my($Status,$Information)=@_;
876 warn "CcFlushCache() not the toplevel function"
877 ." (".join(",",map({ $_->{"line_enter"}.":".$_->{"by"}; } @$EnterLeave)).")"
879 || (1==@$EnterLeave && ${$EnterLeave}[0]->{"by"} eq "IRP_MJ_FILE_SYSTEM_CONTROL"));
880 if ($Status ne "0x".("F"x8) || $Information ne "0x".("F"x8)) {
881 warn "Unexpected Status $Status" if eval $Status;
882 warn "Unexpected Information $Information while CcFlushCached=".$Object->{"CcFlushCached"}
883 if eval($Information)!=eval($Object->{"CcFlushCached"})*0x1000;
887 sub CcPrepareMdlWrite($$$)
889 my($FileObject,$FileOffset,$Length)=@_;
891 $Object->{"FileObject"}=$FileObject;
892 warn "FileOffset $FileOffset not divisible by 0x1000" if eval($FileOffset)%0x1000;
893 $Object->{"FileOffset"}=$FileOffset;
894 warn "Length $Length not divisible by 0x1000" if eval($Length)%0x1000;
895 $Object->{"Length"}=$Length;
898 sub CcPrepareMdlWrite_leave($$$)
900 my($MdlChain,$Status,$Information)=@_;
902 do { warn "Unexpected Status $Status"; return; } if eval $Status;
903 warn "Unexpected Information $Information" if $Information ne $Object->{"Length"};
904 warn "MdlChain $MdlChain already exists" if $MdlChain{$MdlChain};
905 $MdlChain{$MdlChain}=$Object;
908 sub CcMdlWriteComplete($$$)
910 my($FileObject,$FileOffset,$MdlChain)=@_;
912 return if !(my $MObject=MObject $MdlChain);
913 warn "CcMdlWriteComplete() parameter FileObject $FileObject"
914 ." not matching MdlChain $MdlChain FileObject ".$MObject->{"FileObject"}
915 if $FileObject ne $MObject->{"FileObject"};
916 warn "CcMdlWriteComplete() parameter FileOffset $FileOffset"
917 ." not matching MdlChain $MdlChain FileOffset ".$MObject->{"FileOffset"}
918 if $FileOffset ne $MObject->{"FileOffset"};
919 # Propose MdlChain to a simulated Bcb.
920 # We must split it by pages as pin can be just 0x1000 sized.
921 return if !(my $CObject=CObject_from_FileObject $MObject->{"FileObject"});
922 for my $reloffs (0..eval($MObject->{"Length"})/0x1000-1) {
923 my $BObject={ %$MObject };
924 $BObject->{"Bcb"}="MdlChain $MdlChain reloffs $reloffs";
925 $BObject->{"FileOffset"}=tohex(eval($MObject->{"FileOffset"})+$reloffs*0x1000);
926 $BObject->{"SharedCacheMap"}=$CObject->{"SharedCacheMap"};
927 $BObject->{"type"}="pin";
928 $BObject->{"ref_count"}=0;
929 $BObject->{"dirty"}=1;
930 warn "Bcb ".$BObject->{"Bcb"}." already exists" if $Bcb{$BObject->{"Bcb"}};
931 $Bcb{$BObject->{"Bcb"}}=$BObject;
933 delete $MdlChain{$MdlChain};
936 sub CcMdlWriteAbort($$)
938 my($FileObject,$MdlChain)=@_;
940 warn "CcMdlWriteAbort() not handled";
943 sub AcquireForLazyWrite_leave($)
947 warn "Unexpected 'r' $r" if $r ne "1";
948 warn "AcquireForLazyWrite() not the toplevel function" if @$EnterLeave;
949 return if !(my $CObject=CObject $Object->{"data"}[0]{"SharedCacheMap"});
950 $CObject->{"AcquireForLazyWrite"}++;
953 sub ReleaseFromLazyWrite_leave()
955 warn "ReleaseFromLazyWrite() not the toplevel function" if @$EnterLeave;
956 return if !(my $CObject=CObject $Object->{"data"}[0]{"SharedCacheMap"});
957 warn "Invalid 'AcquireForLazyWrite' value ".$CObject->{"AcquireForLazyWrite"}
958 if !($CObject->{"AcquireForLazyWrite"}>=1);
959 $CObject->{"AcquireForLazyWrite"}--;
966 return if !(my $BObject=BObject $Bcb);
967 map_new $BObject->{"SharedCacheMap"};
968 $Object->{"Buffer"}=tohex(eval($BObject->{"Buffer"})-eval($BObject->{"FileOffset"} || 0));
971 sub CcRemapBcb_leave($)
982 return if !(my $BObject=BObject $Bcb);
983 return if --$BObject->{"ref_count"};
984 if ($BObject->{"dirty"}) {
985 # last unpin of unreferenced dirty Bcb will no longer allow reincarnation
986 # of the same Bcb to the pin map of its SharedCacheMap.
987 return if !(my $CObject=CObject $BObject->{"SharedCacheMap"});
988 warn "unpin() of pin Bcb $Bcb but it is already not registered in SharedCacheMap ".$BObject->{"SharedCacheMap"}." pin map"
989 if (!$CObject->{"pin"}{$BObject->{"FileOffset"}} || $CObject->{"pin"}{$BObject->{"FileOffset"}} ne $Bcb)
990 && !$BObject->{"OwnerPointer"};
991 delete $CObject->{"pin"}{$BObject->{"FileOffset"}}
992 if $CObject->{"pin"}{$BObject->{"FileOffset"}} && ($CObject->{"pin"}{$BObject->{"FileOffset"}} eq $Bcb);
995 delete_BObject $BObject;
1005 sub CcUnpinDataForThread($)
1012 sub CcSetBcbOwnerPointer($$)
1014 my($Bcb,$OwnerPointer)=@_;
1016 return if !(my $BObject=BObject $Bcb);
1017 warn "CcSetBcbOwnerPointer() on map Bcb $Bcb" if $BObject->{"type"} ne "pin";
1018 return if !(my $CObject=CObject $BObject->{"SharedCacheMap"});
1019 warn "Double CcSetBcbOwnerPointer() on Bcb $Bcb" if defined $BObject->{"OwnerPointer"};
1020 my $val=$CObject->{"pin"}{$BObject->{"FileOffset"}};
1021 warn "CcSetBcbOwnerPointer() on unregistered pin Bcb $Bcb" if !$val || $val ne $Bcb;
1022 delete $CObject->{"pin"}{$BObject->{"FileOffset"}} if $val && $val eq $Bcb;
1023 $BObject->{"OwnerPointer"}=$OwnerPointer;
1026 sub IRP_MJ_CLOSE_leave()
1028 my $FileObject=$Object->{"data"}[0]{"FileObject"};
1029 # # IRP_MJ_CLOSE of FileObject w/o CcInitializeCacheMap()?
1030 # return if !$FileObject{$FileObject};
1031 return if !(my $FObject=FObject $FileObject);
1032 if (eval(my $SectionObjectPointer=$FObject->{"SectionObjectPointer"})) {
1033 return if !(my $SObject=SObject $SectionObjectPointer);
1034 my $SharedCacheMap=$SObject->{"SharedCacheMap"};
1035 if (eval $SharedCacheMap) {
1036 return if !(my $CObject=CObject $SObject->{"SharedCacheMap"});
1037 # SharedCacheMap may still exist for FCB although this FileObject gets destroyed now.
1038 # warn "SectionObjectPointer $SectionObjectPointer still exists during IRP_MJ_CLOSE"
1039 # ." while SharedCacheMap ".$CObject->{"SharedCacheMap"}." ref_count ".$CObject->{"ref_count"}
1040 # if $SectionObjectPointer && $CObject->{"ref_count"};
1043 delete_FObject $FObject;
1048 my $hex='0x[\dA-F]+';
1053 # We may get some foreign garbage without '\n' before our debug data line:
1054 # Do not use '\bTraceFS' as there really can be precediny _any_ data.
1055 s#^.*?TraceFS[(]($hex/$hex)[)]: ## or do { print "$_\n" if $filter; next; };
1059 if (/^enter: (\w+)/) {
1062 $Object->{"line_enter"}=$.;
1063 $Object->{"ProcessThread"}=$ProcessThread;
1064 push @{$EnterLeave{$ProcessThread}},$Object;
1066 elsif (/^leave: (\w+)/) {
1067 warn "Empty pop stack during 'leave' of $1" if !($Object=pop @{$EnterLeave{$ProcessThread}});
1068 warn "Non-matching popped 'by' ".$Object->{"by"}." ne current 'leave' $1"
1069 if $Object->{"by"} ne $1;
1070 $Object->{"line_leave"}=$.;
1071 push @{$LastLeave{$ProcessThread}},$Object;
1073 elsif (my($FileObject,$FileName,$Flags,$SectionObjectPointer,$SharedCacheMap)=
1074 /^FileObject=($hex): FileName=(?:NULL|'(.*)'),Flags=($hex),SectionObjectPointer=($hex),->SharedCacheMap=($hex)/) {
1075 my $aref=$EnterLeave{$ProcessThread};
1076 warn "Empty stack during 'data' line" if !($Object=${$aref}[$#$aref]);
1078 "FileObject"=>$FileObject,
1079 "FileName"=>$FileName,
1081 "SectionObjectPointer"=>$SectionObjectPointer,
1082 "SharedCacheMap"=>$SharedCacheMap,
1085 push @{$Object->{"data"}},$data;
1086 my $isinit={ map(($_=>1),qw(
1087 CcInitializeCacheMap
1088 CcUninitializeCacheMap
1090 )) }->{$Object->{"by"}};
1092 if 1==@{$Object->{"data"}} || !$isinit;
1094 # Prevent 'SharedCacheMap' 0->N change by CcInitializeCacheMap() called inside.
1095 for my $ref (@$aref[0..$#$aref-1]) {
1096 $ref->{"data"}[0]->{"SharedCacheMap"}=$SharedCacheMap;
1099 if (2<=@{$Object->{"data"}}) {
1100 my $data_prev=$Object->{"data"}[$#{$Object->{"data"}}-1];
1101 for my $field (qw(FileObject FileName Flags),($isinit ? () : qw(SharedCacheMap))) {
1102 next if !defined(my $prev=$data_prev->{$field});
1103 next if !defined(my $now=$data->{$field});
1104 my $by=$Object->{"by"};
1105 if ($field eq "Flags") {
1106 next if $by eq "IRP_MJ_CREATE" && $field eq "Flags";
1107 my $FO_CLEANUP_COMPLETE=0x4000;
1108 $now=tohex(eval($now)&~$FO_CLEANUP_COMPLETE) if $by eq "IRP_MJ_CLEANUP";
1109 my $FO_FILE_FAST_IO_READ=0x80000;
1110 $prev=tohex(eval($prev)&~$FO_FILE_FAST_IO_READ) if $by eq "IRP_MJ_CLEANUP";
1111 $now=tohex(eval($now)&~$FO_FILE_FAST_IO_READ) if $by eq "IRP_MJ_READ" && !(eval($prev)&$FO_FILE_FAST_IO_READ);
1112 my $FO_FILE_MODIFIED=0x1000;
1113 $now=tohex(eval($now)&~$FO_FILE_MODIFIED) if $by eq "IRP_MJ_WRITE" && !(eval($prev)&$FO_FILE_MODIFIED);
1114 my $FO_FILE_SIZE_CHANGED=0x2000;
1115 $prev=tohex(eval($prev)&~$FO_FILE_MODIFIED)
1116 if $by eq "IRP_MJ_SET_INFORMATION" && !(eval($now)&$FO_FILE_MODIFIED);
1117 $prev=tohex(eval($prev)&~$FO_FILE_SIZE_CHANGED)
1118 if $by eq "IRP_MJ_SET_INFORMATION" && !(eval($now)&$FO_FILE_SIZE_CHANGED);
1120 next if $by eq "IRP_MJ_CLOSE" && $field eq "FileName";
1121 $prev=~s#\\$## if $by eq "IRP_MJ_CREATE";
1122 $prev="\\" if $by eq "IRP_MJ_CREATE" && $prev eq "";
1123 $prev=~s#:.*## if $by eq "IRP_MJ_CREATE" && $prev ne $now;
1124 next if $field eq "SharedCacheMap" && !SharedCacheMap_valid $prev && !SharedCacheMap_valid $now;
1125 do { warn "Changed data field $field, prev=".$data_prev->{$field}.", now=".$data->{$field}." by $by";
1126 # print STDERR Dumper $data_prev,$data;
1132 elsif (my($op,$ByteOffset,$Length)=
1133 /^(READ|WRITE): ByteOffset=($hex),Length=($hex)/) {
1134 my $aref=$EnterLeave{$ProcessThread};
1135 warn "Empty stack during 'data' line" if !($Object=${$aref}[$#$aref]);
1137 "ByteOffset"=>$ByteOffset,
1143 $LastLeave=${$LastLeave{$ProcessThread}}[$#{$LastLeave{$ProcessThread}}-1];
1144 $EnterLeave=$EnterLeave{$ProcessThread};
1147 /^leave: IRP_MJ_\w+: r=($hex)/) {
1148 # Failed requests should make no consequences.
1152 if (my($FileObject,$AllocationSize,$FileSize,$ValidDataLength,$PinAccess)=
1153 /^enter: CcInitializeCacheMap: FileObject=($hex),FileSizes,->AllocationSize=($hex),->FileSize=($hex),->ValidDataLength=($hex),PinAccess=([01]),/) {
1154 CcInitializeCacheMap $FileObject,eval($AllocationSize),eval($FileSize),eval($ValidDataLength),eval($PinAccess);
1157 if (/^leave: CcInitializeCacheMap\b/) {
1158 CcInitializeCacheMap_leave;
1162 if (my($FileObject,$TruncateSize)=
1163 /^enter: CcUninitializeCacheMap: FileObject=($hex),TruncateSize=($hex),/) {
1164 CcUninitializeCacheMap $FileObject,eval($TruncateSize);
1168 /^leave: CcUninitializeCacheMap: r=([01])/) {
1169 CcUninitializeCacheMap_leave $r;
1173 if (my($FileObject,$AllocationSize,$FileSize,$ValidDataLength)=
1174 /^enter: CcSetFileSizes: FileObject=($hex),FileSizes,->AllocationSize=($hex),->FileSize=($hex),->ValidDataLength=($hex)/) {
1175 CcSetFileSizes $FileObject,eval($AllocationSize),eval($FileSize),eval($ValidDataLength);
1179 if (/^leave: IRP_MJ_CREATE\b/) {
1180 IRP_MJ_CREATE_leave;
1184 if (/^leave: IRP_MJ_CLOSE\b/) {
1189 if (my($FileObject,$FileOffset,$Length)=
1190 /^enter: CcMapData: FileObject=($hex),FileOffset=($hex),Length=($hex),Flags=0x1/) {
1191 CcMapData $FileObject,eval($FileOffset),eval($Length);
1194 if (my($Bcb,$Buffer)=
1195 /^leave: CcMapData: r=1,Bcb=($hex),Buffer=($hex)/) {
1196 CcMapData_leave $Bcb,$Buffer;
1200 if (my($FileObject,$FileOffset,$Length)=
1201 /^enter: CcPinRead: FileObject=($hex),FileOffset=($hex),Length=($hex),Flags=0x1/) {
1202 CcPinRead $FileObject,eval($FileOffset),eval($Length);
1205 if (my($Bcb,$Buffer)=
1206 /^leave: CcPinRead: r=1,Bcb=($hex),Buffer=($hex)/) {
1207 CcPinRead_leave $Bcb,$Buffer;
1211 if (my($FileObject,$FileOffset,$Length)=
1212 /^enter: CcPreparePinWrite: FileObject=($hex),FileOffset=($hex),Length=($hex),Zero=([01]),Flags=0x1/) {
1213 CcPreparePinWrite $FileObject,eval($FileOffset),eval($Length);
1216 if (my($Bcb,$Buffer)=
1217 /^leave: CcPreparePinWrite: r=1,Bcb=($hex),Buffer=($hex)/) {
1218 CcPreparePinWrite_leave $Bcb,$Buffer;
1222 if (my($FileObject,$FileOffset,$Length)=
1223 /^enter: CcPinMappedData: FileObject=($hex),FileOffset=($hex),Length=($hex),Flags=0x1/) {
1224 CcPinMappedData $FileObject,eval($FileOffset),eval($Length);
1228 /^leave: CcPinMappedData: r=1,Bcb=($hex)/) {
1229 CcPinMappedData_leave $Bcb;
1233 if (my($BcbVoid,$Lsn)=
1234 /^enter: CcSetDirtyPinnedData: BcbVoid=($hex),Lsn=($hex)/) {
1235 CcSetDirtyPinnedData $BcbVoid,$Lsn;
1239 if (my($LogHandle,$Lsn)=
1240 /^enter: FlushToLsnRoutine: LogHandle=($hex),Lsn=($hex)/) {
1241 FlushToLsnRoutine $LogHandle,$Lsn;
1245 if (/^leave: IRP_MJ_READ\b/) {
1250 if (my($SectionObjectPointer,$SharedCacheMap,$FileOffset,$Length,$UninitializeCacheMaps)=
1251 /^enter: CcPurgeCacheSection: SectionObjectPointer=($hex),->SharedCacheMap=($hex),FileOffset=($hex),Length=($hex),UninitializeCacheMaps=([01])/) {
1252 CcPurgeCacheSection $SectionObjectPointer,$SharedCacheMap,$FileOffset,$Length,$UninitializeCacheMaps;
1256 if (/^leave: IRP_MJ_WRITE\b/) {
1261 if (my($SectionObjectPointer,$SharedCacheMap,$FileOffset,$Length)=
1262 /^enter: CcFlushCache: SectionObjectPointer=($hex),->SharedCacheMap=($hex),FileOffset=($hex),Length=($hex)/) {
1263 CcFlushCache $SectionObjectPointer,$SharedCacheMap,$FileOffset,$Length;
1267 if (my($Status,$Information)=
1268 /^leave: CcFlushCache: IoStatus->Status=($hex),IoStatus->Information=($hex)/) {
1269 CcFlushCache_leave $Status,$Information;
1274 /^leave: AcquireForLazyWrite: r=([01])/) {
1275 AcquireForLazyWrite_leave $r;
1278 if (/^leave: ReleaseFromLazyWrite\b/) {
1279 ReleaseFromLazyWrite_leave;
1282 if (my($FileObject,$LogHandle,$FlushToLsnRoutine)=
1283 /^enter: CcSetLogHandleForFile: FileObject=($hex),LogHandle=($hex),FlushToLsnRoutine=($hex)/) {
1284 CcSetLogHandleForFile $FileObject,$LogHandle,$FlushToLsnRoutine;
1288 if (my($FileObject,$FileOffset,$Length)=
1289 /^enter: CcPrepareMdlWrite: FileObject=($hex),FileOffset=($hex),Length=($hex)/) {
1290 CcPrepareMdlWrite $FileObject,$FileOffset,$Length;
1293 if (my($MdlChain,$Status,$Information)=
1294 /^leave: CcPrepareMdlWrite: MdlChain=($hex),IoStatus->Status=($hex),IoStatus->Information=($hex)/) {
1295 CcPrepareMdlWrite_leave $MdlChain,$Status,$Information;
1299 if (my($FileObject,$FileOffset,$MdlChain)=
1300 /^enter: CcMdlWriteComplete: FileObject=($hex),FileOffset=($hex),MdlChain=($hex)/) {
1301 CcMdlWriteComplete $FileObject,$FileOffset,$MdlChain;
1305 if (my($FileObject,$MdlChain)=
1306 /^enter: CcMdlWriteAbort: FileObject=($hex),MdlChain=($hex)/) {
1307 CcMdlWriteAbort $FileObject,$MdlChain;
1312 /^enter: CcRemapBcb: Bcb=($hex)/) {
1317 /^leave: CcRemapBcb: r=($hex)/) {
1318 CcRemapBcb_leave $r;
1323 /^enter: CcUnpinData: Bcb=($hex)/) {
1328 /^enter: CcUnpinDataForThread: Bcb=($hex)/) {
1329 CcUnpinDataForThread $Bcb;
1333 if (my($Bcb,$OwnerPointer)=
1334 /^enter: CcSetBcbOwnerPointer: Bcb=($hex),OwnerPointer=($hex)/) {
1335 CcSetBcbOwnerPointer $Bcb,$OwnerPointer;
1339 print "$_\n" if $filter;
1341 for my $FileObject (keys(%FileObject)) {
1342 warn "EXIT: still CcInitializeCacheMap FileObject $FileObject";
1343 next if !(my $FObject=FObject $FileObject);