ksud: Fix overlayfs mount

This commit is contained in:
weishu
2024-02-01 16:30:18 +08:00
parent 0fc25cf091
commit 4efc8164f1

View File

@@ -75,29 +75,31 @@ pub fn mount_ext4(source: impl AsRef<Path>, target: impl AsRef<Path>) -> Result<
#[cfg(any(target_os = "linux", target_os = "android"))] #[cfg(any(target_os = "linux", target_os = "android"))]
pub fn umount_dir(src: impl AsRef<Path>) -> Result<()> { pub fn umount_dir(src: impl AsRef<Path>) -> 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(()) Ok(())
} }
#[cfg(any(target_os = "linux", target_os = "android"))] #[cfg(any(target_os = "linux", target_os = "android"))]
fn mount_overlayfs( pub fn mount_overlayfs(
lower_dirs: &[String], lower_dirs: &[String],
lowest: impl AsRef<Path>, lowest: &str,
dest: impl AsRef<Path>, dest: impl AsRef<Path>,
) -> Result<()> { ) -> Result<()> {
let options = format!( let lowerdir_config = lower_dirs
"lowerdir={}:{}", .iter()
lower_dirs.join(":"), .map(|s| s.as_ref())
lowest.as_ref().display() .chain(std::iter::once(lowest))
); .collect::<Vec<_>>()
.join(":");
info!( info!(
"mount overlayfs on {}, options={}", "mount overlayfs on {}, options={}",
dest.as_ref().display(), dest.as_ref().display(),
options lowerdir_config
); );
let fs = fsopen("overlay", FsOpenFlags::FSOPEN_CLOEXEC)?; let fs = fsopen("overlay", FsOpenFlags::FSOPEN_CLOEXEC)?;
let fs = fs.as_fd(); 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_set_string(fs, "source", KSU_OVERLAY_SOURCE)?;
fsconfig_create(fs)?; fsconfig_create(fs)?;
let mount = fsmount(fs, FsMountFlags::FSMOUNT_CLOEXEC, MountAttrFlags::empty())?; let mount = fsmount(fs, FsMountFlags::FSMOUNT_CLOEXEC, MountAttrFlags::empty())?;