Article 6JP08 How to get full mountpoint path name by the sturct fc_context

How to get full mountpoint path name by the sturct fc_context

by
harry.hycc
from LinuxQuestions.org on (#6JP08)
I currently have a syscall hook named "fsconfig" within my module (develop for kernel 6.6) 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 (/tmp/mytest is already mounted), 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:

1. 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.

2. 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.

3. 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.
External Content
Source RSS or Atom Feed
Feed Location https://feeds.feedburner.com/linuxquestions/latest
Feed Title LinuxQuestions.org
Feed Link https://www.linuxquestions.org/questions/
Reply 0 comments