LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Kernel (https://www.linuxquestions.org/questions/linux-kernel-70/)
-   -   How to get full mountpoint path name by the sturct fc_context (https://www.linuxquestions.org/questions/linux-kernel-70/how-to-get-full-mountpoint-path-name-by-the-sturct-fc_context-4175733916/)

harry.hycc 02-16-2024 01:22 AM

How to get full mountpoint path name by the sturct fc_context
 
I currently have a syscall hook named "fsconfig" within my own module because I need to perform some operations regarding remounting readonly mountpoints.

For example, if a user issues the command: mount /dev/sda /tmp/mytest -o remount,ro, I would like to obtain the string "/tmp/mytest" within the fsconfig hook.

Within fsconfig, I have referred to the kernel's approach, which allows obtaining an fs_context structure through an fd. What I aim to do is to obtain the mount point path through this structure (or any other method).

It seems that the fs_context provides all the information available at this step.

Currently, I have attempted:

Starting from fc_context->dentry, I have found some functions like dentry_path_raw, but the returned string is "/", which does not meet my requirements.

There is some information on the internet suggesting the use of d_path, but it requires a path structure containing dentry and vfsmount, which I cannot obtain within fsconfig. Therefore, this method seems impractical.

I have referenced the approach used in /proc/mounts, where they iterate through each mountpoint using the list within mnt_namespace. However, we cannot access the members of mnt_namespace and mount structures within the module (kernel declare them in fs/namespace), making this method unusable.

I would like to ask if there are any other methods (perhaps some kernel APIs I am not aware of) to meet my requirements. Thank you very much.

And i want my module to support kernel version 6.6

pan64 02-17-2024 09:08 AM

duplicate of https://www.linuxquestions.org/quest...xt-4175733917/


All times are GMT -5. The time now is 11:05 PM.