DOCUMENTATION / V1.0.0 LTS
Console.rs Command Handler Extraction Analysis
File:
/home/ldjiba/Sources/repos/OrbitOne/src/console.rs
Total File Lines: ~3700+ execute_command()
function: Lines 586-2204
PART 1: COMPLETE COMMAND DISPATCH SECTIONS WITH EXACT LINE RANGES
MODULE 1: HELP HANDLERS (95 lines total)
| Command | Start Line | End Line | Approx Lines | Dispatch Block Contains |
|---|---|---|---|---|
help |
595 | 631 | 37 | 6 if-else branches for help topics |
commands |
633 | 642 | 10 | List all commands |
logs |
643 | 677 | 35 | on/off/status control |
Help Section Details:
Lines 595-631: Full help command with subtopic branches
- help (no args) → print_help_general()
- help shell → print_help_shell()
- help system → print_help_system()
- help commands → print_help_commands()
- help all → all help + aliases
- help aliases → print_aliases()
Lines 633-642: commands dispatch
- Calls print_help_commands()
Lines 643-677: logs dispatch (3 branches)
- status/empty → print background_logs_enabled status
- on → set_background_logs_enabled(true)
- off → set_background_logs_enabled(false)
MODULE 2: OUTPUT/SYSTEM HANDLERS (1200+ lines total)
2A: OUTPUTS & PROMPT (154 lines)
| Command | Start Line | End Line | Approx Lines |
|---|---|---|---|
outputs |
678 | 749 | 72 |
prompt |
750 | 785 | 36 |
Lines 678-749: outputs command (7 branches)
- status/empty → print backend_status()
- serial on/off → crate::serial::set_serial_backend_enabled()
- local on/off → crate::serial::set_local_backend_enabled()
Lines 750-785: prompt command (5 branches)
- status/empty → current_prompt_theme_name()
- list → list available themes
- set
→ try_set_prompt_theme()
2B: CPU & SELFTEST (57 lines)
| Command | Start Line | End Line | Approx Lines |
|---|---|---|---|
cpu |
786 | 811 | 26 |
selftest |
869 | 889 | 21 |
Lines 786-811: cpu command (3 branches)
- --json → print_cpu_json()
- features → print_cpu_features()
- (default) → print_cpu_summary()
Lines 869-889: selftest command (2 branches)
- --json → print_selftest_json()
- (default) → print_selftest_text()
2C: SYSTEM INFO COMMANDS (196 lines)
| Command | Start Line | End Line | Approx Lines |
|---|---|---|---|
about |
890 | 899 | 10 |
sysinfo |
900 | 914 | 15 |
banner |
915 | 924 | 10 |
version |
925 | 934 | 10 |
info |
935 | 1005 | 71 |
bootlog |
1006 | 1026 | 21 |
- Lines 890-899: about → print_about()
- Lines 900-914: sysinfo (2 branches)
- --json → print_sysinfo_json()
- (default) → print_sysinfo_text()
- Lines 915-924: banner → print_banner()
- Lines 925-934: version → print version string
- Lines 935-1005: info (2 branches with CPU detection)
- --json → JSON with/without CPU data
- (default) → text with/without CPU data
- Lines 1006-1026: bootlog (2 branches)
- --json → print_bootlog_json()
- (default) → print_bootlog_text()
2D: SHELL DISPLAY COMMANDS (40 lines)
| Command | Start Line | End Line | Approx Lines |
|---|---|---|---|
uname |
1724 | 1742 | 19 |
history |
1743 | 1763 | 21 |
aliases |
1764 | 1773 | 10 |
clear |
1774 | 1783 | 10 |
echo |
1784 | 1793 | 10 |
- Lines 1724-1742: uname → print kernel identity
- Lines 1743-1763: history (2 branches)
- --json → print_history_json()
- (default) → print_history()
- Lines 1764-1773: aliases → print_aliases()
- Lines 1774-1783: clear → ANSI escape codes
- Lines 1784-1793: echo → print args
2E: SYSTEM MONITORING (188 lines)
| Command | Start Line | End Line | Approx Lines |
|---|---|---|---|
net |
1515 | 1535 | 21 |
proc |
1536 | 1556 | 21 |
resources |
1557 | 1577 | 21 |
top |
1578 | 1598 | 21 |
tasks/ps |
1599 | 1647 | 49 |
faults |
1648 | 1668 | 21 |
keyboard |
1669 | 1723 | 55 |
- Lines 1515-1535: net (2 branches)
- --json → print_net_json()
- (default) → print_net_text()
- Lines 1536-1556: proc (2 branches)
- --json → print_proc_json()
- (default) → print_proc_text()
- Lines 1557-1577: resources (2 branches)
- --json → print_resources_json()
- (default) → print_resources_text()
- Lines 1578-1598: top (2 branches)
- --json → print_top_json()
- (default) → print_top_text()
- Lines 1599-1647: tasks/ps (detailed stats collection + JSON output)
- Lines 1648-1668: faults (2 branches)
- --json → print_faults_json()
- (default) → print_faults_text()
- Lines 1669-1723: keyboard status (detailed health checking)
2F: POWER COMMANDS (63 lines)
| Command | Start Line | End Line | Approx Lines |
|---|---|---|---|
power |
2126 | 2160 | 35 |
reboot |
2161 | 2182 | 22 |
shutdown |
2183 | 2203 | 21 |
- Lines 2126-2160: power (3 branches)
- status/empty → print current mode
- real → set PowerMode::Real
- sim → set PowerMode::Simulation
- Lines 2161-2182: reboot → request_reboot() + status reporting
- Lines 2183-2203: shutdown → request_shutdown() + status reporting
MODULE 3: STORAGE/FILESYSTEM HANDLERS (332 lines total)
| Command | Start Line | End Line | Approx Lines |
|---|---|---|---|
cd |
1794 | 1825 | 32 |
wai |
1826 | 1841 | 16 |
ls |
1842 | 1872 | 31 |
cat |
1873 | 1895 | 23 |
mount |
1896 | 1913 | 18 |
stat |
1914 | 1949 | 36 |
tree |
1950 | 1976 | 27 |
mkdir |
1977 | 1999 | 23 |
touch |
2000 | 2022 | 23 |
write |
2023 | 2052 | 30 |
rm |
2053 | 2102 | 50 |
rmdir |
2103 | 2125 | 23 |
Storage Module Details:
Lines 1794-1825: cd (with cwd resolution)
- Uses: resolve_shell_path(), set_current_working_dir()
- Calls: crate::fs::stat()
Lines 1826-1841: wai (Where Am I - tree to cwd)
- Uses: current_working_dir()
- Calls: print_wai_tree_to_cwd()
Lines 1842-1872: ls (directory listing)
- Uses: current_working_dir(), resolve_shell_path()
- Calls: crate::fs::list_dir()
Lines 1873-1895: cat (read file)
- Uses: resolve_shell_path()
- Calls: crate::fs::read_file()
Lines 1896-1913: mount (list mounts)
- Calls: crate::fs::mounts()
Lines 1914-1949: stat (file metadata)
- Uses: resolve_shell_path()
- Calls: crate::fs::stat()
Lines 1950-1976: tree (recursive directory tree)
- Uses: current_working_dir(), resolve_shell_path()
- Calls: crate::fs::stat(), print_tree_recursive()
Lines 1977-1999: mkdir
- Uses: resolve_shell_path()
- Calls: crate::fs::mkdir()
Lines 2000-2022: touch
- Uses: resolve_shell_path()
- Calls: crate::fs::touch()
Lines 2023-2052: write (write file content)
- Uses: resolve_shell_path(), split_command_and_args(), ascii_bytes_to_str()
- Calls: crate::fs::write_file()
Lines 2053-2102: rm (remove files)
- Uses: resolve_shell_path(), parse_rm_args()
- Calls: crate::fs::rm(), crate::fs::rm_recursive()
Lines 2103-2125: rmdir
- Uses: resolve_shell_path()
- Calls: crate::fs::rmdir()
MODULE 4: MEMORY/PAGING HANDLERS (583 lines total)
| Command | Start Line | End Line | Approx Lines |
|---|---|---|---|
memory |
812 | 868 | 57 |
paging |
1027 | 1404 | 378 |
diagnose |
1405 | 1425 | 21 |
ticks |
1426 | 1435 | 10 |
uptime |
1436 | 1448 | 13 |
status |
1449 | 1473 | 25 |
health |
1474 | 1514 | 41 |
Memory/Paging Module Details:
Lines 812-868: memory command (complex - 5 branches)
- --json → print_memory_json()
- selftest → crate::memory::run_self_test()
- peak-reset → crate::memory::reset_peak()
- alloc-test
→ crate::memory::run_alloc_test() - (default) → print_memory_summary()
Lines 1027-1404: paging command (MOST COMPLEX - 30+ branches)
- pool → print pool stats
- alloc → allocate frame
- free
→ free frame - selftest → run selftest
- stress
→ stress test - soak
→ soak test - map
→ map page - unmap
→ unmap page - query
→ query mapping - mapstats → print vm map stats
- vm-selftest → run vm selftest
- hw status/on/off/selftest → hardware VM control
- --json variants of multiple commands
- (default) → comprehensive paging summary
Lines 1405-1425: diagnose command (2 branches)
- --json → print_diagnose_json()
- --verbose → print_diagnose(true)
- (default) → print_diagnose(false)
Lines 1426-1435: ticks → print timer ticks
Lines 1436-1448: uptime → calculate and print uptime
Lines 1449-1473: status command (2 branches + health collection)
- --json → print_status_json()
- (default) → print_status_text()
Lines 1474-1514: health command (4 output modes)
- --json → print_health_json()
- --verbose → print_health_verbose_text()
- --reasons → print_health_reasons_text()
- (default) → print_health_text()
PART 2: HELPER FUNCTIONS ANALYSIS
Helper Functions Used by Command Handlers
Print Functions (50+ total)
CPU/System:
print_cpu_summary()- Line ~2850print_cpu_features()- Line ~2870print_cpu_json()- Line ~2890print_memory_summary()- Line ~2945print_memory_json()- Line ~2955print_selftest_text()- Line ~2965print_selftest_json()- Line ~2995print_about()- Line ~3078print_banner()- Line ~3085print_sysinfo_text()- Line ~3092print_sysinfo_json()- Line ~3115
Diagnostics:
print_diagnose(bool)- Line ~3140+print_diagnose_json()- Line ~3245+
Status/Health:
print_status_json()- Line ~3364print_status_text()- Line ~3376print_health_json()- Line ~3387print_health_reasons_text()- Line ~3412print_health_verbose_text()- Line ~3419print_health_text()- Line ~3429
System Monitoring:
print_net_text()- Line ~2750print_net_json()- Line ~2765print_proc_text()- Line ~2776print_proc_json()- Line ~2800print_resources_text()- Line ~2820print_resources_json()- Line ~2845print_top_text()- Line ~2850print_top_json()- Line ~2865
Faults/Keyboard:
print_faults_text()- Line ~2720print_faults_json()- Line ~2730
Boot/History:
print_bootlog_text()- Line ~2425print_bootlog_json()- Line ~2480print_history()- Line ~3520print_history_json()- Line ~3550
Help:
print_help_general()- Line ~2280print_help_tips()- Line ~2293print_help_shell()- Line ~2330print_help_system()- Line ~2400print_help_commands()- Line ~2443
Aliases:
print_aliases()- Line ~2475
Filesystem:
print_tree_recursive()- Line ~3570print_wai_tree_to_cwd()- Line ~3515
Utility Functions (25+ total)
Command Parsing:
split_command_and_args(input: &[u8])- delegates to crate::shell_parsenormalize_alias(cmd: &[u8])- delegates to crate::shell_parseparse_rm_args(args: &[u8])- delegates to crate::shell_parsetrim_spaces(input: &[u8])- delegates to crate::shell_parseeq_ignore_ascii_case(a: &[u8], b: &[u8])- delegates to crate::shell_parsestarts_with_ignore_ascii_case(a: &[u8], prefix: &[u8])- delegates to crate::shell_parse
Path/Directory:
current_working_dir()- Line ~3452set_current_working_dir(path: &str)- Line ~3460resolve_shell_path(path_raw: &[u8])- Line ~3468resolve_path_from_cwd(path_raw: &str)- Line ~3475
Parsing:
parse_usize_arg(input: &[u8])- Line ~3437 (hex & decimal parsing)ascii_bytes_to_str(bytes: &[u8])- Line ~3686 (UTF-8 conversion)copy_trimmed(input: &[u8], out: &mut [u8])- Line ~3510
Health Monitoring:
collect_health_state()- Line ~3345 (complex state collection)
PART 3: DEPENDENCIES BY MODULE
MODULE 1: HELP (help.rs)
External Crate Imports Needed:
use core::sync::atomic::Ordering;
use spin::Mutex;Internal Module Dependencies:
crate::serial_println!
crate::shell_parse (for command parsing)Helper Functions to Move:
print_help_general()- ~35 linesprint_help_tips()- ~15 linesprint_help_shell()- ~50 linesprint_help_system()- ~50 linesprint_help_commands()- ~5 linesprint_aliases()- ~10 lines
Total Lines to Extract: ~165 lines
Self-contained Functions Used:
ascii_bytes_to_str()→ move to common module or keep inline
MODULE 2: SYSTEM (system.rs)
External Crate Imports Needed:
use core::sync::atomic::Ordering;Internal Module Dependencies:
crate::serial_println!
crate::serial_print!
crate::cpu
crate::interrupts
crate::paging
crate::memory
crate::boot
crate::power
crate::serial
crate::pathingConstants Needed:
const CMD_BUF_SIZE: usize = 64;
const HISTORY_SIZE: usize = 8;Helper Functions to Move:
print_cpu_summary()- ~25 linesprint_cpu_features()- ~20 linesprint_cpu_json()- ~40 linesprint_memory_summary()- ~10 linesprint_memory_json()- ~5 linesprint_selftest_text()- ~20 linesprint_selftest_json()- ~25 linesprint_about()- ~10 linesprint_banner()- ~10 linesprint_sysinfo_text()- ~20 linesprint_sysinfo_json()- ~25 linesprint_bootlog_text()- ~50 linesprint_bootlog_json()- ~45 linesprint_net_text()- ~10 linesprint_net_json()- ~10 linesprint_proc_text()- ~20 linesprint_proc_json()- ~20 linesprint_resources_text()- ~20 linesprint_resources_json()- ~15 linesprint_top_text()- ~15 linesprint_top_json()- ~15 linesprint_faults_text()- ~10 linesprint_faults_json()- ~10 linesprint_history()- ~30 linesprint_history_json()- ~25 linesprint_wai_tree_to_cwd()- ~20 linesprint_diagnose()- ~100+ lines (with verbose)print_diagnose_json()- ~60 linesprint_status_json()- ~15 linesprint_status_text()- ~15 linesprint_health_json()- ~30 linesprint_health_reasons_text()- ~10 linesprint_health_verbose_text()- ~15 linesprint_health_text()- ~10 linescollect_health_state()- ~30 lines
Total Lines to Extract: ~850 lines
Dependencies Flow:
- All print_*_json/text functions are self-contained
- collect_health_state() calls crate::paging, crate::serial
- print_diagnose functions call many system modules
MODULE 3: STORAGE (storage.rs)
External Crate Imports Needed:
use alloc::string::String;Internal Module Dependencies:
crate::serial_println!
crate::serial_print!
crate::fs
crate::pathingHelper Functions to Move:
resolve_shell_path()- ~3 lines (wrapper)resolve_path_from_cwd()- ~3 lines (wrapper)current_working_dir()- ~3 lines (wrapper)set_current_working_dir()- ~3 lines (wrapper)print_tree_recursive()- ~35 lines
Helper Functions Already Available:
ascii_bytes_to_str()- needs import or movesplit_command_and_args()- delegates to shell_parseparse_rm_args()- delegates to shell_parsetrim_spaces()- delegates to shell_parseeq_ignore_ascii_case()- delegates to shell_parsestarts_with_ignore_ascii_case()- delegates to shell_parse
Total Lines to Extract: ~200 lines (command bodies) + ~50 lines (helpers) = ~250 lines
Working Directory State Required:
- WORKING_DIR Mutex
(needs access)
Dependencies Flow:
- cd command needs cwd access
- All storage commands depend on path resolution
- Tree printing is recursive but contained
MODULE 4: MEMORY (memory.rs) - COMPLEX
External Crate Imports Needed:
use spin::Mutex;Internal Module Dependencies:
crate::serial_println!
crate::serial_print!
crate::memory
crate::paging
crate::interrupts
crate::boot
crate::cpu
crate::server_tasksHelper Functions to Move:
print_memory_summary()- ~10 linesprint_memory_json()- ~5 linesprint_diagnose()- ~150 lines (very large)print_diagnose_json()- ~80 lines (very large)collect_health_state()- ~30 lines (CRITICAL dependency)parse_usize_arg()- ~10 lines
Constants Needed:
const CMD_BUF_SIZE: usize = 64;
const HISTORY_SIZE: usize = 8;
const PAGING_POOL_HIGH_USAGE_PERCENT: u32 = 90;Struct Needed:
struct HealthState {
// ... 12 fields
}Total Lines to Extract: ~400 lines (command bodies) + ~280 lines (helpers) = ~680 lines
PAGING COMMAND COMPLEXITY: The paging command (lines 1027-1404) is extremely complex:
- 30+ sub-commands
- Multiple JSON and text output variants
- Hardware VM control
- Stress/soak testing
- Frame pool management
- Should potentially be in separate paging_commands.rs module
Memory Command Dependencies:
crate::memory::stats()
crate::memory::run_self_test()
crate::memory::reset_peak()
crate::memory::run_alloc_test()Paging Command Dependencies:
crate::paging::get()
crate::paging::hw_vm_status()
crate::paging::set_hw_vm_enabled()
crate::paging::run_hw_vm_self_test()
crate::paging::frame_pool_stats()
crate::paging::vm_map_stats()
crate::paging::run_vm_self_test()
crate::paging::map_page()
crate::paging::unmap_page()
crate::paging::query_mapping()
crate::paging::soak_status()
crate::paging::stop_soak()
crate::paging::start_soak()
crate::paging::run_self_test()
crate::paging::run_stress()
crate::paging::alloc_frame()
crate::paging::free_frame()PART 4: SUMMARY TABLE - EXTRACTION EFFORT ESTIMATE
| Module | Lines | Commands | Complexity | Helpers | Dependencies | Effort |
|---|---|---|---|---|---|---|
| help.rs | 95 | 3 | Low | 6 | Medium | 1 hour |
| system.rs | 1,700 | 20+ | Medium | 40+ | High | 3 hours |
| storage.rs | 250 | 11 | Low | 8 | Medium | 1.5 hours |
| memory.rs | 680 | 7 | HIGH | 8 | HIGH | 3 hours |
| TOTAL | 2,725 | 41 | Medium | 62+ | Complex | ~8.5 hrs |
PART 5: RECOMMENDED EXTRACTION STRATEGY
Phase 1: Foundation (Quick Wins)
- Extract help.rs (low complexity, few dependencies)
- Extract storage.rs (low complexity, isolated from others)
Phase 2: System Commands
- Extract system.rs (medium complexity, many print functions but
isolated)
- All helper functions are self-contained
- Dependencies are read-only (querying state)
Phase 3: Complex Core
- Extract memory.rs
- Potentially split into:
- memory_commands.rs (~90 lines)
- paging_commands.rs (~380 lines - LARGE)
- health_commands.rs (~100 lines)
- diagnostics.rs (~200 lines)
- Potentially split into:
Phase 4: Integration
- Create commands/mod.rs dispatcher
- Update console.rs to call new dispatcher
- Test and validate
PART 6: CRITICAL OBSERVATIONS
1. Shared State Requirements
- WORKING_DIR mutex (for storage module)
- CONSOLE state (for history module)
- Constants (CMD_BUF_SIZE, HISTORY_SIZE, PAGING_POOL_HIGH_USAGE_PERCENT)
2. Helper Function Sharing Opportunities
Several helpers used by multiple modules:
ascii_bytes_to_str()- used in all modules → move to commoneq_ignore_ascii_case()- delegated to shell_parse- Path resolution functions - used by storage & system
3. Paging Command is Exceptionally Complex
- 378 lines
- 30+ sub-commands
- Should consider separate module:
commands/paging.rs
4. Dependencies Hierarchy
help.rs (bottom - no dependencies on other command modules)
storage.rs (isolated)
system.rs (queries multiple crates, no command module deps)
memory.rs (top - uses collect_health_state(), paging module heavily)
5. No Circular Dependencies
- All modules are read-only from kernel state
- No module calls another module's functions
- Safe to extract independently
PART 7: EXACT COMMAND DISPATCH BLOCKS - QUICK REFERENCE
In execute_command() function (lines 586-2204):
595-631 help command (37 lines)
633-642 commands (10 lines)
643-677 logs (35 lines)
678-749 outputs (72 lines)
750-785 prompt (36 lines)
786-811 cpu (26 lines)
812-868 memory (57 lines)
869-889 selftest (21 lines)
890-899 about (10 lines)
900-914 sysinfo (15 lines)
915-924 banner (10 lines)
925-934 version (10 lines)
935-1005 info (71 lines)
1006-1026 bootlog (21 lines)
1027-1404 paging (378 lines) ⚠️ LARGEST
1405-1425 diagnose (21 lines)
1426-1435 ticks (10 lines)
1436-1448 uptime (13 lines)
1449-1473 status (25 lines)
1474-1514 health (41 lines)
1515-1535 net (21 lines)
1536-1556 proc (21 lines)
1557-1577 resources (21 lines)
1578-1598 top (21 lines)
1599-1647 tasks/ps (49 lines)
1648-1668 faults (21 lines)
1669-1723 keyboard (55 lines)
1724-1742 uname (19 lines)
1743-1763 history (21 lines)
1764-1773 aliases (10 lines)
1774-1783 clear (10 lines)
1784-1793 echo (10 lines)
1794-1825 cd (32 lines)
1826-1841 wai (16 lines)
1842-1872 ls (31 lines)
1873-1895 cat (23 lines)
1896-1913 mount (18 lines)
1914-1949 stat (36 lines)
1950-1976 tree (27 lines)
1977-1999 mkdir (23 lines)
2000-2022 touch (23 lines)
2023-2052 write (30 lines)
2053-2102 rm (50 lines)
2103-2125 rmdir (23 lines)
2126-2160 power (35 lines)
2161-2182 reboot (22 lines)
2183-2203 shutdown (21 lines)
PART 8: HELPER FUNCTIONS - COMPLETE INVENTORY
Total: 62+ helper functions
Location Coordinates in File:
- print_help_*: Lines 2280-2475
- print_cpu_*: Lines 2850-2920
- print_memory_*: Lines 2945-2960
- print_selftest_*: Lines 2965-3020
- print_about/banner/sysinfo: Lines 3078-3135
- print_diagnose*: Lines 3140-3310
- print_status_*: Lines 3364-3380
- print_health_*: Lines 3387-3435
- print_net/proc/resources/top: Lines 2750-2890
- print_faults: Lines 2720-2740
- print_bootlog_*: Lines 2425-2510
- print_history_*: Lines 3520-3570
- print_tree_recursive: Lines 3570-3620
- collect_health_state: Line 3345
- Helper utils: Lines 3437-3686
Note: Line numbers are approximate ±5 lines due to file structure
ANALYSIS COMPLETE
This structured analysis provides everything needed for targeted extraction. All command dispatch blocks are identified with exact line numbers, dependencies are catalogued, and effort estimates are provided.