From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2155) id 99F723858D35; Tue, 5 Sep 2023 08:46:14 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 99F723858D35 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1693903574; bh=zQP9uBdcAmrbkuF/rRya2DIKJDSweJjq3bCnCDkD1lQ=; h=From:To:Subject:Date:From; b=cOWJdWbKMXnWT7kRrLUe8v9HA9JbdDkC7OLSP8udNzrOL9Ij/u+8VikEZfqzzYqTd HF6FGOErIHHW45aHd1/njHRIhkoq64MN+gcNrHhAJ7C+ZtEKExGIkHEMQAXisUZn3c 8mrR9dxPI64EVfz4gOHykIxmaVBoQgUMcX9IJMJ0= 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: enable usage of FIFOs on NFS X-Act-Checkin: newlib-cygwin X-Git-Author: Corinna Vinschen X-Git-Refname: refs/heads/main X-Git-Oldrev: 24b029ba8ea78cee7d94bc736ff4462eb8889f30 X-Git-Newrev: 622fb0776ea333dd708ff312f08ec98311138fbe Message-Id: <20230905084614.99F723858D35@sourceware.org> Date: Tue, 5 Sep 2023 08:46:14 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dnewlib-cygwin.git;h=3D622fb0776ea= 333dd708ff312f08ec98311138fbe commit 622fb0776ea333dd708ff312f08ec98311138fbe Author: Corinna Vinschen AuthorDate: Sat Aug 26 15:41:18 2023 +0200 Commit: Corinna Vinschen CommitDate: Mon Sep 4 10:41:02 2023 +0200 Cygwin: enable usage of FIFOs on NFS =20 FIFOs on NFS were never recogized as such in path handling. =20 stat(2) indicated native FIFOs as FIFOs but the path handling code didn't set the matching values in the inner symlink checking code, so the followup behaviour was wrong. =20 Basically for the same reason, Cygwin-created FIFOs were just treated as symlinks with weird content by stat(2) as well as path handling. =20 Add code to enable both types of FIFOs on NFS as Cygwin FIFOs. =20 Signed-off-by: Corinna Vinschen Diff: --- winsup/cygwin/fhandler/disk_file.cc | 22 +++++++++++++-------- winsup/cygwin/path.cc | 38 +++++++++++++++++++++++++++++++++= ---- 2 files changed, 48 insertions(+), 12 deletions(-) diff --git a/winsup/cygwin/fhandler/disk_file.cc b/winsup/cygwin/fhandler/d= isk_file.cc index 19c976aaae41..94f7ef566756 100644 --- a/winsup/cygwin/fhandler/disk_file.cc +++ b/winsup/cygwin/fhandler/disk_file.cc @@ -210,13 +210,14 @@ fhandler_base::fstat_by_nfs_ea (struct stat *buf) cyg_ldap cldap; bool ldap_open =3D false; =20 - if (get_handle ()) + /* NFS stumbles over its own caching. If you write to the file, + a subsequent fstat does not return the actual size of the file, + but the size at the time the handle has been opened. Unless + access through another handle invalidates the caching within the + NFS client. Skip this for Cygwin-created Symlinks playing FIFOs + (this sets the filler1 member to NF3FIFO). */ + if (get_handle () && nfs_attr->filler1 !=3D NF3FIFO) { - /* NFS stumbles over its own caching. If you write to the file, - a subsequent fstat does not return the actual size of the file, - but the size at the time the handle has been opened. Unless - access through another handle invalidates the caching within the - NFS client. */ if (get_access () & GENERIC_WRITE) FlushFileBuffers (get_handle ()); pc.get_finfo (get_handle ()); @@ -357,8 +358,13 @@ fhandler_base::fstat_fs (struct stat *buf) =20 if (get_stat_handle ()) { - if (!nohandle () && (!is_fs_special () || get_flags () & O_PATH)) - res =3D pc.fs_is_nfs () ? fstat_by_nfs_ea (buf) : fstat_by_handle (buf); + if (!nohandle ()) + { + if (pc.fs_is_nfs ()) + res =3D fstat_by_nfs_ea (buf); + else if (!is_fs_special () || get_flags () & O_PATH) + res =3D fstat_by_handle (buf); + } if (res) res =3D fstat_by_name (buf); return res; diff --git a/winsup/cygwin/path.cc b/winsup/cygwin/path.cc index 37e46c08ba89..c631fa8869b9 100644 --- a/winsup/cygwin/path.cc +++ b/winsup/cygwin/path.cc @@ -3513,11 +3513,41 @@ restart: } =20 /* If the file is on an NFS share and could be opened with extended - attributes, check if it's a symlink. Only files can be symlinks - (which can be symlinks to directories). */ - else if (fs.is_nfs () && (conv_hdl.nfsattr ()->type & 7) =3D=3D NF3L= NK) + attributes, check if it's a symlink or FIFO. */ + else if (fs.is_nfs ()) { - res =3D check_nfs_symlink (h); + /* Make sure filler1 is 0, so we can use it safely as a marker. */ + conv_hdl.nfsattr ()->filler1 =3D 0; + switch (conv_hdl.nfsattr ()->type & 7) + { + case NF3LNK: + res =3D check_nfs_symlink (h); + /* Enable Cygwin-created FIFOs to be recognized as FIFOs. + We have to overwrite the NFS fattr3 data, otherwise the + info returned by Cygwin's stat will still claim the file + is a symlink. */ + if (res && contents[0] =3D=3D ':' && contents[1] =3D=3D '\\' + && parse_device (contents) && 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; + } + break; + case NF3FIFO: + /* Enable real FIFOs recognized as such. */ + major =3D _major (FH_FIFO); + minor =3D _minor (FH_FIFO); + mode =3D S_IFIFO | (conv_hdl.nfsattr ()->mode & ~S_IFMT); + isdevice =3D true; + break; + default: + break; + } if (res) break; }