Do correct handling of file modes, including support for mode changes.