diff options
author | Corinna Vinschen <corinna@vinschen.de> | 2023-11-27 21:14:49 +0100 |
---|---|---|
committer | Corinna Vinschen <corinna@vinschen.de> | 2023-11-28 10:55:52 +0100 |
commit | 89a1e4a573d40b233011402f42630b970ff71291 (patch) | |
tree | cbeedcf1aca909d5bac5f4c377df1eda1ec9fa53 /winsup/cygwin/fhandler/base.cc | |
parent | 8e009dce7c82538119766cc0e3a6c91f3248ea5a (diff) | |
download | newlib-cygwin-3.4.10.zip newlib-cygwin-3.4.10.tar.gz newlib-cygwin-3.4.10.tar.bz2 |
Cygwin: open(2): reset sparseness on O_TRUNCated filescygwin-3.4.10
open(2) implements O_TRUNC by just reducing the size of the file
to 0, to make sure EAs stay available.
Turns out, file sparseness is not removed this way either, so add
code to do just that.
Fixes: 603ef545bdbd ("* fhandler.cc (fhandler_base::open): Never open files with FILE_OVERWITE/FILE_OVERWRITE_IF.")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
Diffstat (limited to 'winsup/cygwin/fhandler/base.cc')
-rw-r--r-- | winsup/cygwin/fhandler/base.cc | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/winsup/cygwin/fhandler/base.cc b/winsup/cygwin/fhandler/base.cc index 58b63da..05e5153 100644 --- a/winsup/cygwin/fhandler/base.cc +++ b/winsup/cygwin/fhandler/base.cc @@ -773,6 +773,15 @@ fhandler_base::open (int flags, mode_t mode) NtClose (fh); goto done; } + /* Drop sparseness */ + if (pc.file_attributes () & FILE_ATTRIBUTE_SPARSE_FILE) + { + FILE_SET_SPARSE_BUFFER fssb = { SetSparse: FALSE }; + status = NtFsControlFile (fh, NULL, NULL, NULL, &io, + FSCTL_SET_SPARSE, &fssb, sizeof fssb, NULL, 0); + if (NT_SUCCESS (status)) + pc.file_attributes (pc.file_attributes () & ~FILE_ATTRIBUTE_SPARSE_FILE); + } } set_handle (fh); |