public inbox for cygwin-cvs@sourceware.org
help / color / mirror / Atom feed
* [newlib-cygwin/main] Cygwin: NFS: create devices (especially FIFOs) as shortcut files
@ 2023-09-09 21:29 Corinna Vinschen
  0 siblings, 0 replies; only message in thread
From: Corinna Vinschen @ 2023-09-09 21:29 UTC (permalink / raw)
  To: cygwin-cvs

https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=c0aa6ac30ec483ad6da6af701625e7aea7536663

commit c0aa6ac30ec483ad6da6af701625e7aea7536663
Author:     Corinna Vinschen <corinna@vinschen.de>
AuthorDate: Sat Sep 9 23:23:52 2023 +0200
Commit:     Corinna Vinschen <corinna@vinschen.de>
CommitDate: Sat Sep 9 23:28:55 2023 +0200

    Cygwin: NFS: create devices (especially FIFOs) as shortcut files
    
    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:
    
    - 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.
    
    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.
    
    Fixes: 622fb0776ea3 ("Cygwin: enable usage of FIFOs on NFS")
    Signed-off-by: Corinna Vinschen <corinna@vinschen.de>

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/disk_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 = (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 = 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 = 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 = 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 = 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] != ':' || contents[1] != '\\'
 		   || !parse_device (contents))
 	    break;
+	  if (fs.is_nfs () && major == _major (FH_FIFO))
+	    {
+	      conv_hdl.nfsattr ()->type = NF3FIFO;
+	      conv_hdl.nfsattr ()->mode = mode;
+	      conv_hdl.nfsattr ()->size = 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 = NF3FIFO;
+	    }
 	}
 
       /* If searching for `foo' and then finding a `foo.lnk' which is

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-09-09 21:29 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-09 21:29 [newlib-cygwin/main] Cygwin: NFS: create devices (especially FIFOs) as shortcut files Corinna Vinschen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).