diff --git a/Cargo.lock b/Cargo.lock index 172c61fc3..afe9eb44d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -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", diff --git a/services/libs/jinux-std/Cargo.toml b/services/libs/jinux-std/Cargo.toml index 684cc5453..dc5fab1d3 100644 --- a/services/libs/jinux-std/Cargo.toml +++ b/services/libs/jinux-std/Cargo.toml @@ -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" diff --git a/services/libs/jinux-std/src/fs/initramfs.rs b/services/libs/jinux-std/src/fs/initramfs.rs index 7721f7efe..e4279caa1 100644 --- a/services/libs/jinux-std/src/fs/initramfs.rs +++ b/services/libs/jinux-std/src/fs/initramfs.rs @@ -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> { - 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) -} diff --git a/services/libs/jinux-std/src/vm/vmo/static_cap.rs b/services/libs/jinux-std/src/vm/vmo/static_cap.rs index 40b5fe52e..c96c1c520 100644 --- a/services/libs/jinux-std/src/vm/vmo/static_cap.rs +++ b/services/libs/jinux-std/src/vm/vmo/static_cap.rs @@ -139,8 +139,8 @@ impl Vmo> { /// Strict the access rights. #[require(R > R1)] - pub fn restrict(self) -> Vmo { - Vmo(self.0, R1::new()) + pub fn restrict(self) -> Vmo> { + Vmo(self.0, TRightSet(R1::new())) } }