|
|
@ -1,6 +1,6 @@
|
|
|
|
use bit_vec::BitVec;
|
|
|
|
use bit_vec::BitVec;
|
|
|
|
use alloc::{boxed::Box, vec::Vec, collections::BTreeMap, sync::{Arc, Weak}, string::String};
|
|
|
|
use alloc::{boxed::Box, vec::Vec, collections::BTreeMap, sync::{Arc, Weak}, string::String};
|
|
|
|
use core::mem::{uninitialized, size_of};
|
|
|
|
use core::mem::uninitialized;
|
|
|
|
use core::slice;
|
|
|
|
use core::slice;
|
|
|
|
use core::fmt::{Debug, Formatter, Error};
|
|
|
|
use core::fmt::{Debug, Formatter, Error};
|
|
|
|
use core::any::Any;
|
|
|
|
use core::any::Any;
|
|
|
@ -98,11 +98,11 @@ impl INodeImpl {
|
|
|
|
self._read_at(i as usize * BLKSIZE, entry.as_buf_mut()).unwrap();
|
|
|
|
self._read_at(i as usize * BLKSIZE, entry.as_buf_mut()).unwrap();
|
|
|
|
(entry, i)
|
|
|
|
(entry, i)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
.find(|(entry, id)| entry.name.as_ref() == name)
|
|
|
|
.find(|(entry, _)| entry.name.as_ref() == name)
|
|
|
|
.map(|(entry, id)| (entry.id as INodeId, id as usize))
|
|
|
|
.map(|(entry, id)| (entry.id as INodeId, id as usize))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fn get_file_inode_id(&self, name: &str) -> Option<INodeId> {
|
|
|
|
fn get_file_inode_id(&self, name: &str) -> Option<INodeId> {
|
|
|
|
self.get_file_inode_and_entry_id(name).map(|(inode_id, entry_id)| { inode_id })
|
|
|
|
self.get_file_inode_and_entry_id(name).map(|(inode_id, _)| inode_id)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/// Init dir content. Insert 2 init entries.
|
|
|
|
/// Init dir content. Insert 2 init entries.
|
|
|
|
/// This do not init nlinks, please modify the nlinks in the invoker.
|
|
|
|
/// This do not init nlinks, please modify the nlinks in the invoker.
|
|
|
@ -248,7 +248,7 @@ impl INodeImpl {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
impl vfs::INode for INodeImpl {
|
|
|
|
impl vfs::INode for INodeImpl {
|
|
|
|
fn open(&self, flags: u32) -> vfs::Result<()> {
|
|
|
|
fn open(&self, _flags: u32) -> vfs::Result<()> {
|
|
|
|
// Do nothing
|
|
|
|
// Do nothing
|
|
|
|
Ok(())
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -339,7 +339,7 @@ impl vfs::INode for INodeImpl {
|
|
|
|
inode.nlinks_dec(); //for .
|
|
|
|
inode.nlinks_dec(); //for .
|
|
|
|
self.nlinks_dec(); //for ..
|
|
|
|
self.nlinks_dec(); //for ..
|
|
|
|
}
|
|
|
|
}
|
|
|
|
self.remove_dirent_page(entry_id);
|
|
|
|
self.remove_dirent_page(entry_id)?;
|
|
|
|
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -401,7 +401,7 @@ impl vfs::INode for INodeImpl {
|
|
|
|
dest._resize(old_size + BLKSIZE).unwrap();
|
|
|
|
dest._resize(old_size + BLKSIZE).unwrap();
|
|
|
|
dest._write_at(old_size, entry.as_buf()).unwrap();
|
|
|
|
dest._write_at(old_size, entry.as_buf()).unwrap();
|
|
|
|
|
|
|
|
|
|
|
|
self.remove_dirent_page(entry_id);
|
|
|
|
self.remove_dirent_page(entry_id)?;
|
|
|
|
|
|
|
|
|
|
|
|
if inode.info()?.type_ == vfs::FileType::Dir {
|
|
|
|
if inode.info()?.type_ == vfs::FileType::Dir {
|
|
|
|
self.nlinks_dec();
|
|
|
|
self.nlinks_dec();
|
|
|
@ -436,7 +436,7 @@ impl Drop for INodeImpl {
|
|
|
|
fn drop(&mut self) {
|
|
|
|
fn drop(&mut self) {
|
|
|
|
self.sync().expect("failed to sync");
|
|
|
|
self.sync().expect("failed to sync");
|
|
|
|
if self.disk_inode.read().nlinks <= 0 {
|
|
|
|
if self.disk_inode.read().nlinks <= 0 {
|
|
|
|
self._resize(0);
|
|
|
|
self._resize(0).unwrap();
|
|
|
|
self.disk_inode.write().sync();
|
|
|
|
self.disk_inode.write().sync();
|
|
|
|
self.fs.free_block(self.id);
|
|
|
|
self.fs.free_block(self.id);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -481,7 +481,7 @@ impl SimpleFileSystem {
|
|
|
|
}.wrap())
|
|
|
|
}.wrap())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/// Create a new SFS on blank disk
|
|
|
|
/// Create a new SFS on blank disk
|
|
|
|
pub fn create(mut device: Box<Device>, space: usize) -> Arc<Self> {
|
|
|
|
pub fn create(device: Box<Device>, space: usize) -> Arc<Self> {
|
|
|
|
let blocks = (space / BLKSIZE).min(BLKBITS);
|
|
|
|
let blocks = (space / BLKSIZE).min(BLKBITS);
|
|
|
|
assert!(blocks >= 16, "space too small");
|
|
|
|
assert!(blocks >= 16, "space too small");
|
|
|
|
|
|
|
|
|
|
|
|