Skip to content

Commit a6951d9

Browse files
ext2: inode read
Signed-off-by: Andy-Python-Programmer <[email protected]>
1 parent 5d30c36 commit a6951d9

File tree

4 files changed

+203
-76
lines changed

4 files changed

+203
-76
lines changed

src/aero_kernel/src/drivers/block/nvme/queue.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ impl<'bell, T: QueueType> Queue<'bell, T> {
6666

6767
impl Queue<'_, Completion> {
6868
pub fn next_cmd_result(&mut self) -> Option<CompletionEntry> {
69+
let queue_len = self.queue.len();
6970
let cmd = &mut self.queue[self.index];
7071

7172
while (cmd.get_mut().status & 0x1) != self.phase as u16 {
@@ -80,7 +81,13 @@ impl Queue<'_, Completion> {
8081
return None;
8182
}
8283

83-
self.index += 1;
84+
self.index = (self.index + 1) % queue_len;
85+
86+
// invert the phase bit since we are in the next cycle/phase.
87+
if self.index == 0 {
88+
self.phase = !self.phase;
89+
}
90+
8491
self.doorbell.0.set(self.index as u32);
8592

8693
Some(cmd.clone())
@@ -91,7 +98,7 @@ impl Queue<'_, Submisson> {
9198
pub fn submit_command(&mut self, command: Command) {
9299
self.queue[self.index] = UnsafeCell::new(command);
93100

94-
self.index += 1;
101+
self.index = (self.index + 1) % self.queue.len();
95102
self.doorbell.0.set(self.index as u32); // ring ring!
96103
}
97104
}

src/aero_kernel/src/fs/block/mod.rs

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ use crate::fs::devfs::install_device;
3232
use crate::fs::{Path, Result, MOUNT_MANAGER};
3333

3434
use crate::fs::ext2::Ext2;
35-
use crate::mem::paging::{align_down, align_up};
3635
use crate::utils::sync::Mutex;
3736

3837
use super::devfs::{alloc_device_marker, Device};
@@ -45,20 +44,27 @@ pub trait BlockDeviceInterface: Send + Sync {
4544
fn write_block(&self, sector: usize, buf: &[u8]) -> Option<usize>;
4645

4746
fn read(&self, offset: usize, dest: &mut [MaybeUninit<u8>]) -> Option<usize> {
48-
let aligned_offset = align_down(offset as u64, self.block_size() as u64) as usize;
49-
let sector = aligned_offset / self.block_size();
47+
let mut progress = 0;
48+
let block_size = self.block_size();
5049

51-
let aligned_size = align_up(dest.len() as u64, self.block_size() as u64) as usize;
52-
let mut buffer = Box::<[u8]>::new_uninit_slice(aligned_size);
50+
while progress < dest.len() {
51+
let block = (offset + progress) / block_size;
52+
let loc = (offset + progress) % block_size;
5353

54-
self.read_block(sector, MaybeUninit::slice_as_bytes_mut(&mut buffer))?;
55-
// SAFETY: We have initialized the buffer above.
56-
let buffer = unsafe { buffer.assume_init() };
54+
let mut chunk = dest.len() - progress;
5755

58-
let offset = offset - aligned_offset;
59-
MaybeUninit::write_slice(dest, &buffer[offset..(offset + dest.len())]);
56+
if chunk > (block_size - loc) {
57+
chunk = block_size - loc;
58+
}
59+
60+
let mut buffer = Box::<[u8]>::new_uninit_slice(block_size);
61+
self.read_block(block, MaybeUninit::slice_as_bytes_mut(&mut buffer))?;
62+
63+
dest[progress..(progress + chunk)].copy_from_slice(&buffer[loc..loc + chunk]);
64+
progress += chunk;
65+
}
6066

61-
Some(dest.len())
67+
Some(progress)
6268
}
6369
}
6470

0 commit comments

Comments
 (0)