Support for Read/OpenDirectory

This commit is contained in:
Mark Poliakov 2023-07-22 00:39:50 +03:00
parent 6b2350f266
commit 34f1c2ccf7
4 changed files with 42 additions and 9 deletions

View File

@ -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 {

View File

@ -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<RawFd>::None
pub const NONE: Self = Self(u32::MAX);
}

View File

@ -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 {

View File

@ -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,