FileKind

Enum FileKind 

Source
pub enum FileKind {
    RegularFile {
        file: RegularFile,
        position: usize,
    },
    Directory {
        dir: Directory,
        position: usize,
    },
    Stdio,
    Rx(Receiver<u8>),
    Tx(Sender<u8>),
}
Expand description

The type of a file in the filesystem.

This enum provides a way to distinguish between regular files and special files like standard input (stdin), standard output (stdout), standard error (stderr), and interprocess communication (IPC) channels such as pipes. It allows the system to treat these different types of files accordingly when performing file operations like reading, writing, or seeking.

Variants§

§

RegularFile

A regular file on the filesystem.

Fields

§file: RegularFile

A RegularFile object, which holds the underlying kernel structure that represents the actual file in the kernel’s memory. This structure contains additional metadata about the file, such as its name.

§position: usize

The current position in the file (offset).

This field keeps track of the current position of the file pointer within the file. The position is measured in bytes from the beginning of the file. It is updated whenever a read or write operation is performed, allowing the system to track where the next operation will occur.

Example: If the file’s position is 100, the next read or write operation will begin at byte 100.

§

Directory

A directory of the filesystem.

This variant represents a directory in the filesystem. Unlike regular files, directories serve as containers for other files and directories. Operations on directories typically include listing contents, searching for files, and navigating file structures.

Fields

§position: usize

The current position in the directory (offset).

This field is internally used in readdir() function to track how much entries

§

Stdio

A special file for standard input/output streams.

This variant represents standard I/O streams like stdin, stdout, and stderr. These are not associated with physical files on disk but are used for interaction between processes and the console or terminal.

  • Standard Input (stdin): Used to receive user input.
  • Standard Output (stdout): Used to display process output.
  • Standard Error (stderr): Used to display error messages.
§

Rx(Receiver<u8>)

A receive endpoint for interprocess communication (IPC).

This variant represents a receiving channel in an IPC mechanism, commonly used for message-passing between processes. It acts as a read-only endpoint, allowing a process to receive data from a corresponding FileKind::Tx (transmit) channel.

Data sent through the corresponding FileKind::Tx endpoint is buffered and can be read asynchronously using this receiver. Once all FileKind::Tx handles are closed, reads will return an end-of-file (EOF) indication.

This is useful for implementing features like pipes, message queues, or event notifications.

§

Tx(Sender<u8>)

A transmit endpoint for interprocess communication (IPC).

This variant represents a sending channel in an IPC mechanism. It serves as a write-only endpoint, allowing a process to send data to a corresponding FileKind::Rx (receive) channel.

Data written to this FileKind::Tx endpoint is buffered until it is read by the corresponding FileKind::Rx endpoint. If no receiver exists, writes may block or fail depending on the system’s IPC behavior.

This is commonly used in pipes, producer-consumer queues, and task synchronization mechanisms.

Trait Implementations§

Source§

impl Clone for FileKind

Source§

fn clone(&self) -> FileKind

Returns a duplicate of the value. Read more
1.0.0§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

§

impl Freeze for FileKind

§

impl !RefUnwindSafe for FileKind

§

impl Send for FileKind

§

impl Sync for FileKind

§

impl Unpin for FileKind

§

impl !UnwindSafe for FileKind

Blanket Implementations§

§

impl<T> Any for T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Borrow<T> for T
where T: ?Sized,

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

impl<T> BorrowMut<T> for T
where T: ?Sized,

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> CloneToUninit for T
where T: Clone,

§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, U> Into<U> for T
where U: From<T>,

§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.