[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 659
  • Last Modified:

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 ....
0
UniformOfDestruction
Asked:
UniformOfDestruction
  • 3
  • 3
1 Solution
 
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
 
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now