From 8f0161e8492d090b09782c13b43ef71201787186 Mon Sep 17 00:00:00 2001 From: Tilman Sauerbeck Date: Thu, 9 Jan 2020 11:00:28 +0100 Subject: [PATCH] common: Factor out Logger::read_sector_header(). --- src/common/logger.rs | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/common/logger.rs b/src/common/logger.rs index be06327..d958193 100644 --- a/src/common/logger.rs +++ b/src/common/logger.rs @@ -323,19 +323,23 @@ impl<'a> Logger<'a> { // Reading the directory entries one by one means // we won't need an as large buffer on the stack. for i in 0..NUM_SECTORS { - let address = i * SECTOR_SIZE; - let mut chunk = [0u8; 4]; + self.read_sector_header(i); + } + } - self.storage.read(address, &mut chunk); + fn read_sector_header(&mut self, sector_index: usize) { + let address = sector_index * SECTOR_SIZE; + let mut chunk = [0u8; 4]; - let sector_header_ptr: *mut SectorHeader = - &mut self.sector_header[i]; + self.storage.read(address, &mut chunk); - unsafe { - core::ptr::copy(chunk.as_ptr(), - sector_header_ptr as *mut u8, - chunk.len()); - } + let sector_header_ptr: *mut SectorHeader = + &mut self.sector_header[sector_index]; + + unsafe { + core::ptr::copy(chunk.as_ptr(), + sector_header_ptr as *mut u8, + chunk.len()); } } -- 2.30.2