Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions awkernel_async_lib/src/file/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,7 @@ impl AsyncVfsPath {
///
/// Note that the parent directory must exist, while the given path must not exist.
///
/// Returns VfsErrorKind::FileExists if a file already exists at the given path
/// Returns VfsErrorKind::DirectoryExists if a directory already exists at the given path
/// Returns VfsErrorKind::AlreadyExists if a file already exists at the given path
///
/// ```
/// # use vfs::async_vfs::{AsyncMemoryFS, AsyncVfsPath};
Expand Down Expand Up @@ -200,7 +199,7 @@ impl AsyncVfsPath {
let directory = &path[..end];
if let Err(error) = self.fs.fs.create_dir(directory).await {
match error.kind() {
VfsErrorKind::DirectoryExists => {}
VfsErrorKind::AlreadyExists => {}
_ => {
return Err(error.with_path(directory).with_context(|| {
format!("Could not create directories at '{}'", path)
Expand Down
1 change: 1 addition & 0 deletions awkernel_lib/src/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ pub mod error;
pub mod fatfs;
pub mod io;
pub mod memfs;
pub mod vfs;
23 changes: 21 additions & 2 deletions awkernel_lib/src/file/fatfs/error.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
use super::super::error::IoError;
use super::super::vfs::error::VfsErrorKind;
use alloc::format;

/// Error enum with all errors that can be returned by functions from this crate
///
/// Generic parameter `T` is a type of external error returned by the user provided storage
#[derive(Debug, Clone)]
#[non_exhaustive]
pub enum Error<T> {
pub enum Error<T: IoError> {
/// A user provided storage instance returned an error during an input/output operation.
Io(T),
/// A read operation cannot be completed because an end of a file has been reached prematurely.
Expand All @@ -30,7 +32,24 @@ pub enum Error<T> {
UnsupportedFileNameCharacter,
}

impl<T: core::fmt::Display> core::fmt::Display for Error<T> {
impl<E: core::fmt::Debug + IoError> From<Error<E>> for VfsErrorKind<E> {
fn from(err: Error<E>) -> Self {
match err {
Error::Io(io_error_t) => VfsErrorKind::IoError(io_error_t),
Error::NotFound => VfsErrorKind::NotFound,
Error::DirectoryIsNotEmpty => VfsErrorKind::DirectoryIsNotEmpty,
Error::AlreadyExists => VfsErrorKind::AlreadyExists,
Error::InvalidInput => VfsErrorKind::InvalidPath,
Error::CorruptedFileSystem => VfsErrorKind::CorruptedFileSystem,
Error::NotEnoughSpace => VfsErrorKind::NotEnoughSpace,
Error::InvalidFileNameLength => VfsErrorKind::InvalidPath,
Error::UnsupportedFileNameCharacter => VfsErrorKind::NotSupported,
_ => VfsErrorKind::Other(format!("Error from fatfs: {err:?}")),
}
}
}

impl<T: core::fmt::Display + IoError> core::fmt::Display for Error<T> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
Error::Io(io_error) => write!(f, "IO error: {io_error}"),
Expand Down
37 changes: 24 additions & 13 deletions awkernel_lib/src/file/vfs/error.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
//! Error and Result definitions

use super::super::error::IoError;
use super::super::fatfs::error::Error as FatfsError;
use alloc::{
boxed::Box,
string::{String, ToString},
Expand Down Expand Up @@ -82,19 +81,25 @@ pub enum VfsErrorKind<E: IoError> {
IoError(E),

/// The file or directory at the given path could not be found
FileNotFound,
NotFound,

/// The given path is invalid, e.g. because contains '.' or '..'
InvalidPath,

/// Generic error variant
Other(String),

/// There is already a directory at the given path
DirectoryExists,
/// There is already a file or a directory at the given path
AlreadyExists,

/// There is already a file at the given path
FileExists,
/// An operation cannot be finished because a directory is not empty.
DirectoryIsNotEmpty,

/// File system internal structures are corrupted/invalid.
CorruptedFileSystem,

/// There is not enough free space on the storage to finish the requested operation.
NotEnoughSpace,

/// Functionality not supported by this filesystem
NotSupported,
Expand All @@ -106,7 +111,7 @@ impl<E: fmt::Display + IoError> fmt::Display for VfsErrorKind<E> {
VfsErrorKind::IoError(cause) => {
write!(f, "IO error: {cause}")
}
VfsErrorKind::FileNotFound => {
VfsErrorKind::NotFound => {
write!(f, "The file or directory could not be found")
}
VfsErrorKind::InvalidPath => {
Expand All @@ -115,14 +120,20 @@ impl<E: fmt::Display + IoError> fmt::Display for VfsErrorKind<E> {
VfsErrorKind::Other(message) => {
write!(f, "FileSystem error: {message}")
}
VfsErrorKind::NotSupported => {
write!(f, "Functionality not supported by this filesystem")
VfsErrorKind::AlreadyExists => {
write!(f, "File or directory already exists")
}
VfsErrorKind::DirectoryExists => {
write!(f, "Directory already exists")
VfsErrorKind::DirectoryIsNotEmpty => {
write!(f, "Directory is not empty")
}
VfsErrorKind::FileExists => {
write!(f, "File already exists")
VfsErrorKind::CorruptedFileSystem => {
write!(f, "Corrupted file system")
}
VfsErrorKind::NotEnoughSpace => {
write!(f, "Not enough space")
}
VfsErrorKind::NotSupported => {
write!(f, "Functionality not supported by this filesystem")
}
}
}
Expand Down
5 changes: 2 additions & 3 deletions awkernel_lib/src/file/vfs/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,7 @@ impl VfsPath {
///
/// Note that the parent directory must exist, while the given path must not exist.
///
/// Returns VfsErrorKind::FileExists if a file already exists at the given path
/// Returns VfsErrorKind::DirectoryExists if a directory already exists at the given path
/// Returns VfsErrorKind::ALreadyExitsts if a file or a directory already exists at the given path
///
/// ```
/// # use vfs::{MemoryFS, VfsError, VfsFileType, VfsPath};
Expand Down Expand Up @@ -284,7 +283,7 @@ impl VfsPath {
let directory = &path[..end];
if let Err(error) = self.fs.fs.create_dir(directory) {
match error.kind() {
VfsErrorKind::DirectoryExists => {}
VfsErrorKind::AlreadyExists => {}
_ => {
return Err(error.with_path(directory).with_context(|| {
format!("Could not create directories at '{}'", path)
Expand Down