OSDN Git Service

* new-features.sgml (ov-new1.7.2): Accommodate name change of getlocale
[pf3gnuchains/pf3gnuchains4x.git] / winsup / doc / pathnames.sgml
1 <sect1 id="using-pathnames"><title>Mapping path names</title>
2
3 <sect2 id="pathnames-intro"><title>Introduction</title>
4
5 <para>Cygwin supports both Win32- and POSIX-style paths.  Directory
6 delimiters may be either forward slashes or backslashes.  Paths using
7 backslashes are always handled as Win32 paths.  POSIX paths must only
8 use forward slashes as delimiter, otherwise they are treated as Win32
9 paths and file access might fail in surprising ways.  UNC pathnames
10 (starting with two slashes and a network name) are also supported.</para>
11
12 <note><para>The usage of Win32 paths, though possible, is deprecated,
13 since it circumvents important internal path handling mechanisms. 
14 See <xref linkend="pathnames-win32"></xref> for more information.
15 </para></note>
16
17 <para>POSIX operating systems (such as Linux) do not have the concept
18 of drive letters.  Instead, all absolute paths begin with a
19 slash (instead of a drive letter such as "c:") and all file systems
20 appear as subdirectories (for example, you might buy a new disk and
21 make it be the <filename>/disk2</filename> directory).</para>
22
23 <para>Because many programs written to run on UNIX systems assume
24 the existance of a single unified POSIX file system structure, Cygwin
25 maintains a special internal POSIX view of the Win32 file system
26 that allows these programs to successfully run under Windows.  Cygwin
27 uses this mapping to translate from POSIX to Win32 paths as
28 necessary.</para>
29
30 </sect2>
31
32 <sect2 id="mount-table"><title>The Cygwin Mount Table</title>
33
34 <para>The <filename>/etc/fstab</filename> file is used to map Win32
35 drives and network shares into Cygwin's internal POSIX directory tree.
36 This is a similar concept to the typical UNIX fstab file.  The mount
37 points stored in <filename>/etc/fstab</filename> are globally set for
38 all users.  Sometimes there's a requirement to have user specific
39 mount points.  The Cygwin DLL supports user specific fstab files.
40 These are stored in the directory <filename>/etc/fstab.d</filename>
41 and the name of the file is the Cygwin username of the user, as it's
42 stored in the <filename>/etc/passwd</filename> file.  The content of the
43 user specifc file is identical to the system-wide
44 <filename>fstab</filename> file.</para>
45
46 <para>The file fstab contains descriptive information about the various file
47 systems.  fstab is only read by programs, and not written; it is the
48 duty of the system administrator to properly create and maintain this
49 file.  Each filesystem is described on a separate line; fields on each
50 line are separated by tabs or spaces.  Lines starting with '#' are
51 comments.</para>
52
53 <para>The first field describes the block special device or
54 remote filesystem to be mounted.  On Cygwin, this is the native Windows
55 path which the mount point links in.  As path separator you MUST use a
56 slash.  Usage of a backslash might lead to unexpected results.  UNC
57 paths (using slashes, not backslashes) are allowed.  If the path
58 contains spaces these can be escaped as <literal>'\040'</literal>.</para>
59
60 <para>The second field describes the mount point for the filesystem. 
61 If the name of the mount point contains spaces these can be
62 escaped as '\040'.</para>
63
64 <para>The third field describes the type of the filesystem.
65 Cygwin supports any string here, since the file system type is usually
66 not evaluated.  The notable exception is the file system type
67 cygdrive.  This type is used to set the cygdrive prefix.</para>
68
69 <para>The fourth field describes the mount options associated
70 with the filesystem.  It is formatted as a comma separated list of
71 options.  It contains at least the type of mount (binary or text) plus
72 any additional options appropriate to the filesystem type.  Recognized
73 options are binary, text, nouser, user, exec, notexec, cygexec, nosuid,
74 posix=[0|1].  The meaning of the options is as follows.</para>
75
76 <screen>
77   acl       - Cygwin uses the filesystem's access control lists (ACLs) to
78               implement real POSIX permissions (default).  This flag only
79               affects filesystems supporting ACLs (NTFS) and is ignored
80               otherwise.
81   auto      - Ignored.
82   binary    - Files default to binary mode (default).
83   cygexec   - Treat all files below mount point as cygwin executables.
84   exec      - Treat all files below mount point as executable.
85   noacl     - Cygwin ignores filesystem ACLs and only fakes a subset of
86               permission bits based on the DOS readonly attribute.  This
87               behaviour is the default on FAT and FAT32.  The flag is
88               ignored on NFS filesystems.
89   nosuid    - No suid files are allowed (currently unimplemented).
90   notexec   - Treat all files below mount point as not executable.
91   nouser    - Mount is a system-wide mount.
92   override  - Force the override of an immutable mount point (currently "/").
93   posix=0   - Switch off case sensitivity for paths under this mount point
94               (default for the cygdrive prefix).
95   posix=1   - Switch on case sensitivity for paths under this mount point
96               (default for all other mount points).
97   text      - Files default to CRLF text mode line endings.
98   user      - Mount is a user mount.
99 </screen>
100
101 <para>While normally the execute permission bits are used to evaluate
102 executability, this is not possible on filesystems which don't support
103 permissions at all (like FAT/FAT32), or if ACLs are ignored on filesystems
104 supporting them (see the aforementioned <literal>acl</literal> mount option).
105 In these cases, the following heuristic is used to evaluate if a file is
106 executable: Files ending in certain extensions (.exe, .com, .bat, .btm,
107 .cmd) are assumed to be executable.  Files whose first two characters begin
108 with '#!' are also considered to be executable.
109 The <literal>exec</literal> option is used to instruct Cygwin that the
110 mounted file is "executable".  If the <literal>exec</literal> option is used
111 with a directory then all files in the directory are executable.
112 This option allows other files to be marked as executable and avoids the
113 overhead of opening each file to check for a '#!'.  The
114 <literal>cygexec</literal> option is very similar to <literal>exec</literal>,
115 but also prevents Cygwin from setting up commands and environment variables
116 for a normal Windows program, adding another small performance gain.  The
117 opposite of these options is the <literal>notexec</literal> option, which
118 means that no files should be marked as executable under that mount point.</para>
119 <para>A correct root directory is quite essential to the operation of
120 Cygwin.  A default root directory is evaluated at startup so a
121 <filename>fstab</filename> entry for the root directory is not necessary.
122 If it's wrong, nothing will work as expected.  Therefore, the root directory
123 evaluated by Cygwin itself is treated as an immutable mount point and can't
124 be overridden in /etc/fstab... unless you think you really know what you're
125 doing.  In this case, use the <literal>override</literal> flag in the options
126 field in the <filename>/etc/fstab</filename> file.  Since this is a dangerous
127 thing to do, do so at your own risk.</para>
128
129 <para><filename>/usr/bin</filename> and <filename>/usr/lib</filename> are
130 by default also automatic mount points generated by the Cygwin DLL similar
131 to the way the root directory is evaluated.  <filename>/usr/bin</filename>
132 points to the directory the Cygwin DLL is installed in,
133 <filename>/usr/lib</filename> is supposed to point to the
134 <filename>/lib</filename> directory.  This choice is safe and usually
135 shouldn't be changed.  An fstab entry for them is not required.</para>
136
137 <para><literal>nouser</literal> mount points are not overridable by a later
138 call to <command>mount</command>.
139 Mount points given in <filename>/etc/fstab</filename> are by default
140 <literal>nouser</literal> mount points, unless you specify the option
141 <literal>user</literal>.  This allows the administrator to set certain
142 paths so that they are not overridable by users.  In contrast, all mount
143 points in the user specific fstab file are <literal>user</literal> mount
144 points.</para>
145
146 <para>The fifth and sixth field are ignored.  They are
147 so far only specified to keep a Linux-like fstab file layout.</para>
148
149 <para>Note that you don't have to specify an fstab entry for the root dir,
150 unless you want to have the root dir pointing to somewhere entirely
151 different (hopefully you know what you're doing), or if you want to
152 mount the root dir with special options (for instance, as text mount).</para>
153
154 <para>Example entries:</para>
155
156 <itemizedlist spacing="compact">
157 <listitem>
158   <para>Just a normal mount point:</para>
159   <screen>c:/foo /bar fat32 binary 0 0</screen>
160 </listitem>
161 <listitem>
162   <para>A mount point for a textmode mount with case sensitivity switched off:</para>
163   <screen>C:/foo /bar/baz ntfs text,posix=0 0 0</screen>
164 </listitem>
165 <listitem>
166   <para>A mount point for a Windows directory with spaces in it:</para>
167   <screen>C:/Documents\040and\040Settings /docs ext3 binary 0 0</screen>
168 </listitem>
169 <listitem>
170   <para>A mount point for a remote directory without ACL support:</para>
171   <screen>//server/share/subdir /srv/subdir smbfs binary,noacl 0 0</screen>
172 </listitem>
173 <listitem>
174   <para>This is just a comment:</para>
175   <screen># This is just a comment</screen>
176 </listitem>
177 <listitem>
178   <para>Set the cygdrive prefix to /mnt:</para>
179   <screen>none /mnt cygdrive binary 0 0</screen>
180 </listitem>
181 </itemizedlist>
182
183 <para>Whenever Cygwin generates a Win32 path from a POSIX one, it uses
184 the longest matching prefix in the mount table.  Thus, if
185 <filename>C:</filename> is mounted as <filename>/c</filename> and also
186 as <filename>/</filename>, then Cygwin would translate
187 <filename>C:/foo/bar</filename> to <filename>/c/foo/bar</filename>.
188 This translation is normally only used when trying to derive the
189 POSIX equivalent current directory.  Otherwise, the handling of MS-DOS
190 filenames bypasses the mount table.
191 </para>
192
193 <para>If you want to see the current set of mount points valid in your
194 session, you can invoking the Cygwin tool <command>mount</command> without
195 arguments:</para>
196
197 <example id="pathnames-mount-ex">
198 <title>Displaying the current set of mount points</title>
199 <screen>
200 <prompt>bash$</prompt> <userinput>mount</userinput>
201 f:/cygwin/bin on /usr/bin type system (binary,auto)
202 f:/cygwin/lib on /usr/lib type system (binary,auto)
203 f:/cygwin on / type system (binary,auto)
204 e:/src on /usr/src type system (binary)
205 c: on /cygdrive/c type user (binary,posix=0,user,noumount,auto)
206 e: on /cygdrive/e type user (binary,posix=0,user,noumount,auto)
207 </screen>
208 </example>
209
210 <para>You can also use the <command>mount</command> command to add
211 new mount points, and the <command>umount</command> to delete
212 them.  However, since they are only noted in memory, these mount
213 points will disappear as soon as your last Cygwin process ends.
214 See <xref linkend="mount"></xref> and <xref linkend="umount"></xref> for more
215 information.</para>
216
217 <note><para>
218 When you upgrade an existing older Cygwin installation to Cygwin 1.7,
219 your old system mount points (stored in the HKEY_LOCAL_MACHINE branch
220 of your registry) are read by a script and the <filename>/etc/fstab</filename>
221 file is generated from these entries.  Note that entries for
222 <filename>/</filename>, <filename>/usr/bin</filename>, and
223 <filename>/usr/lib</filename> are <emphasis>never</emphasis> generated.
224 </para>
225
226 <para>
227 The old user mount points in your HKEY_CURRENT_USER branch of the registry
228 are not used to generate <filename>/etc/fstab</filename>.  If you want
229 to create a user specific <filename>/etc/fstab.d/${USER}</filename> file
230 from your old entries, there's a script available which does exactly
231 that for you, <filename>/bin/copy-user-registry-fstab</filename>.  Just
232 start the script and it will create your user specific fstab file.  Stop
233 all your Cygwin processes and restart them, and you can simply use your
234 old user mount points as before.
235 </para></note>
236
237 </sect2>
238
239 <sect2 id="cygdrive"><title>The cygdrive path prefix</title>
240
241 <para>As already outlined in <xref linkend="ov-hi-files"></xref>, you can
242 access arbitary drives on your system by using the cygdrive path prefix.
243 The default value for this prefix is <literal>/cygdrive</literal>, and
244 a path to any drive can be constructed by using the cygdrive prefix and
245 appending the drive letter as subdirectory, like this:</para>
246
247 <screen>
248   bash$ ls -l /cygdrive/f/somedir
249 </screen>
250
251 <para>This lists the content of the directory F:\somedir.</para>
252
253 <para>The cygdrive prefix is a virtual directory under which all drives
254 on a system are subsumed.  The mount options of the cygdrive prefix is
255 used for all file access through the cygdrive prefixed drives.  For instance,
256 assuming the cygdrive mount options are <literal>binary,posix=0</literal>,
257 then any file <literal>/cygdrive/x/file</literal> will be opened in
258 binary mode by default (mount option <literal>binary</literal>, and the case
259 of the filename doesn't matter (mount option <literal>posix=0</literal>.
260 </para>
261
262 <para>The cygdrive prefix flags are also used for all UNC paths starting with
263 two slashes, unless they are accessed through a mount point.  For instance,
264 consider these <filename>/etc/fstab</filename> entries:</para>
265
266 <screen>
267   //server/share /mysrv    ntfs     posix=1,acl   0 0
268   none           /cygdrive cygdrive posix=0,noacl 0 0
269 </screen>
270
271 <para>Assume there's a file <filename>\\server\share\foo</filename> on the
272 share.  When accessing it as <filename>/mysrv/foo</filename>, then the flags
273 <literal>posix=1,acl</literal> of the /mysrv mount point are used.  When
274 accessing it as <filename>//server/share/foo</filename>, then the flags
275 for the cygdrive prefix, <literal>posix=0,noacl</literal> are used.</para>
276
277 <note><para>This only applies to UNC paths using forward slashes.  When
278 using backslashes the flags for native paths are used.  See
279 <xref linkend="pathnames-win32"></xref>.</para></note>
280
281 <para>The cygdrive prefix may be changed in the fstab file as outlined above.
282 Please note that you must not use the cygdrive prefix for any other mount
283 point.  For instance this:</para>
284
285 <screen>
286   none /cygdrive cygdrive binary 0 0
287   D:   /cygdrive/d somefs text 0 0
288 </screen>
289
290 <para>will not make file access using the /mnt/d path prefix suddenly using
291 textmode.  If you want to mount any drive explicitly in another mode than
292 the cygdrive prefix, use a distinct path prefix:</para>
293
294 <screen>
295   none /cygdrive cygdrive binary 0 0
296   D:   /mnt/d somefs text 0 0
297 </screen>
298
299 </sect2>
300
301 <sect2 id="pathnames-win32"><title>Using native Win32 paths</title>
302
303 <para>Using native Win32 paths in Cygwin, while possible, is generally
304 inadvisable.  Those paths circumvent all internal integrity checking and
305 bypass the information given in the Cygwin mount table.</para>
306
307 <para>The following paths are treated as native Win32 paths in Cygwin:</para>
308
309 <itemizedlist spacing="compact">
310   <listitem>
311     <para>All paths starting with a drive specifier</para>
312     <screen>
313        C:\foo
314        C:/foo
315     </screen>
316   </listitem>
317   <listitem>
318     <para>All paths containing at least one backslash as path component</para>
319     <screen>
320        C:/foo/bar<emphasis role='bold'>\</emphasis>baz/...
321     </screen>
322   </listitem>
323   <listitem>
324     <para>UNC paths using backslashes</para>
325     <screen>
326        \\server\share\...
327     </screen>
328   </listitem>
329 </itemizedlist>
330
331 <para>When accessing files using native Win32 paths as above, Cygwin uses a
332 default setting for the mount flags.  All paths using DOS notation will be
333 treated as caseinsensitive, and permissions are just faked as if the
334 underlying drive is a FAT drive.  This also applies to NTFS and other
335 filesystems which usually are capable of casesensitivity and storing
336 permissions.</para>
337
338 </sect2>
339
340 <sect2 id="pathnames-additional"><title>Additional Path-related Information</title>
341
342 <para>The <command>cygpath</command> program provides the ability to
343 translate between Win32 and POSIX pathnames in shell scripts. See
344 <xref linkend="cygpath"></xref> for the details.</para>
345
346 <para>The <envar>HOME</envar>, <envar>PATH</envar>, and
347 <envar>LD_LIBRARY_PATH</envar> environment variables are automatically
348 converted from Win32 format to POSIX format (e.g.  from
349 <filename>c:/cygwin\bin</filename> to <filename>/bin</filename>, if
350 there was a mount from that Win32 path to that POSIX path) when a Cygwin
351 process first starts.</para>
352
353 <para>Symbolic links can also be used to map Win32 pathnames to POSIX.
354 For example, the command
355 <command>ln -s //pollux/home/joe/data /data</command> would have about
356 the same effect as creating a mount point from
357 <filename>//pollux/home/joe/data</filename> to <filename>/data</filename>
358 using <command>mount</command>, except that symbolic links cannot set
359 the default file access mode.  Other differences are that the mapping is
360 distributed throughout the file system and proceeds by iteratively
361 walking the directory tree instead of matching the longest prefix in a
362 kernel table.  Note that symbolic links will only work on network
363 drives that are properly configured to support the "system" file
364 attribute.  Many do not do so by default (the Unix Samba server does
365 not by default, for example).</para>
366
367 </sect2>
368
369 </sect1>
370
371 <sect1 id="using-specialnames"><title>Special filenames</title>
372
373 <sect2 id="pathnames-etc"><title>Special files in /etc</title>
374
375 <para>Certain files in Cygwin's <filename>/etc</filename> directory are
376 read by Cygwin before the mount table has been established.  The list
377 of files is</para>
378
379 <screen>
380   /etc/fstab
381   /etc/fstab.d/$USER
382   /etc/passwd
383   /etc/group
384 </screen>
385
386 <para>These file are read using native Windows NT functions which have
387 no notion of Cygwin symlinks or POSIX paths.  For that reason
388 there are a few requirements as far as <filename>/etc</filename> is
389 concerned.</para>
390
391 <para>To access these files, the Cygwin DLL evaluates it's own full
392 Windows path, strips off the innermost directory component and adds
393 "\etc".  Let's assume the Cygwin DLL is installed as
394 <filename>C:\cygwin\bin\cygwin1.dll</filename>.  First the DLL name as
395 well as the innermost directory (<filename>bin</filename>) is stripped
396 off: <filename>C:\cygwin\</filename>.  Then "etc" and the filename to
397 look for is attached: <filename>C:\cygwin\etc\fstab</filename>.  So the
398 /etc directory must be parallel to the directory in which the cygwin1.dll
399 exists and <filename>/etc</filename> must not be a Cygwin symlink
400 pointing to another directory.  Consequentially none of the files from
401 the above list, including the directory <filename>/etc/fstab.d</filename>
402 is allowed to be a Cygwin symlink either.</para>
403
404 <para>However, native NTFS symlinks and reparse points are transparent
405 when accessing the above files so all these files as well as
406 <filename>/etc</filename> itself may be NTFS symlinks or reparse
407 points.</para>
408
409 <para>Last but not least, make sure that these files are world-readable.
410 Every process of any user account has to read these files potentially,
411 so world-readability is essential.  The only exception are the user
412 specific files <filename>/etc/fstab.d/$USER</filename>, which only have
413 to be readable by the $USER user account itself.</para>
414
415 </sect2>
416
417 <sect2 id="pathnames-dosdevices"><title>Invalid filenames</title>
418
419 <para>Filenames invalid under Win32 are not necessarily invalid
420 under Cygwin since release 1.7.0.  There are a few rules which
421 apply to Windows filenames.  Most notably, DOS device names like
422 <filename>AUX</filename>, <filename>COM1</filename>,
423 <filename>LPT1</filename> or <filename>PRN</filename> (to name a few)
424 cannot be used as filename or extension in a native Win32 application.
425 So filenames like <filename>prn.txt</filename> or <filename>foo.aux</filename>
426 are invalid filenames for native Win32 applications.</para>
427
428 <para>This restriction doesn't apply to Cygwin applications.  Cygwin
429 can create and access files with such names just fine.  Just don't try
430 to use these files with native Win32 applications.</para>
431
432 </sect2>
433
434 <sect2 id="pathnames-specialchars">
435 <title>Forbidden characters in filenames</title>
436
437 <para>Win32 filenames can't contain trailing dots and spaces for backward
438 compatibility.  When trying to create files with trailing dots or spaces,
439 all of them are removed before the file is created.  This restriction only
440 affects native Win32 applications.  Cygwin applications can create and
441 access files with trailing dots and spaces without problems.</para>
442
443 <para>Additionally, some characters are disallowed in filenames on Windows
444 filesystems.  These forbidden characters are the ASCII control characters
445 from ASCII value 1 to 31, plus the following characters which have a special
446 meaning in the Win32 API:</para>
447
448 <screen>
449   "   *   :   &lt;   &gt;   ?   |   \
450 </screen>
451
452 <para>Cygwin can't fix this, but it has a method to workaround this
453 restriction.  All of the above characters, except for the backslash,
454 are converted to special UNICODE characters in the range 0xf000 to 0xf0ff
455 (the "Private use area") when creating or accessing files.</para>
456
457 <para>The backslash has to be exempt from this conversion, because Cygwin
458 accepts Win32 filenames including backslashes as path separators on input. 
459 Converting backslashes using the above method would make this impossible.</para>
460
461 </sect2>
462
463 <sect2 id="pathnames-unusual">
464 <title>Filenames with unusual (foreign) characters</title>
465
466 <para> Windows filesystems use Unicode encoded as UTF-16
467 to store filename information.  If you don't use the UTF-8
468 character set (see <xref linkend="setup-locale"></xref>) then there's a
469 chance that a filename is using one or more characters which have no
470 representation in the character set you're using.</para>
471
472 <note><para>In the default "C" locale, Cygwin creates filenames using
473 the UTF-8 charset.  This will always result in some valid filename by
474 default, but again might impose problems when switching to a non-"C"
475 or non-"UTF-8" charset.</para></note>
476
477 <note><para>To avoid this scenario altogether, always use UTF-8 as the
478 character set.</para></note>
479
480 <para>If you don't want or can't use UTF-8 as character set for whatever
481 reason, you will nevertheless be able to access the file.  How does that
482 work?  When Cygwin converts the filename from UTF-16 to your character
483 set, it recognizes characters which can't be converted.  If that occurs,
484 Cygwin replaces the non-convertible character with a special character
485 sequence.  The sequence starts with an ASCII CAN character (hex code
486 0x18, equivalent Control-X), followed by the UTF-8 representation of the
487 character.  The result is a filename containing some ugly looking
488 characters.  While it doesn't <emphasis>look</emphasis> nice, it
489 <emphasis>is</emphasis> nice, because Cygwin knows how to convert this
490 filename back to UTF-16.  The filename will be converted using your
491 usual character set.  However, when Cygwin recognizes an ASCII CAN
492 character, it skips over the ASCII CAN and handles the following bytes as
493 a UTF-8 character.  Thus, the filename is symmetrically converted back to
494 UTF-16 and you can access the file.</para>
495
496 <note><para>Please be aware that this method is not entirely foolproof.
497 In some character set combinations it might not work for certain native
498 characters.</para>
499
500 <para>Only by using the UTF-8 charset you can avoid this problem safely.
501 </para></note>
502
503 </sect2>
504
505 <sect2 id="pathnames-casesensitive">
506 <title>Case sensitive filenames</title>
507
508 <para>In the Win32 subsystem filenames are only case-preserved, but not
509 case-sensitive.  You can't access two files in the same directory which
510 only differ by case, like <filename>Abc</filename> and
511 <filename>aBc</filename>.  While NTFS (and some remote filesystems)
512 support case-sensitivity, the NT kernel starting with Windows XP does
513 not support it by default.  Rather, you have to tweak a registry setting
514 and reboot.  For that reason, case-sensitivity can not be supported by Cygwin,
515 unless you change that registry value.</para>
516
517 <para>If you really want case-sensitivity in Cygwin, you can switch it
518 on by setting the registry value</para>
519
520 <screen>
521 HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\kernel\obcaseinsensitive
522 </screen>
523
524 <para>to 0 and reboot the machine.  For least surprise, Cygwin expects
525 this registry value also on Windows NT4 and Windows 2000, which usually
526 both don't know this registry key.  If you want case-sensitivity on these
527 systems, create that registry value and set it to 0.  On these systems
528 (and <emphasis role='bold'>only</emphasis> on these systems) you don't have to reboot to bring it
529 into effect, rather stopping all Cygwin processes and then restarting them
530 is sufficient.</para>
531
532 <note>
533 <para>
534 When installing Microsoft's Services For Unix (SFU), you're asked if
535 you want to use case-sensitive filenames.  If you answer "yes" at this point,
536 the installer will change the aforementioned registry value to 0, too.  So, if
537 you have SFU installed, there's some chance that the registry value is already
538 set to case sensitivity.
539 </para>
540 </note>
541
542 <para>After you set this registry value to 0, Cygwin will be case-sensitive
543 by default on NTFS and NFS filesystems.  However, there are limitations: 
544 while two <emphasis role='bold'>programs</emphasis> <filename>Abc.exe</filename>
545 and <filename>aBc.exe</filename> can be created and accessed like other files,
546 starting applications is still case-insensitive due to Windows limitations
547 and so the program you try to launch may not be the one actually started.  Also,
548 be aware that using two filenames which only differ by case might
549 result in some weird interoperability issues with native Win32 applications.  
550 You're using case-sensitivity at your own risk.  You have been warned! </para>
551
552 <para>Even if you use case-sensitivity, it might be feasible to switch to
553 case-insensitivity for certain paths for better interoperability with
554 native Win32 applications (even if it's just Windows Explorer).  You can do
555 this on a per-mount point base, by using the "posix=0" mount option in
556 <filename>/etc/fstab</filename>, or your <filename>/etc/fstab.d/$USER</filename>
557 file.</para>
558
559 <para><filename>/cygdrive</filename> paths are case-insensitive by default.
560 The reason is that the native Windows %PATH% environment variable is not
561 always using the correct case for all paths in it.  As a result, if you use
562 case-sensitivity on the <filename>/cygdrive</filename> prefix, your shell
563 might claim that it can't find Windows commands like <command>attrib</command>
564 or <command>net</command>.  To ease the pain, the <filename>/cygdrive</filename>
565 path is case-insensitive by default and you have to use the "posix=1" setting
566 explicitly in <filename>/etc/fstab</filename> or
567 <filename>/etc/fstab.d/$USER</filename> to switch it to case-sensitivity,
568 or you have to make sure that the native Win32 %PATH% environment variable
569 is using the correct case for all paths throughout.</para>
570
571 <para>Note that mount points as well as device names and virtual
572 paths like /proc are always case-sensitive!  The only exception are
573 the subdirectories and filenames under /proc/registry, /proc/registry32
574 and /proc/registry64.  Registry access is always case-insensitive.
575 Read on for more information.</para>
576
577 </sect2>
578
579 <sect2 id="pathnames-posixdevices"> <title>POSIX devices</title>
580 <para>There is no need to create a POSIX <filename>/dev</filename> 
581 directory as Cygwin automatically simulates it internally. 
582 These devices cannot be seen with the command <command>ls /dev/</command>
583 although commands such as <command>ls /dev/tty</command> work fine.
584 If you want to be able to see all well-known devices in
585 <filename>/dev/</filename>, you can use Igor Pechtchanski's
586 <ulink
587 url="http://cygwin.com/ml/cygwin/2004-03/txt00028.txt">create_devices.sh</ulink>
588 script.  This script does not add the raw disk devices, though.  Again,
589 it's not necessary to see an existing device in /dev to access it.  The script
590 is just for the fun of it.
591 </para>
592
593 <para>
594 Cygwin supports the following character devices commonly found on POSIX systems:
595 </para>
596
597 <screen>
598 /dev/null
599 /dev/zero
600 /dev/full
601
602 /dev/console    Pseudo device name for the standard console window created
603                 by Windows.  Same as the one used for cmd.exe.  Every one
604                 of them has this name.  It's not quite comparable with the
605                 console device on UNIX machines.
606
607 /dev/tty        The current tty of a session running in a pseudo tty.
608 /dev/ptmx       Pseudo tty master device.
609 /dev/ttym
610
611 /dev/tty0       Pseudo ttys are numbered from /dev/tty0 upwards as they are
612 /dev/tty1       requested.
613 ...
614
615 /dev/ttyS0      Serial communication devices.  ttyS0 == Win32 COM1,
616 /dev/ttyS1      ttyS1 == COM2, etc.
617 ...
618
619 /dev/pipe
620 /dev/fifo
621
622 /dev/mem        The physical memory of the machine.  Note that access to the
623 /dev/port       physical memory has been restricted with Windows Server 2003.
624 /dev/kmem       Since this OS, you can't access physical memory from user space.
625
626 /dev/kmsg       Kernel message pipe, for usage with sys logger services.
627
628 /dev/random     Random number generator.
629 /dev/urandom
630
631 /dev/dsp        Default sound device of the system.
632 </screen>
633
634 <para>
635 Cygwin also has several Windows-specific devices:
636 </para>
637
638 <screen>
639 /dev/com1       The serial ports, starting with COM1 which is the same as ttyS0.
640 /dev/com2       Please use /dev/ttySx instead.
641 ...
642
643 /dev/conin      Same as Windows CONIN$.
644 /dev/conout     Same as Windows CONOUT$.
645 /dev/clipboard  The Windows clipboard, text only
646 /dev/windows    The Windows message queue.
647 </screen>
648
649 <para>
650 Block devices are accessible by Cygwin processes using fixed POSIX device
651 names.  These POSIX device names are generated using a direct conversion
652 from the POSIX namespace to the internal NT namespace.
653 E.g. the first harddisk is the NT internal device \device\harddisk0\partition0
654 or the first partition on the third harddisk is \device\harddisk2\partition1.
655 The first floppy in the system is \device\floppy0, the first CD-ROM is
656 \device\cdrom0 and the first tape drive is \device\tape0.</para>
657
658 <para>The mapping from physical device to the name of the device in the
659 internal NT namespace can be found in various places.  For hard disks and
660 CD/DVD drives, the Windows "Disk Management" utility (part of the
661 "Computer Management" console) shows that the mapping of "Disk 0" is
662 \device\harddisk0.  "CD-ROM 2" is \device\cdrom2.  Another place to find
663 this mapping is the "Device Management" console.  Disks have a
664 "Location" number, tapes have a "Tape Symbolic Name", etc.
665 Unfortunately, the places where this information is found is not very
666 well-defined.</para>
667
668 <para>
669 For external disks (USB-drives, CF-cards in a cardreader, etc) you can use
670 Cygwin to show the mapping.  <filename>/proc/partitions</filename>
671 contains a list of raw drives known to Cygwin.  The <command>df</command>
672 command shows a list of drives and their respective sizes.  If you match
673 the information between <filename>/proc/partitions</filename> and the
674 <command>df</command> output, you should be able to figure out which
675 external drive corresponds to which raw disk device name.</para>
676
677 <note><para>Apart from tape devices which are not block devices and are
678 by default accessed directly, accessing mass storage devices raw
679 is something you should only do if you know what you're doing and know how to
680 handle the information.  <emphasis role='bold'>Writing</emphasis> to a raw
681 mass storage device you should only do if you
682 <emphasis role='bold'>really</emphasis> know what you're doing and are aware
683 of the fact that any mistake can destroy important information, for the
684 device, and for you.  So, please, handle this ability with care.
685 <emphasis role='bold'>You have been warned.</emphasis></para></note>
686
687 <para>
688 Last but not least, the mapping from POSIX /dev namespace to internal
689 NT namespace is as follows:
690 </para>
691
692 <screen>
693 POSIX device name     Internal NT device name
694
695 /dev/st0              \device\tape0, rewind
696 /dev/nst0             \device\tape0, no-rewind
697 /dev/st1              \device\tape1
698 /dev/nst1             \device\tape1
699 ...
700 /dev/st15
701 /dev/nst15
702
703 /dev/fd0              \device\floppy0
704 /dev/fd1              \device\floppy1
705 ...
706 /dev/fd15
707
708 /dev/sr0              \device\cdrom0
709 /dev/sr1              \device\cdrom1
710 ...
711 /dev/sr15
712
713 /dev/scd0             \device\cdrom0
714 /dev/scd1             \device\cdrom1
715 ...
716 /dev/scd15
717
718 /dev/sda              \device\harddisk0\partition0      (whole disk)
719 /dev/sda1             \device\harddisk0\partition1      (first partition)
720 ...
721 /dev/sda15            \device\harddisk0\partition15     (fifteenth partition)
722
723 /dev/sdb              \device\harddisk1\partition0
724 /dev/sdb1             \device\harddisk1\partition1
725
726 [up to]
727
728 /dev/sddx             \device\harddisk127\partition0
729 /dev/sddx1            \device\harddisk127\partition1
730 ...
731 /dev/sddx15           \device\harddisk127\partition15
732 </screen>
733
734 <para>
735 if you don't like these device names, feel free to create symbolic
736 links as they are created on Linux systems for convenience:
737 </para>
738
739 <screen>
740 ln -s /dev/sr0 /dev/cdrom
741 ln -s /dev/nst0 /dev/tape
742 ...
743 </screen>
744
745 </sect2>
746
747 <sect2 id="pathnames-exe"><title>The .exe extension</title>
748
749 <para>Win32 executable filenames end with <filename>.exe</filename>
750 but the <filename>.exe</filename> need not be included in the command,
751 so that traditional UNIX names can be used.  However, for programs that
752 end in <filename>.bat</filename> and <filename>.com</filename>, you
753 cannot omit the extension.  </para>
754
755 <para>As a side effect, the <command> ls filename</command> gives
756 information about <filename>filename.exe</filename> if
757 <filename>filename.exe</filename> exists and <filename>filename</filename>
758 does not.  In the same situation the function call
759 <function>stat("filename",..)</function> gives information about
760 <filename>filename.exe</filename>.  The two files can be distinguished
761 by examining their inodes, as demonstrated below.
762 <screen>
763 <prompt>bash$</prompt> <userinput>ls * </userinput>
764 a      a.exe     b.exe
765 <prompt>bash$</prompt> <userinput>ls -i a a.exe</userinput>
766 445885548 a       435996602 a.exe
767 <prompt>bash$</prompt> <userinput>ls -i b b.exe</userinput>
768 432961010 b       432961010 b.exe
769 </screen>
770 If a shell script <filename>myprog</filename> and a program
771 <filename>myprog.exe</filename> coexist in a directory, the shell
772 script has precedence and is selected for execution of
773 <command>myprog</command>.  Note that this was quite the reverse up to
774 Cygwin 1.5.19.  It has been changed for consistency with the rest of Cygwin.
775 </para>
776
777 <para>The <command>gcc</command> compiler produces an executable named
778 <filename>filename.exe</filename> when asked to produce
779 <filename>filename</filename>. This allows many makefiles written
780 for UNIX systems to work well under Cygwin.</para>
781
782 </sect2>
783
784 <sect2 id="pathnames-proc"><title>The /proc filesystem</title> 
785 <para>
786 Cygwin, like Linux and other similar operating systems, supports the
787 <filename>/proc</filename> virtual filesystem. The files in this
788 directory are representations of various aspects of your system,
789 for example the command <userinput>cat /proc/cpuinfo</userinput> 
790 displays information such as what model and speed processor you have.
791 </para>
792 <para>
793 One unique aspect of the Cygwin <filename>/proc</filename> filesystem
794 is <filename>/proc/registry</filename>, see next section.
795 </para>
796 <para>
797 The Cygwin <filename>/proc</filename> is not as complete as the
798 one in Linux, but it provides significant capabilities. The
799 <systemitem>procps</systemitem> package contains several utilities
800 that use it.
801 </para>
802 </sect2>
803
804 <sect2 id="pathnames-proc-registry"><title>The /proc/registry filesystem</title>
805 <para>
806 The <filename>/proc/registry</filename> filesystem provides read-only
807 access to the Windows registry.  It displays each <literal>KEY</literal>
808 as a directory and each <literal>VALUE</literal> as a file.  As anytime
809 you deal with the Windows registry, use caution since changes may result
810 in an unstable or broken system.  There are additionally subdirectories called
811 <filename>/proc/registry32</filename> and <filename>/proc/registry64</filename>.
812 They are identical to <filename>/proc/registry</filename> on 32 bit
813 host OSes.  On 64 bit host OSes, <filename>/proc/registry32</filename>
814 opens the 32 bit processes view on the registry, while
815 <filename>/proc/registry64</filename> opens the 64 bit processes view.
816 </para>
817 <para>
818 Reserved characters ('/', '\', ':', and '%') or reserved names
819 (<filename>.</filename> and <filename>..</filename>) are converted by
820 percent-encoding:
821 <screen>
822 <prompt>bash$</prompt> <userinput>regtool list -v '\HKEY_LOCAL_MACHINE\SYSTEM\MountedDevices'</userinput>
823 ...
824 \DosDevices\C: (REG_BINARY) = cf a8 97 e8 00 08 fe f7
825 ...
826 <prompt>bash$</prompt> <userinput>cd /proc/registry/HKEY_LOCAL_MACHINE/SYSTEM</userinput>
827 <prompt>bash$</prompt> <userinput>ls -l MountedDevices</userinput>
828 ...
829 -r--r----- 1 Admin SYSTEM  12 Dec 10 11:20 %5CDosDevices%5CC%3A
830 ...
831 <prompt>bash$</prompt> <userinput>od -t x1 MountedDevices/%5CDosDevices%5CC%3A</userinput>
832 0000000 cf a8 97 e8 00 08 fe f7 01 00 00 00
833 </screen>
834 The unnamed (default) value of a key can be accessed using the filename
835 <filename>@</filename>.
836 </para>
837 <para>
838 If a registry key contains a subkey and a value with the same name
839 <filename>foo</filename>, Cygwin displays the subkey as
840 <filename>foo</filename> and the value as <filename>foo%val</filename>.
841 </para>
842 </sect2>
843
844 <sect2 id="pathnames-at"><title>The @pathnames</title> 
845 <para>To circumvent the limitations on shell line length in the native
846 Windows command shells, Cygwin programs expand their arguments
847 starting with "@" in a special way.  If a file
848 <filename>pathname</filename> exists, the argument
849 <filename>@pathname</filename> expands recursively to the content of
850 <filename>pathname</filename>. Double quotes can be used inside the
851 file to delimit strings containing blank space. 
852 Embedded double quotes must be repeated.
853 In the following example compare the behaviors of the bash built-in
854 <command>echo</command> and of the program <command>/bin/echo</command>.</para>
855
856 <example id="pathnames-at-ex"><title> Using @pathname</title>
857 <screen>
858 <prompt>bash$</prompt> <userinput>echo  'This   is   "a     long"  line' > mylist</userinput>
859 <prompt>bash$</prompt> <userinput>echo @mylist</userinput>
860 @mylist
861 <prompt>bash$</prompt> <userinput>cmd</userinput>
862 <prompt>c:\&gt;</prompt> <userinput>c:\cygwin\bin\echo @mylist</userinput>
863 This is a     long line
864 </screen>
865 </example>
866 </sect2> 
867 </sect1>