From 4efc8164f1538ceee4b01341aab2a3c6299b15ec Mon Sep 17 00:00:00 2001 From: weishu Date: Thu, 1 Feb 2024 16:30:18 +0800 Subject: [PATCH] ksud: Fix overlayfs mount --- userspace/ksud/src/mount.rs | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/userspace/ksud/src/mount.rs b/userspace/ksud/src/mount.rs index 163f4b824a65..44c89fe86b5d 100644 --- a/userspace/ksud/src/mount.rs +++ b/userspace/ksud/src/mount.rs @@ -75,29 +75,31 @@ pub fn mount_ext4(source: impl AsRef, target: impl AsRef) -> Result< #[cfg(any(target_os = "linux", target_os = "android"))] pub fn umount_dir(src: impl AsRef) -> Result<()> { - unmount(src.as_ref(), UnmountFlags::empty()).with_context(|| format!("Failed to umount {}", src.as_ref().display()))?; + unmount(src.as_ref(), UnmountFlags::empty()) + .with_context(|| format!("Failed to umount {}", src.as_ref().display()))?; Ok(()) } #[cfg(any(target_os = "linux", target_os = "android"))] -fn mount_overlayfs( +pub fn mount_overlayfs( lower_dirs: &[String], - lowest: impl AsRef, + lowest: &str, dest: impl AsRef, ) -> Result<()> { - let options = format!( - "lowerdir={}:{}", - lower_dirs.join(":"), - lowest.as_ref().display() - ); + let lowerdir_config = lower_dirs + .iter() + .map(|s| s.as_ref()) + .chain(std::iter::once(lowest)) + .collect::>() + .join(":"); info!( "mount overlayfs on {}, options={}", dest.as_ref().display(), - options + lowerdir_config ); let fs = fsopen("overlay", FsOpenFlags::FSOPEN_CLOEXEC)?; let fs = fs.as_fd(); - fsconfig_set_string(fs, "lowerdir", lower_dirs.join(":"))?; + fsconfig_set_string(fs, "lowerdir", lowerdir_config)?; fsconfig_set_string(fs, "source", KSU_OVERLAY_SOURCE)?; fsconfig_create(fs)?; let mount = fsmount(fs, FsMountFlags::FSMOUNT_CLOEXEC, MountAttrFlags::empty())?;