From ca10d11264c85932e95e6c7c29e8b10c91ae0720 Mon Sep 17 00:00:00 2001 From: WangRunji Date: Sat, 4 Aug 2018 14:09:37 +0800 Subject: [PATCH] Fit for newest Rust nightly. BitSet -> BitVec. --- .travis.yml | 2 +- Cargo.toml | 2 +- src/lib.rs | 2 +- src/sfs.rs | 30 +++++++++++++++--------------- src/vfs.rs | 2 +- 5 files changed, 19 insertions(+), 19 deletions(-) diff --git a/.travis.yml b/.travis.yml index 3b2fc9c..0f33674 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,3 +1,3 @@ language: rust rust: - - nightly-2018-04-01 \ No newline at end of file + - nightly \ No newline at end of file diff --git a/Cargo.toml b/Cargo.toml index c6e07e9..8f342a4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,7 +4,7 @@ version = "0.0.1" authors = ["WangRunji "] [dependencies] -bit-set = { default-features = false, version = "0.5" } # default-features contains 'std' +bit-vec = { default-features = false, git = "https://github.com/AltSysrq/bit-vec.git" } # default-features contains 'std' static_assertions = "0.2.5" [features] diff --git a/src/lib.rs b/src/lib.rs index b406fd2..eeaab74 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -8,7 +8,7 @@ extern crate std; #[macro_use] extern crate alloc; -extern crate bit_set; +extern crate bit_vec; #[macro_use] extern crate static_assertions; diff --git a/src/sfs.rs b/src/sfs.rs index 3dd7787..3e47564 100644 --- a/src/sfs.rs +++ b/src/sfs.rs @@ -1,5 +1,5 @@ -use bit_set::BitSet; -use alloc::{boxed::Box, Vec, BTreeMap, rc::{Rc, Weak}, String}; +use bit_vec::BitVec; +use alloc::{boxed::Box, vec::Vec, collections::BTreeMap, rc::{Rc, Weak}, string::String}; use core::cell::{RefCell, RefMut}; use core::mem::{uninitialized, size_of}; use core::slice; @@ -331,7 +331,7 @@ pub struct SimpleFileSystem { /// on-disk superblock super_block: RefCell>, /// blocks in use are mared 0 - free_map: RefCell>, + free_map: RefCell>, /// inode list inodes: RefCell>>, /// device @@ -351,7 +351,7 @@ impl SimpleFileSystem { Some(SimpleFileSystem { super_block: RefCell::new(Dirty::new(super_block)), - free_map: RefCell::new(Dirty::new(BitSet::from_bytes(&free_map))), + free_map: RefCell::new(Dirty::new(BitVec::from_bytes(&free_map))), inodes: RefCell::new(BTreeMap::>::new()), device: RefCell::new(device), self_ptr: Weak::default(), @@ -369,9 +369,9 @@ impl SimpleFileSystem { info: Str32::from("simple file system"), }; let free_map = { - let mut bitset = BitSet::with_capacity(BLKBITS); + let mut bitset = BitVec::from_elem(BLKBITS, false); for i in 3..blocks { - bitset.insert(i); + bitset.set(i, true); } bitset }; @@ -417,8 +417,8 @@ impl SimpleFileSystem { /// Free a block fn free_block(&self, block_id: usize) { let mut free_map = self.free_map.borrow_mut(); - assert!(!free_map.contains(block_id)); - free_map.insert(block_id); + assert!(!free_map[block_id]); + free_map.set(block_id, true); self.super_block.borrow_mut().unused_blocks += 1; } @@ -436,7 +436,7 @@ impl SimpleFileSystem { /// Get inode by id. Load if not in memory. /// ** Must ensure it's a valid INode ** fn get_inode(&self, id: INodeId) -> Ptr { - assert!(!self.free_map.borrow().contains(id)); + assert!(!self.free_map.borrow()[id]); // Load if not in memory. if !self.inodes.borrow().contains_key(&id) { @@ -510,24 +510,24 @@ trait BitsetAlloc { fn alloc(&mut self) -> Option; } -impl BitsetAlloc for BitSet { +impl BitsetAlloc for BitVec { fn alloc(&mut self) -> Option { // TODO: more efficient - let id = (0..self.len()).find(|&i| self.contains(i)); + let id = (0..self.len()).find(|&i| self[i]); if let Some(id) = id { - self.remove(id); + self.set(id, false); } id } } -impl AsBuf for BitSet { +impl AsBuf for BitVec { fn as_buf(&self) -> &[u8] { - let slice = self.get_ref().storage(); + let slice = self.storage(); unsafe { slice::from_raw_parts(slice as *const _ as *const u8, slice.len() * 4) } } fn as_buf_mut(&mut self) -> &mut [u8] { - let slice = self.get_ref().storage(); + let slice = self.storage(); unsafe { slice::from_raw_parts_mut(slice as *const _ as *mut u8, slice.len() * 4) } } } diff --git a/src/vfs.rs b/src/vfs.rs index fa85633..ad2b560 100644 --- a/src/vfs.rs +++ b/src/vfs.rs @@ -1,4 +1,4 @@ -use alloc::{Vec, String, rc::{Rc, Weak}}; +use alloc::{vec::Vec, string::String, rc::{Rc, Weak}}; use core::cell::RefCell; use core::mem::size_of; use core;