helpers: fix d_path() for bind mounts

d_path() for bind mounts returns the wrong path. E.g., for

  mount --bind /tmp/foo /tmp/foo

print_mounts() shows '/tmp/foo/foo'. Let's do exactly what
prepend_path() in the kernel does, which fixes this case.
This commit is contained in:
Omar Sandoval 2019-11-18 13:54:28 -08:00
parent 5fbe1b1ba9
commit 20a7c8c85f

View File

@ -148,18 +148,19 @@ def d_path(path_or_vfsmnt, dentry=None):
components = []
while True:
while True:
d_parent = dentry.d_parent.read_()
if dentry == d_parent:
if dentry == mnt.mnt.mnt_root:
mnt_parent = mnt.mnt_parent.read_()
if mnt == mnt_parent:
break
components.append(dentry.d_name.name.string_())
components.append(b'/')
dentry = d_parent
mnt_parent = mnt.mnt_parent.read_()
if mnt == mnt_parent:
dentry = mnt.mnt_mountpoint.read_()
mnt = mnt_parent
continue
d_parent = dentry.d_parent.read_()
if dentry == d_parent:
break
dentry = mnt.mnt_mountpoint
mnt = mnt_parent
components.append(dentry.d_name.name.string_())
components.append(b'/')
dentry = d_parent
if components:
return b''.join(reversed(components))
else: