common: Factor out Logger::read_sector_header().
authorTilman Sauerbeck <tilman@code-monkey.de>
Thu, 9 Jan 2020 10:00:28 +0000 (11:00 +0100)
committerTilman Sauerbeck <tilman@code-monkey.de>
Thu, 9 Jan 2020 14:19:36 +0000 (15:19 +0100)
src/common/logger.rs

index be0632792af1177fab3c40993f1228486cd5ce61..d958193c281d97205b694bd333a5adee51998ec5 100644 (file)
@@ -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());
         }
     }