mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-24 09:53:24 +00:00
Simplify the unzipping ramdisk file to reduce the heap allocation
This commit is contained in:
committed by
Tate, Hongliang Tian
parent
4c83ff9411
commit
4b3cf8daeb
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -175,6 +175,7 @@ dependencies = [
|
||||
name = "cpio-decoder"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"core2",
|
||||
"int-to-c-enum",
|
||||
]
|
||||
|
||||
@ -574,7 +575,6 @@ dependencies = [
|
||||
"ascii",
|
||||
"bitflags",
|
||||
"controlled",
|
||||
"core2",
|
||||
"cpio-decoder",
|
||||
"getrandom",
|
||||
"int-to-c-enum",
|
||||
|
@ -36,7 +36,6 @@ ringbuf = { version = "0.3.2", default-features = false, features = ["alloc"] }
|
||||
keyable-arc = { path = "../keyable-arc" }
|
||||
# unzip initramfs
|
||||
libflate = { git = "https://github.com/jinzhao-dev/libflate", rev = "b781da6", features = ["no_std"] }
|
||||
core2 = { version = "0.4", default_features = false, features = ["alloc"] }
|
||||
|
||||
spin = "0.9.4"
|
||||
vte = "0.10"
|
||||
|
@ -1,18 +1,18 @@
|
||||
use crate::prelude::*;
|
||||
|
||||
use super::fs_resolver::{FsPath, FsResolver};
|
||||
use super::utils::{InodeMode, InodeType};
|
||||
use core2::io::Read;
|
||||
use crate::prelude::*;
|
||||
|
||||
use cpio_decoder::{CpioDecoder, FileType};
|
||||
use libflate::gzip::Decoder as GZipDecoder;
|
||||
|
||||
/// Unpack and prepare the fs from the ramdisk CPIO buffer.
|
||||
pub fn init(ramdisk_buf: &[u8]) -> Result<()> {
|
||||
pub fn init(gzip_ramdisk_buf: &[u8]) -> Result<()> {
|
||||
println!("[kernel] unzipping ramdisk.cpio.gz ...");
|
||||
let unzipped_ramdisk_buf = unzip(ramdisk_buf)?;
|
||||
println!("[kernel] unzip ramdisk.cpio.gz done");
|
||||
let decoder = CpioDecoder::new(&unzipped_ramdisk_buf);
|
||||
let fs = FsResolver::new();
|
||||
let mut decoder = CpioDecoder::new(
|
||||
GZipDecoder::new(gzip_ramdisk_buf)
|
||||
.map_err(|_| Error::with_message(Errno::EINVAL, "invalid gzip buffer"))?,
|
||||
);
|
||||
for entry_result in decoder.decode_entries() {
|
||||
let entry = entry_result?;
|
||||
|
||||
@ -59,13 +59,3 @@ pub fn init(ramdisk_buf: &[u8]) -> Result<()> {
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn unzip(buf: &[u8]) -> Result<Vec<u8>> {
|
||||
let mut decoder = GZipDecoder::new(buf)
|
||||
.map_err(|_| Error::with_message(Errno::EINVAL, "invalid gzip buffer"))?;
|
||||
let mut unzipped_buf = Vec::new();
|
||||
decoder
|
||||
.read_to_end(&mut unzipped_buf)
|
||||
.map_err(|_| Error::with_message(Errno::EINVAL, "invalid gzip buffer"))?;
|
||||
Ok(unzipped_buf)
|
||||
}
|
||||
|
@ -139,8 +139,8 @@ impl<R: TRights> Vmo<TRightSet<R>> {
|
||||
|
||||
/// Strict the access rights.
|
||||
#[require(R > R1)]
|
||||
pub fn restrict<R1: TRights>(self) -> Vmo<R1> {
|
||||
Vmo(self.0, R1::new())
|
||||
pub fn restrict<R1: TRights>(self) -> Vmo<TRightSet<R1>> {
|
||||
Vmo(self.0, TRightSet(R1::new()))
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user