mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-24 18:03:25 +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"
|
name = "cpio-decoder"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"core2",
|
||||||
"int-to-c-enum",
|
"int-to-c-enum",
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -574,7 +575,6 @@ dependencies = [
|
|||||||
"ascii",
|
"ascii",
|
||||||
"bitflags",
|
"bitflags",
|
||||||
"controlled",
|
"controlled",
|
||||||
"core2",
|
|
||||||
"cpio-decoder",
|
"cpio-decoder",
|
||||||
"getrandom",
|
"getrandom",
|
||||||
"int-to-c-enum",
|
"int-to-c-enum",
|
||||||
|
@ -36,7 +36,6 @@ ringbuf = { version = "0.3.2", default-features = false, features = ["alloc"] }
|
|||||||
keyable-arc = { path = "../keyable-arc" }
|
keyable-arc = { path = "../keyable-arc" }
|
||||||
# unzip initramfs
|
# unzip initramfs
|
||||||
libflate = { git = "https://github.com/jinzhao-dev/libflate", rev = "b781da6", features = ["no_std"] }
|
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"
|
spin = "0.9.4"
|
||||||
vte = "0.10"
|
vte = "0.10"
|
||||||
|
@ -1,18 +1,18 @@
|
|||||||
use crate::prelude::*;
|
|
||||||
|
|
||||||
use super::fs_resolver::{FsPath, FsResolver};
|
use super::fs_resolver::{FsPath, FsResolver};
|
||||||
use super::utils::{InodeMode, InodeType};
|
use super::utils::{InodeMode, InodeType};
|
||||||
use core2::io::Read;
|
use crate::prelude::*;
|
||||||
|
|
||||||
use cpio_decoder::{CpioDecoder, FileType};
|
use cpio_decoder::{CpioDecoder, FileType};
|
||||||
use libflate::gzip::Decoder as GZipDecoder;
|
use libflate::gzip::Decoder as GZipDecoder;
|
||||||
|
|
||||||
/// Unpack and prepare the fs from the ramdisk CPIO buffer.
|
/// 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 ...");
|
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 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() {
|
for entry_result in decoder.decode_entries() {
|
||||||
let entry = entry_result?;
|
let entry = entry_result?;
|
||||||
|
|
||||||
@ -59,13 +59,3 @@ pub fn init(ramdisk_buf: &[u8]) -> Result<()> {
|
|||||||
|
|
||||||
Ok(())
|
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.
|
/// Strict the access rights.
|
||||||
#[require(R > R1)]
|
#[require(R > R1)]
|
||||||
pub fn restrict<R1: TRights>(self) -> Vmo<R1> {
|
pub fn restrict<R1: TRights>(self) -> Vmo<TRightSet<R1>> {
|
||||||
Vmo(self.0, R1::new())
|
Vmo(self.0, TRightSet(R1::new()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user