From 41706c567622979fbb36fb36cc5208a5fba3491c Mon Sep 17 00:00:00 2001 From: Mark Poliakov Date: Fri, 5 Nov 2021 14:06:38 +0200 Subject: [PATCH] misc: format sources --- fs/fat32/src/file.rs | 6 +++--- fs/memfs/src/bvec.rs | 8 ++++++-- fs/memfs/src/file.rs | 4 ++-- fs/vfs/src/char.rs | 2 +- fs/vfs/src/fs.rs | 6 +++--- fs/vfs/src/ioctx.rs | 13 +++++++----- fs/vfs/src/lib.rs | 2 +- fs/vfs/src/node.rs | 11 +++++++--- init/src/main.rs | 13 +++++++----- kernel/src/arch/aarch64/boot/mod.rs | 8 ++++++-- kernel/src/arch/aarch64/context.rs | 4 ++-- kernel/src/arch/aarch64/exception.rs | 6 +++--- .../src/arch/aarch64/mach_orangepi3/uart.rs | 5 +++-- kernel/src/arch/aarch64/mach_rpi3/mod.rs | 8 ++++++-- kernel/src/config.rs | 20 +++++++++---------- kernel/src/dev/mod.rs | 2 +- kernel/src/dev/sd.rs | 5 ++++- kernel/src/dev/serial/pl011.rs | 3 ++- kernel/src/dev/tty.rs | 8 ++++---- kernel/src/main.rs | 2 +- kernel/src/proc/elf.rs | 2 +- kernel/src/sync.rs | 2 +- kernel/src/syscall/arg.rs | 6 +++++- kernel/src/syscall/mod.rs | 2 +- libusr/src/io.rs | 6 ++---- syscall/src/abi.rs | 1 - syscall/src/stat.rs | 8 ++------ 27 files changed, 94 insertions(+), 69 deletions(-) diff --git a/fs/fat32/src/file.rs b/fs/fat32/src/file.rs index 7984c7b..9d8a1f5 100644 --- a/fs/fat32/src/file.rs +++ b/fs/fat32/src/file.rs @@ -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 { diff --git a/fs/memfs/src/bvec.rs b/fs/memfs/src/bvec.rs index 19d0b44..f75039f 100644 --- a/fs/memfs/src/bvec.rs +++ b/fs/memfs/src/bvec.rs @@ -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); diff --git a/fs/memfs/src/file.rs b/fs/memfs/src/file.rs index 2348625..6856f34 100644 --- a/fs/memfs/src/file.rs +++ b/fs/memfs/src/file.rs @@ -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>, diff --git a/fs/vfs/src/char.rs b/fs/vfs/src/char.rs index a16b18e..dd7a904 100644 --- a/fs/vfs/src/char.rs +++ b/fs/vfs/src/char.rs @@ -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 diff --git a/fs/vfs/src/fs.rs b/fs/vfs/src/fs.rs index 0496601..4b60358 100644 --- a/fs/vfs/src/fs.rs +++ b/fs/vfs/src/fs.rs @@ -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 diff --git a/fs/vfs/src/ioctx.rs b/fs/vfs/src/ioctx.rs index acf5313..a736c06 100644 --- a/fs/vfs/src/ioctx.rs +++ b/fs/vfs/src/ioctx.rs @@ -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 { 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) diff --git a/fs/vfs/src/lib.rs b/fs/vfs/src/lib.rs index 17afafe..f80a9b2 100644 --- a/fs/vfs/src/lib.rs +++ b/fs/vfs/src/lib.rs @@ -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; diff --git a/fs/vfs/src/node.rs b/fs/vfs/src/node.rs index 7357e28..292ba51 100644 --- a/fs/vfs/src/node.rs +++ b/fs/vfs/src/node.rs @@ -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 { + pub fn create( + self: &VnodeRef, + name: &str, + mode: FileMode, + kind: VnodeKind, + ) -> Result { 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; diff --git a/init/src/main.rs b/init/src/main.rs index 591cbaa..b315b8d 100644 --- a/init/src/main.rs +++ b/init/src/main.rs @@ -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 diff --git a/kernel/src/arch/aarch64/boot/mod.rs b/kernel/src/arch/aarch64/boot/mod.rs index 2fc28df..afe913f 100644 --- a/kernel/src/arch/aarch64/boot/mod.rs +++ b/kernel/src/arch/aarch64/boot/mod.rs @@ -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, diff --git a/kernel/src/arch/aarch64/context.rs b/kernel/src/arch/aarch64/context.rs index 881d841..b86f0bd 100644 --- a/kernel/src/arch/aarch64/context.rs +++ b/kernel/src/arch/aarch64/context.rs @@ -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, } } diff --git a/kernel/src/arch/aarch64/exception.rs b/kernel/src/arch/aarch64/exception.rs index 05285b9..3aa9376 100644 --- a/kernel/src/arch/aarch64/exception.rs +++ b/kernel/src/arch/aarch64/exception.rs @@ -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; diff --git a/kernel/src/arch/aarch64/mach_orangepi3/uart.rs b/kernel/src/arch/aarch64/mach_orangepi3/uart.rs index 83b696d..84fda53 100644 --- a/kernel/src/arch/aarch64/mach_orangepi3/uart.rs +++ b/kernel/src/arch/aarch64/mach_orangepi3/uart.rs @@ -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, diff --git a/kernel/src/arch/aarch64/mach_rpi3/mod.rs b/kernel/src/arch/aarch64/mach_rpi3/mod.rs index 11b6a0a..91cbf7c 100644 --- a/kernel/src/arch/aarch64/mach_rpi3/mod.rs +++ b/kernel/src/arch/aarch64/mach_rpi3/mod.rs @@ -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; diff --git a/kernel/src/config.rs b/kernel/src/config.rs index 60260a1..2a4bb3e 100644 --- a/kernel/src/config.rs +++ b/kernel/src/config.rs @@ -20,7 +20,7 @@ pub enum ConfigKey { Console, MemLimit, InitrdBase, - InitrdSize + InitrdSize, } struct ConfigString { @@ -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), } } diff --git a/kernel/src/dev/mod.rs b/kernel/src/dev/mod.rs index 144de1c..b0e9dae 100644 --- a/kernel/src/dev/mod.rs +++ b/kernel/src/dev/mod.rs @@ -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; diff --git a/kernel/src/dev/sd.rs b/kernel/src/dev/sd.rs index f65da0e..fe60b98 100644 --- a/kernel/src/dev/sd.rs +++ b/kernel/src/dev/sd.rs @@ -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 diff --git a/kernel/src/dev/serial/pl011.rs b/kernel/src/dev/serial/pl011.rs index 69c7799..b38de03 100644 --- a/kernel/src/dev/serial/pl011.rs +++ b/kernel/src/dev/serial/pl011.rs @@ -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; diff --git a/kernel/src/dev/tty.rs b/kernel/src/dev/tty.rs index 2da4fd2..b9ad5f0 100644 --- a/kernel/src/dev/tty.rs +++ b/kernel/src/dev/tty.rs @@ -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 { rd: usize, wr: usize, data: [u8; N], - flags: u8 + flags: u8, } /// Ring buffer for TTYs @@ -51,7 +51,7 @@ impl CharRing { rd: 0, wr: 0, data: [0; N], - flags: 0 + flags: 0, }), wait_read: Wait::new(), wait_write: Wait::new(), @@ -99,7 +99,7 @@ impl CharRing { Ok(ch) => ch, Err(Errno::Interrupt) => { todo!() - }, + } Err(e) => return Err(e), }; diff --git a/kernel/src/main.rs b/kernel/src/main.rs index 38867ef..3cc3a3b 100644 --- a/kernel/src/main.rs +++ b/kernel/src/main.rs @@ -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) -> ! { diff --git a/kernel/src/proc/elf.rs b/kernel/src/proc/elf.rs index a2f1a13..28df5b5 100644 --- a/kernel/src/proc/elf.rs +++ b/kernel/src/proc/elf.rs @@ -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; diff --git a/kernel/src/sync.rs b/kernel/src/sync.rs index 22c8966..f6bfa2e 100644 --- a/kernel/src/sync.rs +++ b/kernel/src/sync.rs @@ -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 { diff --git a/kernel/src/syscall/arg.rs b/kernel/src/syscall/arg.rs index 2183536..51c46b0 100644 --- a/kernel/src/syscall/arg.rs +++ b/kernel/src/syscall/arg.rs @@ -61,7 +61,11 @@ pub fn validate_user_ptr_null<'a>(base: usize, len: usize) -> Result(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 }) } diff --git a/kernel/src/syscall/mod.rs b/kernel/src/syscall/mod.rs index b893466..e9a80d7 100644 --- a/kernel/src/syscall/mod.rs +++ b/kernel/src/syscall/mod.rs @@ -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; diff --git a/libusr/src/io.rs b/libusr/src/io.rs index ce90b74..e7b9ae7 100644 --- a/libusr/src/io.rs +++ b/libusr/src/io.rs @@ -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 { 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!(); } diff --git a/syscall/src/abi.rs b/syscall/src/abi.rs index ffb6e34..c4a9c70 100644 --- a/syscall/src/abi.rs +++ b/syscall/src/abi.rs @@ -1,4 +1,3 @@ - pub const SYS_EX_DEBUG_TRACE: usize = 128; pub const SYS_EX_NANOSLEEP: usize = 129; diff --git a/syscall/src/stat.rs b/syscall/src/stat.rs index 63a52a8..733f77f 100644 --- a/syscall/src/stat.rs +++ b/syscall/src/stat.rs @@ -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) } } }