|
|
@ -199,7 +199,7 @@ impl INodeImpl {
|
|
|
|
let disk_inode = self.disk_inode.read();
|
|
|
|
let disk_inode = self.disk_inode.read();
|
|
|
|
match disk_inode.type_ {
|
|
|
|
match disk_inode.type_ {
|
|
|
|
FileType::Dir => disk_inode.blocks as usize * BLKSIZE,
|
|
|
|
FileType::Dir => disk_inode.blocks as usize * BLKSIZE,
|
|
|
|
FileType::File => disk_inode.size as usize,
|
|
|
|
FileType::File | FileType::Link => disk_inode.size as usize,
|
|
|
|
_ => panic!("Unknown file type"),
|
|
|
|
_ => panic!("Unknown file type"),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -209,7 +209,7 @@ impl INodeImpl {
|
|
|
|
let mut disk_inode = self.disk_inode.write();
|
|
|
|
let mut disk_inode = self.disk_inode.write();
|
|
|
|
disk_inode.size = match disk_inode.type_ {
|
|
|
|
disk_inode.size = match disk_inode.type_ {
|
|
|
|
FileType::Dir => disk_inode.blocks as usize * DIRENT_SIZE,
|
|
|
|
FileType::Dir => disk_inode.blocks as usize * DIRENT_SIZE,
|
|
|
|
FileType::File => len,
|
|
|
|
FileType::File | FileType::Link => len,
|
|
|
|
_ => panic!("Unknown file type"),
|
|
|
|
_ => panic!("Unknown file type"),
|
|
|
|
} as u32
|
|
|
|
} as u32
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -265,14 +265,14 @@ impl INodeImpl {
|
|
|
|
|
|
|
|
|
|
|
|
impl vfs::INode for INodeImpl {
|
|
|
|
impl vfs::INode for INodeImpl {
|
|
|
|
fn read_at(&self, offset: usize, buf: &mut [u8]) -> vfs::Result<usize> {
|
|
|
|
fn read_at(&self, offset: usize, buf: &mut [u8]) -> vfs::Result<usize> {
|
|
|
|
if self.disk_inode.read().type_!=FileType::File {
|
|
|
|
if self.disk_inode.read().type_ != FileType::File && self.disk_inode.read().type_ != FileType::Link {
|
|
|
|
return Err(FsError::NotFile);
|
|
|
|
return Err(FsError::NotFile);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
self._read_at(offset, buf)
|
|
|
|
self._read_at(offset, buf)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fn write_at(&self, offset: usize, buf: &[u8]) -> vfs::Result<usize> {
|
|
|
|
fn write_at(&self, offset: usize, buf: &[u8]) -> vfs::Result<usize> {
|
|
|
|
let DiskINode { type_, size, .. } = **self.disk_inode.read();
|
|
|
|
let DiskINode { type_, size, .. } = **self.disk_inode.read();
|
|
|
|
if type_ != FileType::File {
|
|
|
|
if type_ != FileType::File && type_ != FileType::Link {
|
|
|
|
return Err(FsError::NotFile);
|
|
|
|
return Err(FsError::NotFile);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// resize if not large enough
|
|
|
|
// resize if not large enough
|
|
|
@ -289,7 +289,7 @@ impl vfs::INode for INodeImpl {
|
|
|
|
dev: 0,
|
|
|
|
dev: 0,
|
|
|
|
inode: self.id,
|
|
|
|
inode: self.id,
|
|
|
|
size: match disk_inode.type_ {
|
|
|
|
size: match disk_inode.type_ {
|
|
|
|
FileType::File => disk_inode.size as usize,
|
|
|
|
FileType::File | FileType::Link => disk_inode.size as usize,
|
|
|
|
FileType::Dir => disk_inode.blocks as usize,
|
|
|
|
FileType::Dir => disk_inode.blocks as usize,
|
|
|
|
_ => panic!("Unknown file type"),
|
|
|
|
_ => panic!("Unknown file type"),
|
|
|
|
},
|
|
|
|
},
|
|
|
@ -317,7 +317,7 @@ impl vfs::INode for INodeImpl {
|
|
|
|
self.sync_all()
|
|
|
|
self.sync_all()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fn resize(&self, len: usize) -> vfs::Result<()> {
|
|
|
|
fn resize(&self, len: usize) -> vfs::Result<()> {
|
|
|
|
if self.disk_inode.read().type_!=FileType::File {
|
|
|
|
if self.disk_inode.read().type_ != FileType::File && self.disk_inode.read().type_ != FileType::Link {
|
|
|
|
return Err(FsError::NotFile);
|
|
|
|
return Err(FsError::NotFile);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
self._resize(len)
|
|
|
|
self._resize(len)
|
|
|
@ -338,7 +338,7 @@ impl vfs::INode for INodeImpl {
|
|
|
|
|
|
|
|
|
|
|
|
// Create new INode
|
|
|
|
// Create new INode
|
|
|
|
let inode = match type_ {
|
|
|
|
let inode = match type_ {
|
|
|
|
vfs::FileType::File => self.fs.new_inode_file()?,
|
|
|
|
vfs::FileType::File | vfs::FileType::SymLink => self.fs.new_inode_file()?,
|
|
|
|
vfs::FileType::Dir => self.fs.new_inode_dir(self.id)?,
|
|
|
|
vfs::FileType::Dir => self.fs.new_inode_dir(self.id)?,
|
|
|
|
_ => return Err(vfs::FsError::InvalidParam),
|
|
|
|
_ => return Err(vfs::FsError::InvalidParam),
|
|
|
|
};
|
|
|
|
};
|
|
|
@ -761,6 +761,7 @@ impl From<FileType> for vfs::FileType {
|
|
|
|
fn from(t: FileType) -> Self {
|
|
|
|
fn from(t: FileType) -> Self {
|
|
|
|
match t {
|
|
|
|
match t {
|
|
|
|
FileType::File => vfs::FileType::File,
|
|
|
|
FileType::File => vfs::FileType::File,
|
|
|
|
|
|
|
|
FileType::Link => vfs::FileType::SymLink,
|
|
|
|
FileType::Dir => vfs::FileType::Dir,
|
|
|
|
FileType::Dir => vfs::FileType::Dir,
|
|
|
|
_ => panic!("unknown file type"),
|
|
|
|
_ => panic!("unknown file type"),
|
|
|
|
}
|
|
|
|
}
|
|
|
|