Sfoglia il codice sorgente

Add method to get capacity of block device. (#34)

Andrew Walbran 2 anni fa
parent
commit
8a85d3af33
1 ha cambiato i file con 7 aggiunte e 2 eliminazioni
  1. 7 2
      src/blk.rs

+ 7 - 2
src/blk.rs

@@ -13,7 +13,7 @@ use log::*;
 pub struct VirtIOBlk<H: Hal, T: Transport> {
     transport: T,
     queue: VirtQueue<H>,
-    capacity: usize,
+    capacity: u64,
 }
 
 impl<H: Hal, T: Transport> VirtIOBlk<H, T> {
@@ -40,10 +40,15 @@ impl<H: Hal, T: Transport> VirtIOBlk<H, T> {
         Ok(VirtIOBlk {
             transport,
             queue,
-            capacity: capacity as usize,
+            capacity,
         })
     }
 
+    /// Gets the capacity of the block device, in 512 byte sectors.
+    pub fn capacity(&self) -> u64 {
+        self.capacity
+    }
+
     /// Acknowledge interrupt.
     pub fn ack_interrupt(&mut self) -> bool {
         self.transport.ack_interrupt()