Fix header mode bug, store mode+perms.

Add header tests.