![]() |
|
|
grep unix.com with google
|
|||||||
| Forums | Register | Blog | Man Pages | Forum Rules | Links | Albums | FAQ | Our Members | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 !! |
![]() |
|
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|||
|
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
|
|
|||
|
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. |
|
|||
|
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 | ||
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
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 |