diff --git a/kernel/src/fs/initramfs.rs b/kernel/src/fs/initramfs.rs new file mode 100644 index 00000000..6a603180 --- /dev/null +++ b/kernel/src/fs/initramfs.rs @@ -0,0 +1 @@ +// TODO: Add initramfs folder to archive and pass it to limine. Parse the archive here and add the folder and files to the tmpfs diff --git a/kernel/src/fs/mod.rs b/kernel/src/fs/mod.rs index 8b90926c..7f769848 100644 --- a/kernel/src/fs/mod.rs +++ b/kernel/src/fs/mod.rs @@ -1,7 +1,9 @@ //! The design and implementation of this virtual file system is heavily influenced by BSD. +use core::{error::Error, fmt::Display}; + #[derive(Debug)] -pub enum Error { +pub enum VfsError { VNodeNotFound, NotADirectory, IsADirectory, @@ -12,7 +14,15 @@ pub enum Error { FileSystemNotFound, } -pub type Result = core::result::Result; +impl Display for VfsError { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + todo!() + } +} + +impl Error for VfsError {} + +pub type Result = core::result::Result; pub mod file; mod mount; @@ -21,3 +31,7 @@ pub mod tmpfs; pub mod vfs; pub mod vfs_syscalls; pub mod vnode; + +// todo: create fs init function which initializes vfs and initramfs + +pub fn init() {} diff --git a/kernel/src/fs/mount.rs b/kernel/src/fs/mount.rs index dfb9dd44..ee73950d 100644 --- a/kernel/src/fs/mount.rs +++ b/kernel/src/fs/mount.rs @@ -40,10 +40,6 @@ impl Mount { self.mnt_op_data.lock().vfs_root() } - pub fn vfs_quotactl(&self) { - self.mnt_op_data.lock().vfs_quotactl() - } - pub fn vfs_statvfs(&self) { self.mnt_op_data.lock().vfs_statvfs() } @@ -60,14 +56,6 @@ impl Mount { self.mnt_op_data.lock().vfs_lookup(path) } - pub fn vfs_fhtovp(&self) { - self.mnt_op_data.lock().vfs_fhtovp() - } - - pub fn vfs_vptofh(&self) { - self.mnt_op_data.lock().vfs_vptofh() - } - pub fn vfs_init(&mut self) { self.mnt_op_data.lock().vfs_init() } @@ -76,10 +64,6 @@ impl Mount { self.mnt_op_data.lock().vfs_done() } - pub fn vfs_extattrctl(&self) { - self.mnt_op_data.lock().vfs_extattrctl() - } - pub fn vfs_name(&self) -> String { self.mnt_op_data.lock().vfs_name() } @@ -100,14 +84,9 @@ pub trait VfsOps { /// Gets the file system root vnode. fn vfs_root(&self) -> Result>>; - /// Queries or modifies space quotas. - fn vfs_quotactl(&self) { - unimplemented!("{} does not implement vfs_quotactl", self.vfs_name()); - } - /// Gets file system statistics. fn vfs_statvfs(&self) { - unimplemented!("{} does not implement vfs_statvfs", self.vfs_name()); + todo!("{} does not implement vfs_statvfs", self.vfs_name()); } /// Flushes file system buffers. @@ -118,22 +97,12 @@ pub trait VfsOps { fn vfs_lookup(&self, path: &PathBuf) -> Result>>; - /// Converts a NFS file handle to a vnode. - fn vfs_fhtovp(&self) { - unimplemented!("{} does not implement vfs_fhtovp", self.vfs_name()); - } - - /// Converts a vnode to a NFS file handle. - fn vfs_vptofh(&self) { - unimplemented!("{} does not implement vfs_vptofh", self.vfs_name()); - } - /// Initializes the file system driver. fn vfs_init(&mut self); /// Reinitializes the file system driver. fn vfs_reinit(&self) { - unimplemented!("{} does not implement vfs_reinit", self.vfs_name()); + todo!("{} does not implement vfs_reinit", self.vfs_name()); } /// Finalizes the file system driver. @@ -141,14 +110,7 @@ pub trait VfsOps { /// Mounts an instance of the file system as the root file system. fn vfs_mountroot(&self) { - unimplemented!("{} does not implement vfs_mountroot", self.vfs_name()); - } - - /// Controls extended attributes. - // The generic vfs_stdextattrctl function is provided as a simple hook for file system that do not support this operation - // TODO: create a generic vfs_stdextattrctl function - fn vfs_extattrctl(&self) { - unimplemented!("{} does not implement vfs_extattrctl", self.vfs_name()); + todo!("{} does not implement vfs_mountroot", self.vfs_name()); } /// Returns the name of the file system diff --git a/kernel/src/fs/pathbuf.rs b/kernel/src/fs/pathbuf.rs index ddc4ffdc..7a78733c 100644 --- a/kernel/src/fs/pathbuf.rs +++ b/kernel/src/fs/pathbuf.rs @@ -68,10 +68,14 @@ impl PathBuf { } // TODO: - pub fn push(&mut self) {} + pub fn push(&mut self) { + todo!(); + } // TODO: - pub fn pop(&mut self) {} + pub fn pop(&mut self) { + todo!(); + } } impl From for PathBuf { diff --git a/kernel/src/fs/tmpfs.rs b/kernel/src/fs/tmpfs.rs index e8e62bae..881b5e9d 100644 --- a/kernel/src/fs/tmpfs.rs +++ b/kernel/src/fs/tmpfs.rs @@ -6,7 +6,7 @@ use alloc::{ }; use libxernel::{boot::InitAtBoot, sync::Spinlock}; -use crate::{fs::Error, fs::Result}; +use crate::{fs::Result, fs::VfsError}; use super::{ mount::{Mount, VfsOps}, @@ -137,7 +137,7 @@ impl VNodeOperations for TmpfsNode { if let TmpfsNodeData::Directory(children) = &mut self.data { children.push((PathBuf::from(file_name), new_node.clone())); } else { - return Err(Error::NotADirectory); + return Err(VfsError::NotADirectory); } Ok(new_node) @@ -165,7 +165,7 @@ impl VNodeOperations for TmpfsNode { .iter() .find(|(pt, _)| pt == components[0]) .map(|(_, node)| node.clone()); - node.ok_or(Error::EntryNotFound) + node.ok_or(VfsError::EntryNotFound) } core::cmp::Ordering::Greater => { let node = children @@ -176,13 +176,13 @@ impl VNodeOperations for TmpfsNode { if let Some(node) = node { return node.lock().lookup(&stripped_path); } else { - Err(Error::EntryNotFound) + Err(VfsError::EntryNotFound) } } core::cmp::Ordering::Less => todo!(), } } else { - Err(Error::NotADirectory) + Err(VfsError::NotADirectory) } } @@ -202,7 +202,7 @@ impl VNodeOperations for TmpfsNode { Ok(max_read) } else { - Err(Error::IsADirectory) + Err(VfsError::IsADirectory) } } @@ -218,7 +218,7 @@ impl VNodeOperations for TmpfsNode { Ok(max_write) } else { - Err(Error::IsADirectory) + Err(VfsError::IsADirectory) } } diff --git a/kernel/src/fs/vfs.rs b/kernel/src/fs/vfs.rs index c78ee514..3ecfeadb 100644 --- a/kernel/src/fs/vfs.rs +++ b/kernel/src/fs/vfs.rs @@ -12,7 +12,7 @@ use super::{ pathbuf::PathBuf, tmpfs::Tmpfs, vnode::VNode, - {Error, Result}, + {Result, VfsError}, }; pub static VFS: Spinlock = Spinlock::new(Vfs::new()); @@ -45,7 +45,7 @@ impl Vfs { .iter() .find(|(pt, _)| pt == mounted_on) .map(|(_, mnt)| mnt) - .ok_or(Error::MountPointNotFound) + .ok_or(VfsError::MountPointNotFound) .cloned() } @@ -59,7 +59,7 @@ impl Vfs { .iter() .find(|(name, _)| name == name_of_fs) .map(|(_, driver)| driver) - .ok_or(Error::FileSystemNotFound)?; + .ok_or(VfsError::FileSystemNotFound)?; let node_covered = if where_to_mount == "/" { None @@ -68,7 +68,7 @@ impl Vfs { if let Ok(node) = self.lookuppn(where_to_mount.to_string()) { Some(node) } else { - return Err(Error::EntryNotFound); + return Err(VfsError::EntryNotFound); } }; @@ -98,7 +98,7 @@ impl Vfs { .iter() .find(|(pt, _)| pt == mnt_point) .map(|(_, mnt)| mnt) - .ok_or(Error::MountPointNotFound)?; + .ok_or(VfsError::MountPointNotFound)?; mnt.lock().vfs_lookup(&path.strip_prefix(mnt_point)) } @@ -110,7 +110,7 @@ impl Vfs { .filter(|(pt, _)| path.starts_with(pt)) .max_by_key(|(pt, _)| pt.len()) .map(|(pt, _)| pt) - .ok_or(Error::MountPointNotFound)?; + .ok_or(VfsError::MountPointNotFound)?; Ok(mnt_point) } diff --git a/kernel/src/fs/vnode.rs b/kernel/src/fs/vnode.rs index eb3ef524..6ebdad30 100644 --- a/kernel/src/fs/vnode.rs +++ b/kernel/src/fs/vnode.rs @@ -61,10 +61,6 @@ impl VNode { self.v_data_op.lock().access() } - pub fn bmap(&self) { - self.v_data_op.lock().bmap() - } - pub fn create(&mut self, path: String, v_type: VType) -> Result>> { self.v_data_op.lock().create(path, v_type, self.vfsp.clone()) } @@ -101,10 +97,6 @@ impl VNode { self.v_data_op.lock().open() } - pub fn pathconf(&self) { - self.v_data_op.lock().pathconf() - } - pub fn read(&self, buf: &mut [u8]) -> Result { self.v_data_op.lock().read(buf) } @@ -148,36 +140,18 @@ impl VNode { pub fn write(&self, buf: &mut [u8]) -> Result { self.v_data_op.lock().write(buf) } - - pub fn kqfilter(&self) { - self.v_data_op.lock().kqfilter() - } } /// This trait maps logical operations to real functions. It is file system specific as the actions taken by each operation depend heavily on the file system where the file resides. pub trait VNodeOperations { /// Aborts an in-progress operation. fn abortop(&self) { - unimplemented!() + todo!() } /// Checks access permissions on a file. fn access(&self) { - unimplemented!() - } - - fn advlock(&self) { - unimplemented!() - } - - /// Maps a logical block number to a physical block number. - fn bmap(&self) { - unimplemented!() - } - - /// Writes a system buffer. - fn bwrite(&self) { - unimplemented!() + todo!() } /// Closes a file. @@ -188,17 +162,17 @@ pub trait VNodeOperations { /// Synchronizes the file with on-disk contents. fn fsync(&self) { - unimplemented!() + todo!() } /// Gets a file's attributes. fn getattr(&self) { - unimplemented!() + todo!() } /// Marks the vnode as inactive. fn inactive(&self) { - unimplemented!() + todo!() } /// Performs an ioctl on a file. @@ -206,7 +180,7 @@ pub trait VNodeOperations { /// Creates a new hard link for a file. fn link(&self) { - unimplemented!() + todo!() } /// Performs a path name lookup. @@ -218,11 +192,6 @@ pub trait VNodeOperations { /// Opens a file. fn open(&self); - /// Returns pathconf information. - fn pathconf(&self) { - unimplemented!() - } - /// Reads a chunk of data from a file. fn read(&self, buf: &mut [u8]) -> Result; @@ -249,12 +218,7 @@ pub trait VNodeOperations { /// Sets a file's attributes. fn setattr(&self) { - unimplemented!() - } - - /// Performs a file transfer between the file system's backing store and memory. - fn strategy(&self) { - unimplemented!() + todo!() } /// Creates a new symbolic link for a file. @@ -262,49 +226,4 @@ pub trait VNodeOperations { /// Writes a chunk of data to a file. fn write(&mut self, buf: &mut [u8]) -> Result; - - fn kqfilter(&self) { - unimplemented!() - } - - fn print(&self) { - unimplemented!() - } // OpenBSD has it, NetBSD not?! - - /// Performs a fcntl on a file. - fn fcntl(&self) { - unimplemented!() - } // NetBSD has it, OpenBSD not?! - /// Performs a poll on a file. - fn poll(&self) { - unimplemented!() - } // NetBSD has it, OpenBSD not?! - /// Revoke access to a vnode and all aliases. - fn revoke(&self) { - unimplemented!() - } // NetBSD has it, OpenBSD not?! - /// Maps a file on a memory region. - fn mmap(&self) { - unimplemented!() - } // NetBSD has it, OpenBSD not?! - /// Test and inform file system of seek - fn seek(&self) { - unimplemented!() - } // NetBSD has it, OpenBSD not?! - /// Truncates a file. - fn truncate(&self) { - unimplemented!() - } // NetBSD has it, OpenBSD not?! - /// Updates a file's times. - fn update(&self) { - unimplemented!() - } // NetBSD has it, OpenBSD not?! - /// Reads memory pages from the file. - fn getpages(&self) { - unimplemented!() - } // NetBSD has it, OpenBSD not?! - /// Writes memory pages to the file. - fn putpages(&self) { - unimplemented!() - } // NetBSD has it, OpenBSD not?! } diff --git a/kernel/src/syscall/mod.rs b/kernel/src/syscall/mod.rs index c0d53fa0..8bfe5d94 100644 --- a/kernel/src/syscall/mod.rs +++ b/kernel/src/syscall/mod.rs @@ -18,17 +18,17 @@ use crate::{ mem::mmap::mmap, }; -impl From for SyscallError { - fn from(err: fs::Error) -> SyscallError { +impl From for SyscallError { + fn from(err: fs::VfsError) -> SyscallError { match err { - fs::Error::VNodeNotFound => SyscallError::VNodeNotFound, - fs::Error::NotADirectory => SyscallError::NotADirectory, - fs::Error::IsADirectory => SyscallError::IsADirectory, - fs::Error::NoSpace => SyscallError::NoSpace, - fs::Error::NotEmpty => SyscallError::NotEmpty, - fs::Error::EntryNotFound => SyscallError::EntryNotFound, - fs::Error::MountPointNotFound => SyscallError::MountPointNotFound, - fs::Error::FileSystemNotFound => SyscallError::FileSystemNotFound, + fs::VfsError::VNodeNotFound => SyscallError::VNodeNotFound, + fs::VfsError::NotADirectory => SyscallError::NotADirectory, + fs::VfsError::IsADirectory => SyscallError::IsADirectory, + fs::VfsError::NoSpace => SyscallError::NoSpace, + fs::VfsError::NotEmpty => SyscallError::NotEmpty, + fs::VfsError::EntryNotFound => SyscallError::EntryNotFound, + fs::VfsError::MountPointNotFound => SyscallError::MountPointNotFound, + fs::VfsError::FileSystemNotFound => SyscallError::FileSystemNotFound, } } }