Refactor common code for generating a test filesystem