From 83c218aadb0bd4e3b69e5c69457f724be78863c5 Mon Sep 17 00:00:00 2001 From: gaotianyu1350 Date: Fri, 12 Apr 2019 13:57:31 +0800 Subject: [PATCH] add device inode id to DiskINode --- rcore-fs-sfs/src/lib.rs | 17 ++++------------- rcore-fs-sfs/src/structs.rs | 8 +++++++- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/rcore-fs-sfs/src/lib.rs b/rcore-fs-sfs/src/lib.rs index cd414ab..0b61166 100644 --- a/rcore-fs-sfs/src/lib.rs +++ b/rcore-fs-sfs/src/lib.rs @@ -846,17 +846,7 @@ impl SimpleFileSystem { /// Create a new INode struct, then insert it to self.inodes /// Private used for load or create INode fn _new_inode(&self, id: INodeId, disk_inode: Dirty) -> Arc { - let inode = Arc::new(INodeImpl { - 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, device_inode_id: usize) -> Arc { + let device_inode_id = disk_inode.device_inode_id; let inode = Arc::new(INodeImpl { id, disk_inode: RwLock::new(disk_inode), @@ -866,6 +856,7 @@ impl SimpleFileSystem { self.inodes.write().insert(id, Arc::downgrade(&inode)); inode } + /// Get inode by id. Load if not in memory. /// ** Must ensure it's a valid INode ** fn get_inode(&self, id: INodeId) -> Arc { @@ -904,8 +895,8 @@ impl SimpleFileSystem { /// Create a new INode chardevice pub fn new_inode_chardevice(&self, device_inode_id: usize) -> vfs::Result> { let id = self.alloc_block().ok_or(FsError::NoDeviceSpace)?; - let disk_inode = Dirty::new_dirty(DiskINode::new_chardevice()); - let new_inode = self._new_inode_with_device(id, disk_inode, device_inode_id); + let disk_inode = Dirty::new_dirty(DiskINode::new_chardevice(device_inode_id)); + let new_inode = self._new_inode(id, disk_inode); Ok(new_inode) } fn flush_weak_inodes(&self) { diff --git a/rcore-fs-sfs/src/structs.rs b/rcore-fs-sfs/src/structs.rs index 3bfb15e..fd84e98 100644 --- a/rcore-fs-sfs/src/structs.rs +++ b/rcore-fs-sfs/src/structs.rs @@ -44,6 +44,8 @@ pub struct DiskINode { pub indirect: u32, /// double indirect blocks pub db_indirect: u32, + /// device inode id + pub device_inode_id: usize } /* @@ -134,6 +136,7 @@ impl DiskINode { direct: [0; NDIRECT], indirect: 0, db_indirect: 0, + device_inode_id: NODEVICE } } pub const fn new_symlink() -> Self { @@ -145,6 +148,7 @@ impl DiskINode { direct: [0; NDIRECT], indirect: 0, db_indirect: 0, + device_inode_id: NODEVICE } } pub const fn new_dir() -> Self { @@ -156,9 +160,10 @@ impl DiskINode { direct: [0; NDIRECT], 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 { size: 0, type_: FileType::CharDevice, @@ -167,6 +172,7 @@ impl DiskINode { direct: [0; NDIRECT], indirect: 0, db_indirect: 0, + device_inode_id: device_inode_id } } }