简体   繁体   English

谁来处理Cygwin中的路径

[英]Who handles the paths in Cygwin

I am curious to find out who handles the paths in cygwin. 我很好奇,找出谁处理了Cygwin中的路径。

For instance if I do the following, it works: 例如,如果我执行以下操作,它将起作用:

cd C:\

However when I do: 但是,当我这样做时:

$ pwd
/cygdrive/c

Who is responsible for the discrepancy here? 谁负责这里的差异? The reason I am curious is that "cd C:" among'st other tools accept windows paths but when it comes to displaying them they show something different. 我很好奇的原因是,“ cd C:”以及其他工具都接受Windows路径,但是在显示它们时,它们却显示出不同的东西。

If I do include the cygwin bin folder in my path (under regular cmd) then I know it all works as in cmd, so what is it thats causing this convertion, is it the bash/shell? 如果我确实在路径中(在常规cmd下)包含cygwin bin文件夹,那么我知道它们都可以在cmd中正常工作,那么是什么导致了这种转换,是bash / shell吗?

I am curious to find out who handles the paths in cygwin. 我很好奇,找出谁处理了Cygwin中的路径。

Largely, a small bit of C++ code in winsup/cygwin/path.cc . 在很大程度上,在winsup/cygwin/path.cc有一小部分C ++代码。 A particularly important function is normalize_posix_path . 一个特别重要的功能是normalize_posix_path This code ends up compiled in the DLL cygwin1.dll which is used by all Cygwin applications. 该代码最终在所有Cygwin应用程序使用的DLL cygwin1.dll进行编译。

All paths in Cygwin are "POSIX" paths resolved by the Cygwin DLL itself. Cygwin中的所有路径都是由Cygwin DLL本身解析的“ POSIX”路径。 The normalize_posix_path function recognizes the presence of certain syntax in paths (drive letter names and backslashes), and arranges for them to be treated as "Win32 paths". normalize_posix_path函数可识别路径中某些语法的存在(驱动器号名称和反斜杠),并将它们安排为“ Win32路径”。

That is the reason why you can feed c:/Users/... to a Cygwin program, as an alternative to /cygdrive/c/Users/... . 这就是为什么您可以将c:/Users/...馈送到Cygwin程序,以替代/cygdrive/c/Users/...

$ pwd

/cygdrive/c

How this works is that Cygwin maintains a native Win32 current working directory, and so it knows perfectly well that this is C:\\ . Cygwin的工作方式是维护一个本地Win32当前工作目录,因此非常清楚这是C:\\ However, this native information is mapped backwards to a POSIX path. 但是,此本机信息向后映射到POSIX路径。 Cygwin does this by scanning through its mount table where it sees that C:\\ is "mounted" as /cygdrive/c . Cygwin通过扫描其挂载表来完成此操作,在该表中可以看到C:\\被“挂载”为/cygdrive/c (The pwd utility is just reporting what Cygwin's implementation of the POSIX getcwd function is returning. The backwards mapping happens inside that function). pwd实用工具仅报告Cygwin的POSIX getcwd函数的实现返回什么。向后映射发生在该函数内部)。 Note that since Cygwin is operating in a virtual POSIX namespace created by its mount table, that space contains abstract places which have no Win32 native counterpart. 请注意,由于Cygwin在由其装入表创建的虚拟POSIX名称空间中运行,因此该空间包含没有Win32本机副本的抽象位置。 For instance, you can cd to the /dev directory where you have entries like tty . 例如,您可以cd/dev目录,其中有tty条目。 This has no native location, and so getcwd will just report the POSIX path. 它没有本机位置,因此getcwd将仅报告POSIX路径。 Cygwin tries to keep the Cygwin-internal current working directory in sync with the Win32 one when there is a corespondence; Cygwin尝试在有核心支持时使Cygwin内部的当前工作目录与Win32保持同步。 it does so without using the SetCurrentDirectory Win32 function, and without maintaining the concept that Windows drives have individual current working directories. 这样做无需使用SetCurrentDirectory Win32函数,也无需维护Windows驱动器具有单个当前工作目录的概念。

If I do include the cygwin bin folder in my path (under regular cmd) then I know it all works as in cmd, so what is it thats causing this convertion, is it the bash/shell? 如果我确实在路径中(在常规cmd下)包含cygwin bin文件夹,那么我知道它们都可以在cmd中正常工作,那么是什么导致了这种转换,是bash / shell吗?

Actually, it does not all work as in cmd ! 实际上,它并不像cmd 那样全部起作用! Though Cygwin programs understand "Win32-ish" paths, the support is not complete. 尽管Cygwin程序了解“ Win32 ish”路径,但支持不完整。 You can pass a path like D:file.txt to a truly native Windows program. 您可以将D:file.txt类的路径传递给真正的本机Windows程序。 It resolves via the current directory associated with the D drive, which could be D:\\bob\\documents , in which case the path stands for D:\\bob\\documents\\file.txt . 它通过与D驱动器关联的当前目录来解析,该目录可以是D:\\bob\\documents ,在这种情况下,该路径代表D:\\bob\\documents\\file.txt If there is no such directory then it stands for D:\\file.txt . 如果没有这样的目录,则代表D:\\file.txt A Cygwin program will not understand this drive-relative path. Cygwin程序将无法理解此驱动器相对路径。 In fact, D:file.txt won't even be recognized as a drive-letter reference (as of Cygwin 2.5.2). 实际上, D:file.txt甚至不会被识别为驱动器盘符引用(从Cygwin 2.5.2开始)。 This is because the colon is not followed by a directory separator character (backslash or slash). 这是因为冒号后没有目录分隔符(反斜杠或斜杠)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM