file: add support for setting mode when writing files