Skip to content

Commit 1b7b49b

Browse files
committed
Adds mnt_op
1 parent 6dd4c35 commit 1b7b49b

File tree

5 files changed

+45
-5
lines changed

5 files changed

+45
-5
lines changed

kernel-1100/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use self::file::File;
44
use self::lock::{LockObject, Mtx};
55
use self::malloc::Malloc;
6-
use self::mount::{Filesystem, FsStats, Mount};
6+
use self::mount::{Filesystem, FsOps, FsStats, Mount};
77
use self::pcpu::Pcpu;
88
use self::socket::Socket;
99
use self::thread::Thread;
@@ -52,6 +52,7 @@ impl okf::Kernel for Kernel {
5252

5353
type File = File;
5454
type Filesystem = Filesystem;
55+
type FsOps = FsOps;
5556
type FsStats = FsStats;
5657
type LockObject = LockObject;
5758
type Malloc = Malloc;

kernel-1100/src/mount.rs

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
use crate::lock::Mtx;
2+
use crate::vnode::Vnode;
23
use crate::Kernel;
3-
use core::ffi::c_char;
4+
use core::ffi::{c_char, c_int};
5+
use core::mem::MaybeUninit;
6+
use core::num::NonZero;
47
use okf::queue::TailQueueEntry;
58

69
/// Implementation of [`okf::mount::Mount`] for 11.00.
@@ -9,7 +12,7 @@ pub struct Mount {
912
mtx: Mtx,
1013
pad1: [u8; 0x8],
1114
entry: TailQueueEntry<Self>,
12-
pad2: [u8; 8],
15+
ops: *const FsOps,
1316
fs: *mut Filesystem,
1417
pad3: [u8; 0x38],
1518
flags: u64,
@@ -34,6 +37,10 @@ impl okf::mount::Mount<Kernel> for Mount {
3437
self.fs
3538
}
3639

40+
fn ops(&self) -> &'static FsOps {
41+
unsafe { &*self.ops }
42+
}
43+
3744
unsafe fn flags(&self) -> u64 {
3845
self.flags
3946
}
@@ -56,6 +63,25 @@ impl okf::mount::Filesystem for Filesystem {
5663
}
5764
}
5865

66+
/// Implementation of [`okf::mount::FsOps`] for 11.00.
67+
#[repr(C)]
68+
pub struct FsOps {
69+
pad1: [u8; 0x18],
70+
root: unsafe extern "C" fn(*mut Mount, c_int, *mut *mut Vnode) -> c_int,
71+
}
72+
73+
impl okf::mount::FsOps<Kernel> for FsOps {
74+
unsafe fn root(&self, mp: *mut Mount, flags: c_int) -> Result<*mut Vnode, NonZero<c_int>> {
75+
let mut vp = MaybeUninit::uninit();
76+
let errno = (self.root)(mp, flags, vp.as_mut_ptr());
77+
78+
match NonZero::new(errno) {
79+
Some(v) => Err(v),
80+
None => Ok(vp.assume_init()),
81+
}
82+
}
83+
}
84+
5985
/// Implementation of [`okf::mount::FsStats`] for 11.00.
6086
#[repr(C)]
6187
pub struct FsStats {

src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use self::fd::OpenFlags;
44
use self::file::File;
55
use self::lock::{LockObject, Mtx};
66
use self::malloc::{Malloc, MallocFlags};
7-
use self::mount::{Filesystem, FsStats, Mount};
7+
use self::mount::{Filesystem, FsOps, FsStats, Mount};
88
use self::pcpu::Pcpu;
99
use self::queue::TailQueue;
1010
use self::socket::{SockAddr, Socket};
@@ -60,6 +60,7 @@ pub trait Kernel: MappedKernel {
6060

6161
type File: File;
6262
type Filesystem: Filesystem;
63+
type FsOps: FsOps<Self>;
6364
type FsStats: FsStats;
6465
type LockObject: LockObject;
6566
type Malloc: Malloc;

src/mount/fs.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
1-
use core::ffi::c_char;
1+
use crate::Kernel;
2+
use core::ffi::{c_char, c_int};
3+
use core::num::NonZero;
24

35
/// Represents `vfsconf` structure.
46
pub trait Filesystem: Sized {
57
/// Returns `vfc_name`.
68
fn name(&self) -> *const c_char;
79
}
10+
11+
/// Represents `vfsops` structure.
12+
pub trait FsOps<K: Kernel>: Sized {
13+
/// Invoke `vfs_root`.
14+
unsafe fn root(&self, mp: *mut K::Mount, flags: c_int)
15+
-> Result<*mut K::Vnode, NonZero<c_int>>;
16+
}

src/mount/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ pub trait Mount<K: Kernel>: Sized {
2626
/// Returns `mnt_vfc`.
2727
fn fs(&self) -> *mut K::Filesystem;
2828

29+
/// Returns `mnt_op`.
30+
fn ops(&self) -> &'static K::FsOps;
31+
2932
/// Returns the value of `mnt_flag`.
3033
///
3134
/// # Safety

0 commit comments

Comments
 (0)