| delorie.com/archives/browse.cgi | search |
| DMARC-Filter: | OpenDMARC Filter v1.4.2 delorie.com 57BNZvTg1318132 |
| Authentication-Results: | delorie.com; dmarc=pass (p=none dis=none) header.from=cygwin.com |
| Authentication-Results: | delorie.com; spf=pass smtp.mailfrom=cygwin.com |
| DKIM-Filter: | OpenDKIM Filter v2.11.0 delorie.com 57BNZvTg1318132 |
| Authentication-Results: | delorie.com; |
| dkim=pass (1024-bit key, unprotected) header.d=cygwin.com header.i=@cygwin.com header.a=rsa-sha256 header.s=default header.b=CcHQS3ih | |
| X-Recipient: | archive-cygwin AT delorie DOT com |
| DKIM-Filter: | OpenDKIM Filter v2.11.0 sourceware.org A02013858CB6 |
| DKIM-Signature: | v=1; a=rsa-sha256; c=relaxed/relaxed; d=cygwin.com; |
| s=default; t=1754955355; | |
| bh=S0+d4ZRpE/GuVTBAZS9ZKjEd2e7zGJ9sgvf4Jk30ao8=; | |
| h=Date:To:Subject:In-Reply-To:References:List-Id:List-Unsubscribe: | |
| List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: | |
| From; | |
| b=CcHQS3ihrhpuEfP7VV3H+eJWGdmVjvqBTivOoH6qmWym2KCriOdBY4MuTDl6+eS2K | |
| q0lc9Fkz/qWWPXGFJRWrpEmluWUOGWjxTCs7o7C5H1DDepYYg1U6aGF0nNtv/HuZnX | |
| 6Nq1EDW6CxdyNk+GIplsVbAK+eTas37HRPjROJ34= | |
| X-Original-To: | cygwin AT cygwin DOT com |
| Delivered-To: | cygwin AT cygwin DOT com |
| DMARC-Filter: | OpenDMARC Filter v1.4.2 sourceware.org 73E173858D38 |
| ARC-Filter: | OpenARC Filter v1.0.0 sourceware.org 73E173858D38 |
| ARC-Seal: | i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1754955294; cv=none; |
| b=EfpAKUoDrJrUObGWA7Kyt7eZCCCNRWkFxsXDKR3S5BEaC0DzrIb9iWxo3v7SbVI/2oDDETASdgECziitOXTPHMIPLxtNKgdpOB7okWVrFNWwiejY+5ToRDpnhAtE/eS69jfzB+eBmhn+wIf18E/hRlyqAB8Ko0mM6bl7W3g8/pQ= | |
| ARC-Message-Signature: | i=1; a=rsa-sha256; d=sourceware.org; s=key; |
| t=1754955294; c=relaxed/simple; | |
| bh=8iKHwf4zyNJISecrjpnFRIyf+YLAyRErCvCFfV9COiM=; | |
| h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; | |
| b=wU1BOJ4fqJs9SE4HVBk43qWxhdP8iL6+3lZvvr9D3UTFX/A43/y6Ae6FbqYQkbmMgMRABs3CbxosLfpNhY1sVzesLk3XccTPeiMifBEN6ZCCP8d0a/HVnBklsMS1pNAtADhV2lzJdIR19F//Syw0tLUiFLF7xqbpuGTzJzSEcaA= | |
| ARC-Authentication-Results: | i=1; server2.sourceware.org |
| DKIM-Filter: | OpenDKIM Filter v2.11.0 sourceware.org 73E173858D38 |
| Date: | Mon, 11 Aug 2025 16:34:53 -0700 (PDT) |
| X-X-Sender: | jeremyd AT resin DOT csoft DOT net |
| To: | Cygwin <cygwin AT cygwin DOT com> |
| Subject: | Re: getting the on-disk case for a path |
| In-Reply-To: | <81c4de12-856c-2d1d-d6bf-ee0fe96f3429@jdrake.com> |
| Message-ID: | <c5e53703-e4d3-9c5a-ceab-32e3edbc9a3e@jdrake.com> |
| References: | <36a0093c-fc8b-f268-9cbf-71c1c1268ef7 AT jdrake DOT com> |
| <11a5bd41-e977-4f25-9bf8-4917f1c65934 AT towo DOT net> | |
| <585f65a8-a675-4a1e-a774-5dc4ff2337f8 AT systematicsw DOT ab DOT ca> | |
| <81c4de12-856c-2d1d-d6bf-ee0fe96f3429 AT jdrake DOT com> | |
| MIME-Version: | 1.0 |
| X-Content-Filtered-By: | Mailman/MimeDel 2.1.30 |
| X-BeenThere: | cygwin AT cygwin DOT com |
| X-Mailman-Version: | 2.1.30 |
| List-Id: | General Cygwin discussions and problem reports <cygwin.cygwin.com> |
| List-Unsubscribe: | <https://cygwin.com/mailman/options/cygwin>, |
| <mailto:cygwin-request AT cygwin DOT com?subject=unsubscribe> | |
| List-Archive: | <https://cygwin.com/pipermail/cygwin/> |
| List-Post: | <mailto:cygwin AT cygwin DOT com> |
| List-Help: | <mailto:cygwin-request AT cygwin DOT com?subject=help> |
| List-Subscribe: | <https://cygwin.com/mailman/listinfo/cygwin>, |
| <mailto:cygwin-request AT cygwin DOT com?subject=subscribe> | |
| From: | Jeremy Drake via Cygwin <cygwin AT cygwin DOT com> |
| Reply-To: | Jeremy Drake <cygwin AT jdrake DOT com> |
| Errors-To: | cygwin-bounces~archive-cygwin=delorie DOT com AT cygwin DOT com |
| Sender: | "Cygwin" <cygwin-bounces~archive-cygwin=delorie DOT com AT cygwin DOT com> |
| X-MIME-Autoconverted: | from base64 to 8bit by delorie.com id 57BNZvTg1318132 |
On Fri, 8 Aug 2025, Jeremy Drake via Cygwin wrote:
> On Fri, 8 Aug 2025, Brian Inglis via Cygwin wrote:
>
> > On 2025-08-08 00:53, Thomas Wolff via Cygwin wrote:
> > > Am 08.08.2025 um 02:31 schrieb Jeremy Drake via Cygwin:
> > >> On a case-insensitive but case-preserving filesystem, is there a Cygwin
> > >> API to get the on-disk case for a given path? It seems like `realpath`
> > >> ought to do it but running
> > >> $ touch case-test
> > >> $ realpath CASE-TEST
> > >> returns CASE-TEST.
> > > On the command line, you could use
> > > ls | grep -i
> > >
> > >> Regardless, canonicalize_file_name or realpath may not
> > >> be what I want because it would dereference symlinks.
> > >>
> > >> Background: I'm trying to debug some test failures in Clang, due to a
> > >> warning that's supposed to be issued when you #include "foo.h" but the
> > >> file on disk that it opened is "Foo.h".
> >
> > Looks like if you use wildcards, it should work correctly:
> >
> > $ lsattr -dl .
> > . ---
> > $ l *_exit*
> > _Exit.2 _exit.3
> > $ l _exit.?
> > _Exit.2 _exit.3
> > $ l _exit.[23]
> > _Exit.2 _exit.3
> > $ l *EXIT-TEST*
> > exit-test
> > $ l *exit*
> > _Exit.2 _exit.3 EXIT exit-test
> >
> > also, you could just opendir(3)/readdir(3)/closedir(3) and strcasecmp(3).
> >
>
> Yeah, globbing is opendir/readdir/closedir, but it'd have to be done on
> each path component to recover the on-disk case for a path. I'll explain
> now that I have a better idea what clang is doing under the hood.
>
> llvm has an API that opens a file with an out parameter for the "real"
> path. On Windows, it uses GetFinalPathNameByHandleW
> (FILE_NAME_NORMALIZED|VOLUME_NAME_DOS), with some massaging for UNC. On
> Unix, it first would prefer fcntl with F_GETPATH. It doesn't look like
> Cygwin provides that. If that's not available, available, it tries
> readlink on /proc/self/fd/%d. If that's not available, it falls back to
> realpath on the name input. I had a breakpoint on realpath that was not
> hit, so it appears that readlink is what it's doing.
>
I came up with this hack that seems to work. It's pretty stupid, but
maybe a start of a discussion? Maybe it'd make more sense to factor out
the GetFinalPathNameByHandleW-handling code from symlink_info::check and
call that to convert it to a posix path?
diff --git a/winsup/cygwin/fhandler/base.cc b/winsup/cygwin/fhandler/base.cc
index 5321ad7ff1..cbdd20d743 100644
--- a/winsup/cygwin/fhandler/base.cc
+++ b/winsup/cygwin/fhandler/base.cc
@@ -29,6 +29,7 @@ details. */
#include "shared_info.h"
#include <asm/socket.h>
#include "cygwait.h"
+#include "tls_pbuf.h"
static const int CHUNK_SIZE = 1024; /* Used for crlf conversions */
@@ -133,6 +134,27 @@ char *fhandler_base::get_proc_fd_name (char *buf)
stpcpy (stpcpy (buf, get_name ()), " (deleted)");
return buf;
}
+ if (get_device () == FH_FS && get_name ())
+ {
+ tmp_pathbuf tp;
+ PWCHAR fpbuf = tp.w_get ();
+ DWORD ret;
+
+ ret = GetFinalPathNameByHandleW (get_handle (), fpbuf, NT_MAX_PATH, 0);
+ if (ret)
+ {
+ PWCHAR ubuf = tp.w_get ();
+ UNICODE_STRING uc = {2, 2, ubuf + sys_mbstowcs (ubuf, NT_MAX_PATH, get_name ())},
+ fc = {2, 2, fpbuf + ret + 1};
+ while (--uc.Buffer >= ubuf && --fc.Buffer >= fpbuf &&
+ (RtlCompareUnicodeString (&uc, &fc, TRUE) == 0 ||
+ (iswdirsep (*uc.Buffer) && iswdirsep (*fc.Buffer))))
+ if (!iswdirsep (*uc.Buffer))
+ *uc.Buffer = *fc.Buffer;
+ sys_wcstombs (buf, NT_MAX_PATH, ubuf);
+ return buf;
+ }
+ }
if (get_name ())
return strcpy (buf, get_name ());
if (dev ().name ())
--
Problem reports: https://cygwin.com/problems.html
FAQ: https://cygwin.com/faq/
Documentation: https://cygwin.com/docs.html
Unsubscribe info: https://cygwin.com/ml/#unsubscribe-simple
| webmaster | delorie software privacy |
| Copyright © 2019 by DJ Delorie | Updated Jul 2019 |