Export permstat and add tests for it