2.6.1.3.7 Crash Recovery and AMap Rebuilding

The fAMapValid flag in the ROOT structure is used to indicate whether the AMaps in the PST file are in a known-valid state. In general, this flag is set to one of the two valid states described in section 2.2.2.5.

At the beginning of any operation that either allocates or frees space in the PST file, implementations set the fAMapValid value to INVALID_AMAP, which signifies that the AMaps (and also PMaps, FMaps, and FPMaps, for that matter) cannot be trusted. When the operation is complete, this value is set back to the valid state. In the event where the PST file is abnormally closed before the operation is finished, it is likely that fAMapValid was never restored back to the valid state. In that case, the PST file MUST go through a very expensive recovery operation the next time an attempt to allocate file space is made.

This recovery operation uses a process called an "AMap rebuild", which involves first marking all the AMaps as "free" and then walking the NBT and BBT to mark pages and blocks as "allocated" in the map pages as they appear.<23> The rebuild process also ensures that all space occupied by the AMaps, PMaps, FMaps and FPMaps are properly marked as allocated.

Implementations are NOT required to implement AMap Rebuild algorithms, but MUST first check the fAMapValid value before manipulating the AMaps in any way. If the fAMapValid value is set to invalid, implementations that do not implement AMap Rebuild algorithms MUST NOT modify the PST file in any way. Read-only implementations, however, MAY ignore the fAMapValid value.