[squeak-dev] Re: Strange Unix file behavior?

Paolo Bonzini bonzini at gnu.org
Thu Aug 7 12:50:12 UTC 2008


Tony Garnock-Jones wrote:
> David T. Lewis wrote:
>> Strictly speaking, opening a directory as a file stream is not wrong.
> 
> Interesting. I was under the impression that that changed, quite some 
> time ago now. I recall using cat on directories in Minix 1.5, and 
> getting halfway-useful (if file-system specific) results, but modern 
> Linux and OS X machines don't seem to let you read anything out of 
> directories without using the special directory-traversal functions.

They don't allow reading, but they do allow opening for reading.  The 
resulting descriptor is meant to be used with openat() and other similar 
system calls suffixed "at". openat() allows an application to avoid race 
conditions that could occur when using open(2) to open files in 
directories other than the current working directory. These race 
conditions result from the fact that some component of the directory 
prefix given to open() could be changed in parallel with the call to 
open(). Such races can be avoided by opening a file descriptor for the 
target directory, and then specifying that file descriptor as the dirfd 
argument of openat().

Paolo



More information about the Squeak-dev mailing list