device names tidbit

Parker, Ron rdparker@butlermfg.org
Mon Jan 10 15:04:00 GMT 2000


Their is another version of this syntax uses a '?' inplace of the '.'. For
example:
	DEL \\?\c:\somedir\aux

I seem to recall that this only works on NT.  I may be wrong, but I vaguely
recall working on a winsup patch that used this under NT.  (It was not a
complete solution, so I never submitted it.)  It is the same mechanism that
allows us to use "\\.\a:" for raw floppy access in CYGWIN under NT.

For those that care here is what is going on and why this works.  Forgive me
if you have seen it before, but I believe it provides a little more
background than the MS documentation that I was able to find when I was
working on my local patch a couple years ago. Most of the obscure and
limited documentation about this is in the Win32 DDK.  The rest is what I
have managed to determine by experimentation and my own research.

If you download and run the SysInternals' WinObj program it may make the
following explanation a little clearer.  This program lets you take a look
at the Object Manager Namespace in NT. It is available for download at
http://www.sysinternals.com/winobj.htm .

If you look in the "??" folder in WinObj you will find a number of symbolic
links that have been registered with the Object Manager.  These are used by
the Win32 subsystem and NTVDM to map DOS style device names to their
corresponding NT devices.  Additionally they use it to reject certain
filenames, like "aux", before they are passed to the Object Manager for
handling.  Using one of the "\\.\" and "\\?\" prefixs causes the filename to
be passed to the Object Manager in NT without this filename check occuring.
The nominal Posix subsystem in NT always passes its filenames to the Object
Manager without doing this "device name check". 

I don't remember whether or not the prefix is stripped before going into the
Object manager.  But when the Object Manager gets the filename, it checks
the beginning of the filename against the list of device names in its
symbolic link table.  On my machine C: maps to \Device\Harddisk0\Partition1.
WinObj shows this as a \Device\Harddisk0 folder with a Partition1 device in
it.  So using DJ's example of "\\.\c:\somedir\aux" the filename
"somedir\aux" is passed on to the device that is registered as
\Device\Harddisk0\Partition1 for further processing.  That is how the
filename eventually reaches the driver.

Just to put filename processing in graphical terms here are two examples of
how a filename is processed in NT.

Filename         Route taken through the OS
--------
------------------------------------------------------------
\\.\C:\dir\file  App->(NTVDM)->Win32 subsystem->Object Manager->Device
Driver
C:\dir\file      App->(NTVDM)->Win32 subsystem->
				Win32 filename check->Object Manager->Device
Driver
                        |
				+--> Possibly rejected at this point.

-----Original Message-----
From: DJ Delorie [ mailto:dj@delorie.com ]
Sent: Friday, January 07, 2000 3:29 PM
To: cygwin-developers@sourceware.cygnus.com
Subject: device names tidbit



I just ran across this in MSDN.  I wonder if we should use this trick
to be able to create/delete otherwise "reserved" names?

--

Another option is to use a syntax that bypasses the normal
reserve-word checks altogether. For example, you can possibly delete
any file with a command such as:

   DEL \\.\<drive letter>:\<path>\<file name>

For example: 

   DEL \\.\c:\somedir\aux
-------------- next part --------------
A non-text attachment was scrubbed...
Name: bin00000.bin
Type: application/vnd.ms-tnef
Size: 3764 bytes
Desc: not available
URL: <http://cygwin.com/pipermail/cygwin-developers/attachments/20000110/32652895/attachment.tnef>


More information about the Cygwin-developers mailing list