Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!auspex!guy From: guy@auspex.auspex.com (Guy Harris) Newsgroups: comp.unix.questions Subject: Re: /bin/pwd Message-ID: <4062@auspex.auspex.com> Date: 14 Sep 90 20:47:49 GMT References: <2488@idunno.Princeton.EDU> <13851@smoke.BRL.MIL> <2497@idunno.Princeton.EDU> Organization: Auspex Systems, Santa Clara Lines: 22 >For example, how do you find out the name of "."? You could find out >its inode, and then check the previous directory to see which name >matches its inode; but that only works until you get to the root of the >filesystem your directory is mounted in (I don't mean "/"). What then? Do >you have to check /etc/mtab? No. You just have to do a little more work to see which name matches the inode. I.e., if the directory whose name you're trying to find, and the directory in which you're trying to find it, are on the same file system, *and* you know that the directory entries you get back from "readdir()" or whatever contain i-numbers (POSIX does *not* guarantee this, although the SVID and XPG3 do), you can use the i-number from the directory entry. However, if they're *not* on the same file system, for each directory entry in the directory you're reading you have to construct the path of the file that entry refers to and "stat()" it (or "lstat()" it, if you have "lstat()") to find out its inumber; the directory entry's inumber will be the inumber of the mount point, but the "stat()" will give the inumber of the file mounted atop that mount point.