Repository navigation
Expand file tree
/
Copy pathlib.rs
More file actions
132 lines (125 loc) · 3.8 KB
/
Copy pathlib.rs
File metadata and controls
132 lines (125 loc) · 3.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#![allow(unused_imports)]
#![allow(clippy::byte_char_slices)]
#![allow(clippy::needless_range_loop)]
#![allow(clippy::manual_contains)]
#![allow(clippy::while_let_loop)]
#![allow(clippy::if_same_then_else)]
#![allow(clippy::question_mark)]
#![allow(dead_code)]
#![allow(clippy::drop_non_drop)]
#![allow(clippy::while_let_on_iterator)]
#![allow(clippy::single_match)]
#![allow(clippy::ifs_same_cond)]
#![allow(clippy::needless_late_init)]
#![allow(clippy::needless_question_mark)]
#![allow(clippy::explicit_iter_loop)]
#![allow(clippy::manual_range_contains)]
#![allow(clippy::large_enum_variant)]
#![allow(unused_variables)]
#![allow(unused_mut)]
#![allow(unused_doc_comments)]
#![allow(clippy::field_reassign_with_default)]
#![allow(clippy::too_many_arguments)]
#![allow(clippy::write_with_newline)]
#![allow(clippy::manual_div_ceil)]
#![allow(clippy::manual_is_multiple_of)]
#![allow(clippy::ptr_arg)]
#![allow(clippy::string_lit_as_bytes)]
#![allow(clippy::new_without_default)]
#![allow(clippy::search_is_some)]
//! Virtual File System (VFS) Layer
//!
//! This module provides a unified interface for different filesystems:
//! - Device filesystem (devfs) for /dev
//! - RAM filesystem (ramfs) for temporary storage
//! - Future: disk-based filesystems
//!
//! # Architecture
//!
//! ```text
//! +-------------------+
//! | Syscalls | sys_open, sys_read, sys_write, sys_stat, etc.
//! +-------------------+
//! |
//! v
//! +-------------------+
//! | VFS Manager | Path resolution, mount table, caching
//! +-------------------+
//! |
//! +-----+-----+
//! | |
//! v v
//! +------+ +-------+
//! | devfs| | ramfs | FileSystem trait implementations
//! +------+ +-------+
//! ```
//!
//! # Usage
//!
//! ```rust,ignore
//! // Initialize VFS (sets up devfs at /dev)
//! vfs::init();
//!
//! // Open a device file
//! let fd = vfs::open("/dev/null", OpenFlags::new(OpenFlags::O_RDWR))?;
//!
//! // Get file status
//! let stat = vfs::stat("/dev/console")?;
//! ```
#![no_std]
#![feature(allocator_api)]
extern crate alloc;
// Tests that perturb shared heap admission or assert exact class charges must
// share this lock even when their fixtures span several filesystem modules.
#[cfg(test)]
pub(crate) static HEAP_TEST_LOCK: spin::Mutex<()> = spin::Mutex::new(());
#[macro_use]
extern crate drivers;
#[macro_use]
extern crate klog;
#[cfg(all(test, feature = "host_harness"))]
mod allocation_probe;
pub mod cgroupfs;
mod context;
pub mod devfs;
pub mod ext2;
mod identity;
pub mod initramfs;
pub mod manager;
pub mod mount_namespace;
mod path;
pub mod procfs;
pub mod ramfs;
mod topology;
pub mod traits;
pub mod types;
// Re-exports for convenience
pub use cgroupfs::CgroupFs;
pub use devfs::DevFs;
pub use ext2::{Ext2Fs, Ext2Inode};
pub use initramfs::Initramfs;
pub use manager::{
init, mount, normalize_path, open, readdir, register_block_device, split_path, stat, umount,
VFS,
};
pub use procfs::ProcFs;
pub use ramfs::{RamFs, RamFsInode};
pub use traits::{
FileHandle, FileSystem, Inode, PreparedFileHandle, SharedFileOffset, WeakSharedFileOffset,
};
pub use types::{DirEntry, FileMode, FileType, FsError, OpenFlags, SeekWhence, Stat, TimeSpec};
// Mount namespace re-exports
pub use mount_namespace::{
add_mount, clone_namespace, copy_mounts, get_mount, init as mount_ns_init, remove_mount, Mount,
MountFlags, MountNamespace, MountNsError, MAX_MNT_NS_LEVEL, ROOT_MNT_NAMESPACE,
};
/// Initialize the VFS subsystem
///
/// This sets up:
/// - The global VFS instance
/// - Device filesystem mounted at /dev
/// - Standard device files (null, zero, console)
pub fn vfs_init() {
manager::init();
klog_always!("VFS subsystem initialized");
}