resolved merge conflict
This commit is contained in:
commit
c1f436bcfb
@ -0,0 +1,6 @@
|
|||||||
|
|
||||||
|
|
||||||
|
pub struct Filesys {
|
||||||
|
pub free_map_file : Open_File, //Bit map of free disk blocks, represented as a file
|
||||||
|
pub directory_file : Open_file //"Root" directory -- list of file names, represented as a file
|
||||||
|
}
|
@ -0,0 +1,66 @@
|
|||||||
|
use std::{fs::File, io::{Seek, SeekFrom, Read}};
|
||||||
|
|
||||||
|
use super::filesys;
|
||||||
|
|
||||||
|
pub const TRANSFER_SIZE: usize = 10;
|
||||||
|
|
||||||
|
/// copy the contents of the UNIX file "from" to the Nachos file "to"
|
||||||
|
///
|
||||||
|
/// `panic!` when the file from doesn't exist
|
||||||
|
///
|
||||||
|
/// - **from** file UNIX
|
||||||
|
/// - **to** BurritOS file
|
||||||
|
pub fn copy(from : &str, to : &str) {
|
||||||
|
|
||||||
|
let file_from_opt = File::options().read(true).open(from);
|
||||||
|
let mut file_from : File;
|
||||||
|
match file_from_opt {
|
||||||
|
Err(e) => {
|
||||||
|
panic!("Copy: couldn't open Unix file {}", from);
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(f) => {
|
||||||
|
file_from = f;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut file_length_buf = [0; 1];
|
||||||
|
file_from.seek(SeekFrom::End(2));
|
||||||
|
file_from.read(&mut file_length_buf);
|
||||||
|
file_from.seek(SeekFrom::Start(0));
|
||||||
|
let file_length = file_length_buf[0];
|
||||||
|
|
||||||
|
filesys::create(to, file_length);
|
||||||
|
let open_file = filesys::open(to);
|
||||||
|
|
||||||
|
let mut buffer = [0; TRANSFER_SIZE];
|
||||||
|
loop {
|
||||||
|
let amount_read = file_from.read(&mut buffer).expect("copy : couldn't read the UNIX file");
|
||||||
|
open_file.write(&buffer[..amount_read]);
|
||||||
|
|
||||||
|
if amount_read != TRANSFER_SIZE {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Print the contents of the Nachos file "name".
|
||||||
|
///
|
||||||
|
/// `panic!` when the file name doewn't exist
|
||||||
|
///
|
||||||
|
/// - **name** of the BurritOS file
|
||||||
|
pub fn print(name : &str) {
|
||||||
|
let open_file = filesys::open(name);
|
||||||
|
|
||||||
|
let mut buffer = [0; TRANSFER_SIZE];
|
||||||
|
loop {
|
||||||
|
let amount_read = open_file.read(&mut buffer);
|
||||||
|
for i in 0..amount_read {
|
||||||
|
print!("{:1x} ", buffer[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if amount_read != TRANSFER_SIZE {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -14,6 +14,7 @@ mod kernel;
|
|||||||
pub mod utility;
|
pub mod utility;
|
||||||
/// module containing drivers
|
/// module containing drivers
|
||||||
pub mod drivers;
|
pub mod drivers;
|
||||||
|
mod filesys;
|
||||||
|
|
||||||
use std::{rc::Rc, cell::RefCell};
|
use std::{rc::Rc, cell::RefCell};
|
||||||
|
|
||||||
@ -22,9 +23,11 @@ use simulator::{machine::Machine, print::print};
|
|||||||
|
|
||||||
use drivers::drv_disk::DrvDisk;
|
use drivers::drv_disk::DrvDisk;
|
||||||
use simulator::disk::Disk;
|
use simulator::disk::Disk;
|
||||||
|
use filesys::fsmisc;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
fsmisc::copy("ici", "là");
|
||||||
|
/*
|
||||||
let machine = Machine::init_machine();
|
let machine = Machine::init_machine();
|
||||||
let system = Rc::new(RefCell::new(System::new(machine)));
|
let system = Rc::new(RefCell::new(System::new(machine)));
|
||||||
|
|
||||||
@ -49,4 +52,5 @@ fn main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
System::freeze(system);
|
System::freeze(system);
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user