Chapter 3. Using Cygwin

Table of Contents

Mapping path names
Introduction
The Cygwin Mount Table
Additional Path-related Information
Text and Binary modes
The Issue
The default Cygwin behavior
Example
Binary or text?
Programming
File permissions
Special filenames
DOS devices
POSIX devices
The .exe extension
The /proc filesystem
The @pathnames
The CYGWIN environment variable
Cygserver
What is Cygserver?
Cygserver command line options
How to start Cygserver
How to use the Cygserver services
The Cygserver configuration file
Cygwin Utilities
cygcheck
cygpath
dumper
getfacl
kill
mkgroup
mkpasswd
mount
passwd
ps
regtool
setfacl
ssp
strace
umount
Using Cygwin effectively with Windows
Pathnames
Console Programs
Cygwin and Windows Networking
The cygutils package
Creating shortcuts with cygutils
Printing with cygutils

This chapter explains some key differences between the Cygwin environment and traditional UNIX systems. It assumes a working knowledge of standard UNIX commands.

Mapping path names

Introduction

Cygwin supports both Win32- and POSIX-style paths, where directory delimiters may be either forward or back slashes. UNC pathnames (starting with two slashes and a network name) are also supported.

POSIX operating systems (such as Linux) do not have the concept of drive letters. Instead, all absolute paths begin with a slash (instead of a drive letter such as "c:") and all file systems appear as subdirectories (for example, you might buy a new disk and make it be the /disk2 directory).

Because many programs written to run on UNIX systems assume the existance of a single unified POSIX file system structure, Cygwin maintains a special internal POSIX view of the Win32 file system that allows these programs to successfully run under Windows. Cygwin uses this mapping to translate from POSIX to Win32 paths as necessary.

The Cygwin Mount Table

The mount utility program is used to to map Win32 drives and network shares into Cygwin's internal POSIX directory tree. This is a similar concept to the typical UNIX mount program. For those people coming from a Windows background, the mount utility is very similar to the old DOS join, in that it makes your drive letters appear as subdirectories somewhere else.

The mapping is stored in the current user's Cygwin mount table in the Windows registry so that the information will be retrieved next time the user logs in. Because it is sometimes desirable to have system-wide as well as user-specific mounts, there is also a system-wide mount table that all Cygwin users inherit. The system-wide table may only be modified by a user with the appropriate privileges (Administrator privileges in Windows NT).

The current user's table is located under "HKEY_CURRENT_USER/Software/Cygnus Solutions/Cygwin/mounts v<version>" where <version> is the latest registry version associated with the Cygwin library (this version is not the same as the release number). The system-wide table is located under the same subkeys under HKEY_LOCAL_SYSTEM. The user mount table takes precedence over the system-wide table if a path is mounted in both. This includes the setting of the cygdrive prefix.

The mount command can set the POSIX root / to any directory in the Windows file system. In absence of such a mount, Cygwin maps / to the root of the current Windows working directory (for example, H:\ or \\computer\share). Normally Cygwin's setup.exe creates the initial mount point for the POSIX root.

Whenever Cygwin generates a Win32 path from a POSIX one, it uses the longest matching prefix in the mount table. Thus, if C: is mounted as /c and also as /, then Cygwin would translate C:/foo/bar to /c/foo/bar. This translation is normally only used when trying to derive the POSIX equivalent current directory. Otherwise, the handling of MS-DOS filenames bypasses the mount table.

Invoking mount without any arguments displays Cygwin's current set of mount points. In the following example, the C drive is the POSIX root and D drive is mapped to /d. Note that in this case, the root mount is a system-wide mount point that is visible to all users running Cygwin programs, whereas the /d mount is only visible to the current user.

Example 3.1. Displaying the current set of mount points

c:\> mount
f:\cygwin\bin on /usr/bin type system (binmode)
f:\cygwin\lib on /usr/lib type system (binmode)
f:\cygwin on / type system (binmode)
e:\src on /usr/src type system (binmode)
c: on /cygdrive/c type user (binmode,noumount)
e: on /cygdrive/e type user (binmode,noumount)

You can also use the mount command to add new mount points, and the umount to delete them. See the section called “mount” and the section called “umount” for more information on how to use these utilities to set up your Cygwin POSIX file system.

Whenever Cygwin cannot use any of the existing mounts to convert from a particular Win32 path to a POSIX one, Cygwin will automatically default to an imaginary mount point under the default POSIX path /cygdrive. For example, if Cygwin accesses Z:\foo and the Z drive is not currently in the mount table, then Z:\ would be automatically converted to /cygdrive/Z. The default prefix of /cygdrive may be changed (see the the section called “mount” for more information).

It is possible to assign some special attributes to each mount point. Automatically mounted partitions are displayed as "auto" mounts. Mounts can also be marked as either "textmode" or "binmode" -- whether text files are read in the same manner as binary files by default or not (see the section called “Text and Binary modes” for more information on text and binary modes.

Additional Path-related Information

The cygpath program provides the ability to translate between Win32 and POSIX pathnames in shell scripts. See the section called “cygpath” for the details.

The HOME, PATH, and LD_LIBRARY_PATH environment variables are automatically converted from Win32 format to POSIX format (e.g. from c:\cygwin\bin to /bin, if there was a mount from that Win32 path to that POSIX path) when a Cygwin process first starts.

Symbolic links can also be used to map Win32 pathnames to POSIX. For example, the command ln -s //pollux/home/joe/data /data would have about the same effect as creating a mount point from //pollux/home/joe/data to /data using mount, except that symbolic links cannot set the default file access mode. Other differences are that the mapping is distributed throughout the file system and proceeds by iteratively walking the directory tree instead of matching the longest prefix in a kernel table. Note that symbolic links will only work on network drives that are properly configured to support the "system" file attribute. Many do not do so by default (the Unix Samba server does not by default, for example).