How can I get a filename from a file descriptor inside a kernel module?

Don’t call SYS_readlink – use the same method that procfs does when one of those links is read. Start with the code in proc_pid_readlink() and proc_fd_link() in fs/proc/base.c. Broadly, given an int fd and a struct files_struct *files from the task you’re interested in (which you have taken a reference to), you want to do: … Read more

Read/write files within a Linux kernel module

Since version 4.14 of Linux kernel, vfs_read and vfs_write functions are no longer exported for use in modules. Instead, functions exclusively for kernel’s file access are provided: # Read the file from the kernel space. ssize_t kernel_read(struct file *file, void *buf, size_t count, loff_t *pos); # Write the file from the kernel space. ssize_t kernel_write(struct … Read more