How to get list of all files open in the system
sergei.starovoi at gmail.com
Sat Nov 14 13:13:26 EST 2015
I'm writing a kernel module. One of its tasks requires getting full paths of all open files in the system.
My first solution essentially looks like:
iterate_fd(files, 0, my_callback, NULL);
my_callback calls d_path for passed file->f_path to get its full path.
But this solution has obvious problems:
A. It will skip files which were opened directly from kernel code (using filp_open for example);
B. It iterates over fd_table for each thread, performing a lot of unnecessary work (invoking my_callback multiple times for one file).
My questions are:
1) Is there any bettter way to get full paths of all open files?
2) If there is no better way, what kind of locking should i use
a) to protect access to task list when invoking for_each_process_thread?
b) to protect access to thread's fd_table when invoking iterate_fd?
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Kernelnewbies