78 lines
3.1 KiB
Rust
78 lines
3.1 KiB
Rust
|
|
use liblbos::fs::{DirectoryReader, FileReader, FileSystem, Record, RecordType};
|
||
|
|
use liblbos::ktask;
|
||
|
|
use crate::strprint::twodigit;
|
||
|
|
use crate::syscalls::{kinfo, read_inbuf};
|
||
|
|
use crate::trafficcontrol::{INBUF_LEN};
|
||
|
|
|
||
|
|
pub fn turntable_task() -> ! {
|
||
|
|
print(b"turntable task\n");
|
||
|
|
|
||
|
|
fn print(bytes: &[u8]) {
|
||
|
|
crate::syscalls::write_terminal(bytes);
|
||
|
|
}
|
||
|
|
|
||
|
|
let mut buf: [u8; INBUF_LEN] = [0; INBUF_LEN];
|
||
|
|
loop {
|
||
|
|
let read = read_inbuf(&mut buf);
|
||
|
|
if read > 0 {
|
||
|
|
for c in &buf[0..read] {
|
||
|
|
if *c == b'\r' {
|
||
|
|
let kinfo = kinfo();
|
||
|
|
print(b"\nkinfo\n");
|
||
|
|
print(b"task count ");
|
||
|
|
print(&twodigit(kinfo.current_process_count as u8));
|
||
|
|
print(b"\ntotal mem ");
|
||
|
|
print(&twodigit(kinfo.total_mem_blocks as u8));
|
||
|
|
print(b"\nfree mem ");
|
||
|
|
print(&twodigit(kinfo.free_mem_blocks as u8));
|
||
|
|
print(b"\n");
|
||
|
|
|
||
|
|
let mut fs = FileSystem::empty();
|
||
|
|
if ktask::ktask_fsopen(&mut fs) != 0 {
|
||
|
|
print(b"failed to open fs\n");
|
||
|
|
}
|
||
|
|
let mut dir = DirectoryReader::empty();
|
||
|
|
if ktask::ktask_fsopendir(&fs, &mut dir, b"/") != 0 {
|
||
|
|
print(b"failed to open dir\n");
|
||
|
|
}
|
||
|
|
let mut record = Record {
|
||
|
|
name: [0; 12],
|
||
|
|
record_type: 0,
|
||
|
|
target: 0,
|
||
|
|
total_size_bytes: 0,
|
||
|
|
};
|
||
|
|
while ktask::ktask_fsreaddir(&fs, &mut dir, &mut record) == 0 {
|
||
|
|
print(b"\n");
|
||
|
|
if record.record_type == 0 {
|
||
|
|
print(b"unexpected eod");
|
||
|
|
break;
|
||
|
|
}
|
||
|
|
print(b" - ");
|
||
|
|
print(&record.name[..record.name.iter().position(|&x| x == 0).unwrap_or(11)]);
|
||
|
|
if record.record_type == RecordType::Directory as u8 {
|
||
|
|
print(b" (dir)");
|
||
|
|
} else {
|
||
|
|
print(b" (file)");
|
||
|
|
let mut reader = FileReader::empty();
|
||
|
|
let mut buf = [0u8; 16];
|
||
|
|
if ktask::ktask_fsopenfile(&fs, &record, &mut reader) != 0 {
|
||
|
|
print(b" failed to open file\n");
|
||
|
|
continue;
|
||
|
|
}
|
||
|
|
if ktask::ktask_fsreadfile(&fs, &mut reader, &mut buf) != 0 {
|
||
|
|
print(b" failed to read file\n");
|
||
|
|
continue;
|
||
|
|
}
|
||
|
|
print(b"\n (");
|
||
|
|
print(&buf);
|
||
|
|
print(b")\n");
|
||
|
|
}
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
print(&[*c]);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|