update disk

This commit is contained in:
Baptiste 2023-03-22 15:43:10 +01:00
parent 12c28f7681
commit b07c675986

View File

@ -49,12 +49,14 @@ impl Disk {
open(DISK_PATH).unwrap();
disk_file.write_at(&magic_to_write[..], 0);
disk_file.set_len(DISK_SIZE as u64);
}
Ok(f) => {
disk_file = f;
let magic_to_write : [u8 ; 5] = [0xAB, 0xBA, 0xCD, 0xDC, 0];
let magic_to_write : [u8 ; 4] = [0xAB, 0xBA, 0xCD, 0xDC];
disk_file.write_at(&magic_to_write[..], 0);
disk_file.set_len(DISK_SIZE as u64);
}
}
@ -108,10 +110,9 @@ impl Disk {
}
disk.active = true;
let mut f = File::open(DISK_PATH)?;
f.seek(SeekFrom::Start((sector_number * SECTOR_SIZE) as u64))?;
disk.disk_file.seek(SeekFrom::Start((sector_number * SECTOR_SIZE) as u64))?;
let mut buffer = [0; SECTOR_SIZE as usize];
f.read(&mut buffer)?;
disk.disk_file.read(&mut buffer)?;
for byte in buffer {
data.push(byte);
}
@ -141,8 +142,7 @@ impl Disk {
}
disk.active = true;
let mut f = File::create(DISK_PATH)?;
f.seek(SeekFrom::Start((sector_number * SECTOR_SIZE) as u64))?;
disk.disk_file.seek(SeekFrom::Start((sector_number * SECTOR_SIZE) as u64))?;
let mut i = 0;
let mut buff = Vec::new();
for value in data {
@ -153,7 +153,7 @@ impl Disk {
}
}
let res = f.write(&buff);
let res = disk.disk_file.write(&buff);
match res {
Ok(_) => println!("Data written successfully"),
Err(e) => println!("{:?}", e),