Should only truncate the file once, at the end of the loop - the file entries can be removed from the free list one by one, though.