ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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).
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.
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.
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.
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.
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
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.