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

commit 890086ad3704fc1aaedca96d3bf67448e7a66775
Author:     Corinna Vinschen <[email protected]>
AuthorDate: Tue Jan 21 17:16:56 2025 +0100
Commit:     Corinna Vinschen <[email protected]>
CommitDate: Tue Jan 21 17:31:13 2025 +0100

    Cygwin: path_conv: simplify, rearrange, rename combined device checks
    
    Some checks in path_conv are checking for various properties
    to generate a boolean value, mostly to indicate different
    combinations of on-disk files and devices.
    
    Simplify these checks and, especially, document them inline.
    
    Drop the isdevice() check in favor of a new isondisk() check.
    
    Fixes: 4fc922b2c8a5 ("Cygwin: POSIX msg queues: Convert mqd_t to a 
descriptor")
    Signed-off-by: Corinna Vinschen <[email protected]>

Diff:
---
 winsup/cygwin/local_includes/path.h | 26 +++++++++++++++++++-------
 winsup/cygwin/path.cc               |  3 +--
 winsup/cygwin/syscalls.cc           |  2 +-
 3 files changed, 21 insertions(+), 10 deletions(-)

diff --git a/winsup/cygwin/local_includes/path.h 
b/winsup/cygwin/local_includes/path.h
index 2a05cf44d40a..924c93eed006 100644
--- a/winsup/cygwin/local_includes/path.h
+++ b/winsup/cygwin/local_includes/path.h
@@ -214,21 +214,33 @@ class path_conv
   {
     return (path_flags & (PATH_REP | PATH_REP_NOAPI)) == PATH_REP;
   }
-  int isdevice () const {return dev.not_device (FH_FS) && dev.not_device 
(FH_FIFO);}
+
   int isfifo () const {return dev.is_device (FH_FIFO);}
-  int isspecial () const {return dev.not_device (FH_FS);}
   int iscygdrive () const {return dev.is_device (FH_CYGDRIVE);}
-  int is_fs_special () const {return dev.is_fs_special ();}
-
-  int is_lnk_special () const {return (isdevice () && is_fs_special ()
-                                      && !issocket ())
-      || isfifo () || is_lnk_symlink ();}
 #ifdef __WITH_AF_UNIX
   int issocket () const {return dev.is_device (FH_LOCAL)
                                || dev.is_device (FH_UNIX);}
 #else
   int issocket () const {return dev.is_device (FH_LOCAL);}
 #endif /* __WITH_AF_UNIX */
+
+  /* FIXME: This needs a cleanup with better, descriptive names and checking
+     all usages for correctness. */
+
+  /* Any file or device with representation on disk.  This includes local
+     sockets, FIFOs, message queues and devices created with mknod.  It does
+     not include the /proc hierarchy. */
+  int isondisk () const {return dev.isfs ();}
+  /* Any device, virtual or with on-disk representation, and anything under
+     /proc. */
+  int isspecial () const {return dev.not_device (FH_FS);}
+  /* Devices with representation on disk. This includes local sockets, FIFOs,
+     message queues and devices created with mknod.  It does not include
+     the /proc hierarchy. */
+  int is_fs_special () const {return dev.is_fs_special ();}
+  /* Like is_fs_special but excluding local sockets. */
+  int is_lnk_special () const {return is_fs_special () && !issocket ();}
+
   int iscygexec () const {return mount_flags & MOUNT_CYGWIN_EXEC;}
   int isopen () const {return path_flags & PATH_OPEN;}
   int isctty_capable () const {return path_flags & PATH_CTTY;}
diff --git a/winsup/cygwin/path.cc b/winsup/cygwin/path.cc
index 452b4034ac89..c10f2e8e1bd8 100644
--- a/winsup/cygwin/path.cc
+++ b/winsup/cygwin/path.cc
@@ -2080,8 +2080,7 @@ symlink_worker (const char *oldpath, path_conv 
&win32_newpath, bool isdevice)
       syscall_printf ("symlink (%s, %S) wsym_type %d", oldpath,
                      win32_newpath.get_nt_native_path (), wsym_type);
 
-      if ((!isdevice && win32_newpath.exists ())
-         || (win32_newpath.isdevice () && !win32_newpath.is_fs_special ()))
+      if (win32_newpath.exists() && (!isdevice || !win32_newpath.isondisk ()))
        {
          set_errno (EEXIST);
          __leave;
diff --git a/winsup/cygwin/syscalls.cc b/winsup/cygwin/syscalls.cc
index 00ad04088986..52a5601d2c9a 100644
--- a/winsup/cygwin/syscalls.cc
+++ b/winsup/cygwin/syscalls.cc
@@ -1136,7 +1136,7 @@ unlink (const char *ourname)
       set_errno (EROFS);
       goto done;
     }
-  if (isdevfd_dev (devn) || (win32_name.isdevice () && !win32_name.issocket 
()))
+  if (!win32_name.isondisk ())
     {
       set_errno (EPERM);
       goto done;

Reply via email to