/bin/pwd

Guy Harris guy at auspex.auspex.com
Sat Sep 15 06:47:49 AEST 1990


>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.



More information about the Comp.unix.questions mailing list