On close, rewrite all metadata.

Previously we wrote only the trailing footer. If we rewrite everything
then we can adjust things like size and guarantee they get flushed on
close.

Signed-off-by: David Scott <dave.scott@citrix.com>