Implement disk read
This commit is contained in:
Generated
+1
@@ -98,6 +98,7 @@ name = "redox_bootloader"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"linked_list_allocator",
|
||||
"redox_syscall",
|
||||
"redoxfs",
|
||||
]
|
||||
|
||||
|
||||
+2
-1
@@ -10,7 +10,8 @@ crate-type = ["staticlib"]
|
||||
|
||||
|
||||
[dependencies]
|
||||
linked_list_allocator = "0.9.0"
|
||||
linked_list_allocator = "0.9.1"
|
||||
redox_syscall = "0.2.10"
|
||||
|
||||
[dependencies.redoxfs]
|
||||
git = "https://gitlab.redox-os.org/redox-os/redoxfs.git"
|
||||
|
||||
+33
-18
@@ -1,10 +1,8 @@
|
||||
use std::fs::{File, OpenOptions};
|
||||
use std::io::{Read, Seek, SeekFrom, Write};
|
||||
use std::path::Path;
|
||||
use core::{mem, ptr};
|
||||
use redoxfs::{BLOCK_SIZE, Disk};
|
||||
use syscall::error::{Error, Result, EIO};
|
||||
|
||||
use crate::disk::Disk;
|
||||
use crate::BLOCK_SIZE;
|
||||
use crate::{DISK_ADDRESS_PACKET_ADDR, DISK_BIOS_ADDR, ThunkData};
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
#[repr(packed)]
|
||||
@@ -21,10 +19,10 @@ impl DiskAddressPacket {
|
||||
pub fn from_block(block: u64) -> DiskAddressPacket {
|
||||
let blocks = BLOCK_SIZE / 512;
|
||||
DiskAddressPacket {
|
||||
size: mem::size_of::<DiskAddressPacket>(),
|
||||
size: mem::size_of::<DiskAddressPacket>() as u8,
|
||||
reserved: 0,
|
||||
blocks,
|
||||
buffer: DISK_BIOS_ADDR,
|
||||
blocks: blocks as u16,
|
||||
buffer: DISK_BIOS_ADDR as u16,
|
||||
segment: 0,
|
||||
address: block * blocks,
|
||||
}
|
||||
@@ -36,27 +34,44 @@ pub struct DiskBios {
|
||||
}
|
||||
|
||||
impl DiskBios {
|
||||
pub fn block_dap(block: u64) -> DiskAddressPacket {
|
||||
pub fn new(thunk13: extern "C" fn()) -> Self {
|
||||
Self { thunk13 }
|
||||
}
|
||||
}
|
||||
|
||||
impl Disk for DiskBios {
|
||||
unsafe fn read_at(&mut self, block: u64, buffer: &mut [u8]) -> Result<usize> {
|
||||
let mut dap = DiskAddressPacket::from_block(block);
|
||||
for (i, chunk) in buffer.chunks_mut(BLOCK_SIZE as usize).enumerate() {
|
||||
let mut dap = DiskAddressPacket::from_block(block);
|
||||
ptr::write(DISK_ADDRESS_PACKET_ADDR as *mut DiskAddressPacket, dap);
|
||||
|
||||
try_disk!(self.file.seek(SeekFrom::Start(block * BLOCK_SIZE)));
|
||||
let count = try_disk!(self.file.read(buffer));
|
||||
Ok(count)
|
||||
let mut data = ThunkData::new();
|
||||
data.ax = 0x4200;
|
||||
//TODO: get original drive number!
|
||||
data.dx = 0x0080;
|
||||
data.si = DISK_ADDRESS_PACKET_ADDR as u16;
|
||||
|
||||
data.with(self.thunk13);
|
||||
|
||||
//TODO: return result on error
|
||||
assert_eq!(data.ax, 0);
|
||||
|
||||
//TODO: check blocks transferred
|
||||
dap = ptr::read(DISK_ADDRESS_PACKET_ADDR as *mut DiskAddressPacket);
|
||||
|
||||
ptr::copy(DISK_BIOS_ADDR as *const u8, chunk.as_mut_ptr(), chunk.len());
|
||||
}
|
||||
|
||||
Ok(buffer.len())
|
||||
}
|
||||
|
||||
unsafe fn write_at(&mut self, block: u64, buffer: &[u8]) -> Result<usize> {
|
||||
try_disk!(self.file.seek(SeekFrom::Start(block * BLOCK_SIZE)));
|
||||
let count = try_disk!(self.file.write(buffer));
|
||||
Ok(count)
|
||||
//TODO
|
||||
Ok(0)
|
||||
}
|
||||
|
||||
fn size(&mut self) -> Result<u64> {
|
||||
let size = try_disk!(self.file.seek(SeekFrom::End(0)));
|
||||
Ok(size)
|
||||
//TODO
|
||||
Ok(0)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ use self::thunk::ThunkData;
|
||||
use self::vbe::{VbeCardInfo, VbeModeInfo};
|
||||
use self::vga::{VgaTextBlock, VgaTextColor, Vga};
|
||||
|
||||
mod disk;
|
||||
mod panic;
|
||||
mod thunk;
|
||||
mod vbe;
|
||||
|
||||
Reference in New Issue
Block a user