Revise the content of root field for the mountinfo file

This commit is contained in:
Chen Chengjun 2025-11-06 08:51:09 +00:00 committed by Ruihan Li
parent e336882eee
commit cda06613f0
4 changed files with 26 additions and 2 deletions

View File

@ -332,6 +332,27 @@ impl Dentry {
}
Ok(())
}
/// Gets the absolute path name of this `Dentry` within the filesystem.
pub(super) fn path_name(&self) -> String {
let mut path_name = self.name().to_string();
let mut current_dir = self.this();
while let Some(parent_dir) = current_dir.parent() {
path_name = {
let parent_name = parent_dir.name();
if parent_name != "/" {
parent_name + "/" + &path_name
} else {
parent_name + &path_name
}
};
current_dir = parent_dir;
}
debug_assert!(path_name.starts_with('/'));
path_name
}
}
#[inherit_methods(from = "self.inode")]

View File

@ -102,6 +102,8 @@ impl Path {
/// Gets the absolute path.
///
/// It will resolve the mountpoint automatically.
//
// FIXME: This method needs to be aware of the current process's root path.
pub fn abs_path(&self) -> String {
let mut path_name = self.effective_name();
let mut current_dir = self.this();
@ -126,6 +128,8 @@ impl Path {
///
/// If it is the root of a mount, it will go up to the mountpoint
/// to get the name of the mountpoint recursively.
//
// FIXME: This method needs to be aware of the current process's root path.
fn effective_name(&self) -> String {
if !self.is_mount_root() {
return self.dentry.name();

View File

@ -534,7 +534,7 @@ impl Mount {
let mount_id = mount.id();
let parent = mount.parent().and_then(|parent| parent.upgrade());
let parent_id = parent.as_ref().map_or(mount_id, |p| p.id());
let root = Path::new_fs_root(mount.clone()).abs_path();
let root = mount.root_dentry().path_name();
let mount_point = if let Some(parent) = parent {
if let Some(mount_point_dentry) = mount.mountpoint() {
Path::new(parent, mount_point_dentry).abs_path()

View File

@ -35,7 +35,6 @@ ProcSysVmMmapMinAddr.HasNumericValue
ProcSysVmOvercommitMemory.HasNumericValue
ProcFilesystems.PresenceOfShmMaxMniAll
ProcMounts.IsSymlink
ProcSelfMountinfo.RequiredFieldsArePresent
ProcSelfMounts.RequiredFieldsArePresent
Proc.GetdentsEnoent
Proc.PidTidIOAccounting