mirror of
https://github.com/rcore-os/rCore-Tutorial-v3.git
synced 2024-11-22 09:26:26 +04:00
Change single file limit from 70KiB to 94KiB & pack apps and list them.
This commit is contained in:
parent
d13380603b
commit
ecccea65a0
@ -5,7 +5,7 @@ use easy_fs::{
|
||||
BlockDevice,
|
||||
EasyFileSystem,
|
||||
};
|
||||
use std::fs::{File, OpenOptions};
|
||||
use std::fs::{File, OpenOptions, read_dir};
|
||||
use std::io::{Read, Write, Seek, SeekFrom};
|
||||
use std::sync::Mutex;
|
||||
use alloc::sync::Arc;
|
||||
@ -37,7 +37,48 @@ fn main() {
|
||||
easy_fs_pack().expect("Error when packing easy-fs!");
|
||||
}
|
||||
|
||||
static TARGET_PATH: &str = "../user/target/riscv64gc-unknown-none-elf/release/";
|
||||
|
||||
fn easy_fs_pack() -> std::io::Result<()> {
|
||||
let block_file = Arc::new(BlockFile(Mutex::new({
|
||||
let f = OpenOptions::new()
|
||||
.read(true)
|
||||
.write(true)
|
||||
.create(true)
|
||||
.open(format!("{}{}", TARGET_PATH, "fs.img"))?;
|
||||
f.set_len(8192 * 512);
|
||||
f
|
||||
})));
|
||||
// 4MiB, at most 4095 files
|
||||
let efs = EasyFileSystem::create(
|
||||
block_file.clone(),
|
||||
8192,
|
||||
1,
|
||||
);
|
||||
let mut root_inode = Arc::new(EasyFileSystem::root_inode(&efs));
|
||||
let apps: Vec<_> = read_dir("../user/src/bin")
|
||||
.unwrap()
|
||||
.into_iter()
|
||||
.map(|dir_entry| {
|
||||
let mut name_with_ext = dir_entry.unwrap().file_name().into_string().unwrap();
|
||||
name_with_ext.drain(name_with_ext.find('.').unwrap()..name_with_ext.len());
|
||||
name_with_ext
|
||||
})
|
||||
.collect();
|
||||
for app in apps {
|
||||
// load app data from host file system
|
||||
let mut host_file = File::open(format!("{}{}", TARGET_PATH, app)).unwrap();
|
||||
let mut all_data: Vec<u8> = Vec::new();
|
||||
let app_size = host_file.read_to_end(&mut all_data).unwrap();
|
||||
// create a file in easy-fs
|
||||
let inode = root_inode.create(app.as_str()).unwrap();
|
||||
// write data to easy-fs
|
||||
inode.write_at(0, all_data.as_slice());
|
||||
}
|
||||
// list apps
|
||||
for app in root_inode.ls() {
|
||||
println!("{}", app);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
@ -8,7 +8,7 @@ use alloc::sync::Arc;
|
||||
use alloc::vec::Vec;
|
||||
|
||||
const EFS_MAGIC: u32 = 0x3b800001;
|
||||
const INODE_DIRECT_COUNT: usize = 12;
|
||||
const INODE_DIRECT_COUNT: usize = 60;
|
||||
const NAME_LENGTH_LIMIT: usize = 27;
|
||||
|
||||
#[repr(C)]
|
||||
|
@ -104,7 +104,7 @@ impl Inode {
|
||||
});
|
||||
}
|
||||
|
||||
pub fn create(&mut self, name: &str) -> Option<Arc<Inode>> {
|
||||
pub fn create(&self, name: &str) -> Option<Arc<Inode>> {
|
||||
let mut fs = self.fs.lock();
|
||||
println!("creating name {}", name);
|
||||
let mut inode = self.get_disk_inode(&mut fs);
|
||||
|
Loading…
Reference in New Issue
Block a user