www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/12/22/10:41:37

Date: Sun, 22 Dec 1996 17:22:09 +0200 (IST)
From: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>
To: Ian Romanick <idr AT cs DOT pdx DOT edu>
cc: djgpp AT delorie DOT com
Subject: Re: File utils are crap?
In-Reply-To: <32B9752D.5A86@cs.pdx.edu>
Message-ID: <Pine.SUN.3.91.961222164757.973B-100000@is>
MIME-Version: 1.0

On Thu, 19 Dec 1996, Ian Romanick wrote:

> Anyway, are the file utils that come with 2.01 totally hosed?  Witness
> the following LS antics:

Short answer: don't call any of your top-level directories "/dev".

Long answer about the true story behind "/dev" in DJGPP v2 follows.  But
first, a request:  please don't use words like ``crap'', or ``hosed'', or
anything in thereabouts in conjunction with DJGPP packages, unless you are
their author or maintainer, especially since you probably already know
that the behavior you describe is limited to "/dev"; any other directory
works as you'd expect.  Somehow, such friendly titles don't make the
motivation to help you higher... 

Anyway, the /dev directory is special in both Unix and DOS as the place
where the devices reside.  However, DOS handles it rather half-heartedly:
it reserves it for the above function (since most DOS machines won't
actually have it), but also lets you create a directory by that name.  For
instance, assuming there is no \DEV directory on your disk C:, try these
commands from the DOS prompt (DOS response is to the right of the arrow): 

	truename c:\dev\con   ==> C:/CON
	truename c:\dos\con   ==> C:\DOS\CON
	dir c:\dev\con        ==> File not found
	truename c:\dev\xyzzy ==> C:\DEV\XYZZY

See?  First, DOS knows that \dev\con is different from \dos\con.  Second, 
some (most) DOS commands and functions will fail for "\dev\con" (or 
"\dev\nul", or any other device name).  Third, DOS knows that "con" is a 
device name, but "xyzzy" is not.

OTOH, many Unix programs assume that the null device is called 
"/dev/null" and the terminal is called "/dev/tty".  It is a porter's 
nightmare to go through the sources looking for these names and replace 
them with DOS "NUL" and "CON".

DJGPP v2 tries both to mimic DOS behavior (up to a point) and
transparently translate names like "/dev/tty" into their DOS counterparts
so that ported programs still work.  When any DJGPP program calls a DOS
file-oriented function with a name which begins with "/dev" or "x:/dev" 
(where x is a drive letter), the low-level functions that put the filename
into the transfer buffer before they call DOS, convert the full pathname
into the corresponding DOS name.  For devices such as "null" for which the
translation is known, DJGPP also changes the device name.  For
DOS-specific devices such as "clock$" there is no such translation, but we
still want DJGPP to tell us if these are devices.  For example, if you
call `stat("/dev/clock$")' you want it to return the character-device bit
set in struct stat.  DOS scans the list of installed devices and then
knows if device by a given name is installed.  To avoid such a costly
test, DJGPP just strips away the "/dev/" part and lets DOS decide if the
rest is a known file.  This makes "ls -l /dev/tty" and "ls -l /dev/clock$"
work.  Unfortunately, it also has a nasty side-effect if you really have a
directory called "/dev".  End of story. 

Does this make The Fileutils port (or indeed all of the DJGPP
file-oriented functions) ``crap''?  I don't think so.  But you decide. 

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019