aboutsummaryrefslogtreecommitdiff
path: root/winsup/cygwin/path.cc
AgeCommit message (Collapse)AuthorFilesLines
2025-02-03Cygwin: factor out code to resolve a symlink target.Jeremy Drake via Cygwin-patches1-34/+28
This code was duplicated between the lnk symlink type and the native symlink type. Signed-off-by: Jeremy Drake <cygwin@jdrake.com>
2025-01-27Cygwin: message queues are not devicesCorinna Vinschen1-4/+1
Message queues are basically just files and in most cases can be handled like normal files. So it was a mistake to set the "on-disk-device" flag for them to fix the mq_unlink() problem reported in https://cygwin.com/pipermail/cygwin/2025-January/257119.html Rather, given that unlink() just checks if the object to be deleted has an on-disk representation, make sure message queues are added to the path_conv::isondisk() predicate. This also reverts commit d870655f570f25393dcefbaf0b1dc807f277749c. Fixes: d870655f570f ("Cygwin: path_conv: set on-disk-device flag for message queue files") Reported-by: Christian Franke <Christian.Franke@t-online.de> Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2025-01-21Cygwin: path_conv: simplify, rearrange, rename combined device checksCorinna Vinschen1-2/+1
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 <corinna@vinschen.de>
2025-01-21Cygwin: path_conv: set on-disk-device flag for message queue filesCorinna Vinschen1-1/+4
This simplifies further checks for on-disk-devices in places with special handling for such files. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-11-28Cygwin: cache IsWow64Process2 host arch in wincap.Jeremy Drake1-4/+2
This was already used in the FAST_CWD check, and could be used in a couple other places. I found the "emulated"/process value returned from the function largely useless, so I did not cache it. It is useless because, as the docs say, it is set to IMAGE_FILE_MACHINE_UNKNOWN (0) if the process is not running under WOW64, but Microsoft also doesn't consider x64-on-ARM64 to be WOW64, so it is set to 0 regardless if the process is ARM64 or x64. You can tell the difference via GetProcessInformation(ProcessMachineTypeInfo), but for the current process even that's overkill: what we really want to know is the IMAGE_FILE_MACHINE_* constant for the Cygwin dll itself, which is conveniently located in memory already, so cache that in wincap also for easy comparisons. Signed-off-by: Jeremy Drake <cygwin@jdrake.com>
2024-04-04Cygwin: FILE_OPEN_NO_RECALL is incompatible with FILE_DIRECTORY_FILECorinna Vinschen1-2/+0
If FILE_DIRECTORY_FILE is given, FILE_OPEN_NO_RECALL is not allowed, otherwise NtCreateFile returns STATUS_INVALID_PARAMETER. Drop FILE_OPEN_NO_RECALL where FILE_DIRECTORY_FILE is specified. Fixes: f6b56abec186 ("Cygwin: try to avoid recalling offline files") Reported-by: Bruce Jerrick <bmj001@gmail.com> Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-04-02Cygwin: fhandler_virtual: move fileid to path_conv memberCorinna Vinschen1-0/+2
Commit 80f722e97cf7 ("Cygwin: opendir(3): move ENOTDIR check into main function") introduced a bug in fhandler_virtual handling. While the assertion that path_conv::check() already calls exists() and sets FILE_ATTRIBUTE_DIRECTORY accordingly, the exists() function is called on a fhandler_virtual object created for just this code snippet. The side effect of this is that the fileid member in the calling fhandler_virtual object is not set after path_conv::check(). Move the fhandler_virtual::fileid member to path_conv::_virt_fileid and create matching path_conv::virt_fileid() and fhandler_virtual::fileid() methods. Let path_conv::check() propagate the fileid set in the local fhandler_virtual::exists() call to its own _virt_fileid. Use new fhandler_virtual::fileid() method throughout. Fixes: 80f722e97cf7 ("Cygwin: opendir(3): move ENOTDIR check into main function") Reported-by: Bruce Jerrick <bmj001@gmail.com> Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-03-08Cygwin: try to avoid recalling offline filesCorinna Vinschen1-5/+14
Chances are high that Cygwin recalls offline files from remote storage, even if the file is only accessed during stat(2) or readdir(3). To avoid this - make sure Cygwin is placeholder-aware, - open files in path_conv handling, as well as in stat(2)/readdir(3) scenarios with FILE_OPEN_NO_RECALL, and - during symlink checking or testing for executablility, don't even try to open the file if one of the OFFLINE attributes is set. Reported-by: Marcin Wisnicki <mwisnicki@gmail.com> Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-02-13Cygwin: find_fast_cwd: don't run assembler checking code on ARM64Corinna Vinschen1-15/+13
https://cygwin.com/pipermail/cygwin/2024-February/255397.html reports a crash on ARM64 probably related to checking x86_64 code on the x86_64 emulator on AArch64. At least for testing, pull the code checking the host HW up to be called before trying to evaluate assembler code. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-01-31Cygwin: path: convert symlink_info to classCorinna Vinschen1-140/+165
encapsulate everything Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-01-31Cygwin: files: slightly simplify suffix handlingCorinna Vinschen1-21/+15
- drop appending .exe.lnk to files - drop exe_suffixes, it's the same as stat_suffixes for a long time Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-01-11Cygwin: path.cc: fix comment starting with // but ending in */Corinna Vinschen1-1/+1
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2023-10-30Cygwin: cwd: avoid releasing the cwdstuff SRW Lock twiceCorinna Vinschen1-2/+1
cwdstuff::set has a code snippet handling the case where a process can't create a handle to a directory, e. g., due to permissions. Commit 88443b0a22589 ("cwdstuff: Don't leave from setting the CWD prematurely on init") introduced a special case to handle this situation at process initialization. It also introduces an early mutex release, which is not required, but ok, because we're in the init phase. Releasing the mutex twice is no problem since the mutexes are recursive. Fast forward to commit 0819679a7a210 ("Cygwin: cwd: use SRWLOCK instead of muto"). The mechanical change from a recursive mutex to a non-recursive SRWLOCK failed to notice that this very specific situation will release the SRWLOCK twice. Remove the superfluous release action. While at it, don't set dir to NULL, but h, since dir will get the value of h anyway later on. Setting h to NULL may not be necessary, but better safe than sorry. Reported-by: tryandbuy >tryandbuy@proton.me> Fixes: 88443b0a22589 ("cwdstuff: Don't leave from setting the CWD prematurely on init") Fixes: 0819679a7a210 ("Cygwin: cwd: use SRWLOCK instead of muto") Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2023-09-09Cygwin: NFS: remove recognizing native symlinks as FIFOsCorinna Vinschen1-15/+0
Given the downsides of NFS symlinks as FIFOs, drop the code added to recognize them as such. Fixes: 622fb0776ea3 ("Cygwin: enable usage of FIFOs on NFS") Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2023-09-09Cygwin: NFS: create devices (especially FIFOs) as shortcut filesCorinna Vinschen1-1/+11
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>
2023-09-09Cygwin: NFS: fetch actual DOS attributesCorinna Vinschen1-1/+1
MSFT NFSv3 fakes DOS attributes based on file type and permissions. Rather than just faking FILE_ATTRIBUTE_DIRECTORY for dirs, fetch the "real" DOS attributes returned by NFS. This allows to handle the "R/O" attribute on shortcut files and thus reading and creating device shortcut files on NFS. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2023-09-04Cygwin: enable usage of FIFOs on NFSCorinna Vinschen1-4/+34
FIFOs on NFS were never recogized as such in path handling. 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. Basically for the same reason, Cygwin-created FIFOs were just treated as symlinks with weird content by stat(2) as well as path handling. Add code to enable both types of FIFOs on NFS as Cygwin FIFOs. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2023-05-24Cygwin: Adjust CWD magic to accommodate for the latest Windows previewsJohannes Schindelin1-3/+17
Reportedly Windows 11 build 25*** from Insider changed the current working directory logic a bit, and Cygwin's "magic" (or: "technologically sufficiently advanced") code needs to be adjusted accordingly. This fixes https://github.com/git-for-windows/git/issues/4429 Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2023-03-29Cygwin: dirname: fix handling of leading slashesCorinna Vinschen1-1/+1
Per https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/xbd_chap04.html: "A pathname that begins with two successive slashes may be interpreted in an implementation-defined manner, although more than two leading slashes shall be treated as a single slash." So more than 2 leading slashes are supposed to be folded into one, which our dirname neglected. Fix that. Fixes: 24e8fc6872a3b ("* cygwin.din (basename): Export.") Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2022-12-21Cygwin: path_conv: make sure sym.path_flags is always initializedCorinna Vinschen1-1/+1
Commit c1023ee353705 introduced a split between mount flags and path flags. It didn't initialize symlink_info::path_flags in path_conv::check, because that's done in symlink_info::check. However, there are two code paths expecting symlink_info::path_flags being already initialized and both skip symlink_info::check. Make sure symlink_info::path_flags is initalized to 0 early in path_conv::check. Fixes: c1023ee353705 ("Cygwin: path_conv: decouple path_types from mount types") Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2022-12-20Cygwin: check_reparse_point_target: fix comment formatCorinna Vinschen1-4/+4
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2022-12-12Cygwin: path handling: never substitute virtual drive with target pathCorinna Vinschen1-62/+87
Move the drive substitution code after the call to GetFinalPathNameByHandleW into a local function revert_virtual_drive and add code to handle non-remote virtual drives, i. e., those created with the subst command. (Try to) make sure that virtual drives are never treated like symlinks. Fixes: 19d59ce75d53 ("Cygwin: path_conv: Rework handling native symlinks as inner path components") Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2022-12-04Cygwin: simplify FAST_CWD accessCorinna Vinschen1-132/+33
Dropping Windows 7 and 8 also drops the need to handle three different FAST_CWD structures. Simplify code accordingly. While at it, use dynamic allocation of the FAST_CWD structure based on the length of the CWD path. This may help in future to enable working with systems and native apps with long paths enabled (Win 10 1607 and later), see https://learn.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation?tabs=registry#enable-long-paths-in-windows-10-version-1607-and-later Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2022-08-23Cygwin: cwd: use SRWLOCK instead of mutoCorinna Vinschen1-11/+9
To reduce thread contention, use reader/writer locks as required. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2022-08-09Cygwin: fix return value of symlink_info::checkKen Brown1-13/+9
Currently it is possible for symlink_info::check to return -1 in case we're searching for foo and find foo.lnk that is not a Cygwin symlink. This contradicts the new meaning attached to a negative return value in commit 19d59ce75d. Fix this by setting "res" to 0 at the beginning of the main loop and not seting it to -1 later. Also fix the commentary preceding the function definition to reflect the current behavior. Addresses: https://cygwin.com/pipermail/cygwin/2022-August/252030.html
2022-08-05Cygwin: drop last usage of RtlCreateUnicodeStringFromAsciizCorinna Vinschen1-2/+4
This function is just bad. It really only works for ASCII chars, everything else is broken after the conversion. Introduce new helper function sys_mbstouni to replace RtlCreateUnicodeStringFromAsciiz in hash_path_name. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2022-08-03Cygwin: path: Make some symlinks to /cygdrive/* work.Takashi Yano1-1/+5
- Previously, some symbolic links to /cygdrive/* (e.g. /cygdrive/C, /cygdrive/./c, /cygdrive//c, etc.) did not work. This patch fixes the issue. Addresses: https://cygwin.com/pipermail/cygwin/2022-July/251994.html
2022-05-29Cygwin: remove miscellaneous 32-bit codeKen Brown1-102/+0
2022-05-29Cygwin: remove some 32-bit only path conversion functionsKen Brown1-64/+0
2022-05-29Cygwin: remove regparm.hKen Brown1-6/+6
This file defines the macros __reg1, __reg2, and __reg3, which are defined to be empty on 64-bit Cygwin. Remove all occurrences of these macros.
2022-05-29Cygwin: simplify some function namesKen Brown1-2/+2
Remove "32" or "64" from each of the following names: acl32, aclcheck32, aclfrommode32, aclfrompbits32, aclfromtext32, aclsort32, acltomode32, acltopbits32, acltotext32, facl32, fchown32, fcntl64, fstat64, _fstat64, _fstat64_r, ftruncate64, getgid32, getgrent32, getgrgid32, getgrnam32, getgroups32, getpwuid32, getpwuid_r32, getuid32, getuid32, initgroups32, lseek64, lstat64, mknod32, mmap64, setegid32, seteuid32, setgid32, setgroups32, setregid32, setreuid32, setuid32, stat64, _stat64_r, truncate64. Remove prototypes and macro definitions of these names. Remove "#ifndef __INSIDE_CYGWIN__" from some headers so that the new names will be available when compiling Cygwin. Remove aliases that are no longer needed. Include <unistd.h> in fhandler_clipboard.cc for the declarations of geteuid and getegid.
2022-05-13Cygwin: drop a few minor references to WOW64Corinna Vinschen1-2/+1
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2022-05-13Cygwin: wincap: drop wow64 flag and all conditions depending on itCorinna Vinschen1-22/+0
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2022-03-14Cygwin: path: Convert type of variable 'remlen' to DWORD.Takashi Yano1-2/+1
- Variable remlen stores the return value of QueryDosDeviceW(), so it is better to be DWORD.
2022-03-14Cygwin: path: Add fallback for DFS mounted drive.Takashi Yano1-5/+12
- If UNC path for DFS is mounted to a drive with drive letter, the error "Too many levels of symbolic links" occurs when accessing to that drive. This is because GetDosDeviceW() returns unexpected string such as "\Device\Mup\DfsClient\;Z:000000000003fb89\dfsserver \dfs\linkname" for the mounted UNC path "\??\UNC\fileserver\share". This patch adds a workaround for this issue. Addresses: https://cygwin.com/pipermail/cygwin/2022-March/250979.html
2022-02-03Cygwin: path: Fix UNC path handling for SMB3 mounted to a drive.Takashi Yano1-2/+11
- If an UNC path is mounted to a drive using SMB3.11, accessing to the drive fails with error "Too many levels of symbolic links." This patch fixes the issue.
2022-01-18Cygwin: path_conv: do not get confused by a directory with `.lnk` suffixJohannes Schindelin1-0/+1
When trying to create a directory called `xyz` in the presence of a directory `xyz.lnk`, the Cygwin runtime errors out with an `ENOENT`. The root cause is actually a bit deeper: the `symlink_info::check()` method tries to figure out whether the given path refers to a symbolic link as emulated via `.lnk` files, but since it is a directory, that is not the case, and that hypothesis is rejected. However, the `fileattr` field is not cleared, so that a later `.exists()` call on the instance mistakenly thinks that the symlink actually exists. Let's clear that field. This fixes https://github.com/msys2/msys2-runtime/issues/81 Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2021-12-11Cygwin: path: Fix path conversion of virtual drive.Takashi Yano1-21/+35
- The last change in path.cc introduced a bug that causes an error when accessing a virtual drive which mounts UNC path such as "\\server\share\dir" rather than "\\server\share". This patch fixes the issue.
2021-12-08Cygwin: path: Convert UNC path prefix back to drive letter.Takashi Yano1-1/+36
- When symlink_info::check() is called with the path having drive letter and UNC path is mounted to the drive, the path is replaced with UNC path. With this patch, UNC path prefix is converted back to drive letter. This fixes the issue: https://cygwin.com/pipermail/cygwin/2021-November/250087.html https://cygwin.com/pipermail/cygwin/2021-December/250103.html
2021-11-16Revert "Cygwin: set the FILE_ATTRIBUTE_ARCHIVE DOS attribute on file creation"Corinna Vinschen1-2/+2
This reverts commit 2b28977149b1e8858b597890906f21cdecde84ce. This patch fixes the symptoms, but not the actual problem. Revert and try again.
2021-11-15Cygwin: set the FILE_ATTRIBUTE_ARCHIVE DOS attribute on file creationCorinna Vinschen1-2/+2
Do this for normal files and symlinks, not for temporary files, device files or unix sockets. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-07-30Cygwin: Add winsymlinks:sysJon Turney1-1/+2
Add winsymlinks:sys, to explicitly select always using plain files with the system attribute containing a magic cookie to represent a symlink.
2021-07-30Cygwin: Rename WSYM_sysfile to WSYM_defaultJon Turney1-3/+3
Rename WSYM_sysfile to WSYM_default, since it selects more than just sysfile with magic cookie now.
2021-07-07Cygwin: respect PC_SYM_FOLLOW and PC_SYM_NOFOLLOW_REP with inner links.Jeremy Drake1-43/+45
The new GetFinalPathNameW handling for native symlinks in inner path components is disabled if caller doesn't want to follow symlinks, or doesn't want to follow reparse points.
2021-07-06Revert "Cygwin: Handle virtual drives as non-symlinks"Jeremy Drake1-2/+7
This reverts commit c8949d04001e3dbc03651475b6cd1c5623400835.
2021-05-25Cygwin: path_conv: fix mqueue path checkCorinna Vinschen1-15/+7
The check for a file or dir within /dev/mqueue is accidentally using the incoming path, which could be a relative path. Make sure to restore the absolute POSIX path in path_copy and only then test the path. Also, move the actual check for a valid path below /dev/mqueue into the fhandler_mqueue class. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-05-25Cygwin: cwdstuff: check if /dev existsCorinna Vinschen1-2/+18
/dev has been handled as virtual dir in cwdstuff, thus not allowing to start native apps from /dev as CWD, even if /dev actually exists on disk. Unfortunately this also affects Cygwin executables started from a debugger. When chdir'ing to /dev, check if /dev exists on disk. If so, treat it as any other existing path. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-05-25Cygwin: POSIX msg queues: implement open/mq_open entirely in fhandlerCorinna Vinschen1-0/+12
The mq_open call is just a framework now. This patch moves the entire functionality into fhandler_mqueue. To support standard OS calls (as on Linux), make fhandler_mqueue a derived class from fhandler_disk_file and keep the base handle the handle to the default stream, to allow implementing O_PATH functionlaity as well as reading from the file and NOT reading binary message queue data. Implement a standard fhandler_mqueue::open method, allowing, for instance, to touch a file under /dev/mqueue and if it doesn't exist, to create a message queue file. FIXME: This introduces a BAD HACK into path_conv::check, which needs reviewing. Keep the posix path intact in the fhandler, and change get_proc_fd_name accordingly to return only the basename plus leading slash for /proc/<PID>/fd. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-05-25Cygwin: get_nt_native_path: allow to append suffixCorinna Vinschen1-1/+7
POSIX message queues will be moved into NTFS streams. Extend get_nt_native_path to provide a filename suffix which is not subject to special character transposition, to allow specifying a colon. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-05-19Cygwin: suppress FAST_CWD warnings on ARM64Jeremy Drake1-24/+9
The old check was insufficient: new insider preview builds of Windows allow running x86_64 process on ARM64. The IsWow64Process2 function seems to be the intended way to figure this situation out.