add device inode id to DiskINode

master
gaotianyu1350 6 years ago
parent 6cb05c35a2
commit 83c218aadb

@ -846,17 +846,7 @@ impl SimpleFileSystem {
/// Create a new INode struct, then insert it to self.inodes /// Create a new INode struct, then insert it to self.inodes
/// Private used for load or create INode /// Private used for load or create INode
fn _new_inode(&self, id: INodeId, disk_inode: Dirty<DiskINode>) -> Arc<INodeImpl> { fn _new_inode(&self, id: INodeId, disk_inode: Dirty<DiskINode>) -> Arc<INodeImpl> {
let inode = Arc::new(INodeImpl { let device_inode_id = disk_inode.device_inode_id;
id,
disk_inode: RwLock::new(disk_inode),
fs: self.self_ptr.upgrade().unwrap(),
device_inode_id: NODEVICE
});
self.inodes.write().insert(id, Arc::downgrade(&inode));
inode
}
fn _new_inode_with_device(&self, id: INodeId, disk_inode: Dirty<DiskINode>, device_inode_id: usize) -> Arc<INodeImpl> {
let inode = Arc::new(INodeImpl { let inode = Arc::new(INodeImpl {
id, id,
disk_inode: RwLock::new(disk_inode), disk_inode: RwLock::new(disk_inode),
@ -866,6 +856,7 @@ impl SimpleFileSystem {
self.inodes.write().insert(id, Arc::downgrade(&inode)); self.inodes.write().insert(id, Arc::downgrade(&inode));
inode inode
} }
/// Get inode by id. Load if not in memory. /// Get inode by id. Load if not in memory.
/// ** Must ensure it's a valid INode ** /// ** Must ensure it's a valid INode **
fn get_inode(&self, id: INodeId) -> Arc<INodeImpl> { fn get_inode(&self, id: INodeId) -> Arc<INodeImpl> {
@ -904,8 +895,8 @@ impl SimpleFileSystem {
/// Create a new INode chardevice /// Create a new INode chardevice
pub fn new_inode_chardevice(&self, device_inode_id: usize) -> vfs::Result<Arc<INodeImpl>> { pub fn new_inode_chardevice(&self, device_inode_id: usize) -> vfs::Result<Arc<INodeImpl>> {
let id = self.alloc_block().ok_or(FsError::NoDeviceSpace)?; let id = self.alloc_block().ok_or(FsError::NoDeviceSpace)?;
let disk_inode = Dirty::new_dirty(DiskINode::new_chardevice()); let disk_inode = Dirty::new_dirty(DiskINode::new_chardevice(device_inode_id));
let new_inode = self._new_inode_with_device(id, disk_inode, device_inode_id); let new_inode = self._new_inode(id, disk_inode);
Ok(new_inode) Ok(new_inode)
} }
fn flush_weak_inodes(&self) { fn flush_weak_inodes(&self) {

@ -44,6 +44,8 @@ pub struct DiskINode {
pub indirect: u32, pub indirect: u32,
/// double indirect blocks /// double indirect blocks
pub db_indirect: u32, pub db_indirect: u32,
/// device inode id
pub device_inode_id: usize
} }
/* /*
@ -134,6 +136,7 @@ impl DiskINode {
direct: [0; NDIRECT], direct: [0; NDIRECT],
indirect: 0, indirect: 0,
db_indirect: 0, db_indirect: 0,
device_inode_id: NODEVICE
} }
} }
pub const fn new_symlink() -> Self { pub const fn new_symlink() -> Self {
@ -145,6 +148,7 @@ impl DiskINode {
direct: [0; NDIRECT], direct: [0; NDIRECT],
indirect: 0, indirect: 0,
db_indirect: 0, db_indirect: 0,
device_inode_id: NODEVICE
} }
} }
pub const fn new_dir() -> Self { pub const fn new_dir() -> Self {
@ -156,9 +160,10 @@ impl DiskINode {
direct: [0; NDIRECT], direct: [0; NDIRECT],
indirect: 0, indirect: 0,
db_indirect: 0, db_indirect: 0,
device_inode_id: NODEVICE
} }
} }
pub const fn new_chardevice() -> Self { pub const fn new_chardevice(device_inode_id: usize) -> Self {
DiskINode { DiskINode {
size: 0, size: 0,
type_: FileType::CharDevice, type_: FileType::CharDevice,
@ -167,6 +172,7 @@ impl DiskINode {
direct: [0; NDIRECT], direct: [0; NDIRECT],
indirect: 0, indirect: 0,
db_indirect: 0, db_indirect: 0,
device_inode_id: device_inode_id
} }
} }
} }

Loading…
Cancel
Save