From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2155) id 9C8CA3858C50; Sat, 9 Sep 2023 21:29:26 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9C8CA3858C50 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1694294966; bh=6YoncdcdyXtFzWTBBj2ixHdQC8TcoUGSw23qCyrOnhs=; h=From:To:Subject:Date:From; b=Vpe5r+HpE3wpyDrK9GGigqfitpc1Dj6uiz2XFE8BbwXMkoAOGqhG9M6rP+ymuwfd0 BAvIr2yrRDyVXwf1P5ZBRdkLXXjuRUE9/ldfxas7BPGkl0MnsKgTg7WgAde7qffdi0 aVg6zdLz6X0I2kLimdDfAp7uomATilo6XR+XP81g= 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: NFS: create devices (especially FIFOs) as shortcut files X-Act-Checkin: newlib-cygwin X-Git-Author: Corinna Vinschen X-Git-Refname: refs/heads/main X-Git-Oldrev: 8a953be5ef761d4c5cc0572eab3da2cb34b0474b X-Git-Newrev: c0aa6ac30ec483ad6da6af701625e7aea7536663 Message-Id: <20230909212926.9C8CA3858C50@sourceware.org> Date: Sat, 9 Sep 2023 21:29:26 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dnewlib-cygwin.git;h=3Dc0aa6ac30ec= 483ad6da6af701625e7aea7536663 commit c0aa6ac30ec483ad6da6af701625e7aea7536663 Author: Corinna Vinschen AuthorDate: Sat Sep 9 23:23:52 2023 +0200 Commit: Corinna Vinschen CommitDate: Sat Sep 9 23:28:55 2023 +0200 Cygwin: NFS: create devices (especially FIFOs) as shortcut files =20 Creating real NFS symlinks for device files has a major downside: The way we store device info requires to change the symlink target in case of calling chmod(2). This falls flat in two ways: =20 - It requires to remove and recreate the symlink, so it doesn't exist for a short period of time, and - removing fails badly if there's another open handle to the symlink. =20 Therefore, change this to create FIFOs as shortcut files, just as on most other filesystems. Make sure to recognize these new shortcuts on NFS (for devices only) in path handling and readdir. =20 Fixes: 622fb0776ea3 ("Cygwin: enable usage of FIFOs on NFS") Signed-off-by: Corinna Vinschen Diff: --- winsup/cygwin/fhandler/disk_file.cc | 18 +++++++++++++++--- winsup/cygwin/path.cc | 12 +++++++++++- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/winsup/cygwin/fhandler/disk_file.cc b/winsup/cygwin/fhandler/d= isk_file.cc index 0242cae2fd43..245e9bb75dc8 100644 --- a/winsup/cygwin/fhandler/disk_file.cc +++ b/winsup/cygwin/fhandler/disk_file.cc @@ -2348,9 +2348,11 @@ go_ahead: And, since some filesystems choke on the EAs, we don't use them unconditionally. */ f_status =3D (dir->__flags & dirent_nfs_d_ino) - ? NtCreateFile (&hdl, READ_CONTROL, &attr, &io, - NULL, 0, FILE_SHARE_VALID_FLAGS, - FILE_OPEN, FILE_OPEN_FOR_BACKUP_INTENT, + ? NtCreateFile (&hdl, + READ_CONTROL | FILE_READ_ATTRIBUTES, + &attr, &io, NULL, 0, + FILE_SHARE_VALID_FLAGS, FILE_OPEN, + FILE_OPEN_FOR_BACKUP_INTENT, &nfs_aol_ffei, sizeof nfs_aol_ffei) : NtOpenFile (&hdl, READ_CONTROL, &attr, &io, FILE_SHARE_VALID_FLAGS, @@ -2364,6 +2366,16 @@ go_ahead: FILE_INTERNAL_INFORMATION fii; f_status =3D NtQueryInformationFile (hdl, &io, &fii, sizeof fii, FileInternalInformation); + /* On NFS fetch the (faked, but useful) DOS attribute. + We need it to recognize shortcut FIFOs. */ + if ((dir->__flags & dirent_nfs_d_ino)) + { + FILE_BASIC_INFORMATION fbi; + + if (NT_SUCCESS (NtQueryInformationFile (hdl, &io, &fbi, + sizeof fbi, FileBasicInformation))) + FileAttributes =3D fbi.FileAttributes; + } NtClose (hdl); if (NT_SUCCESS (f_status)) { diff --git a/winsup/cygwin/path.cc b/winsup/cygwin/path.cc index 6cf6e02ca88b..0c9d3921a0ea 100644 --- a/winsup/cygwin/path.cc +++ b/winsup/cygwin/path.cc @@ -2005,7 +2005,7 @@ symlink_worker (const char *oldpath, path_conv &win32= _newpath, bool isdevice) variable. Device files are always shortcuts. */ wsym_type =3D isdevice ? WSYM_lnk : allow_winsymlinks; /* NFS has its own, dedicated way to create symlinks. */ - if (win32_newpath.fs_is_nfs ()) + if (win32_newpath.fs_is_nfs () && !isdevice) wsym_type =3D WSYM_nfs; /* MVFS doesn't handle the SYSTEM DOS attribute, but it handles the = R/O attribute. Therefore we create symlinks on MVFS always as shortcuts. */ @@ -3477,6 +3477,16 @@ restart: else if (contents[0] !=3D ':' || contents[1] !=3D '\\' || !parse_device (contents)) break; + if (fs.is_nfs () && major =3D=3D _major (FH_FIFO)) + { + conv_hdl.nfsattr ()->type =3D NF3FIFO; + conv_hdl.nfsattr ()->mode =3D mode; + conv_hdl.nfsattr ()->size =3D 0; + /* Marker for fhandler_base::fstat_by_nfs_ea not to override + the cached fattr3 data with fresh data from the filesystem, + even if the handle is used for other purposes than stat. */ + conv_hdl.nfsattr ()->filler1 =3D NF3FIFO; + } } =20 /* If searching for `foo' and then finding a `foo.lnk' which is