[release/6.0-rc2] File preallocationSize: align Windows and Unix behavior. (#59532)
authorDavid Cantú <dacantu@microsoft.com>
Fri, 24 Sep 2021 21:52:17 +0000 (14:52 -0700)
committerGitHub <noreply@github.com>
Fri, 24 Sep 2021 21:52:17 +0000 (14:52 -0700)
commit157d5915a0e3d0f59ccc57b7dcdd81a1da7bba8b
tree3aeeade276e98c3761526e4cb0057f6733198e10
parentdc8ab405b31c72f6d9977163b1a725f2d00559af
[release/6.0-rc2] File preallocationSize: align Windows and Unix behavior. (#59532)

* Align preallocationSize behavior (#58726)

Co-authored-by: Stephen Toub <stoub@microsoft.com>
* File preallocationSize: align Windows and Unix behavior. (#59338)

* File preallocationSize: align Windows and Unix behavior.

This aligns Windows and Unix behavior of preallocationSize for the
intended use-case of specifing the size of a file that will be written.

For this use-case, the expected FileAccess is Write, and the file should be
a new one (FileMode.Create*) or a truncated file (FileMode.Truncate).
Specifing a preallocationSize for other modes, or non-writable files throws ArgumentException.

The opened file will have a length of zero, and is ready to be written to by the user.

If the requested size cannot be allocated, an IOException is thrown.

When the OS/filesystem does not support pre-allocating, preallocationSize is ignored.

* fix pal_io preprocessor checks

* pal_io more fixes

* ctor_options_as.Windows.cs: fix compilation

* Update tests

* tests: use preallocationSize from all public APIs

* pal_io: add back FreeBSD, fix OSX

* tests: check allocated is zero when preallocation is not supported.

* Only throw for not enough space errors

* Fix compilation

* Add some more tests

* Fix ExtendedPathsAreSupported test

* Apply suggestions from code review

Co-authored-by: David Cantú <dacantu@microsoft.com>
* Update System.Private.CoreLib Strings.resx

* PR feedback

* Remove GetPathToNonExistingFile

* Fix compilation

* Skip checking allocated size on mobile platforms.

Co-authored-by: David Cantú <dacantu@microsoft.com>
* Fix unused fileDescriptor

* void fd when unused

* Address feedback

Co-authored-by: Adam Sitnik <adam.sitnik@gmail.com>
Co-authored-by: Stephen Toub <stoub@microsoft.com>
Co-authored-by: Tom Deseyn <tom.deseyn@gmail.com>
26 files changed:
src/libraries/Common/src/Interop/Unix/System.Native/Interop.FAllocate.cs [moved from src/libraries/Common/src/Interop/Unix/System.Native/Interop.PosixFAllocate.cs with 63% similarity]
src/libraries/Native/Unix/Common/pal_config.h.in
src/libraries/Native/Unix/System.Native/entrypoints.c
src/libraries/Native/Unix/System.Native/pal_io.c
src/libraries/Native/Unix/System.Native/pal_io.h
src/libraries/Native/Unix/configure.cmake
src/libraries/System.IO.FileSystem/tests/File/Open.cs
src/libraries/System.IO.FileSystem/tests/File/OpenHandle.cs
src/libraries/System.IO.FileSystem/tests/FileInfo/Open.cs
src/libraries/System.IO.FileSystem/tests/FileStream/ctor_options.Browser.cs [new file with mode: 0644]
src/libraries/System.IO.FileSystem/tests/FileStream/ctor_options.Unix.cs [new file with mode: 0644]
src/libraries/System.IO.FileSystem/tests/FileStream/ctor_options.Windows.cs [moved from src/libraries/System.IO.FileSystem/tests/FileStream/ctor_options_as.Windows.cs with 71% similarity]
src/libraries/System.IO.FileSystem/tests/FileStream/ctor_options.cs [new file with mode: 0644]
src/libraries/System.IO.FileSystem/tests/FileStream/ctor_options_as.Browser.cs [deleted file]
src/libraries/System.IO.FileSystem/tests/FileStream/ctor_options_as.Unix.cs [deleted file]
src/libraries/System.IO.FileSystem/tests/FileStream/ctor_options_as.cs [deleted file]
src/libraries/System.IO.FileSystem/tests/FileStream/ctor_str_fm.cs
src/libraries/System.IO.FileSystem/tests/Net5CompatTests/System.IO.FileSystem.Net5Compat.Tests.csproj
src/libraries/System.IO.FileSystem/tests/System.IO.FileSystem.Tests.csproj
src/libraries/System.Private.CoreLib/src/Microsoft/Win32/SafeHandles/SafeFileHandle.Unix.cs
src/libraries/System.Private.CoreLib/src/Microsoft/Win32/SafeHandles/SafeFileHandle.Windows.cs
src/libraries/System.Private.CoreLib/src/Resources/Strings.resx
src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems
src/libraries/System.Private.CoreLib/src/System/IO/FileStream.cs
src/libraries/System.Private.CoreLib/src/System/IO/Strategies/FileStreamHelpers.Windows.cs
src/libraries/System.Private.CoreLib/src/System/IO/Strategies/FileStreamHelpers.cs