From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2155) id 9D94B3857359; Tue, 28 Nov 2023 10:03:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9D94B3857359 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1701165790; bh=WThqBbX3EMBQC4fXeozYr5ulnvaqpLvF1HCmMcFaFUw=; h=From:To:Subject:Date:From; b=npSvRc4SI/Cc91u1YUaHd05cp3EFMXZ90RlLePICwICIFWivZoTnSNFgRLJusO1G6 qhQFjXp+pohPcI7Gq9MUwYKBSXpUI45jv/mF1mCORsx+s89ocxRCEbWBDCQjz8avBh bjOihds2pghtMQjVf5Cz2dHSltOzyEtidQbH1B84= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Corinna Vinschen To: cygwin-cvs@sourceware.org Subject: [newlib-cygwin/main] Cygwin: open(2): reset sparseness on O_TRUNCated files X-Act-Checkin: newlib-cygwin X-Git-Author: Corinna Vinschen X-Git-Refname: refs/heads/main X-Git-Oldrev: e01c50c7b0a6c5d2a25feb02958d57902c25c141 X-Git-Newrev: 7f9caa4a3698827010d9b478407d21dd58b8bca5 Message-Id: <20231128100310.9D94B3857359@sourceware.org> Date: Tue, 28 Nov 2023 10:03:10 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dnewlib-cygwin.git;h=3D7f9caa4a369= 8827010d9b478407d21dd58b8bca5 commit 7f9caa4a3698827010d9b478407d21dd58b8bca5 Author: Corinna Vinschen AuthorDate: Mon Nov 27 21:14:49 2023 +0100 Commit: Corinna Vinschen CommitDate: Tue Nov 28 10:55:33 2023 +0100 Cygwin: open(2): reset sparseness on O_TRUNCated files =20 open(2) implements O_TRUNC by just reducing the size of the file to 0, to make sure EAs stay available. =20 Turns out, file sparseness is not removed this way either, so add code to do just that. =20 Fixes: 603ef545bdbd ("* fhandler.cc (fhandler_base::open): Never open f= iles with FILE_OVERWITE/FILE_OVERWRITE_IF.") Signed-off-by: Corinna Vinschen Diff: --- winsup/cygwin/fhandler/base.cc | 9 +++++++++ winsup/cygwin/release/3.4.10 | 3 +++ 2 files changed, 12 insertions(+) diff --git a/winsup/cygwin/fhandler/base.cc b/winsup/cygwin/fhandler/base.cc index d859870cb40d..b9336625419a 100644 --- a/winsup/cygwin/fhandler/base.cc +++ b/winsup/cygwin/fhandler/base.cc @@ -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 =3D { SetSparse: FALSE }; + status =3D 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_FI= LE); + } } =20 set_handle (fh); diff --git a/winsup/cygwin/release/3.4.10 b/winsup/cygwin/release/3.4.10 index 02f6885837b4..632ffcd39493 100644 --- a/winsup/cygwin/release/3.4.10 +++ b/winsup/cygwin/release/3.4.10 @@ -21,3 +21,6 @@ Bug Fixes =20 - 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.