Skip to content

Commit ea7ec62

Browse files
committed
kernel: Rework parts of vfs
1 parent 69227ca commit ea7ec62

8 files changed

Lines changed: 56 additions & 156 deletions

File tree

kernel/src/fs/initramfs.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,4 @@ pub fn load_initramfs() {
4242
pub fn initramfs_read(path: &str) -> Option<Vec<u8>> {
4343
initramfs.lock().get(&path.to_string()).cloned()
4444
}
45+
// TODO: Add initramfs folder to archive and pass it to limine. Parse the archive here and add the folder and files to the tmpfs

kernel/src/fs/mod.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
//! The design and implementation of this virtual file system is heavily influenced by BSD.
22
3+
use core::{error::Error, fmt::Display};
4+
35
#[derive(Debug)]
4-
pub enum Error {
6+
pub enum VfsError {
57
VNodeNotFound,
68
NotADirectory,
79
IsADirectory,
@@ -12,7 +14,15 @@ pub enum Error {
1214
FileSystemNotFound,
1315
}
1416

15-
pub type Result<T, E = Error> = core::result::Result<T, E>;
17+
impl Display for VfsError {
18+
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
19+
todo!()
20+
}
21+
}
22+
23+
impl Error for VfsError {}
24+
25+
pub type Result<T, E = VfsError> = core::result::Result<T, E>;
1626

1727
pub mod file;
1828
pub mod initramfs;
@@ -22,3 +32,7 @@ pub mod tmpfs;
2232
pub mod vfs;
2333
pub mod vfs_syscalls;
2434
pub mod vnode;
35+
36+
// todo: create fs init function which initializes vfs and initramfs
37+
38+
pub fn init() {}

kernel/src/fs/mount.rs

Lines changed: 3 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,6 @@ impl Mount {
4040
self.mnt_op_data.lock().vfs_root()
4141
}
4242

43-
pub fn vfs_quotactl(&self) {
44-
self.mnt_op_data.lock().vfs_quotactl()
45-
}
46-
4743
pub fn vfs_statvfs(&self) {
4844
self.mnt_op_data.lock().vfs_statvfs()
4945
}
@@ -60,14 +56,6 @@ impl Mount {
6056
self.mnt_op_data.lock().vfs_lookup(path)
6157
}
6258

63-
pub fn vfs_fhtovp(&self) {
64-
self.mnt_op_data.lock().vfs_fhtovp()
65-
}
66-
67-
pub fn vfs_vptofh(&self) {
68-
self.mnt_op_data.lock().vfs_vptofh()
69-
}
70-
7159
pub fn vfs_init(&mut self) {
7260
self.mnt_op_data.lock().vfs_init()
7361
}
@@ -76,10 +64,6 @@ impl Mount {
7664
self.mnt_op_data.lock().vfs_done()
7765
}
7866

79-
pub fn vfs_extattrctl(&self) {
80-
self.mnt_op_data.lock().vfs_extattrctl()
81-
}
82-
8367
pub fn vfs_name(&self) -> String {
8468
self.mnt_op_data.lock().vfs_name()
8569
}
@@ -100,14 +84,9 @@ pub trait VfsOps {
10084
/// Gets the file system root vnode.
10185
fn vfs_root(&self) -> Result<Arc<Spinlock<VNode>>>;
10286

103-
/// Queries or modifies space quotas.
104-
fn vfs_quotactl(&self) {
105-
unimplemented!("{} does not implement vfs_quotactl", self.vfs_name());
106-
}
107-
10887
/// Gets file system statistics.
10988
fn vfs_statvfs(&self) {
110-
unimplemented!("{} does not implement vfs_statvfs", self.vfs_name());
89+
todo!("{} does not implement vfs_statvfs", self.vfs_name());
11190
}
11291

11392
/// Flushes file system buffers.
@@ -118,37 +97,20 @@ pub trait VfsOps {
11897

11998
fn vfs_lookup(&self, path: &PathBuf) -> Result<Arc<Spinlock<VNode>>>;
12099

121-
/// Converts a NFS file handle to a vnode.
122-
fn vfs_fhtovp(&self) {
123-
unimplemented!("{} does not implement vfs_fhtovp", self.vfs_name());
124-
}
125-
126-
/// Converts a vnode to a NFS file handle.
127-
fn vfs_vptofh(&self) {
128-
unimplemented!("{} does not implement vfs_vptofh", self.vfs_name());
129-
}
130-
131100
/// Initializes the file system driver.
132101
fn vfs_init(&mut self);
133102

134103
/// Reinitializes the file system driver.
135104
fn vfs_reinit(&self) {
136-
unimplemented!("{} does not implement vfs_reinit", self.vfs_name());
105+
todo!("{} does not implement vfs_reinit", self.vfs_name());
137106
}
138107

139108
/// Finalizes the file system driver.
140109
fn vfs_done(&self);
141110

142111
/// Mounts an instance of the file system as the root file system.
143112
fn vfs_mountroot(&self) {
144-
unimplemented!("{} does not implement vfs_mountroot", self.vfs_name());
145-
}
146-
147-
/// Controls extended attributes.
148-
// The generic vfs_stdextattrctl function is provided as a simple hook for file system that do not support this operation
149-
// TODO: create a generic vfs_stdextattrctl function
150-
fn vfs_extattrctl(&self) {
151-
unimplemented!("{} does not implement vfs_extattrctl", self.vfs_name());
113+
todo!("{} does not implement vfs_mountroot", self.vfs_name());
152114
}
153115

154116
/// Returns the name of the file system

kernel/src/fs/pathbuf.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,14 @@ impl PathBuf {
6868
}
6969

7070
// TODO:
71-
pub fn push(&mut self) {}
71+
pub fn push(&mut self) {
72+
todo!();
73+
}
7274

7375
// TODO:
74-
pub fn pop(&mut self) {}
76+
pub fn pop(&mut self) {
77+
todo!();
78+
}
7579
}
7680

7781
impl From<String> for PathBuf {

kernel/src/fs/tmpfs.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use alloc::{
66
};
77
use libxernel::{boot::InitAtBoot, sync::Spinlock};
88

9-
use crate::{fs::Error, fs::Result};
9+
use crate::{fs::Result, fs::VfsError};
1010

1111
use super::{
1212
mount::{Mount, VfsOps},
@@ -137,7 +137,7 @@ impl VNodeOperations for TmpfsNode {
137137
if let TmpfsNodeData::Directory(children) = &mut self.data {
138138
children.push((PathBuf::from(file_name), new_node.clone()));
139139
} else {
140-
return Err(Error::NotADirectory);
140+
return Err(VfsError::NotADirectory);
141141
}
142142

143143
Ok(new_node)
@@ -165,7 +165,7 @@ impl VNodeOperations for TmpfsNode {
165165
.iter()
166166
.find(|(pt, _)| pt == components[0])
167167
.map(|(_, node)| node.clone());
168-
node.ok_or(Error::EntryNotFound)
168+
node.ok_or(VfsError::EntryNotFound)
169169
}
170170
core::cmp::Ordering::Greater => {
171171
let node = children
@@ -176,13 +176,13 @@ impl VNodeOperations for TmpfsNode {
176176
if let Some(node) = node {
177177
return node.lock().lookup(&stripped_path);
178178
} else {
179-
Err(Error::EntryNotFound)
179+
Err(VfsError::EntryNotFound)
180180
}
181181
}
182182
core::cmp::Ordering::Less => todo!(),
183183
}
184184
} else {
185-
Err(Error::NotADirectory)
185+
Err(VfsError::NotADirectory)
186186
}
187187
}
188188

@@ -202,7 +202,7 @@ impl VNodeOperations for TmpfsNode {
202202

203203
Ok(max_read)
204204
} else {
205-
Err(Error::IsADirectory)
205+
Err(VfsError::IsADirectory)
206206
}
207207
}
208208

@@ -218,7 +218,7 @@ impl VNodeOperations for TmpfsNode {
218218

219219
Ok(max_write)
220220
} else {
221-
Err(Error::IsADirectory)
221+
Err(VfsError::IsADirectory)
222222
}
223223
}
224224

kernel/src/fs/vfs.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use super::{
1212
pathbuf::PathBuf,
1313
tmpfs::Tmpfs,
1414
vnode::VNode,
15-
{Error, Result},
15+
{Result, VfsError},
1616
};
1717

1818
pub static VFS: Spinlock<Vfs> = Spinlock::new(Vfs::new());
@@ -45,7 +45,7 @@ impl Vfs {
4545
.iter()
4646
.find(|(pt, _)| pt == mounted_on)
4747
.map(|(_, mnt)| mnt)
48-
.ok_or(Error::MountPointNotFound)
48+
.ok_or(VfsError::MountPointNotFound)
4949
.cloned()
5050
}
5151

@@ -59,7 +59,7 @@ impl Vfs {
5959
.iter()
6060
.find(|(name, _)| name == name_of_fs)
6161
.map(|(_, driver)| driver)
62-
.ok_or(Error::FileSystemNotFound)?;
62+
.ok_or(VfsError::FileSystemNotFound)?;
6363

6464
let node_covered = if where_to_mount == "/" {
6565
None
@@ -68,7 +68,7 @@ impl Vfs {
6868
if let Ok(node) = self.lookuppn(where_to_mount.to_string()) {
6969
Some(node)
7070
} else {
71-
return Err(Error::EntryNotFound);
71+
return Err(VfsError::EntryNotFound);
7272
}
7373
};
7474

@@ -98,7 +98,7 @@ impl Vfs {
9898
.iter()
9999
.find(|(pt, _)| pt == mnt_point)
100100
.map(|(_, mnt)| mnt)
101-
.ok_or(Error::MountPointNotFound)?;
101+
.ok_or(VfsError::MountPointNotFound)?;
102102

103103
mnt.lock().vfs_lookup(&path.strip_prefix(mnt_point))
104104
}
@@ -110,7 +110,7 @@ impl Vfs {
110110
.filter(|(pt, _)| path.starts_with(pt))
111111
.max_by_key(|(pt, _)| pt.len())
112112
.map(|(pt, _)| pt)
113-
.ok_or(Error::MountPointNotFound)?;
113+
.ok_or(VfsError::MountPointNotFound)?;
114114

115115
Ok(mnt_point)
116116
}

0 commit comments

Comments
 (0)