Re: Comm Ports 10+
- From: Joseph M. Newcomer <newcomer@xxxxxxxxxxxx>
- Date: Fri, 16 Dec 2005 23:34:19 -0500
The general syntax is
\\machinename\sharename\path
so c: is typically
\\.\c\
A friend called me in a panic. He'd copied over a massive system from Unix to Windows,
and there was a header file aux.h and implementation aux.cpp. He couldn't build the
system because the backward-hack recognizer ignores extensions (I forgot to mention that
the extension is completely ignored by this hack). So he did
ren aux.h auxfile.h
and it wouldn't let him rename aux because it is a built-in device . So I told him to do
ren \\.\c\aux.h auxfile.h
and it worked perfectly. If you specify \\.\sharename then the backward-compatible MS-DOS
hack is bypassed entirely.
The naming convention is what is called "UNC", for "Universal Naming Convention" and it
works in Windows, Unix, and a lot of other systems. In Unix, I used to be able to do
cp \\mit\ai\somefile .
because \\ was the global directory system which over the Internet named hundreds of
machines; mit named the site, ai was the MIT AI lab machine. IBM's DFS (distributed file
system) supports this. (DFS is the commercial version of the research system, the Andrew
File System, AFS, developed at CMU at its Information Technology Center. I spent a year
at the ITC, in the last year of its existence; by that time the creators of AFS had gone
off to IBM to build DFS).
Note that the machinename only works if there is a redirector, and there is only a
redirector for the file system. So you can't typically access COM1 on some other machine
by doing
\\thatmachine\COM1
because there is no COM redirector. So unless there's a redirector, the only machinename
you can use for most devices is ".".
All devices are in the internal kernel namespace '??' (aka DosDevices, which is now a
softlink to ??), so \\.\sharename causes the device to be looked up in the kernel ??
table. \\.\Hello looks up the kernel namespace name \??\Hello, which is a softlink to the
kernel namespace \Devices\HiThere (we use a different internal name to show that the names
don't have to be related, although they often are), which is a link to the kernel Device
Object created by IoCreateDevice. Device drivers do not necessarily have
application-visible names; the "exported" name is in \??, while the "private" name (known
only to the kernel) is in \Devices.
Or, to put it another way, MS-DOS device names like c: are just a shortcut for \\.\c\, and
are maintained for backward compatibility. \\.\c is looked up as \??\c. \??\c is
actually a softlink to (usually) \Device\HardDisk0\Partition1 (Partition0 is the entire
physical disk)
Note that in the file system, you can create a sharename for some subdirectory. So, for
example, I once worked at a site where the server had a special share name \\server4\jmn
and that's how they gave me a restricted access to the server (you don't want to know the
political battle just to get that much...) where our source files were maintained. The
sharename was to a subdirectory of something like
d:\projects\something\whatever\ourproject
I could not do "dir .." if I was in that share; I would get "access denied" [well, I was
supposed to get an access denied, but the twits in IT screwed up the ACLs. We told the IT
department that it worked; it turns out I could see the parent directory, and since that
contract is now years in the past, I can say it...but I couldn't imagine what else I'd
need to see, so never went looking for anything]
Active Directory does something like this as well, but I've managed to avoid most of
Active Directory (there's not enough time in this life to get involved in every piece of
Windows technology).
joe
On Sat, 17 Dec 2005 04:44:15 +1000, Ian Semmel <isemmelNOJUNK@xxxxxxxxxxxxxxxxxxxxxxx>
wrote:
>That's interesting, but I wonder how such a syntax was arrived at ?
>
>How does the system name disk drives like c: etc ?
>
>
>
>Joseph M. Newcomer wrote:
>> The explanation goes like this:
>>
>> The formally correct way to access any device on the system is via \\.\devicename. For
>> backward compatibility with MS-DOS programs, there is a special recognizer in CreateFile
>> that looks for "COM"<digit>, "LPT"<digit>, "CON", "AUX", "PRN", and perhaps some other
>> names I've forgotten. However, the recognizer is very precise, e.g., "COM" plus a single
>> digit. It then translates these names into an open request on \\.\name. But for any
>> other device, or devices which do not conform to the hack, e.g., "COM"<digit><digit>, the
>> retrohack is not applied.
>>
>> In our driver course, the first project is a "Hello World" device driver whose name is
>> \\.\Hello.
>>
>> The names are not case-sensitive, by the way, so COM, com, Com, cOm, etc. all get
>> recognized.
>> joe
>>
>> On Tue, 13 Dec 2005 16:07:18 -0500, r norman <NotMyRealEmail@xxxxxxxxxxxx> wrote:
>>
>>
>>>On Tue, 13 Dec 2005 20:51:20 GMT, "AliR" <AliR@xxxxxxxxxxxxx> wrote:
>>>
>>>>"Ian Semmel" <isemmelNOJUNK@xxxxxxxxxxxxxxxxxxxxxxx> wrote in message
>>>>news:OAp2MZCAGHA.1268@xxxxxxxxxxxxxxxxxxxxxxx
>>>
>>>>>USB devices can have a comm port number greater than 9.
>>>>>In these cases, what is passed to CreateFile ?
>>>>>I have something in the back of my mind that there is a different syntax,
>>>>>but anyway, "COM10" doesn't appear to work.
>>>>
>>>>this should work
>>>>CreateFile("\\\\.\\COM10",.....);
>>>
>>>Yes, that is the way to do it. But does anybody have an explanation
>>>why it should be so? Somewhere buried in Microsoft, some code has to
>>>scan the "file" name to see if it is a COM (or LPT) port. But why
>>>only in the root directory and why doesn't it matter what drive might
>>>be the default? And why allow COM1 through 9 without that?
>>>
>>>
>>>
>>>I
>>
>> Joseph M. Newcomer [MVP]
>> email: newcomer@xxxxxxxxxxxx
>> Web: http://www.flounder.com
>> MVP Tips: http://www.flounder.com/mvp_tips.htm
Joseph M. Newcomer [MVP]
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
.
- Follow-Ups:
- Re: Comm Ports 10+
- From: Ian Semmel
- Re: Comm Ports 10+
- References:
- Comm Ports 10+
- From: Ian Semmel
- Re: Comm Ports 10+
- From: AliR
- Re: Comm Ports 10+
- From: r norman
- Re: Comm Ports 10+
- From: Joseph M . Newcomer
- Re: Comm Ports 10+
- From: Ian Semmel
- Comm Ports 10+
- Prev by Date: Re: How to disable AutoPlay programmatically
- Next by Date: Re: ON_UPDATE_COMMAND_UI issue in release mode
- Previous by thread: Re: Comm Ports 10+
- Next by thread: Re: Comm Ports 10+
- Index(es):
Relevant Pages
|