misc: format sources
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
use vfs::{VnodeImpl, VnodeRef, VnodeKind};
|
||||
use error::Errno;
|
||||
use crate::Bpb;
|
||||
use error::Errno;
|
||||
use vfs::{VnodeImpl, VnodeKind, VnodeRef};
|
||||
|
||||
pub struct FileInode {
|
||||
pub cluster: u32,
|
||||
pub size: u32
|
||||
pub size: u32,
|
||||
}
|
||||
|
||||
impl VnodeImpl for FileInode {
|
||||
|
||||
@@ -313,7 +313,9 @@ mod cow_tests {
|
||||
//unsafe {
|
||||
// bvec.setup_cow(source_data.as_ptr(), source_data.len());
|
||||
//}
|
||||
let mut bvec = unsafe { Bvec::new_copy_on_write(TestAlloc {}, source_data.as_ptr(), source_data.len()) };
|
||||
let mut bvec = unsafe {
|
||||
Bvec::new_copy_on_write(TestAlloc {}, source_data.as_ptr(), source_data.len())
|
||||
};
|
||||
assert!(bvec.is_cow());
|
||||
assert_eq!(bvec.size(), source_data.len());
|
||||
assert_eq!(bvec.capacity, 0);
|
||||
@@ -335,7 +337,9 @@ mod cow_tests {
|
||||
for i in 0..source_data.len() {
|
||||
source_data[i] = (i & 0xFF) as u8;
|
||||
}
|
||||
let mut bvec = unsafe { Bvec::new_copy_on_write(TestAlloc {}, source_data.as_ptr(), source_data.len()) };
|
||||
let mut bvec = unsafe {
|
||||
Bvec::new_copy_on_write(TestAlloc {}, source_data.as_ptr(), source_data.len())
|
||||
};
|
||||
assert!(bvec.is_cow());
|
||||
assert_eq!(bvec.size(), source_data.len());
|
||||
assert_eq!(bvec.capacity, 0);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use vfs::{VnodeImpl, VnodeKind, VnodeRef, Stat, OpenFlags};
|
||||
use error::Errno;
|
||||
use crate::{BlockAllocator, Bvec};
|
||||
use error::Errno;
|
||||
use vfs::{OpenFlags, Stat, VnodeImpl, VnodeKind, VnodeRef};
|
||||
|
||||
pub struct FileInode<'a, A: BlockAllocator + Copy + 'static> {
|
||||
data: Bvec<'a, A>,
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
use crate::{VnodeImpl, VnodeKind, VnodeRef, Stat, OpenFlags};
|
||||
use crate::{OpenFlags, Stat, VnodeImpl, VnodeKind, VnodeRef};
|
||||
use error::Errno;
|
||||
|
||||
/// Generic character device trait
|
||||
|
||||
+3
-3
@@ -1,7 +1,7 @@
|
||||
use crate::{VnodeRef, BlockDevice};
|
||||
use core::cell::Ref;
|
||||
use core::any::Any;
|
||||
use crate::{BlockDevice, VnodeRef};
|
||||
use alloc::rc::Rc;
|
||||
use core::any::Any;
|
||||
use core::cell::Ref;
|
||||
use error::Errno;
|
||||
|
||||
/// General filesystem interface
|
||||
|
||||
+8
-5
@@ -1,4 +1,4 @@
|
||||
use crate::{FileMode, FileRef, VnodeKind, VnodeRef, OpenFlags};
|
||||
use crate::{FileMode, FileRef, OpenFlags, VnodeKind, VnodeRef};
|
||||
use error::Errno;
|
||||
use libcommon::{path_component_left, path_component_right};
|
||||
|
||||
@@ -84,8 +84,11 @@ impl Ioctx {
|
||||
mode: FileMode,
|
||||
) -> Result<VnodeRef, Errno> {
|
||||
let (parent, name) = path_component_right(path);
|
||||
self.find(at, parent, true)?
|
||||
.create(name.trim_start_matches('/'), mode, VnodeKind::Directory)
|
||||
self.find(at, parent, true)?.create(
|
||||
name.trim_start_matches('/'),
|
||||
mode,
|
||||
VnodeKind::Directory,
|
||||
)
|
||||
}
|
||||
|
||||
/// Opens (and possibly creates) a filesystem path for access
|
||||
@@ -101,8 +104,8 @@ impl Ioctx {
|
||||
let (parent, name) = path_component_right(path);
|
||||
let at = self.find(at, parent, true)?;
|
||||
at.create(name, mode, VnodeKind::Regular)
|
||||
},
|
||||
o => o
|
||||
}
|
||||
o => o,
|
||||
}?;
|
||||
|
||||
node.open(opts)
|
||||
|
||||
+1
-1
@@ -9,7 +9,7 @@ extern crate std;
|
||||
|
||||
extern crate alloc;
|
||||
|
||||
pub use syscall::stat::{Stat, OpenFlags, FileMode};
|
||||
pub use syscall::stat::{FileMode, OpenFlags, Stat};
|
||||
|
||||
mod block;
|
||||
pub use block::BlockDevice;
|
||||
|
||||
+8
-3
@@ -1,4 +1,4 @@
|
||||
use crate::{FileRef, File, FileMode, Filesystem, Stat, OpenFlags};
|
||||
use crate::{File, FileMode, FileRef, Filesystem, OpenFlags, Stat};
|
||||
use alloc::{borrow::ToOwned, boxed::Box, rc::Rc, string::String, vec::Vec};
|
||||
use core::cell::{RefCell, RefMut};
|
||||
use core::fmt;
|
||||
@@ -235,7 +235,12 @@ impl Vnode {
|
||||
}
|
||||
|
||||
/// Creates a new node `name` in `self`
|
||||
pub fn create(self: &VnodeRef, name: &str, mode: FileMode, kind: VnodeKind) -> Result<VnodeRef, Errno> {
|
||||
pub fn create(
|
||||
self: &VnodeRef,
|
||||
name: &str,
|
||||
mode: FileMode,
|
||||
kind: VnodeKind,
|
||||
) -> Result<VnodeRef, Errno> {
|
||||
if self.kind != VnodeKind::Directory {
|
||||
return Err(Errno::NotADirectory);
|
||||
}
|
||||
@@ -292,7 +297,7 @@ impl Vnode {
|
||||
OpenFlags::O_RDONLY => open_flags |= File::READ,
|
||||
OpenFlags::O_WRONLY => open_flags |= File::WRITE,
|
||||
OpenFlags::O_RDWR => open_flags |= File::READ | File::WRITE,
|
||||
_ => unimplemented!()
|
||||
_ => unimplemented!(),
|
||||
}
|
||||
if flags.contains(OpenFlags::O_CLOEXEC) {
|
||||
open_flags |= File::CLOEXEC;
|
||||
|
||||
+8
-5
@@ -5,18 +5,21 @@
|
||||
#[macro_use]
|
||||
extern crate libusr;
|
||||
|
||||
use libusr::sys::{Stat, AT_FDCWD, OpenFlags, FileMode, AT_EMPTY_PATH};
|
||||
use libusr::sys::{FileMode, OpenFlags, Stat, AT_EMPTY_PATH, AT_FDCWD};
|
||||
|
||||
#[no_mangle]
|
||||
fn main() -> i32 {
|
||||
let mut stat = Stat::default();
|
||||
let fd = unsafe {
|
||||
libusr::sys::sys_openat(AT_FDCWD, "/test.txt", FileMode::empty(), OpenFlags::O_RDONLY)
|
||||
libusr::sys::sys_openat(
|
||||
AT_FDCWD,
|
||||
"/test.txt",
|
||||
FileMode::empty(),
|
||||
OpenFlags::O_RDONLY,
|
||||
)
|
||||
};
|
||||
println!("fd = {}", fd);
|
||||
let ret = unsafe {
|
||||
libusr::sys::sys_fstatat(fd, "", &mut stat, AT_EMPTY_PATH)
|
||||
};
|
||||
let ret = unsafe { libusr::sys::sys_fstatat(fd, "", &mut stat, AT_EMPTY_PATH) };
|
||||
println!("{}, {:?}", ret, stat);
|
||||
|
||||
-1
|
||||
|
||||
@@ -4,10 +4,14 @@ use crate::arch::{
|
||||
aarch64::reg::{CNTKCTL_EL1, CPACR_EL1},
|
||||
machine,
|
||||
};
|
||||
use crate::config::{ConfigKey, CONFIG};
|
||||
use crate::dev::{
|
||||
fdt::{find_prop, DeviceTree},
|
||||
irq::IntSource,
|
||||
Device,
|
||||
};
|
||||
use crate::fs::devfs;
|
||||
use crate::dev::{fdt::{DeviceTree, find_prop}, irq::IntSource, Device};
|
||||
use error::Errno;
|
||||
use crate::config::{CONFIG, ConfigKey};
|
||||
//use crate::debug::Level;
|
||||
use crate::mem::{
|
||||
self, heap,
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
//! Thread context
|
||||
|
||||
use crate::arch::aarch64::exception::ExceptionFrame;
|
||||
use crate::mem::{
|
||||
self,
|
||||
phys::{self, PageUsage},
|
||||
};
|
||||
use crate::arch::aarch64::exception::ExceptionFrame;
|
||||
use core::mem::size_of;
|
||||
|
||||
struct Stack {
|
||||
@@ -86,7 +86,7 @@ impl Context {
|
||||
k_sp: stack.sp,
|
||||
|
||||
stack_base_phys: stack.bp,
|
||||
stack_page_count: 8
|
||||
stack_page_count: 8,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,9 +4,9 @@ use crate::arch::machine;
|
||||
use crate::debug::Level;
|
||||
use crate::dev::irq::{IntController, IrqContext};
|
||||
use crate::syscall;
|
||||
use ::syscall::abi;
|
||||
use cortex_a::registers::{ESR_EL1, FAR_EL1};
|
||||
use tock_registers::interfaces::Readable;
|
||||
use ::syscall::abi;
|
||||
|
||||
/// Trapped SIMD/FP functionality
|
||||
pub const EC_FP_TRAP: u64 = 0b000111;
|
||||
@@ -96,7 +96,7 @@ extern "C" fn __aa64_exc_sync_handler(exc: &mut ExceptionFrame) {
|
||||
Err(err) => {
|
||||
warnln!("fork() syscall failed: {:?}", err);
|
||||
exc.x[0] = usize::MAX;
|
||||
},
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -106,7 +106,7 @@ extern "C" fn __aa64_exc_sync_handler(exc: &mut ExceptionFrame) {
|
||||
Err(err) => {
|
||||
warnln!("syscall {} failed: {:?}", exc.x[8], err);
|
||||
exc.x[0] = usize::MAX
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
return;
|
||||
|
||||
@@ -2,9 +2,9 @@ use crate::arch::machine::{self, IrqNumber};
|
||||
use crate::dev::{
|
||||
irq::{IntController, IntSource},
|
||||
serial::SerialDevice,
|
||||
tty::CharRing, Device,
|
||||
tty::CharRing,
|
||||
Device,
|
||||
};
|
||||
use vfs::CharDevice;
|
||||
use crate::mem::virt::DeviceMemoryIo;
|
||||
use crate::sync::IrqSafeSpinLock;
|
||||
use crate::util::InitOnce;
|
||||
@@ -12,6 +12,7 @@ use error::Errno;
|
||||
use tock_registers::interfaces::{ReadWriteable, Readable, Writeable};
|
||||
use tock_registers::registers::{Aliased, ReadOnly, ReadWrite};
|
||||
use tock_registers::{register_bitfields, register_structs};
|
||||
use vfs::CharDevice;
|
||||
|
||||
register_bitfields! [
|
||||
u32,
|
||||
|
||||
@@ -1,10 +1,14 @@
|
||||
use crate::arch::aarch64::timer::GenericTimer;
|
||||
use crate::dev::{Device, serial::{SerialDevice, pl011::Pl011}, irq::IntSource};
|
||||
use crate::dev::{
|
||||
irq::IntSource,
|
||||
serial::{pl011::Pl011, SerialDevice},
|
||||
Device,
|
||||
};
|
||||
use crate::mem::phys;
|
||||
use error::Errno;
|
||||
|
||||
pub mod irqchip;
|
||||
pub use irqchip::{IrqNumber, Bcm283xIrqchip};
|
||||
pub use irqchip::{Bcm283xIrqchip, IrqNumber};
|
||||
pub mod emmc;
|
||||
pub use emmc::MassMediaController;
|
||||
pub mod mailbox;
|
||||
|
||||
+10
-10
@@ -20,7 +20,7 @@ pub enum ConfigKey {
|
||||
Console,
|
||||
MemLimit,
|
||||
InitrdBase,
|
||||
InitrdSize
|
||||
InitrdSize,
|
||||
}
|
||||
|
||||
struct ConfigString<const N: usize> {
|
||||
@@ -38,7 +38,7 @@ impl const Default for Config {
|
||||
console: ConfigString::empty(),
|
||||
mem_limit: usize::MAX,
|
||||
initrd_base: 0,
|
||||
initrd_size: 0
|
||||
initrd_size: 0,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -47,18 +47,18 @@ impl Config {
|
||||
/// Sets a config key to [usize] value
|
||||
pub fn set_usize(&mut self, key: ConfigKey, value: usize) {
|
||||
match key {
|
||||
ConfigKey::InitrdBase => { self.initrd_base = value }
|
||||
ConfigKey::InitrdSize => { self.initrd_size = value }
|
||||
ConfigKey::MemLimit => { self.mem_limit = value }
|
||||
_ => panic!("Invalid usize key: {:?}", key)
|
||||
ConfigKey::InitrdBase => self.initrd_base = value,
|
||||
ConfigKey::InitrdSize => self.initrd_size = value,
|
||||
ConfigKey::MemLimit => self.mem_limit = value,
|
||||
_ => panic!("Invalid usize key: {:?}", key),
|
||||
}
|
||||
}
|
||||
|
||||
/// Sets a config key to [str] value
|
||||
pub fn set_str(&mut self, key: ConfigKey, value: &str) {
|
||||
match key {
|
||||
ConfigKey::Cmdline => { self.cmdline.set_from_str(value) }
|
||||
_ => panic!("Invalid str key: {:?}", key)
|
||||
ConfigKey::Cmdline => self.cmdline.set_from_str(value),
|
||||
_ => panic!("Invalid str key: {:?}", key),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,7 +68,7 @@ impl Config {
|
||||
ConfigKey::InitrdBase => self.initrd_base,
|
||||
ConfigKey::InitrdSize => self.initrd_size,
|
||||
ConfigKey::MemLimit => self.mem_limit,
|
||||
_ => panic!("Invalid usize key: {:?}", key)
|
||||
_ => panic!("Invalid usize key: {:?}", key),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,7 +77,7 @@ impl Config {
|
||||
match key {
|
||||
ConfigKey::Cmdline => self.cmdline.as_str(),
|
||||
ConfigKey::Console => self.console.as_str(),
|
||||
_ => panic!("Invalid str key: {:?}", key)
|
||||
_ => panic!("Invalid str key: {:?}", key),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,9 +6,9 @@ use error::Errno;
|
||||
pub mod fdt;
|
||||
pub mod gpio;
|
||||
pub mod irq;
|
||||
pub mod sd;
|
||||
pub mod pci;
|
||||
pub mod rtc;
|
||||
pub mod sd;
|
||||
pub mod serial;
|
||||
pub mod timer;
|
||||
pub mod tty;
|
||||
|
||||
@@ -423,7 +423,10 @@ impl SdCommand<'_> {
|
||||
|
||||
/// Returns `true` if cmd is application-specific
|
||||
pub const fn is_acmd(&self) -> bool {
|
||||
matches!(self.number, SdCommandNumber::Acmd41 | SdCommandNumber::Acmd51)
|
||||
matches!(
|
||||
self.number,
|
||||
SdCommandNumber::Acmd41 | SdCommandNumber::Acmd51
|
||||
)
|
||||
}
|
||||
|
||||
/// Returns the command index
|
||||
|
||||
@@ -4,7 +4,8 @@ use crate::arch::machine::{self, IrqNumber};
|
||||
use crate::dev::{
|
||||
irq::{IntController, IntSource},
|
||||
serial::SerialDevice,
|
||||
tty::CharRing, Device,
|
||||
tty::CharRing,
|
||||
Device,
|
||||
};
|
||||
use crate::mem::virt::DeviceMemoryIo;
|
||||
use crate::sync::IrqSafeSpinLock;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//! Teletype (TTY) device facilities
|
||||
use error::Errno;
|
||||
use crate::proc::wait::Wait;
|
||||
use crate::sync::IrqSafeSpinLock;
|
||||
use error::Errno;
|
||||
use vfs::CharDevice;
|
||||
|
||||
#[derive(Debug)]
|
||||
@@ -9,7 +9,7 @@ struct CharRingInner<const N: usize> {
|
||||
rd: usize,
|
||||
wr: usize,
|
||||
data: [u8; N],
|
||||
flags: u8
|
||||
flags: u8,
|
||||
}
|
||||
|
||||
/// Ring buffer for TTYs
|
||||
@@ -51,7 +51,7 @@ impl<const N: usize> CharRing<N> {
|
||||
rd: 0,
|
||||
wr: 0,
|
||||
data: [0; N],
|
||||
flags: 0
|
||||
flags: 0,
|
||||
}),
|
||||
wait_read: Wait::new(),
|
||||
wait_write: Wait::new(),
|
||||
@@ -99,7 +99,7 @@ impl<const N: usize> CharRing<N> {
|
||||
Ok(ch) => ch,
|
||||
Err(Errno::Interrupt) => {
|
||||
todo!()
|
||||
},
|
||||
}
|
||||
Err(e) => return Err(e),
|
||||
};
|
||||
|
||||
|
||||
+1
-1
@@ -31,12 +31,12 @@ pub mod arch;
|
||||
pub mod config;
|
||||
pub mod dev;
|
||||
pub mod fs;
|
||||
pub mod init;
|
||||
pub mod mem;
|
||||
pub mod proc;
|
||||
pub mod sync;
|
||||
pub mod syscall;
|
||||
pub mod util;
|
||||
pub mod init;
|
||||
|
||||
#[panic_handler]
|
||||
fn panic_handler(pi: &core::panic::PanicInfo) -> ! {
|
||||
|
||||
@@ -4,10 +4,10 @@ use crate::mem::{
|
||||
phys::{self, PageUsage},
|
||||
virt::{MapAttributes, Space},
|
||||
};
|
||||
use vfs::FileRef;
|
||||
use core::mem::{size_of, MaybeUninit};
|
||||
use error::Errno;
|
||||
use libcommon::{Read, Seek, SeekDir};
|
||||
use vfs::FileRef;
|
||||
|
||||
trait Elf {
|
||||
type Addr;
|
||||
|
||||
+1
-1
@@ -2,9 +2,9 @@
|
||||
|
||||
use crate::arch::platform::{irq_mask_save, irq_restore};
|
||||
use core::cell::UnsafeCell;
|
||||
use core::fmt;
|
||||
use core::ops::{Deref, DerefMut};
|
||||
use core::sync::atomic::{AtomicBool, Ordering};
|
||||
use core::fmt;
|
||||
|
||||
/// Lock structure ensuring IRQs are disabled when inner value is accessed
|
||||
pub struct IrqSafeSpinLock<T> {
|
||||
|
||||
@@ -61,7 +61,11 @@ pub fn validate_user_ptr_null<'a>(base: usize, len: usize) -> Result<Option<&'a
|
||||
pub fn validate_user_str<'a>(base: usize, len: usize) -> Result<&'a str, Errno> {
|
||||
let bytes = validate_user_ptr(base, len)?;
|
||||
core::str::from_utf8(bytes).map_err(|_| {
|
||||
warnln!("User string contains invalid UTF-8 characters: base={:#x}, len={:#x}", base, len);
|
||||
warnln!(
|
||||
"User string contains invalid UTF-8 characters: base={:#x}, len={:#x}",
|
||||
base,
|
||||
len
|
||||
);
|
||||
Errno::InvalidArgument
|
||||
})
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
use crate::arch::platform::exception::ExceptionFrame;
|
||||
use crate::debug::Level;
|
||||
use crate::proc::{elf, ProcessIo, wait, Pid, Process};
|
||||
use crate::proc::{elf, wait, Pid, Process, ProcessIo};
|
||||
use core::mem::size_of;
|
||||
use core::ops::DerefMut;
|
||||
use core::time::Duration;
|
||||
|
||||
+2
-4
@@ -1,15 +1,13 @@
|
||||
use crate::sys::{self, Stat};
|
||||
use syscall::stat::AT_FDCWD;
|
||||
use core::fmt;
|
||||
use syscall::stat::AT_FDCWD;
|
||||
|
||||
// TODO populate this type
|
||||
pub struct Error;
|
||||
|
||||
pub fn stat(pathname: &str) -> Result<Stat, Error> {
|
||||
let mut buf = Stat::default();
|
||||
let res = unsafe {
|
||||
sys::sys_fstatat(AT_FDCWD, pathname, &mut buf, 0)
|
||||
};
|
||||
let res = unsafe { sys::sys_fstatat(AT_FDCWD, pathname, &mut buf, 0) };
|
||||
if res != 0 {
|
||||
todo!();
|
||||
}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
pub const SYS_EX_DEBUG_TRACE: usize = 128;
|
||||
pub const SYS_EX_NANOSLEEP: usize = 129;
|
||||
|
||||
|
||||
+2
-6
@@ -43,15 +43,11 @@ pub struct Stat {
|
||||
impl FileMode {
|
||||
/// Returns default permission set for directories
|
||||
pub const fn default_dir() -> Self {
|
||||
unsafe {
|
||||
Self::from_bits_unchecked(0o755)
|
||||
}
|
||||
unsafe { Self::from_bits_unchecked(0o755) }
|
||||
}
|
||||
|
||||
/// Returns default permission set for regular files
|
||||
pub const fn default_reg() -> Self {
|
||||
unsafe {
|
||||
Self::from_bits_unchecked(0o644)
|
||||
}
|
||||
unsafe { Self::from_bits_unchecked(0o644) }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user