LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   indoe to file name (https://www.linuxquestions.org/questions/programming-9/indoe-to-file-name-356232/)

$@ya 08-23-2005 02:56 PM

indoe to file name
 
I have the a files i-node number (stat struct) from which I want to get it filename or pathname (any thing useful so that i can open or close this file).

thanx
-neo

AngryLlama 08-25-2005 05:12 PM

I'm unsure if this is even possible. The reason I believe this is because a single inode can have tons of links to it. How would you know which one to get?

Of course, I am probably way off base... I just noticed this thread has been sitting around for a while.

paulsm4 08-26-2005 01:24 AM

Each file is defined by an i-node (so far, so good)...
... but the "name" of a file is stored in a directory - it is *not* associated with the inode itself.

This is how the Linux "link" command works: it simply associates a different name with the inode. And all links are equal: it isn't as though one name is the "real" name and the rest are aliases.

Anyway, in *nix, a "file name" (or "names"!) is a property of the filesystem's directories. There's no such thing as "the file name of an inode".

'Hope that helps .. PSM

PS:
If it doesn't help - or if you're curious - get a copy of Tanenbaum's classic "Operating Systems". He discusses the topic in depth.

$@ya 08-29-2005 04:32 PM

I was totally wrong... i did go back opened my book (richard steven) to see how the inode structure actually is and you were right it is not directly associated with filname(s) [ i mean inode of a flename],

But what i was trying there, was to have a unique identifier for each of my files. So that i can call them by this identifier even when they are renamed or move to a different location and the first thing that came to my mind was inode.

well i guess i will have to create my own unique identifiers and keep track of those or may be use file pointers.

thanx for all the help
neo

lordofring 08-30-2005 11:48 AM

What you said does make sense. I can find the inode number from a file name, but why I can't reversely find the file name from the inode. I just think aloud here. I have a stupid idea to do that. Searching the inode table (whatever the name), and find out which directory owns this inode. Then go through every file under this directory until find the certain inode.

Hko 03-13-2006 11:15 AM

Quote:

Originally Posted by lordofring
I have a stupid idea to do that. Searching the inode table (whatever the name), and find out which directory owns this inode.

There's no such thing as a "directory that owns an inode".

kshkid 03-14-2006 12:24 AM

a live sample,

Code:

ls -il /usr/bin/ksh /usr/bin/rksh
12951 -r-xr-xr-x 3 root bin      201052 Aug  4  2004 /usr/bin/ksh*
12951 -r-xr-xr-x 3 root bin      201052 Aug  4  2004 /usr/bin/rksh*

both ksh and rksh do have the same inode
if you branch out from inode to filenames you have two different filenames for the same inode


All times are GMT -5. The time now is 07:33 AM.