I\'m trying to view the filename via kgdb, so I cannot call functions and macros to get it programatically. I need to find it by manually inspecting data structures.
<In the Linux kernel, the file
structure is essentially how the kernel "sees" the file. The kernel is not interested in the file name, just the inode of the open file. This means that all of the other information which is important to the user is lost.
EDIT: This answer is wrong. You can get the dentry
using filp->f_path.dentry
. From there you can get the name of the dentry or the full path using the relevant FS flags.
You can get the filename from struct file *filp
with filp->f_path.dentry->d_iname
.
To get the full path call dentry_path_raw(filp->f_path.dentry,buf,buflen)
.
The path is stored in the file->f_path structure as it's name implies. Just not in a plain-text form, but parsed into objects that are more useful for kernel operation, namely a chain of dentry
structures, and the vfsmount
structure pointing to the root of the current subtree.
You can use the d_path
function to regenerate a human-readable path name for a struct path like file->f_path. Note that however this is not a cheap operation and it may slow down your workload significantly.
The above mentioned issues about open but unlinked files, multiple hardlinks and similar are valid for mapping from and inode to a pathname, and open file always has a path associated with it. If the file has been unlinked d_path
will prepend a " (deleted)" to the name, and if the filename it has been opened with has been changed to something else using rename since it was opened d_path will not print the original name, but the current name of the entry that was used for opening it.