LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-23-2005, 02:56 PM   #1
$@ya
LQ Newbie
 
Registered: Jun 2005
Distribution: SUSE 9.2
Posts: 13

Rep: Reputation: 0
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
 
Old 08-25-2005, 05:12 PM   #2
AngryLlama
Member
 
Registered: Sep 2004
Location: /dev/urandom
Distribution: Gentoo
Posts: 171

Rep: Reputation: 31
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.
 
Old 08-26-2005, 01:24 AM   #3
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
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.

Last edited by paulsm4; 08-26-2005 at 01:26 AM.
 
Old 08-29-2005, 04:32 PM   #4
$@ya
LQ Newbie
 
Registered: Jun 2005
Distribution: SUSE 9.2
Posts: 13

Original Poster
Rep: Reputation: 0
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
 
Old 08-30-2005, 11:48 AM   #5
lordofring
Member
 
Registered: Feb 2005
Posts: 91

Rep: Reputation: 15
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.
 
Old 03-13-2006, 11:15 AM   #6
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
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".
 
Old 03-14-2006, 12:24 AM   #7
kshkid
Member
 
Registered: Dec 2005
Distribution: RHEL3, FC3
Posts: 383

Rep: Reputation: 30
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
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
forrtl: severe (47): write to READONLY file, unit 5, file /dev/pts/1 terrence Programming 1 10-01-2005 10:22 PM
awk: fatal:cannot open file for reading (no such file or Directory) in Linux sangati vishwanath Linux - Software 4 07-06-2005 12:59 AM
gave wrong syntax for tar as tar -cvzf file file.tgz how to recover the file gautham Linux - General 4 04-13-2005 03:15 AM
Yum update complains missing file (broken dep), but file can be located. davidas Linux - Software 0 03-27-2004 09:11 PM
How to play a media file/ video file/mp3 file recorded in harddisk/cd-rom arindam Linux - Newbie 2 09-05-2003 10:31 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:31 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration