Directory traversal (crossin mount points)

Jonathan I. Kamens jik at athena.mit.edu
Tue Jul 3 02:26:25 AEST 1990


In article <5854 at aplcen.apl.jhu.edu>, trw at aplcen.apl.jhu.edu (Weil
timothy) writes:
|> I'm writing a simple program to emulate the 'pwd' command
|> that traverses from the current directory to the ROOT_INODE
|> via a simple statement like - 
|>  
|>       while (this_dir_inode != ROOT_INO)
|>           chdir ..
|>           match this_dir_inode in parent_directory
|>           ....
|>       et cetra
|>  
|> Question: - since there are repitions of ROOT_INODE (#2)
|> across file system mount points, how can I distinguish the
|> ROOT_INODE for '/'   from '/usr'   or '/usr/users' ?

  The way to tell if you've reached the actual root of the local
filesystem, or just some root inode on a remote filesystem mounted
somewhere in your local filesystem is to check if the inode and device
numbers of "." and ".." in the directory are the same.  If they are,
then you're at the root of the filesystem.

Jonathan Kamens			              USnail:
MIT Project Athena				11 Ashford Terrace
jik at Athena.MIT.EDU				Allston, MA  02134
Office: 617-253-8495			      Home: 617-782-0710



More information about the Comp.unix.questions mailing list