diff options
| author | namilsk <namilsk@namilsk.tech> | 2026-01-02 18:20:45 +0300 |
|---|---|---|
| committer | namilsk <namilsk@namilsk.tech> | 2026-01-02 18:20:45 +0300 |
| commit | 3d1d5c8857f852903434488036ccf5036893f881 (patch) | |
| tree | fa43e2a9e68c4fbc59d1ee7cc87e8cee94b05695 /init/src/main.rs | |
| parent | 4ee948ea41020b80b773509890f6631fd4960004 (diff) | |
Refactored code and implemented it in main()
Diffstat (limited to 'init/src/main.rs')
| -rw-r--r-- | init/src/main.rs | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/init/src/main.rs b/init/src/main.rs index 1138ccf..e944424 100644 --- a/init/src/main.rs +++ b/init/src/main.rs @@ -1,10 +1,36 @@ mod mounts; mod pid_one; +use crate::mounts::fstab::FstabEntry; +use crate::mounts::rescue; use crate::pid_one::check_pid; +// RULE: I will not use .expect() and .unwrap() in this project. This causes panic, +// which will affect stability. + fn main() -> Result<(), Box<dyn std::error::Error>> { println!("Initializing your system."); check_pid().expect("\x1b[31m * \x1b[0m Runned not as first process. init/src/pid_one.rs:8:8"); + + match FstabEntry::parse_fstab("/etc/fstab") { + Ok(entries) => { + println!("\x1b[32m * \x1b[0m Sucessfully parsed /etc/fstab."); + for entry in &entries { + let _ = entry.mount(); + } + }, + Err(error) => { + println!("\x1b[33m * \x1b[0m Looks like fstab broken. Mounting all without reading /etc/fstab."); + println!("\x1b[33m * \x1b[0m Error:\n {}", error); + let _ = rescue::mount_system(); + + // Minimal mounts without fstab, because /etc/fstab needs fixes :) + // Btw it should be used if fstab broken or has syntax-errors + // TODO: If fstab contains syntax errors, mount everything else that does not contain them through it anyway. + } + } + + + Ok(()) } |
