From 34f1c2ccf76e1e321085d5b8c4b03092f66c7031 Mon Sep 17 00:00:00 2001 From: Mark Poliakov Date: Sat, 22 Jul 2023 00:39:50 +0300 Subject: [PATCH] Support for Read/OpenDirectory --- src/io/file.rs | 18 +++++++++++++++++- src/io/mod.rs | 27 ++++++++++++++++++++------- src/macros.rs | 2 +- src/syscall.rs | 4 ++++ 4 files changed, 42 insertions(+), 9 deletions(-) diff --git a/src/io/file.rs b/src/io/file.rs index 94d40499..f8eba099 100644 --- a/src/io/file.rs +++ b/src/io/file.rs @@ -1,4 +1,4 @@ -use crate::bitflags; +use crate::{bitflags, primitive_enum}; bitflags! { #[doc = "Defines the access mode of the file"] @@ -47,6 +47,22 @@ bitflags! { } } +primitive_enum!( + #[doc = "Defines a type of a file"] + pub enum FileType: u32 { + #[doc = "Regular file"] + File = 0, + #[doc = "Directory"] + Directory = 1, + #[doc = "Not yet implemented"] + Symlink = 2, + #[doc = "Block device"] + Block = 3, + #[doc = "Character device (e.g. terminal)"] + Char = 4, + } +); + impl FileMode { /// File mode with all access bits set pub const fn all() -> Self { diff --git a/src/io/mod.rs b/src/io/mod.rs index a9d6261e..50080b47 100644 --- a/src/io/mod.rs +++ b/src/io/mod.rs @@ -1,17 +1,27 @@ //! I/O control data structures +mod file; +mod terminal; + +pub use file::{FileMode, FileType, OpenOptions}; +pub use terminal::{ + TerminalInputOptions, TerminalLineOptions, TerminalOptions, TerminalOutputOptions, +}; + /// Raw file descriptor representation #[derive(Clone, Copy, PartialEq, Debug, PartialOrd, Ord, Eq)] #[repr(transparent)] pub struct RawFd(pub u32); -mod file; -mod terminal; - -pub use file::{FileMode, OpenOptions}; -pub use terminal::{ - TerminalInputOptions, TerminalLineOptions, TerminalOptions, TerminalOutputOptions, -}; +/// Raw directory entry representation +#[derive(Clone, Copy, Debug)] +#[repr(C)] +pub struct DirectoryEntry { + /// Name of the entry + pub name: [u8; 256], + /// Type of the entry + pub ty: FileType, +} /// Describes how a mount operation should be performed #[derive(Clone, Debug)] @@ -40,4 +50,7 @@ impl RawFd { pub const STDOUT: Self = Self(1); /// Error output descriptor of a process pub const STDERR: Self = Self(2); + + /// Temporary hack to represent Option::None + pub const NONE: Self = Self(u32::MAX); } diff --git a/src/macros.rs b/src/macros.rs index 02165bfa..75521902 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -4,7 +4,7 @@ macro_rules! primitive_enum { ($(#[doc = $enum_doc:expr])? $vis:vis enum $name:ident: $repr:ty { $( $(#[doc = $doc:expr])? $variant:ident = $discriminant:literal, )+ }) => { - #[derive(Clone, Copy, Debug, PartialEq)] + #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] #[repr($repr)] $(#[doc = $enum_doc])? $vis enum $name { diff --git a/src/syscall.rs b/src/syscall.rs index bba7a4ff..c709fbd8 100644 --- a/src/syscall.rs +++ b/src/syscall.rs @@ -20,6 +20,10 @@ primitive_enum!( Open = 7, #[doc = "Close a file descriptor"] Close = 8, + #[doc = "Open a directory for reading"] + OpenDirectory = 9, + #[doc = "Read entries from a directory descriptor"] + ReadDirectory = 10, #[doc = "Mount a filesystem"] Mount = 101,