From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2155) id 3A0A23857C5A; Tue, 21 Mar 2023 17:30:34 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3A0A23857C5A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1679419834; bh=n5Qflrfg9ZIXKcufkEgd+qXrCtO11/C3CPXEJb3zEHc=; h=From:To:Subject:Date:From; b=wfmeonGw6Ppq9+DdTLqel44SUIkskPGWMrMlBGfyKyyJ+CnOOxhB/6QylIE1QzmrL QtB+irsCFGReQo+oofGGhPo29rDFRFee+FDaq/kmoPZWBACdWTftUvu+cDtTi0yJvE /xrbkRGrZ4VPZu/+rPtgwssSTL4sAyy8z/yTugH8= 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: don't use unlink/rename POSIX semantics on certain NTFS X-Act-Checkin: newlib-cygwin X-Git-Author: Corinna Vinschen X-Git-Refname: refs/heads/main X-Git-Oldrev: 0a962aa2c293aa69afbb3a52790ff14009921fe0 X-Git-Newrev: fe2545e9faaf4bf9586f61a7b83d5cb5af501194 Message-Id: <20230321173034.3A0A23857C5A@sourceware.org> Date: Tue, 21 Mar 2023 17:30:34 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dnewlib-cygwin.git;h=3Dfe2545e9faa= f4bf9586f61a7b83d5cb5af501194 commit fe2545e9faaf4bf9586f61a7b83d5cb5af501194 Author: Corinna Vinschen AuthorDate: Tue Mar 21 18:29:59 2023 +0100 Commit: Corinna Vinschen CommitDate: Tue Mar 21 18:29:59 2023 +0100 Cygwin: don't use unlink/rename POSIX semantics on certain NTFS =20 If a host NTFS is mapped into a Hyper-V isolated container, the OPEN_BY_FILE_ID filesystem flag is missing, just as if that NTFS is a remote drive. However, NtQueryVolumeInformationFile claims the drive is a local drive. =20 We can use this fact to learn that the process is running under Hyper-V, and that the Hyper-V isolated process can't use rename/unlink with POSIX semantics. Strange enough, the POSIX_UNLINK_RENAME filesyst= em flag is still set... =20 Signed-off-by: Corinna Vinschen Diff: --- winsup/cygwin/syscalls.cc | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/winsup/cygwin/syscalls.cc b/winsup/cygwin/syscalls.cc index af4f870851eb..3e2d42f3aa8b 100644 --- a/winsup/cygwin/syscalls.cc +++ b/winsup/cygwin/syscalls.cc @@ -691,10 +691,12 @@ unlink_nt (path_conv &pc, bool shareable) pc.get_object_attr (attr, sec_none_nih); =20 /* First check if we can use POSIX unlink semantics: W10 1709+, local NT= FS. - With POSIX unlink semantics the entire job gets MUCH easier and faste= r. - Just try to do it and if it fails, it fails. */ + For the OPEN_BY_FILE_ID flag, see MINIMAL_WIN_NTFS_FLAGS comment in + fs_info::update. With POSIX unlink semantics the entire job gets MUCH + easier and faster. Just try to do it and if it fails, it fails. */ if (wincap.has_posix_unlink_semantics () - && !pc.isremote () && pc.fs_is_ntfs ()) + && !pc.isremote () && pc.fs_is_ntfs () + && pc.has_attribute (FILE_SUPPORTS_OPEN_BY_FILE_ID)) { FILE_DISPOSITION_INFORMATION_EX fdie; =20 @@ -2407,10 +2409,12 @@ rename2 (const char *oldpath, const char *newpath, = unsigned int at2flags) __leave; } =20 - /* POSIX semantics only on local NTFS drives. */ + /* POSIX semantics only on local NTFS drives. For the OPEN_BY_FILE_ID + flag, see MINIMAL_WIN_NTFS_FLAGS comment in fs_info::update. */ use_posix_semantics =3D wincap.has_posix_rename_semantics () && !oldpc.isremote () - && oldpc.fs_is_ntfs (); + && oldpc.fs_is_ntfs () + && oldpc.has_attribute (FILE_SUPPORTS_OPEN_BY_FILE_ID); =20 /* Opening the file must be part of the transaction. It's not suffi= cient to call only NtSetInformationFile under the transaction. Therefore we