From: Tilman Sauerbeck Date: Thu, 9 Jan 2020 10:00:28 +0000 (+0100) Subject: common: Factor out Logger::read_sector_header(). X-Git-Url: http://git.code-monkey.de/?a=commitdiff_plain;h=8f0161e8492d090b09782c13b43ef71201787186;p=gps-watch.git common: Factor out Logger::read_sector_header(). --- 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()); } }