refactor: make Vnode::stat() return Stat
This commit is contained in:
parent
564d10e1be
commit
7f939543fe
@ -31,8 +31,8 @@ fn impl_inode_fn<T: ToTokens>(name: &str, behavior: T) -> ImplItem {
|
||||
}
|
||||
},
|
||||
"stat" => quote! {
|
||||
fn stat(&mut self, _at: VnodeRef, _stat: &mut libsys::stat::Stat) ->
|
||||
Result<(), libsys::error::Errno>
|
||||
fn stat(&mut self, _at: VnodeRef) ->
|
||||
Result<libsys::stat::Stat, libsys::error::Errno>
|
||||
{
|
||||
#behavior
|
||||
}
|
||||
|
@ -35,12 +35,13 @@ impl<A: BlockAllocator + Copy + 'static> VnodeImpl for DirInode<A> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn stat(&mut self, node: VnodeRef, stat: &mut Stat) -> Result<(), Errno> {
|
||||
fn stat(&mut self, node: VnodeRef) -> Result<Stat, Errno> {
|
||||
let props = node.props();
|
||||
stat.size = 0;
|
||||
stat.blksize = 4096;
|
||||
stat.mode = props.mode;
|
||||
Ok(())
|
||||
Ok(Stat {
|
||||
size: 0,
|
||||
blksize: 4096,
|
||||
mode: props.mode
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -35,12 +35,13 @@ impl<'a, A: BlockAllocator + Copy + 'static> VnodeImpl for FileInode<'a, A> {
|
||||
Ok(self.data.size())
|
||||
}
|
||||
|
||||
fn stat(&mut self, node: VnodeRef, stat: &mut Stat) -> Result<(), Errno> {
|
||||
fn stat(&mut self, node: VnodeRef) -> Result<Stat, Errno> {
|
||||
let props = node.props();
|
||||
stat.size = self.data.size() as u64;
|
||||
stat.blksize = 4096;
|
||||
stat.mode = props.mode;
|
||||
Ok(())
|
||||
Ok(Stat {
|
||||
size: self.data.size() as u64,
|
||||
blksize: 4096,
|
||||
mode: props.mode
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -82,7 +82,7 @@ pub trait VnodeImpl {
|
||||
) -> Result<usize, Errno>;
|
||||
|
||||
/// Retrieves file status
|
||||
fn stat(&mut self, node: VnodeRef, stat: &mut Stat) -> Result<(), Errno>;
|
||||
fn stat(&mut self, node: VnodeRef) -> Result<Stat, Errno>;
|
||||
|
||||
/// Reports the size of this filesystem object in bytes
|
||||
fn size(&mut self, node: VnodeRef) -> Result<usize, Errno>;
|
||||
@ -451,9 +451,9 @@ impl Vnode {
|
||||
}
|
||||
|
||||
/// Reports file status
|
||||
pub fn stat(self: &VnodeRef, stat: &mut Stat) -> Result<(), Errno> {
|
||||
pub fn stat(self: &VnodeRef) -> Result<Stat, Errno> {
|
||||
if let Some(ref mut data) = *self.data() {
|
||||
data.stat(self.clone(), stat)
|
||||
data.stat(self.clone())
|
||||
} else {
|
||||
Err(Errno::NotImplemented)
|
||||
}
|
||||
|
@ -107,7 +107,8 @@ pub fn syscall(num: SystemCall, args: &[usize]) -> Result<usize, Errno> {
|
||||
|
||||
let proc = Process::current();
|
||||
let mut io = proc.io.lock();
|
||||
find_at_node(&mut io, at_fd, filename, flags & AT_EMPTY_PATH != 0)?.stat(buf)?;
|
||||
let stat = find_at_node(&mut io, at_fd, filename, flags & AT_EMPTY_PATH != 0)?.stat()?;
|
||||
*buf = stat;
|
||||
Ok(0)
|
||||
}
|
||||
SystemCall::Ioctl => {
|
||||
|
Loading…
x
Reference in New Issue
Block a user