The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
grep unix.com with google



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

Closed Thread
English Japanese Spanish French German Portuguese Italian Powered by Powered by Google
 
Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 12-15-2005
Registered User
 

Join Date: Dec 2005
Posts: 6
File Descriptor to File Name

Is there a way to get the file name and/or path (in string form) from a file descriptor?

Last edited by lskuff; 12-16-2005 at 12:26 AM..
  #2 (permalink)  
Old 12-16-2005
Registered User
 

Join Date: Dec 2005
Posts: 23
Question please elaborate...

please elaborate your requirements and the platform on which you are working
  #3 (permalink)  
Old 12-16-2005
Registered User
 

Join Date: Dec 2005
Posts: 6
sorry, I am working on UNIX platform... the problem is that I use an open syscall to open up a file and I get the file descriptor as the return value... later on when I am doign I read I am computing a md5 checksum and storing the value in a file that is called something like filename.checksum..... The problem is that at the point of the read I don't know what the file name is, all I have is the file descriptor. As of now I have used fstat to get the i-node number and am storing the checksum in a file with the name = the i-node id number. ... however, I would instead like to name the checksum file filename.checksum... . know how to get the file name from the fd? thanks
  #4 (permalink)  
Old 12-16-2005
blowtorch's Avatar
AFK
 

Join Date: Dec 2004
Location: Singapore
Posts: 2,351
That is surprising. If you do not know the name of the file, then how are you using open() in the first place? And if at the point of the open() you have the filename, can't you use that?
  #5 (permalink)  
Old 12-16-2005
...@...
 

Join Date: Feb 2004
Location: NM
Posts: 6,006
blowtorch has it right.

The file descriptor structure in memory does not have an actual name of a file in it.
Once you have a file open you can get some information about the file use lstat or fpathconf. Just not the file name. The reason is that the fd keeps track of files by inode number. If you translate and inode to a file name it will have disk device names
as part of the path. You referenced the file thru the filesystem - with a path and a name.

The other issue is: what do you want to do with the file name? You can do absolutely any defined file operation using the fd number.

If you need the path as you received it, then reference it with a global char * pointer.
  #6 (permalink)  
Old 12-16-2005
Registered User
 

Join Date: Dec 2005
Posts: 6
well I am making a dynamically linked library that adds a file system layer that adds some error check abilities... it interposes on all important file system related calls... I know that I have the name of the file in open, but a whole lot of file might be opened before any is read. When the file is read I only have the fd.... In the read() I want to open (if it exists) or create another file with the same name and just a different extension.

I guess from what you guys said the only way to do this is to create my own file table which is like a (very) large string array with each element = the file name and each index corresponding to a fd.

If this is the case I think I will just stick to my i-node naming because that has too much memory overhead. Thanks
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Passing a file descriptor robotball Shell Programming and Scripting 6 06-08-2008 11:41 PM
Problems with file descriptor teo High Level Programming 11 05-09-2005 12:47 PM
File Descriptor Help rahulrathod UNIX for Dummies Questions & Answers 3 10-14-2004 06:08 AM
file activity (open/closed) file descriptor info using KORN shell scripting Gary Dunn UNIX for Dummies Questions & Answers 3 06-07-2004 02:54 PM
bad file descriptor? ftb UNIX for Dummies Questions & Answers 1 02-20-2002 07:19 PM



All times are GMT -4. The time now is 02:26 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0