LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel
User Name
Password
Linux - Kernel This forum is for all discussion relating to the Linux kernel.

Notices


Reply
  Search this Thread
Old 10-06-2011, 07:20 PM   #1
user4321
LQ Newbie
 
Registered: Oct 2011
Posts: 2

Rep: Reputation: Disabled
How to get file name from file descriptor?


Hello,

I want to get the file name from file descriptor of an opened file.

Can anyone help me how to get file name from file descriptor?

Thanks

Last edited by user4321; 10-09-2011 at 02:56 PM.
 
Old 10-07-2011, 11:57 AM   #2
harry edwards
Member
 
Registered: Nov 2007
Location: Lincolnshire, UK
Distribution: CentOS, Fedora, and Suse
Posts: 365

Rep: Reputation: 48
Does this help? http://stackoverflow.com/questions/1...escriptor-in-c
 
Old 10-07-2011, 12:40 PM   #3
user4321
LQ Newbie
 
Registered: Oct 2011
Posts: 2

Original Poster
Rep: Reputation: Disabled
I had gone through this link.
fstat doesnt give filename information and i cannot use readlink because of kernel.

Thanks for the reply.
 
Old 10-08-2011, 03:09 AM   #4
harry edwards
Member
 
Registered: Nov 2007
Location: Lincolnshire, UK
Distribution: CentOS, Fedora, and Suse
Posts: 365

Rep: Reputation: 48
My other thought was that the command lsof lists open files; including the FD and the file-name. I am not sure how; but, the source code is available at http://freshmeat.net/projects/lsof/. In theory lsof is doing exactly what you need; however, whether the code can be extracted and included in kernel module, I have no clue :-)
 
Old 10-08-2011, 05:05 AM   #5
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
Quote:
Originally Posted by user4321 View Post
I am writing Loadable Kernel Module in which i write my own function to read a file and at the end i call the original read function.
What Linux distribution you use and what the purpose is does not matter as long as the file you're reading from or writing to resides in proc VFS. AFAIK Linux LKMs shouldn't read from or write to userland and if you want or think otherwise then that's a potentially lethal design mistake.
 
  


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
Get the absolute path of file using file descriptor. appas Programming 7 01-19-2012 11:47 AM
Too many file open - How can we define Max limit of file descriptor janeshb Linux - Server 11 09-29-2009 10:41 AM
open local file error when creating file descriptor hellgirl Linux - Newbie 1 09-14-2009 10:03 PM
Deleted log file - how to get back via file descriptor and keep alive? prollocks Linux - General 1 05-29-2009 09:08 AM
apt-file returns nothing; 'bad file descriptor' overbored Debian 3 10-03-2004 09:13 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel

All times are GMT -5. The time now is 05:29 PM.

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