Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
weblate committed Jan 30, 2024
2 parents 898ef37 + ca960a2 commit cb59995
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 8 deletions.
11 changes: 11 additions & 0 deletions userspace/ksud/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,13 @@ enum Debug {

Mount,

/// Copy sparse file
Xcp {
/// source file
src: String,
/// destination file
dst: String,
},
/// For testing
Test,
}
Expand Down Expand Up @@ -277,6 +284,10 @@ pub fn run() -> Result<()> {
}
Debug::Su => crate::ksu::grant_root(),
Debug::Mount => event::mount_systemlessly(defs::MODULE_DIR),
Debug::Xcp { src, dst } => {
utils::copy_sparse_file(&src, &dst)?;
Ok(())
}
Debug::Test => todo!(),
},

Expand Down
20 changes: 16 additions & 4 deletions userspace/ksud/src/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,8 @@ fn _install_module(zip: &str) -> Result<()> {
humansize::format_size(zip_uncompressed_size, humansize::DECIMAL)
);

let sparse_image_size = 256 * (1 << 30); // 256G
let sparse_image_size = 1 << 40; // 1T
let jounnel_size = 8; // 8M
if !modules_img_exist && !modules_update_img_exist {
// if no modules and modules_update, it is brand new installation, we should create a new img
// create a tmp module img and mount it to modules_update
Expand All @@ -351,8 +352,8 @@ fn _install_module(zip: &str) -> Result<()> {

// format the img to ext4 filesystem
let result = Command::new("mkfs.ext4")
.arg("-b")
.arg("1024")
.arg("-J")
.arg(format!("size={jounnel_size}"))
.arg(tmp_module_img)
.stdout(Stdio::piped())
.output()?;
Expand All @@ -361,6 +362,7 @@ fn _install_module(zip: &str) -> Result<()> {
"Failed to format ext4 image: {}",
String::from_utf8(result.stderr).unwrap()
);
check_image(tmp_module_img)?;
} else if modules_update_img_exist {
// modules_update.img exists, we should use it as tmp img
info!("Using existing modules_update.img as tmp image");
Expand All @@ -385,21 +387,31 @@ fn _install_module(zip: &str) -> Result<()> {
// legacy image, truncate it to new size.
if std::fs::metadata(modules_img)?.len() < sparse_image_size {
println!("- Truncate legacy image to new size");

// shrink it to minimum size
check_image(tmp_module_img)?;
Command::new("resize2fs")
.arg("-M")
.arg(tmp_module_img)
.stdout(Stdio::piped())
.status()?;

// truncate the file to new size
OpenOptions::new()
.write(true)
.open(tmp_module_img)
.context("Failed to open ext4 image")?
.set_len(sparse_image_size)
.context("Failed to truncate ext4 image")?;

// resize the image to new size
check_image(tmp_module_img)?;
Command::new("resize2fs")
.arg(tmp_module_img)
.stdout(Stdio::piped())
.status()?;
}
}
check_image(tmp_module_img)?;

// ensure modules_update exists
ensure_dir_exists(module_update_tmp_dir)?;
Expand Down
4 changes: 2 additions & 2 deletions website/docs/guide/faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ We do not recommend you to modify the system partition directly. You should use

Of course. But KernelSU doesn't have builtin hosts support, you can install [systemless-hosts](https://github.com/symbuzzer/systemless-hosts-KernelSU-module) to do it.

## Why is there a huge 256G file?
## Why is there a huge 1T file?

The 256G size `modules.img` is a disk image file, **don't worry about its size**, it's a special type of file known as a [sparse file](https://en.wikipedia.org/wiki/Sparse_file), its actual size is only the size of the module you use, and it will dynamically shrink after you delete the module; it does not actually occupy 256G of disk space (actually your mobile phone may not have that much space) .
The 1T size `modules.img` is a disk image file, **don't worry about its size**, it's a special type of file known as a [sparse file](https://en.wikipedia.org/wiki/Sparse_file), its actual size is only the size of the module you use, and it will dynamically shrink after you delete the module; it does not actually occupy 1T of disk space (actually your mobile phone may not have that much space) .

If you're really unhappy with the size of this file, you can use the `resize2fs -M` command to make it the actual size; but the module may not work properly at this time, and we won't provide any support for this.
4 changes: 2 additions & 2 deletions website/docs/zh_CN/guide/faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ GKI1 跟 GKI2 完全是两个东西,所以你需要自行编译内核。

当然可以。但这个功能 KernelSU 没有内置,你可以安装这个 [systemless-hosts](https://github.com/symbuzzer/systemless-hosts-KernelSU-module)

## 为什么有个 256G 的超大文件?
## 为什么有个 1T 的超大文件?

256G 大小的 `modules.img` 是一个磁盘镜像文件,**不要担心它的大小**,它是一种被称之为[稀疏文件](https://en.wikipedia.org/wiki/Sparse_file)的文件格式,它的实际大小只有你使用的模块的大小,并且你在删除模块后它会动态缩小;它并不实际占用 256G 大小的磁盘空间(实际上你手机可能并没有这么多空间)。
1T 大小的 `modules.img` 是一个磁盘镜像文件,**不要担心它的大小**,它是一种被称之为[稀疏文件](https://en.wikipedia.org/wiki/Sparse_file)的文件格式,它的实际大小只有你使用的模块的大小,并且你在删除模块后它会动态缩小;它并不实际占用 1T 大小的磁盘空间(实际上你手机可能并没有这么多空间)。

如果你真的对这个文件的大小感到不爽,你可以使用 `resize2fs -M` 命令让它变成实际大小;但此时模块可能无法正常工作,我们也不会为此提供任何支持。

0 comments on commit cb59995

Please sign in to comment.