This is the mail archive of the cygwin@sources.redhat.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

RE: /bin/pwd (getcwd) and symlinks


>
> Ok.  HP-UX /bin/pwd prints the actual directory.  But, what does /bin/pwd on
> Linux do?  Where is any documentation for what it should do for symlink?  I
> haven't found anything useful that describes what happens for symlink.
>

It is not "what it should do" - it is how symlinks and getcwd are (typically)
implemented.

Symlinks are implemented by storing target name as symlink file content. When
you open symlink, kernel implicitly opens target, giving you (dev,inode) - or
vnode - of _target_. After this step, there is no way to recover the original
name (or inode) of symlink.

getcwd is implemented by fetching inode of current directory, scanning parent
directory (..) and comparing inodes there with current inode. When it is
found, directory entry gives you last part of absolute name. Than getcwd goes
up (cd ..) and repeats it. It does it until it hits root (inode(.) ==
inode(..)).

If you combine both, you see, that there is no way getcwd can actually find
_symlink_ name.

As stated - this is typical implementation. YMMV :-) But I'm really curious to
see any Unix-like system that does it differently.

-andrej


--
Want to unsubscribe from this list?
Send a message to cygwin-unsubscribe@sourceware.cygnus.com


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]