From 1415941a960861d7b602ab5d8ee1a92a8766a7b0 Mon Sep 17 00:00:00 2001 From: Szymon Walter Date: Mon, 19 Mar 2018 19:41:45 +0100 Subject: [PATCH] update `update_global` method on `Ext2` --- src/fs.rs | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/src/fs.rs b/src/fs.rs index 84f9862..18a6ca1 100644 --- a/src/fs.rs +++ b/src/fs.rs @@ -1,3 +1,4 @@ +use core::mem; use alloc::Vec; use error::Error; @@ -53,13 +54,27 @@ where }) } - pub fn update(&mut self) -> Result<(), Error> { - let slice = BufferSlice::from_cast( - &self.superblock.inner, - self.superblock.offset, - ); - let commit = slice.commit(); - self.buffer.commit(commit).map_err(|err| Error::from(err)) + pub fn update_global(&mut self) -> Result<(), Error> { + // superblock + { + let slice = BufferSlice::from_cast( + &self.superblock.inner, + self.superblock.offset, + ); + let commit = slice.commit(); + self.buffer.commit(commit).map_err(|err| Error::from(err))?; + } + + // block group descriptors + let mut offset = self.block_groups.offset; + for descr in &self.block_groups.inner { + let slice = BufferSlice::from_cast(descr, offset); + let commit = slice.commit(); + self.buffer.commit(commit).map_err(|err| Error::from(err))?; + offset += mem::size_of::(); + } + + Ok(()) } fn superblock(&self) -> &Superblock {