Skip to content

Commit

Permalink
Cygwin: path_conv: simplify, rearrange, rename combined device checks
Browse files Browse the repository at this point in the history
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: 4fc922b ("Cygwin: POSIX msg queues: Convert mqd_t to a descriptor")
Signed-off-by: Corinna Vinschen <[email protected]>
  • Loading branch information
github-cygwin committed Jan 21, 2025
1 parent d870655 commit 890086a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 10 deletions.
26 changes: 19 additions & 7 deletions winsup/cygwin/local_includes/path.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;}
Expand Down
3 changes: 1 addition & 2 deletions winsup/cygwin/path.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion winsup/cygwin/syscalls.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 890086a

Please sign in to comment.