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
37 changes: 20 additions & 17 deletions awkernel_lib/src/file/fatfs/dir.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use alloc::sync::Arc;
#[cfg(feature = "lfn")]
use alloc::vec::Vec;
use core::fmt::Debug;
use core::num;
use core::str;
#[cfg(feature = "lfn")]
Expand All @@ -23,12 +24,12 @@ use super::time::TimeProvider;
#[cfg(feature = "lfn")]
const LFN_PADDING: u16 = 0xFFFF;

pub(crate) enum DirRawStream<IO: ReadWriteSeek + Send, TP, OCC> {
pub(crate) enum DirRawStream<IO: ReadWriteSeek + Send + Debug, TP, OCC> {
File(File<IO, TP, OCC>),
Root(DiskSlice<FsIoAdapter<IO, TP, OCC>, FsIoAdapter<IO, TP, OCC>>),
}

impl<IO: ReadWriteSeek + Send, TP, OCC> DirRawStream<IO, TP, OCC> {
impl<IO: ReadWriteSeek + Send + Debug, TP, OCC> DirRawStream<IO, TP, OCC> {
fn abs_pos(&self) -> Option<u64> {
match self {
DirRawStream::File(file) => file.abs_pos(),
Expand All @@ -52,7 +53,7 @@ impl<IO: ReadWriteSeek + Send, TP, OCC> DirRawStream<IO, TP, OCC> {
}

// Note: derive cannot be used because of invalid bounds. See: https://github.com/rust-lang/rust/issues/26925
impl<IO: ReadWriteSeek + Send, TP, OCC> Clone for DirRawStream<IO, TP, OCC> {
impl<IO: ReadWriteSeek + Send + Debug, TP, OCC> Clone for DirRawStream<IO, TP, OCC> {
fn clone(&self) -> Self {
match self {
DirRawStream::File(file) => DirRawStream::File(file.clone()),
Expand All @@ -61,11 +62,11 @@ impl<IO: ReadWriteSeek + Send, TP, OCC> Clone for DirRawStream<IO, TP, OCC> {
}
}

impl<IO: ReadWriteSeek + Send, TP, OCC> IoBase for DirRawStream<IO, TP, OCC> {
impl<IO: ReadWriteSeek + Send + Debug, TP, OCC> IoBase for DirRawStream<IO, TP, OCC> {
type Error = Error<IO::Error>;
}

impl<IO: ReadWriteSeek + Send, TP: TimeProvider, OCC> Read for DirRawStream<IO, TP, OCC> {
impl<IO: ReadWriteSeek + Send + Debug, TP: TimeProvider, OCC> Read for DirRawStream<IO, TP, OCC> {
fn read(&mut self, buf: &mut [u8]) -> Result<usize, Self::Error> {
match self {
DirRawStream::File(file) => file.read(buf),
Expand All @@ -74,7 +75,7 @@ impl<IO: ReadWriteSeek + Send, TP: TimeProvider, OCC> Read for DirRawStream<IO,
}
}

impl<IO: ReadWriteSeek + Send, TP: TimeProvider, OCC> Write for DirRawStream<IO, TP, OCC> {
impl<IO: ReadWriteSeek + Send + Debug, TP: TimeProvider, OCC> Write for DirRawStream<IO, TP, OCC> {
fn write(&mut self, buf: &[u8]) -> Result<usize, Self::Error> {
match self {
DirRawStream::File(file) => file.write(buf),
Expand All @@ -89,7 +90,7 @@ impl<IO: ReadWriteSeek + Send, TP: TimeProvider, OCC> Write for DirRawStream<IO,
}
}

impl<IO: ReadWriteSeek + Send, TP, OCC> Seek for DirRawStream<IO, TP, OCC> {
impl<IO: ReadWriteSeek + Send + Debug, TP, OCC> Seek for DirRawStream<IO, TP, OCC> {
fn seek(&mut self, pos: SeekFrom) -> Result<u64, Self::Error> {
match self {
DirRawStream::File(file) => file.seek(pos),
Expand All @@ -105,7 +106,7 @@ fn split_path(path: &str) -> (&str, Option<&str>) {
})
}

enum DirEntryOrShortName<IO: ReadWriteSeek + Send, TP, OCC> {
enum DirEntryOrShortName<IO: ReadWriteSeek + Send + Debug, TP, OCC> {
DirEntry(DirEntry<IO, TP, OCC>),
ShortName([u8; SFN_SIZE]),
}
Expand All @@ -114,12 +115,12 @@ enum DirEntryOrShortName<IO: ReadWriteSeek + Send, TP, OCC> {
///
/// This struct is created by the `open_dir` or `create_dir` methods on `Dir`.
/// The root directory is returned by the `root_dir` method on `FileSystem`.
pub struct Dir<IO: ReadWriteSeek + Send, TP, OCC> {
pub struct Dir<IO: ReadWriteSeek + Send + Debug, TP, OCC> {
stream: DirRawStream<IO, TP, OCC>,
fs: Arc<FileSystem<IO, TP, OCC>>,
}

impl<IO: ReadWriteSeek + Send, TP, OCC> Dir<IO, TP, OCC> {
impl<IO: ReadWriteSeek + Send + Debug, TP, OCC> Dir<IO, TP, OCC> {
pub(crate) fn new(stream: DirRawStream<IO, TP, OCC>, fs: Arc<FileSystem<IO, TP, OCC>>) -> Self {
Dir { stream, fs }
}
Expand All @@ -132,7 +133,7 @@ impl<IO: ReadWriteSeek + Send, TP, OCC> Dir<IO, TP, OCC> {
}
}

impl<IO: ReadWriteSeek + Send, TP: TimeProvider, OCC: OemCpConverter> Dir<IO, TP, OCC> {
impl<IO: ReadWriteSeek + Send + Debug, TP: TimeProvider, OCC: OemCpConverter> Dir<IO, TP, OCC> {
pub fn find_entry(
&self,
name: &str,
Expand Down Expand Up @@ -619,7 +620,9 @@ impl<IO: ReadWriteSeek + Send, TP: TimeProvider, OCC: OemCpConverter> Dir<IO, TP
}

// Note: derive cannot be used because of invalid bounds. See: https://github.com/rust-lang/rust/issues/26925
impl<IO: ReadWriteSeek + Send, TP: TimeProvider, OCC: OemCpConverter> Clone for Dir<IO, TP, OCC> {
impl<IO: ReadWriteSeek + Send + Debug, TP: TimeProvider, OCC: OemCpConverter> Clone
for Dir<IO, TP, OCC>
{
fn clone(&self) -> Self {
Self {
stream: self.stream.clone(),
Expand All @@ -631,14 +634,14 @@ impl<IO: ReadWriteSeek + Send, TP: TimeProvider, OCC: OemCpConverter> Clone for
/// An iterator over the directory entries.
///
/// This struct is created by the `iter` method on `Dir`.
pub struct DirIter<IO: ReadWriteSeek + Send, TP, OCC> {
pub struct DirIter<IO: ReadWriteSeek + Send + Debug, TP, OCC> {
stream: DirRawStream<IO, TP, OCC>,
fs: Arc<FileSystem<IO, TP, OCC>>,
skip_volume: bool,
err: bool,
}

impl<IO: ReadWriteSeek + Send, TP, OCC> DirIter<IO, TP, OCC> {
impl<IO: ReadWriteSeek + Send + Debug, TP, OCC> DirIter<IO, TP, OCC> {
fn new(
stream: DirRawStream<IO, TP, OCC>,
fs: Arc<FileSystem<IO, TP, OCC>>,
Expand All @@ -653,7 +656,7 @@ impl<IO: ReadWriteSeek + Send, TP, OCC> DirIter<IO, TP, OCC> {
}
}

impl<IO: ReadWriteSeek + Send, TP: TimeProvider, OCC> DirIter<IO, TP, OCC> {
impl<IO: ReadWriteSeek + Send + Debug, TP: TimeProvider, OCC> DirIter<IO, TP, OCC> {
fn should_skip_entry(&self, raw_entry: &DirEntryData) -> bool {
if raw_entry.is_deleted() {
return true;
Expand Down Expand Up @@ -720,7 +723,7 @@ impl<IO: ReadWriteSeek + Send, TP: TimeProvider, OCC> DirIter<IO, TP, OCC> {
}

// Note: derive cannot be used because of invalid bounds. See: https://github.com/rust-lang/rust/issues/26925
impl<IO: ReadWriteSeek + Send, TP, OCC> Clone for DirIter<IO, TP, OCC> {
impl<IO: ReadWriteSeek + Send + Debug, TP, OCC> Clone for DirIter<IO, TP, OCC> {
fn clone(&self) -> Self {
Self {
stream: self.stream.clone(),
Expand All @@ -731,7 +734,7 @@ impl<IO: ReadWriteSeek + Send, TP, OCC> Clone for DirIter<IO, TP, OCC> {
}
}

impl<IO: ReadWriteSeek + Send, TP: TimeProvider, OCC> Iterator for DirIter<IO, TP, OCC> {
impl<IO: ReadWriteSeek + Send + Debug, TP: TimeProvider, OCC> Iterator for DirIter<IO, TP, OCC> {
type Item = Result<DirEntry<IO, TP, OCC>, Error<IO::Error>>;

fn next(&mut self) -> Option<Self::Item> {
Expand Down
12 changes: 6 additions & 6 deletions awkernel_lib/src/file/fatfs/dir_entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use alloc::sync::Arc;
use bitflags::bitflags;
use core::char;
use core::convert::TryInto;
use core::fmt;
use core::fmt::{self, Debug};
#[cfg(not(feature = "unicode"))]
use core::iter;

Expand Down Expand Up @@ -523,7 +523,7 @@ impl DirEntryEditor {
}
}

pub(crate) fn flush<IO: ReadWriteSeek + Send, TP, OCC>(
pub(crate) fn flush<IO: ReadWriteSeek + Send + Debug, TP, OCC>(
&mut self,
fs: &FileSystem<IO, TP, OCC>,
) -> Result<(), IO::Error> {
Expand All @@ -534,7 +534,7 @@ impl DirEntryEditor {
Ok(())
}

fn write<IO: ReadWriteSeek + Send, TP, OCC>(
fn write<IO: ReadWriteSeek + Send + Debug, TP, OCC>(
&self,
fs: &FileSystem<IO, TP, OCC>,
) -> Result<(), IO::Error> {
Expand All @@ -549,7 +549,7 @@ impl DirEntryEditor {
///
/// `DirEntry` is returned by `DirIter` when reading a directory.
#[derive(Clone)]
pub struct DirEntry<IO: ReadWriteSeek + Send, TP, OCC> {
pub struct DirEntry<IO: ReadWriteSeek + Send + Debug, TP, OCC> {
pub(crate) data: DirFileEntryData,
pub(crate) short_name: ShortName,
#[cfg(feature = "lfn")]
Expand All @@ -560,7 +560,7 @@ pub struct DirEntry<IO: ReadWriteSeek + Send, TP, OCC> {
}

#[allow(clippy::len_without_is_empty)]
impl<IO: ReadWriteSeek + Send, TP, OCC: OemCpConverter> DirEntry<IO, TP, OCC> {
impl<IO: ReadWriteSeek + Send + Debug, TP, OCC: OemCpConverter> DirEntry<IO, TP, OCC> {
/// Returns short file name.
///
/// Non-ASCII characters are replaced by the replacement character (U+FFFD).
Expand Down Expand Up @@ -735,7 +735,7 @@ impl<IO: ReadWriteSeek + Send, TP, OCC: OemCpConverter> DirEntry<IO, TP, OCC> {
}
}

impl<IO: ReadWriteSeek + Send, TP, OCC> fmt::Debug for DirEntry<IO, TP, OCC> {
impl<IO: ReadWriteSeek + Send + Debug, TP, OCC> fmt::Debug for DirEntry<IO, TP, OCC> {
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
self.data.fmt(f)
}
Expand Down
19 changes: 10 additions & 9 deletions awkernel_lib/src/file/fatfs/file.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use alloc::sync::Arc;
use core::convert::TryFrom;
use core::fmt::Debug;

use super::super::io::{IoBase, Read, Seek, SeekFrom, Write};
use super::dir_entry::DirEntryEditor;
Expand All @@ -14,7 +15,7 @@ const MAX_FILE_SIZE: u32 = u32::MAX;
/// A FAT filesystem file object used for reading and writing data.
///
/// This struct is created by the `open_file` or `create_file` methods on `Dir`.
pub struct File<IO: ReadWriteSeek + Send, TP, OCC> {
pub struct File<IO: ReadWriteSeek + Send + Debug, TP, OCC> {
// Note first_cluster is None if file is empty
first_cluster: Option<u32>,
// Note: if offset points between clusters current_cluster is the previous cluster
Expand All @@ -38,7 +39,7 @@ pub struct Extent {
pub size: u32,
}

impl<IO: ReadWriteSeek + Send, TP, OCC> File<IO, TP, OCC> {
impl<IO: ReadWriteSeek + Send + Debug, TP, OCC> File<IO, TP, OCC> {
pub(crate) fn new(
first_cluster: Option<u32>,
entry: Option<DirEntryEditor>,
Expand Down Expand Up @@ -221,7 +222,7 @@ impl<IO: ReadWriteSeek + Send, TP, OCC> File<IO, TP, OCC> {
}
}

impl<IO: ReadWriteSeek + Send, TP: TimeProvider, OCC> File<IO, TP, OCC> {
impl<IO: ReadWriteSeek + Send + Debug, TP: TimeProvider, OCC> File<IO, TP, OCC> {
fn update_dir_entry_after_write(&mut self) {
let offset = self.offset;
if let Some(ref mut e) = self.entry {
Expand All @@ -234,7 +235,7 @@ impl<IO: ReadWriteSeek + Send, TP: TimeProvider, OCC> File<IO, TP, OCC> {
}
}

impl<IO: ReadWriteSeek + Send, TP, OCC> Drop for File<IO, TP, OCC> {
impl<IO: ReadWriteSeek + Send + Debug, TP, OCC> Drop for File<IO, TP, OCC> {
fn drop(&mut self) {
if let Err(err) = self.flush() {
log::error!("flush failed {err:?}");
Expand All @@ -243,7 +244,7 @@ impl<IO: ReadWriteSeek + Send, TP, OCC> Drop for File<IO, TP, OCC> {
}

// Note: derive cannot be used because of invalid bounds. See: https://github.com/rust-lang/rust/issues/26925
impl<IO: ReadWriteSeek + Send, TP, OCC> Clone for File<IO, TP, OCC> {
impl<IO: ReadWriteSeek + Send + Debug, TP, OCC> Clone for File<IO, TP, OCC> {
fn clone(&self) -> Self {
File {
first_cluster: self.first_cluster,
Expand All @@ -255,11 +256,11 @@ impl<IO: ReadWriteSeek + Send, TP, OCC> Clone for File<IO, TP, OCC> {
}
}

impl<IO: ReadWriteSeek + Send, TP, OCC> IoBase for File<IO, TP, OCC> {
impl<IO: ReadWriteSeek + Send + Debug, TP, OCC> IoBase for File<IO, TP, OCC> {
type Error = Error<IO::Error>;
}

impl<IO: ReadWriteSeek + Send, TP: TimeProvider, OCC> Read for File<IO, TP, OCC> {
impl<IO: ReadWriteSeek + Send + Debug, TP: TimeProvider, OCC> Read for File<IO, TP, OCC> {
fn read(&mut self, buf: &mut [u8]) -> Result<usize, Self::Error> {
log::trace!("File::read");
let cluster_size = self.fs.cluster_size();
Expand Down Expand Up @@ -314,7 +315,7 @@ impl<IO: ReadWriteSeek + Send, TP: TimeProvider, OCC> Read for File<IO, TP, OCC>
}
}

impl<IO: ReadWriteSeek + Send, TP: TimeProvider, OCC> Write for File<IO, TP, OCC> {
impl<IO: ReadWriteSeek + Send + Debug, TP: TimeProvider, OCC> Write for File<IO, TP, OCC> {
fn write(&mut self, buf: &[u8]) -> Result<usize, Self::Error> {
log::trace!("File::write");
let cluster_size = self.fs.cluster_size();
Expand Down Expand Up @@ -388,7 +389,7 @@ impl<IO: ReadWriteSeek + Send, TP: TimeProvider, OCC> Write for File<IO, TP, OCC
}
}

impl<IO: ReadWriteSeek + Send, TP, OCC> Seek for File<IO, TP, OCC> {
impl<IO: ReadWriteSeek + Send + Debug, TP, OCC> Seek for File<IO, TP, OCC> {
fn seek(&mut self, pos: SeekFrom) -> Result<u64, Self::Error> {
log::trace!("File::seek");
let size_opt = self.size();
Expand Down
Loading