You've already forked Magisk
mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-09-06 06:36:58 +00:00
Make FsPathBuf a trait and rename to FsPathBuilder
This commit is contained in:
@@ -7,8 +7,8 @@ use num_traits::AsPrimitive;
|
||||
|
||||
use base::libc::{c_uint, dev_t};
|
||||
use base::{
|
||||
FsPath, FsPathBuf, FsPathMnt, LibcReturn, LoggedResult, MountInfo, ResultExt, Utf8CStr, cstr,
|
||||
cstr_buf, debug, info, libc, parse_mount_info, warn,
|
||||
FsPath, FsPathBuilder, FsPathMnt, LibcReturn, LoggedResult, MountInfo, ResultExt, Utf8CStr,
|
||||
Utf8CStrBuf, cstr, cstr_buf, debug, info, libc, parse_mount_info, warn,
|
||||
};
|
||||
|
||||
use crate::consts::{MODULEMNT, MODULEROOT, PREINITDEV, PREINITMIRR, WORKERDIR};
|
||||
@@ -21,9 +21,9 @@ pub fn setup_mounts() {
|
||||
let magisk_tmp = get_magisk_tmp();
|
||||
|
||||
// Mount preinit directory
|
||||
let dev_path = FsPathBuf::from(cstr_buf::new::<64>())
|
||||
.join(magisk_tmp)
|
||||
.join(PREINITDEV);
|
||||
let dev_path = cstr_buf::new::<64>()
|
||||
.join_path(magisk_tmp)
|
||||
.join_path(PREINITDEV);
|
||||
let mut linked = false;
|
||||
if let Ok(attr) = dev_path.get_attr() {
|
||||
if attr.st.st_mode & libc::S_IFMT as c_uint == libc::S_IFBLK.as_() {
|
||||
@@ -33,7 +33,9 @@ pub fn setup_mounts() {
|
||||
// What we do instead is to scan through the current mountinfo and find a pre-existing
|
||||
// mount point mounting our desired partition, and then bind mount the target folder.
|
||||
let preinit_dev = attr.st.st_rdev;
|
||||
let mnt_path = FsPathBuf::default().join(magisk_tmp).join(PREINITMIRR);
|
||||
let mnt_path = cstr_buf::default()
|
||||
.join_path(magisk_tmp)
|
||||
.join_path(PREINITMIRR);
|
||||
for info in parse_mount_info("self") {
|
||||
if info.root == "/" && info.device == preinit_dev {
|
||||
if !info.fs_option.split(',').any(|s| s == "rw") {
|
||||
@@ -66,7 +68,9 @@ pub fn setup_mounts() {
|
||||
}
|
||||
|
||||
// Bind remount module root to clear nosuid
|
||||
let module_mnt = FsPathBuf::default().join(magisk_tmp).join(MODULEMNT);
|
||||
let module_mnt = cstr_buf::default()
|
||||
.join_path(magisk_tmp)
|
||||
.join_path(MODULEMNT);
|
||||
let _: LoggedResult<()> = try {
|
||||
module_mnt.mkdir(0o755)?;
|
||||
cstr!(MODULEROOT).bind_mount_to(&module_mnt)?;
|
||||
@@ -77,11 +81,13 @@ pub fn setup_mounts() {
|
||||
pub fn clean_mounts() {
|
||||
let magisk_tmp = get_magisk_tmp();
|
||||
|
||||
let mut module_mnt = FsPathBuf::default().join(magisk_tmp).join(MODULEMNT);
|
||||
module_mnt.unmount().log_ok();
|
||||
let mut buf = cstr_buf::default();
|
||||
|
||||
module_mnt.clear();
|
||||
let worker_dir = module_mnt.join(magisk_tmp).join(WORKERDIR);
|
||||
let module_mnt = buf.append_path(magisk_tmp).append_path(MODULEMNT);
|
||||
module_mnt.unmount().log_ok();
|
||||
buf.clear();
|
||||
|
||||
let worker_dir = buf.append_path(magisk_tmp).append_path(WORKERDIR);
|
||||
let _: LoggedResult<()> = try {
|
||||
worker_dir.set_mount_private(true)?;
|
||||
worker_dir.unmount()?;
|
||||
@@ -180,7 +186,8 @@ pub fn find_preinit_device() -> String {
|
||||
&& let Ok(tmp) = std::env::var("MAGISKTMP")
|
||||
&& !tmp.is_empty()
|
||||
{
|
||||
let mut mirror_dir = FsPathBuf::default().join(&tmp).join(PREINITMIRR);
|
||||
let mut buf = cstr_buf::default();
|
||||
let mirror_dir = buf.append_path(&tmp).append_path(PREINITMIRR);
|
||||
let preinit_dir = Utf8CStr::from_string(&mut preinit_dir);
|
||||
let _: LoggedResult<()> = try {
|
||||
preinit_dir.mkdirs(0o700)?;
|
||||
@@ -190,8 +197,8 @@ pub fn find_preinit_device() -> String {
|
||||
mirror_dir.create_symlink_to(preinit_dir)?;
|
||||
};
|
||||
if std::env::var_os("MAKEDEV").is_some() {
|
||||
mirror_dir.clear();
|
||||
let dev_path = mirror_dir.join(&tmp).join(PREINITDEV);
|
||||
buf.clear();
|
||||
let dev_path = buf.append_path(&tmp).append_path(PREINITDEV);
|
||||
unsafe {
|
||||
libc::mknod(
|
||||
dev_path.as_ptr(),
|
||||
|
||||
Reference in New Issue
Block a user