In a linux kernel module is there a way to get a file name/path from an unsigned int fd
?
I'm aware of this answer: How can I get a filename from a file descriptor inside a kernel module? but if I understand the code right, I need a struct files_struct
too.
EDIT:
Please stop voting as duplicated as it isn't. I'm asking for a way to get file's name/path in plain C from a kernel module, not using system tools. Said in another way: running readlink on /procself/fd/ is not a good answer.
EDIT 2:
Kernel's syscall read ssize_t read(int fd, void *buf, size_t count);
takes 3 arguments, one of them being a fd. It's obvious that somehow read
is able to read from a single file (instead of all files inside an inode). The question is how.