[OT] strange interaction between open and cwd

Gregory Ewing greg.ewing at canterbury.ac.nz
Tue May 4 03:56:13 EDT 2010


Charles wrote:

> In the OP's case, references to the directory have been removed from the 
> file
> system, but his process still has the current working directory reference to 
> it,
> so it has not actually been deleted. When he opens "../abc.txt", the OS 
> searches
> the current directory for ".." and finds the inode for /home/baz/tmp,

This doesn't seem to be quite correct. An experiment I just did
reveals that the link count on the parent directory goes down by
one when the current directory is deleted, suggesting that the ..
link has actually been removed... yet it still works!

I think what must be happening is that the kernel is maintaining
an in-memory reference to the parent directory, and treating ".."
as a special case when looking up a name.

(This probably shouldn't be too surprising, because ".." is special
in another way as well -- at the root of a mounted file system, it
leads to the parent of the mount point, even though the actual ".."
link on disk just points back to the same directory. Probably it
simplifies the name lookup logic to always treat it specially.)

-- 
Greg



More information about the Python-list mailing list