the driver and disk are working

This commit is contained in:
amaury
2023-03-16 17:16:24 +01:00
parent 4c81f0591a
commit edf593cbf8
4 changed files with 27 additions and 19 deletions

View File

@ -5,12 +5,11 @@ use std::io::prelude::*;
use std::fs::File;
use std::io::SeekFrom;
use libc::close;
pub const SECTORS_PER_TRACK : i32 = 32;
pub const NUM_TRACKS : i32 = 64;
pub const NUM_SECTORS : i32 = SECTORS_PER_TRACK * NUM_TRACKS;
pub const SECTOR_SIZE : i32 = 128;
pub const SECTOR_SIZE : i32 = 4;
pub struct Disk {
pub last_selector : i32,
@ -35,14 +34,12 @@ impl Disk {
panic!("sector_number isn't right");
}
let mut f = File::open("test/disk")?;
let mut f = File::open("test/disk.txt")?;
f.seek(SeekFrom::Start((sector_number * SECTOR_SIZE) as u64))?;
let mut reader = BufReader::new(f);
match reader.read(data) {
Ok(_) => println!("Data has been read successfully"),
Err(e) => println!("{:?}", e),
_ => ()
let mut buffer = [0; SECTOR_SIZE as usize];
f.read(&mut buffer)?;
for byte in buffer {
data.push(byte);
}
Ok(())
@ -56,14 +53,24 @@ impl Disk {
panic!("sector_number isn't right");
}
let mut f = File::create("test/disk")?;
let mut f = File::create("test/disk.txt")?;
f.seek(SeekFrom::Start((sector_number * SECTOR_SIZE) as u64))?;
let res = f.write(data);
let mut i = 0;
let mut buff = Vec::new();
for value in data {
buff.push(*value);
i = i+1;
if i >= SECTOR_SIZE {
break;
}
}
let res = f.write(&buff);
match res {
Ok(_) => println!("Data written successfully"),
Err(e) => println!("{:?}", e),
_ => ()
}
}
Ok(())
}