Merge recent update from ch7 && cargo clippy
This commit is contained in:
parent
737340b0a0
commit
c9583b0f53
20 changed files with 236 additions and 163 deletions
|
@ -17,7 +17,7 @@ pub struct Bitmap {
|
|||
/// Return (block_pos, bits64_pos, inner_pos)
|
||||
fn decomposition(mut bit: usize) -> (usize, usize, usize) {
|
||||
let block_pos = bit / BLOCK_BITS;
|
||||
bit = bit % BLOCK_BITS;
|
||||
bit %= BLOCK_BITS;
|
||||
(block_pos, bit / 64, bit % 64)
|
||||
}
|
||||
|
||||
|
@ -70,4 +70,4 @@ impl Bitmap {
|
|||
pub fn maximum(&self) -> usize {
|
||||
self.blocks * BLOCK_BITS
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -289,35 +289,26 @@ impl DiskInode {
|
|||
.lock()
|
||||
.modify(0, |indirect2: &mut IndirectBlock| {
|
||||
// full indirect1 blocks
|
||||
for i in 0..a1 {
|
||||
v.push(indirect2[i]);
|
||||
get_block_cache(
|
||||
indirect2[i] as usize,
|
||||
Arc::clone(block_device),
|
||||
)
|
||||
.lock()
|
||||
.modify(0, |indirect1: &mut IndirectBlock| {
|
||||
for j in 0..INODE_INDIRECT1_COUNT {
|
||||
v.push(indirect1[j]);
|
||||
//indirect1[j] = 0;
|
||||
}
|
||||
});
|
||||
//indirect2[i] = 0;
|
||||
for entry in indirect2.iter_mut().take(a1) {
|
||||
v.push(*entry);
|
||||
get_block_cache(*entry as usize, Arc::clone(block_device))
|
||||
.lock()
|
||||
.modify(0, |indirect1: &mut IndirectBlock| {
|
||||
for entry in indirect1.iter() {
|
||||
v.push(*entry);
|
||||
}
|
||||
});
|
||||
}
|
||||
// last indirect1 block
|
||||
if b1 > 0 {
|
||||
v.push(indirect2[a1]);
|
||||
get_block_cache(
|
||||
indirect2[a1] as usize,
|
||||
Arc::clone(block_device),
|
||||
)
|
||||
.lock()
|
||||
.modify(0, |indirect1: &mut IndirectBlock| {
|
||||
for j in 0..b1 {
|
||||
v.push(indirect1[j]);
|
||||
//indirect1[j] = 0;
|
||||
}
|
||||
});
|
||||
get_block_cache(indirect2[a1] as usize, Arc::clone(block_device))
|
||||
.lock()
|
||||
.modify(0, |indirect1: &mut IndirectBlock| {
|
||||
for entry in indirect1.iter().take(b1) {
|
||||
v.push(*entry);
|
||||
}
|
||||
});
|
||||
//indirect2[a1] = 0;
|
||||
}
|
||||
});
|
||||
|
@ -445,4 +436,4 @@ impl DirEntry {
|
|||
pub fn inode_number(&self) -> u32 {
|
||||
self.inode_number
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -110,12 +110,13 @@ impl Inode {
|
|||
|
||||
pub fn create(&self, name: &str) -> Option<Arc<Inode>> {
|
||||
let mut fs = self.fs.lock();
|
||||
if self.modify_disk_inode(|root_inode| {
|
||||
let op = |root_inode: &mut DiskInode| {
|
||||
// assert it is a directory
|
||||
assert!(root_inode.is_dir());
|
||||
// has the file been created?
|
||||
self.find_inode_id(name, root_inode)
|
||||
}).is_some() {
|
||||
};
|
||||
if self.modify_disk_inode(op).is_some() {
|
||||
return None;
|
||||
}
|
||||
// create a new file
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue