This commit is contained in:
Jaby 2023-02-03 13:36:49 +01:00 committed by Jaby
parent 53b01f19b1
commit 4510feb811
1 changed files with 5 additions and 1 deletions

View File

@ -30,10 +30,14 @@ impl LBAEntry {
pub fn write_entry(&mut self, lba: u16, mut size_bytes: usize) -> Result<(), Error> { pub fn write_entry(&mut self, lba: u16, mut size_bytes: usize) -> Result<(), Error> {
const WORD_SIZE:usize = std::mem::size_of::<u32>(); const WORD_SIZE:usize = std::mem::size_of::<u32>();
if self.lba != 0 || self.size_words != 0 {
return Err(Error::from_str("LBA Entry will overwrite non-zero value!\nIs no space allocated for the LBA Entries?"));
}
size_bytes = (size_bytes + (WORD_SIZE - 1))/WORD_SIZE; size_bytes = (size_bytes + (WORD_SIZE - 1))/WORD_SIZE;
if (size_bytes as u16) as usize != size_bytes { if (size_bytes as u16) as usize != size_bytes {
return Err(Error::from_text(format!("{} words can not be incoded into 16bit", size_bytes))); return Err(Error::from_text(format!("{} words can not be encoded into 16bit", size_bytes)));
} }
let lba = lba.to_le_bytes(); let lba = lba.to_le_bytes();