Special filenames

DOS devices

Windows filenames invalid under Windows are also invalid under Cygwin. This means that base filenames such as AUX, COM1, LPT1 or PRN (to name a few) cannot be used in a regular Cygwin Windows or POSIX path, even with an extension (prn.txt). However the special names can be used as filename extensions (file.aux). You can use the special names as you would under DOS, for example you can print on your default printer with the command cat filename > PRN (make sure to end with a Form Feed).

POSIX devices

There is no need to create a POSIX /dev directory as it is simulated within Cygwin automatically. It supports the following devices: /dev/null, /dev/zero, /dev/tty, /dev/ttyX, /dev/ptmx, /dev/comX (the serial ports), /dev/windows (the windows message queue), /dev/random and /dev/urandom. These devices cannot be seen with the command ls /dev although commands such as ls /dev/tty work fine.

However, on Windows NT/W2K there are different devices which are supported but have to be created as mount points. These are the raw block special devices and tape devices. These devices need a special handling which is enabled through the mount points. The usage of the native Windows device names is not sufficent.

NT/W2K supports raw block special device support for partitions and drives. The device names for partitions is the drive letter with leading \\.\, so the floppy would be \\.\A:, the first partition typically \\.\C:. Complete drives (except floppies which are supported as partitions only) are named \\.\PHYSICALDRIVEx. The x is the drive number which you can check in the disk manager. Each drive line has prepended the text "Disk x".

To access tape drives, NT/W2K uses the file name \\.\TAPEx. For example the first installed tape device is named \\.\tape0.

To access those devices you have to mount them and you have to use the posix name of the device to be recognized by Cygwin. The naming convention is simple: The name has to begin with /dev/ and the rest is as you like. The only exception are tape devices. To identify if the tape device is used as a rewind or a no-rewind device the name must not begin with n (rewind) or has to begin with n (no-rewind).

Some examples:

mount -b //./A: /dev/fd0              # mount floppy as raw block special
mount -b //./physicaldrive1 /dev/hdb  # mount "Disk 1"
mount -b //./tape0 /dev/st0           # mount first tape as the rewind device...
mount -b //./tape0 /dev/nst0          # ...and as the no-rewind device

Note the usage of the -b option. It is best to include the -b option when mounting these devices to ensure that all file I/O is in "binary mode".

The .exe extension

Executable program filenames end with .exe but the .exe need not be included in the command, so that traditional UNIX names can be used. However, for programs that end in ".bat" and ".com", you cannot omit the extension.

As a side effect, the ls filename gives information about filename.exe if filename.exe exists and filename does not. In the same situation the function call stat("filename",..) gives information about filename.exe. The two files can be distinguished by examining their inodes, as demonstrated below.
C:\Cygnus\> ls * 
a      a.exe     b.exe
C:\Cygnus\> ls -i a a.exe
445885548 a       435996602 a.exe
C:\Cygnus\> ls -i b b.exe
432961010 b       432961010 b.exe
If a shell script myprog and a program myprog.exe coexist in a directory, the program has precedence and is selected for execution of myprog.

The gcc compiler produces an executable named filename.exe when asked to produce filename. This allows many makefiles written for UNIX systems to work well under Cygwin.

Unfortunately, the install and strip commands do distinguish between filename and filename.exe. They fail when working on a non-existing filename even if filename.exe exists, thus breaking some makefiles. This problem can be solved by writing install and strip shell scripts to provide the extension ".exe" when needed.

The @pathnames

To circumvent the limitations on shell line length in the native Windows command shells, Cygwin programs expand their arguments starting with "@" in a special way. If a file pathname exists, the argument @pathname expands recursively to the content of pathname. Double quotes can be used inside the file to delimit strings containing blank space. Embedded double quotes must be repeated. In the following example compare the behaviors of the bash built-in echo and of the program /bin/echo.

Example 3-4. Using @pathname

/Cygnus$ echo  'This   is   "a     long"  line' > mylist
/Cygnus$ echo @mylist
@mylist
/Cygnus$ /bin/echo @mylist
This is a     long line
/Cygnus$ rm mylist
/Cygnus$ /bin/echo @mylist
@mylist