inode number -> pathname? (4.2BSD)

Chris Torek chris at umcp-cs.UUCP
Fri Jul 12 09:27:04 AEST 1985


>>> I am looking for a good way to generate the full path name of a directory, 
>>> given only its inode number (plus the device number of its filesystem).
>>> The 'obvious' solution is ... (what "ncheck" does).
 
>> Not only is it the obvious solution, it's the only solution.  No version of
>> UNIX currently in existence or coming out in the near future (nor, I
>> suspect, any version you're likely to see) makes it any easier.

> I disagree!  If it were possible to set the current working directory
> to a given inode and device, then pwd would give you the answer.  All
> the permission information, and even the bit denoting whether or not
> this inode refers to a directory is stored in the inode, and can easily
> be checked in such a call.  Putting such a call in would be easy.  Just
> do what "chdir" (well, actually "chdirec" in 4.2) does after it calls
> "nami".  Why is this hard?

It's "hard" because the difference between chdir and set_my_cdir_inode
is that chdir checks permissions along the *entire pathname* leading
to the ultimate inode that will sit in u.u_cdir.  (Of course you
could restrict the set_my_cdir_inode syscall to the super user....)

Even putting code in the kernel to do what pwd does, and making it
check permissions on all the parent directories, wouldn't be right
as when you log in you get to your home directory by a chdir by
uid 0, so there's no guarantee that any higher level directories
are accessible (anymore).

> Now, what would be hard would be generating the full path name for
> an arbitrary file given just the inode and device. ...  But with
> a directory, you know that (save symbolic links) there is one unique
> path name for that directory.

Actually, you don't "know" it, but you sure hope it's true....
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 4251)
UUCP:	seismo!umcp-cs!chris
CSNet:	chris at umcp-cs		ARPA:	chris at maryland



More information about the Comp.unix.wizards mailing list