4
0
mirror of git://sourceware.org/git/newlib-cygwin.git synced 2025-02-27 19:17:18 +08:00

Cygwin: open(2): reset sparseness on O_TRUNCated files

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>
This commit is contained in:
Corinna Vinschen 2023-11-27 21:14:49 +01:00
parent e01c50c7b0
commit 7f9caa4a36
2 changed files with 12 additions and 0 deletions

View File

@ -776,6 +776,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);

View File

@ -21,3 +21,6 @@ Bug Fixes
- Fix posix_fallocate(3) return value in case of being called on
other than regular files.
- Reset sparseness in case open(2) has been called with O_CREAT|O_TRUNC on
sparse files.