From 3d1d5c8857f852903434488036ccf5036893f881 Mon Sep 17 00:00:00 2001 From: namilsk Date: Fri, 2 Jan 2026 18:20:45 +0300 Subject: Refactored code and implemented it in main() --- init/src/main.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'init/src/main.rs') 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> { 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(()) } -- cgit v1.2.3