mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-24 18:03:25 +00:00
Add support for statfs and fstatfs
This commit is contained in:
committed by
Tate, Hongliang Tian
parent
9f1680d0f3
commit
743344e3fc
@ -262,7 +262,7 @@ impl FsResolver {
|
||||
let inode_handle = file_table
|
||||
.get_file(fd)?
|
||||
.downcast_ref::<InodeHandle>()
|
||||
.ok_or(Error::with_message(Errno::EBADE, "not inode"))?;
|
||||
.ok_or(Error::with_message(Errno::EBADF, "not inode"))?;
|
||||
Ok(inode_handle.dentry().clone())
|
||||
}
|
||||
|
||||
@ -381,7 +381,7 @@ impl<'a> FsPath<'a> {
|
||||
FsPathInner::CwdRelative(path)
|
||||
}
|
||||
} else {
|
||||
return_errno_with_message!(Errno::EINVAL, "invalid dirfd number");
|
||||
return_errno_with_message!(Errno::EBADF, "invalid dirfd number");
|
||||
};
|
||||
|
||||
Ok(Self {
|
||||
|
@ -14,7 +14,7 @@ mod self_;
|
||||
mod template;
|
||||
|
||||
/// Magic number.
|
||||
const PROC_MAGIC: usize = 0x9fa0;
|
||||
const PROC_MAGIC: u64 = 0x9fa0;
|
||||
/// Root Inode ID.
|
||||
const PROC_ROOT_INO: usize = 1;
|
||||
/// Block size.
|
||||
|
@ -11,7 +11,7 @@ use super::*;
|
||||
use crate::fs::device::Device;
|
||||
use crate::fs::utils::{
|
||||
DirentVisitor, FileSystem, FsFlags, Inode, InodeMode, InodeType, IoEvents, IoctlCmd, Metadata,
|
||||
Poller, SuperBlock,
|
||||
Poller, SuperBlock, NAME_MAX,
|
||||
};
|
||||
|
||||
/// A volatile file system whose data and metadata exists only in memory.
|
||||
|
@ -4,7 +4,6 @@ pub use fs::RamFS;
|
||||
|
||||
mod fs;
|
||||
|
||||
const RAMFS_MAGIC: usize = 0x0102_1994;
|
||||
const RAMFS_MAGIC: u64 = 0x0102_1994;
|
||||
const BLOCK_SIZE: usize = 4096;
|
||||
const NAME_MAX: usize = 255;
|
||||
const ROOT_INO: usize = 1;
|
||||
|
@ -4,7 +4,7 @@ use crate::prelude::*;
|
||||
use alloc::string::String;
|
||||
use core::time::Duration;
|
||||
|
||||
use super::{InodeMode, InodeType, Metadata, Vnode, NAME_MAX};
|
||||
use super::{FileSystem, InodeMode, InodeType, Metadata, Vnode, NAME_MAX};
|
||||
|
||||
lazy_static! {
|
||||
static ref DCACHE: Mutex<BTreeMap<DentryKey, Arc<Dentry>>> = Mutex::new(BTreeMap::new());
|
||||
@ -233,6 +233,11 @@ impl Dentry {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Get the filesystem the inode belongs to
|
||||
pub fn fs(&self) -> Arc<dyn FileSystem> {
|
||||
self.vnode.fs()
|
||||
}
|
||||
|
||||
/// Get the inode metadata
|
||||
pub fn inode_metadata(&self) -> Metadata {
|
||||
self.vnode.metadata()
|
||||
|
@ -7,21 +7,21 @@ use crate::prelude::*;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct SuperBlock {
|
||||
pub magic: usize,
|
||||
pub magic: u64,
|
||||
pub bsize: usize,
|
||||
pub blocks: usize,
|
||||
pub bfree: usize,
|
||||
pub bavail: usize,
|
||||
pub files: usize,
|
||||
pub ffree: usize,
|
||||
pub fsid: usize,
|
||||
pub fsid: u64,
|
||||
pub namelen: usize,
|
||||
pub frsize: usize,
|
||||
pub flags: usize,
|
||||
pub flags: u64,
|
||||
}
|
||||
|
||||
impl SuperBlock {
|
||||
pub fn new(magic: usize, block_size: usize, name_len: usize) -> Self {
|
||||
pub fn new(magic: u64, block_size: usize, name_max_len: usize) -> Self {
|
||||
Self {
|
||||
magic,
|
||||
bsize: block_size,
|
||||
@ -31,7 +31,7 @@ impl SuperBlock {
|
||||
files: 0,
|
||||
ffree: 0,
|
||||
fsid: 0,
|
||||
namelen: 255,
|
||||
namelen: name_max_len,
|
||||
frsize: block_size,
|
||||
flags: 0,
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
use super::{
|
||||
DirentVisitor, FsFlags, Inode, InodeMode, InodeType, IoEvents, IoctlCmd, Metadata, PageCache,
|
||||
Poller,
|
||||
DirentVisitor, FileSystem, FsFlags, Inode, InodeMode, InodeType, IoEvents, IoctlCmd, Metadata,
|
||||
PageCache, Poller,
|
||||
};
|
||||
use crate::fs::device::Device;
|
||||
use crate::prelude::*;
|
||||
@ -202,6 +202,10 @@ impl Vnode {
|
||||
self.inner.read().inode.ioctl(cmd, arg)
|
||||
}
|
||||
|
||||
pub fn fs(&self) -> Arc<dyn FileSystem> {
|
||||
self.inner.read().inode.fs()
|
||||
}
|
||||
|
||||
pub fn metadata(&self) -> Metadata {
|
||||
self.inner.read().inode.metadata()
|
||||
}
|
||||
|
Reference in New Issue
Block a user