Fix bugs of borrow_mut & entry[>12].

master
WangRunji 7 years ago
parent 11749fe728
commit 5f244d4538

@ -69,7 +69,7 @@ impl INode {
id if id < NDIRECT => id if id < NDIRECT =>
Some(self.disk_inode.direct[id] as BlockId), Some(self.disk_inode.direct[id] as BlockId),
id if id < NDIRECT + BLK_NENTRY => { id if id < NDIRECT + BLK_NENTRY => {
let mut disk_block_id: BlockId = 0; let mut disk_block_id: u32 = 0;
let fs = self.fs.upgrade().unwrap(); let fs = self.fs.upgrade().unwrap();
fs.borrow_mut().device.read_block( fs.borrow_mut().device.read_block(
self.disk_inode.indirect as usize, self.disk_inode.indirect as usize,
@ -92,8 +92,7 @@ impl vfs::INode for INode {
self.sync() self.sync()
} }
fn read_at(&mut self, offset: usize, buf: &mut [u8]) -> Option<usize> { fn read_at(&mut self, offset: usize, buf: &mut [u8]) -> Option<usize> {
let fs0 = self.fs.upgrade().unwrap(); let fs = self.fs.upgrade().unwrap();
let mut fs = fs0.borrow_mut();
let iter = BlockIter { let iter = BlockIter {
begin: offset, begin: offset,
@ -105,7 +104,7 @@ impl vfs::INode for INode {
for BlockRange { block, begin, end } in iter { for BlockRange { block, begin, end } in iter {
if let Some(disk_block_id) = self.disk_block_id(block) { if let Some(disk_block_id) = self.disk_block_id(block) {
let len = end - begin; let len = end - begin;
fs.device.read_block(disk_block_id, begin, &mut buf[buf_offset..buf_offset + len]); fs.borrow_mut().device.read_block(disk_block_id, begin, &mut buf[buf_offset..buf_offset + len]);
buf_offset += len; buf_offset += len;
} else { } else {
// Failed this time // Failed this time
@ -115,8 +114,7 @@ impl vfs::INode for INode {
Some(buf_offset) Some(buf_offset)
} }
fn write_at(&mut self, offset: usize, buf: &[u8]) -> Option<usize> { fn write_at(&mut self, offset: usize, buf: &[u8]) -> Option<usize> {
let fs0 = self.fs.upgrade().unwrap(); let fs = self.fs.upgrade().unwrap();
let mut fs = fs0.borrow_mut();
let iter = BlockIter { let iter = BlockIter {
begin: offset, begin: offset,
@ -128,7 +126,7 @@ impl vfs::INode for INode {
for BlockRange { block, begin, end } in iter { for BlockRange { block, begin, end } in iter {
if let Some(disk_block_id) = self.disk_block_id(block) { if let Some(disk_block_id) = self.disk_block_id(block) {
let len = end - begin; let len = end - begin;
fs.device.write_block(disk_block_id, begin, &buf[buf_offset..buf_offset + len]); fs.borrow_mut().device.write_block(disk_block_id, begin, &buf[buf_offset..buf_offset + len]);
buf_offset += len; buf_offset += len;
} else { } else {
// Failed this time // Failed this time
@ -166,6 +164,7 @@ struct BlockIter {
end: usize, end: usize,
} }
#[derive(Debug)]
struct BlockRange { struct BlockRange {
block: BlockId, block: BlockId,
begin: usize, begin: usize,

@ -92,7 +92,7 @@ pub trait AsBuf {
impl AsBuf for SuperBlock {} impl AsBuf for SuperBlock {}
impl AsBuf for DiskINode {} impl AsBuf for DiskINode {}
impl AsBuf for DiskEntry {} impl AsBuf for DiskEntry {}
impl AsBuf for BlockId {} impl AsBuf for u32 {}
/* /*
* Simple FS (SFS) definitions visible to ucore. This covers the on-disk format * Simple FS (SFS) definitions visible to ucore. This covers the on-disk format

Loading…
Cancel
Save