Get the filename from a file descriptor in C programming

I am writing a kernel module that will essentially intercept sys_write calls and mirror the write to another location. sys_write only has the file descriptor associated with it, not the actual file name. Does anyone know of a way to get the actual filename that a file descriptor is pointing to? I need to be able to mirror this write to the exact same filename on an NFS mounted drive.



Just for info -- -this is being done on a Redhat 8 machine running kernel 2.4.18 using the C programming language....     A linux specific solution would work just fine ....
UniformOfDestructionAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

RichieHindleCommented:
If you can't find a way to get the information from the system, you can always intercept the open and close calls and keep your own mapping from descriptor to name.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
UniformOfDestructionAuthor Commented:
I thought of intercepting open ... since that includes the file name.   The problem is that I am having a hard time coming up with a way to map a sysopen to a syswrite.   There are tons of sys_opens happening on the system at a given time ... so, I can't see how to grab a sys_open and see which sys_write is it corresponding to.
0
RichieHindleCommented:
The PID and the returned descriptor should be enough, if both are available to you.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

UniformOfDestructionAuthor Commented:
Where can I obtain the original filename that the desciptor is refering to?
0
RichieHindleCommented:
I meant that you could store (PID, returned descriptor, filename) for each sysopen, then for each syswrite use (PID, descriptor) to look up the filename.
0
UniformOfDestructionAuthor Commented:
Ahh ... ok ... that sounds reasonable... let me give it a try and get back to you on that.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.