Quantcast
Channel: Active questions tagged linux-kernel - Stack Overflow
Viewing all articles
Browse latest Browse all 12312

Get bind mount's source with kernel API

$
0
0

Suppose the filesystem on sda1 looks like:

/  fedora/  ubuntu/

The filesystem on sda2 looks like:

/  boot/  bin/  dev/  etc/  home/    owner/  lib/  mnt/    boot/  opt/  proc/  root/  run/  sbin/  srv/  sys/  tmp/  usr/  var/    lib/      containers/        box/          root/

The filesystem on sda3 looks like:

/  app/  bin/  lib/  sbin/  user/

The mounts of the filesystems are as follows:

mount /dev/sda2 /mount /dev/sda1 /mnt/bootmount /dev/sda3 /var/lib/containers/box/root

Several bind mounts are also performed:

mount --bind /mnt/boot/ubuntu /bootmount --bind /home/owner /var/lib/containers/box/root/user

Now, if given a file struct, how can I retrieve its corresponding full path on the filesystem it resides on? If I have I /boot/grub, then the result should be /ubuntu/grub. If I have /var/lib/containers/box/root/user, then I should get /home/owner only know enough to solve this problem by:

  1. Saving a string that is the filename associated with the file struct (my memory is foggy on this).
  2. Saving the device number of the source filesystem of the file struct (I don't know where to begin to get this).
  3. Retrieving the dentry struct that it belongs to (file.f_path.dentry).
  4. Retrieving the parent dentry struct of the above dentry struct or the dentry struct from step 6 (dentry.d_parent).
  5. Saving the device number underlying the dentry struct retrieved in step 3 (I don't know where to begin to get this).
  6. Comparing the device number saved in step 1 to the device number saved in step 4, prepending the corresponding name of the above dentry struct to the saved string and going back to step 4 if the device numbers match OR stopping here if they don't match.

I don't expect the steps I gave above to be efficient and I expect it to slow down kernel operation. I figure that there must be another way given how, in the case of bind mounts, /proc/PID/mountinfo displays the path to the mount source on the underlying filesystem.


Viewing all articles
Browse latest Browse all 12312

Latest Images

Trending Articles



Latest Images