delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2000/10/18/10:10:42

Mailing-List: contact cygwin-help AT sourceware DOT cygnus DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT sources DOT redhat DOT com>
List-Archive: <http://sources.redhat.com/ml/cygwin/>
List-Post: <mailto:cygwin AT sources DOT redhat DOT com>
List-Help: <mailto:cygwin-help AT sources DOT redhat DOT com>, <http://sources.redhat.com/ml/#faqs>
Sender: cygwin-owner AT sources DOT redhat DOT com
Delivered-To: mailing list cygwin AT sources DOT redhat DOT com
X-Envelope-Sender-Is: Andrej DOT Borsenkow AT mow DOT siemens DOT ru (at relayer david.siemens.de)
From: "Andrej Borsenkow" <Andrej DOT Borsenkow AT mow DOT siemens DOT ru>
To: "Earnie Boyd" <earnie_boyd AT yahoo DOT com>,
"Egor Duda" <cygwin AT sources DOT redhat DOT com>
Cc: <cygwin AT sources DOT redhat DOT com>
Subject: RE: /bin/pwd (getcwd) and symlinks
Date: Wed, 18 Oct 2000 18:09:25 +0400
Message-ID: <000c01c0390d$0591e760$21c9ca95@mow.siemens.ru>
MIME-Version: 1.0
X-Priority: 3 (Normal)
X-MSMail-Priority: Normal
X-Mailer: Microsoft Outlook IMO, Build 9.0.2416 (9.0.2911.0)
In-reply-To: <20001018134646.16601.qmail@web113.yahoomail.com>
X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400
Importance: Normal

>
> 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 AT sourceware DOT cygnus DOT com

- Raw text -


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