From 1d098c4e1d3d6bf57f02b6db690507603ea6ff92 Mon Sep 17 00:00:00 2001 From: 4lDO2 <4lDO2@protonmail.com> Date: Sun, 8 Sep 2024 20:32:32 +0200 Subject: [PATCH] Rustfmt. --- src/arch/aarch64.rs | 41 ++- src/arch/nonredox.rs | 10 +- src/arch/riscv64.rs | 27 +- src/arch/x86.rs | 53 +++- src/arch/x86_64.rs | 37 ++- src/call.rs | 127 +++++++-- src/error.rs | 469 +++++++++++++++++---------------- src/flag.rs | 101 ++++--- src/io/io.rs | 26 +- src/io/mmio.rs | 8 +- src/io/mod.rs | 3 +- src/io/pio.rs | 3 +- src/lib.rs | 20 +- src/number.rs | 110 ++++---- src/scheme/mod.rs | 23 +- src/scheme/scheme.rs | 144 ++++++---- src/scheme/scheme_block.rs | 160 +++++++---- src/scheme/scheme_block_mut.rs | 160 +++++++---- src/scheme/scheme_mut.rs | 144 ++++++---- src/scheme/seek.rs | 24 +- src/schemev2.rs | 53 ++-- 21 files changed, 1051 insertions(+), 692 deletions(-) diff --git a/src/arch/aarch64.rs b/src/arch/aarch64.rs index e792427cff..9a2de5b48d 100644 --- a/src/arch/aarch64.rs +++ b/src/arch/aarch64.rs @@ -1,5 +1,8 @@ -use core::{mem, slice}; -use core::ops::{Deref, DerefMut}; +use core::{ + mem, + ops::{Deref, DerefMut}, + slice, +}; use super::error::{Error, Result}; @@ -81,14 +84,17 @@ pub struct IntRegisters { pub x3: usize, pub x2: usize, pub x1: usize, - pub x0: usize + pub x0: usize, } impl Deref for IntRegisters { type Target = [u8]; fn deref(&self) -> &[u8] { unsafe { - slice::from_raw_parts(self as *const IntRegisters as *const u8, mem::size_of::()) + slice::from_raw_parts( + self as *const IntRegisters as *const u8, + mem::size_of::(), + ) } } } @@ -96,7 +102,10 @@ impl Deref for IntRegisters { impl DerefMut for IntRegisters { fn deref_mut(&mut self) -> &mut [u8] { unsafe { - slice::from_raw_parts_mut(self as *mut IntRegisters as *mut u8, mem::size_of::()) + slice::from_raw_parts_mut( + self as *mut IntRegisters as *mut u8, + mem::size_of::(), + ) } } } @@ -106,14 +115,17 @@ impl DerefMut for IntRegisters { pub struct FloatRegisters { pub fp_simd_regs: [u128; 32], pub fpsr: u32, - pub fpcr: u32 + pub fpcr: u32, } impl Deref for FloatRegisters { type Target = [u8]; fn deref(&self) -> &[u8] { unsafe { - slice::from_raw_parts(self as *const FloatRegisters as *const u8, mem::size_of::()) + slice::from_raw_parts( + self as *const FloatRegisters as *const u8, + mem::size_of::(), + ) } } } @@ -121,7 +133,10 @@ impl Deref for FloatRegisters { impl DerefMut for FloatRegisters { fn deref_mut(&mut self) -> &mut [u8] { unsafe { - slice::from_raw_parts_mut(self as *mut FloatRegisters as *mut u8, mem::size_of::()) + slice::from_raw_parts_mut( + self as *mut FloatRegisters as *mut u8, + mem::size_of::(), + ) } } } @@ -136,7 +151,10 @@ impl Deref for EnvRegisters { type Target = [u8]; fn deref(&self) -> &[u8] { unsafe { - slice::from_raw_parts(self as *const EnvRegisters as *const u8, mem::size_of::()) + slice::from_raw_parts( + self as *const EnvRegisters as *const u8, + mem::size_of::(), + ) } } } @@ -144,7 +162,10 @@ impl Deref for EnvRegisters { impl DerefMut for EnvRegisters { fn deref_mut(&mut self) -> &mut [u8] { unsafe { - slice::from_raw_parts_mut(self as *mut EnvRegisters as *mut u8, mem::size_of::()) + slice::from_raw_parts_mut( + self as *mut EnvRegisters as *mut u8, + mem::size_of::(), + ) } } } diff --git a/src/arch/nonredox.rs b/src/arch/nonredox.rs index 1cd3daa31b..5969fe8f4d 100644 --- a/src/arch/nonredox.rs +++ b/src/arch/nonredox.rs @@ -23,8 +23,14 @@ pub unsafe fn syscall4(_a: usize, _b: usize, _c: usize, _d: usize, _e: usize) -> Err(Error::new(ENOSYS)) } -pub unsafe fn syscall5(_a: usize, _b: usize, _c: usize, _d: usize, _e: usize, _f: usize) - -> Result { +pub unsafe fn syscall5( + _a: usize, + _b: usize, + _c: usize, + _d: usize, + _e: usize, + _f: usize, +) -> Result { Err(Error::new(ENOSYS)) } diff --git a/src/arch/riscv64.rs b/src/arch/riscv64.rs index 2a90260da4..199f91c9bf 100644 --- a/src/arch/riscv64.rs +++ b/src/arch/riscv64.rs @@ -1,5 +1,8 @@ -use core::{mem, slice}; -use core::ops::{Deref, DerefMut}; +use core::{ + mem, + ops::{Deref, DerefMut}, + slice, +}; use super::error::{Error, Result}; @@ -56,7 +59,10 @@ impl Deref for IntRegisters { type Target = [u8]; fn deref(&self) -> &[u8] { unsafe { - slice::from_raw_parts(self as *const IntRegisters as *const u8, mem::size_of::()) + slice::from_raw_parts( + self as *const IntRegisters as *const u8, + mem::size_of::(), + ) } } } @@ -64,7 +70,10 @@ impl Deref for IntRegisters { impl DerefMut for IntRegisters { fn deref_mut(&mut self) -> &mut [u8] { unsafe { - slice::from_raw_parts_mut(self as *mut IntRegisters as *mut u8, mem::size_of::()) + slice::from_raw_parts_mut( + self as *mut IntRegisters as *mut u8, + mem::size_of::(), + ) } } } @@ -79,7 +88,10 @@ impl Deref for FloatRegisters { type Target = [u8]; fn deref(&self) -> &[u8] { unsafe { - slice::from_raw_parts(self as *const FloatRegisters as *const u8, mem::size_of::()) + slice::from_raw_parts( + self as *const FloatRegisters as *const u8, + mem::size_of::(), + ) } } } @@ -87,7 +99,10 @@ impl Deref for FloatRegisters { impl DerefMut for FloatRegisters { fn deref_mut(&mut self) -> &mut [u8] { unsafe { - slice::from_raw_parts_mut(self as *mut FloatRegisters as *mut u8, mem::size_of::()) + slice::from_raw_parts_mut( + self as *mut FloatRegisters as *mut u8, + mem::size_of::(), + ) } } } diff --git a/src/arch/x86.rs b/src/arch/x86.rs index 54d8c0a93e..d43021511d 100644 --- a/src/arch/x86.rs +++ b/src/arch/x86.rs @@ -1,6 +1,9 @@ -use core::{mem, slice}; -use core::arch::asm; -use core::ops::{Deref, DerefMut}; +use core::{ + arch::asm, + mem, + ops::{Deref, DerefMut}, + slice, +}; use super::error::{Error, Result}; @@ -47,8 +50,7 @@ syscall! { //syscall5(a, b, c, d, e, f,); } -pub unsafe fn syscall4(mut a: usize, b: usize, c: usize, d: usize, e: usize) - -> Result { +pub unsafe fn syscall4(mut a: usize, b: usize, c: usize, d: usize, e: usize) -> Result { asm!( "xchg esi, {e} int 0x80 @@ -64,8 +66,14 @@ pub unsafe fn syscall4(mut a: usize, b: usize, c: usize, d: usize, e: usize) Error::demux(a) } -pub unsafe fn syscall5(mut a: usize, b: usize, c: usize, d: usize, e: usize, f: usize) - -> Result { +pub unsafe fn syscall5( + mut a: usize, + b: usize, + c: usize, + d: usize, + e: usize, + f: usize, +) -> Result { asm!( "xchg esi, {e} int 0x80 @@ -86,7 +94,6 @@ pub unsafe fn syscall5(mut a: usize, b: usize, c: usize, d: usize, e: usize, f: #[repr(C)] pub struct IntRegisters { // TODO: Some of these don't get set by Redox yet. Should they? - pub ebp: usize, pub esi: usize, pub edi: usize, @@ -112,7 +119,10 @@ impl Deref for IntRegisters { type Target = [u8]; fn deref(&self) -> &[u8] { unsafe { - slice::from_raw_parts(self as *const IntRegisters as *const u8, mem::size_of::()) + slice::from_raw_parts( + self as *const IntRegisters as *const u8, + mem::size_of::(), + ) } } } @@ -120,7 +130,10 @@ impl Deref for IntRegisters { impl DerefMut for IntRegisters { fn deref_mut(&mut self) -> &mut [u8] { unsafe { - slice::from_raw_parts_mut(self as *mut IntRegisters as *mut u8, mem::size_of::()) + slice::from_raw_parts_mut( + self as *mut IntRegisters as *mut u8, + mem::size_of::(), + ) } } } @@ -146,7 +159,10 @@ impl Deref for FloatRegisters { type Target = [u8]; fn deref(&self) -> &[u8] { unsafe { - slice::from_raw_parts(self as *const FloatRegisters as *const u8, mem::size_of::()) + slice::from_raw_parts( + self as *const FloatRegisters as *const u8, + mem::size_of::(), + ) } } } @@ -154,7 +170,10 @@ impl Deref for FloatRegisters { impl DerefMut for FloatRegisters { fn deref_mut(&mut self) -> &mut [u8] { unsafe { - slice::from_raw_parts_mut(self as *mut FloatRegisters as *mut u8, mem::size_of::()) + slice::from_raw_parts_mut( + self as *mut FloatRegisters as *mut u8, + mem::size_of::(), + ) } } } @@ -170,7 +189,10 @@ impl Deref for EnvRegisters { type Target = [u8]; fn deref(&self) -> &[u8] { unsafe { - slice::from_raw_parts(self as *const EnvRegisters as *const u8, mem::size_of::()) + slice::from_raw_parts( + self as *const EnvRegisters as *const u8, + mem::size_of::(), + ) } } } @@ -178,7 +200,10 @@ impl Deref for EnvRegisters { impl DerefMut for EnvRegisters { fn deref_mut(&mut self) -> &mut [u8] { unsafe { - slice::from_raw_parts_mut(self as *mut EnvRegisters as *mut u8, mem::size_of::()) + slice::from_raw_parts_mut( + self as *mut EnvRegisters as *mut u8, + mem::size_of::(), + ) } } } diff --git a/src/arch/x86_64.rs b/src/arch/x86_64.rs index df3293f693..6aaca56066 100644 --- a/src/arch/x86_64.rs +++ b/src/arch/x86_64.rs @@ -1,6 +1,9 @@ -use core::{mem, slice}; -use core::arch::asm; -use core::ops::{Deref, DerefMut}; +use core::{ + arch::asm, + mem, + ops::{Deref, DerefMut}, + slice, +}; use super::error::{Error, Result}; @@ -76,17 +79,13 @@ pub struct IntRegisters { impl Deref for IntRegisters { type Target = [u8]; fn deref(&self) -> &[u8] { - unsafe { - slice::from_raw_parts(self as *const Self as *const u8, mem::size_of::()) - } + unsafe { slice::from_raw_parts(self as *const Self as *const u8, mem::size_of::()) } } } impl DerefMut for IntRegisters { fn deref_mut(&mut self) -> &mut [u8] { - unsafe { - slice::from_raw_parts_mut(self as *mut Self as *mut u8, mem::size_of::()) - } + unsafe { slice::from_raw_parts_mut(self as *mut Self as *mut u8, mem::size_of::()) } } } @@ -111,7 +110,10 @@ impl Deref for FloatRegisters { type Target = [u8]; fn deref(&self) -> &[u8] { unsafe { - slice::from_raw_parts(self as *const FloatRegisters as *const u8, mem::size_of::()) + slice::from_raw_parts( + self as *const FloatRegisters as *const u8, + mem::size_of::(), + ) } } } @@ -119,7 +121,10 @@ impl Deref for FloatRegisters { impl DerefMut for FloatRegisters { fn deref_mut(&mut self) -> &mut [u8] { unsafe { - slice::from_raw_parts_mut(self as *mut FloatRegisters as *mut u8, mem::size_of::()) + slice::from_raw_parts_mut( + self as *mut FloatRegisters as *mut u8, + mem::size_of::(), + ) } } } @@ -134,7 +139,10 @@ impl Deref for EnvRegisters { type Target = [u8]; fn deref(&self) -> &[u8] { unsafe { - slice::from_raw_parts(self as *const EnvRegisters as *const u8, mem::size_of::()) + slice::from_raw_parts( + self as *const EnvRegisters as *const u8, + mem::size_of::(), + ) } } } @@ -142,7 +150,10 @@ impl Deref for EnvRegisters { impl DerefMut for EnvRegisters { fn deref_mut(&mut self) -> &mut [u8] { unsafe { - slice::from_raw_parts_mut(self as *mut EnvRegisters as *mut u8, mem::size_of::()) + slice::from_raw_parts_mut( + self as *mut EnvRegisters as *mut u8, + mem::size_of::(), + ) } } } diff --git a/src/call.rs b/src/call.rs index 4710c70bd0..4dd79f6b73 100644 --- a/src/call.rs +++ b/src/call.rs @@ -1,8 +1,10 @@ -use super::arch::*; -use super::data::{Map, Stat, StatVfs, TimeSpec}; -use super::error::Result; -use super::flag::*; -use super::number::*; +use super::{ + arch::*, + data::{Map, Stat, StatVfs, TimeSpec}, + error::Result, + flag::*, + number::*, +}; use core::mem; @@ -34,13 +36,11 @@ pub fn exit(status: usize) -> Result { /// Change file permissions pub fn fchmod(fd: usize, mode: u16) -> Result { unsafe { syscall2(SYS_FCHMOD, fd, mode as usize) } - } /// Change file ownership pub fn fchown(fd: usize, uid: u32, gid: u32) -> Result { unsafe { syscall3(SYS_FCHOWN, fd, uid as usize, gid as usize) } - } /// Change file descriptor flags @@ -59,7 +59,12 @@ pub fn fcntl(fd: usize, cmd: usize, arg: usize) -> Result { /// `EEXIST` - if [`MapFlags::MAP_FIXED`] was set, and the address specified was already in use. /// pub unsafe fn fmap(fd: usize, map: &Map) -> Result { - syscall3(SYS_FMAP, fd, map as *const Map as usize, mem::size_of::()) + syscall3( + SYS_FMAP, + fd, + map as *const Map as usize, + mem::size_of::(), + ) } /// Unmap whole (or partial) continous memory-mapped files @@ -74,17 +79,38 @@ pub fn fpath(fd: usize, buf: &mut [u8]) -> Result { /// Rename a file pub fn frename>(fd: usize, path: T) -> Result { - unsafe { syscall3(SYS_FRENAME, fd, path.as_ref().as_ptr() as usize, path.as_ref().len()) } + unsafe { + syscall3( + SYS_FRENAME, + fd, + path.as_ref().as_ptr() as usize, + path.as_ref().len(), + ) + } } /// Get metadata about a file pub fn fstat(fd: usize, stat: &mut Stat) -> Result { - unsafe { syscall3(SYS_FSTAT, fd, stat as *mut Stat as usize, mem::size_of::()) } + unsafe { + syscall3( + SYS_FSTAT, + fd, + stat as *mut Stat as usize, + mem::size_of::(), + ) + } } /// Get metadata about a filesystem pub fn fstatvfs(fd: usize, stat: &mut StatVfs) -> Result { - unsafe { syscall3(SYS_FSTATVFS, fd, stat as *mut StatVfs as usize, mem::size_of::()) } + unsafe { + syscall3( + SYS_FSTATVFS, + fd, + stat as *mut StatVfs as usize, + mem::size_of::(), + ) + } } /// Sync a file descriptor to its underlying medium @@ -99,13 +125,32 @@ pub fn ftruncate(fd: usize, len: usize) -> Result { // Change modify and/or access times pub fn futimens(fd: usize, times: &[TimeSpec]) -> Result { - unsafe { syscall3(SYS_FUTIMENS, fd, times.as_ptr() as usize, times.len() * mem::size_of::()) } + unsafe { + syscall3( + SYS_FUTIMENS, + fd, + times.as_ptr() as usize, + times.len() * mem::size_of::(), + ) + } } /// Fast userspace mutex -pub unsafe fn futex(addr: *mut i32, op: usize, val: i32, val2: usize, addr2: *mut i32) - -> Result { - syscall5(SYS_FUTEX, addr as usize, op, (val as isize) as usize, val2, addr2 as usize) +pub unsafe fn futex( + addr: *mut i32, + op: usize, + val: i32, + val2: usize, + addr2: *mut i32, +) -> Result { + syscall5( + SYS_FUTEX, + addr as usize, + op, + (val as isize) as usize, + val2, + addr2 as usize, + ) } /// Get the effective group ID @@ -190,13 +235,25 @@ pub unsafe fn mprotect(addr: usize, size: usize, flags: MapFlags) -> Result Result { - unsafe { syscall2(SYS_NANOSLEEP, req as *const TimeSpec as usize, - rem as *mut TimeSpec as usize) } + unsafe { + syscall2( + SYS_NANOSLEEP, + req as *const TimeSpec as usize, + rem as *mut TimeSpec as usize, + ) + } } /// Open a file pub fn open>(path: T, flags: usize) -> Result { - unsafe { syscall3(SYS_OPEN, path.as_ref().as_ptr() as usize, path.as_ref().len(), flags) } + unsafe { + syscall3( + SYS_OPEN, + path.as_ref().as_ptr() as usize, + path.as_ref().len(), + flags, + ) + } } /// Read from a file descriptor into a buffer @@ -206,7 +263,13 @@ pub fn read(fd: usize, buf: &mut [u8]) -> Result { /// Remove a directory pub fn rmdir>(path: T) -> Result { - unsafe { syscall2(SYS_RMDIR, path.as_ref().as_ptr() as usize, path.as_ref().len()) } + unsafe { + syscall2( + SYS_RMDIR, + path.as_ref().as_ptr() as usize, + path.as_ref().len(), + ) + } } /// Set the process group ID @@ -236,7 +299,13 @@ pub fn umask(mask: usize) -> Result { /// Remove a file pub fn unlink>(path: T) -> Result { - unsafe { syscall2(SYS_UNLINK, path.as_ref().as_ptr() as usize, path.as_ref().len()) } + unsafe { + syscall2( + SYS_UNLINK, + path.as_ref().as_ptr() as usize, + path.as_ref().len(), + ) + } } /// Convert a virtual address to a physical one @@ -250,7 +319,14 @@ pub unsafe fn virttophys(virtual_address: usize) -> Result { /// Check if a child process has exited or received a signal pub fn waitpid(pid: usize, status: &mut usize, options: WaitFlags) -> Result { - unsafe { syscall3(SYS_WAITPID, pid, status as *mut usize as usize, options.bits()) } + unsafe { + syscall3( + SYS_WAITPID, + pid, + status as *mut usize as usize, + options.bits(), + ) + } } /// Write a buffer to a file descriptor @@ -285,7 +361,14 @@ pub fn sched_yield() -> Result { pub fn sendfd(receiver_socket: usize, fd: usize, flags: usize, arg: u64) -> Result { #[cfg(target_pointer_width = "32")] unsafe { - syscall5(SYS_SENDFD, receiver_socket, fd, flags, arg as u32 as usize, (arg >> 32) as u32 as usize) + syscall5( + SYS_SENDFD, + receiver_socket, + fd, + flags, + arg as u32 as usize, + (arg >> 32) as u32 as usize, + ) } #[cfg(target_pointer_width = "64")] diff --git a/src/error.rs b/src/error.rs index 83779a5723..1fe9987a82 100644 --- a/src/error.rs +++ b/src/error.rs @@ -29,7 +29,10 @@ impl Error { } pub fn text(&self) -> &'static str { - STR_ERROR.get(self.errno as usize).map(|&x| x).unwrap_or("Unknown Error") + STR_ERROR + .get(self.errno as usize) + .map(|&x| x) + .unwrap_or("Unknown Error") } } @@ -54,105 +57,105 @@ impl From for std::io::Error { } } -pub const EPERM: i32 = 1; /* Operation not permitted */ -pub const ENOENT: i32 = 2; /* No such file or directory */ -pub const ESRCH: i32 = 3; /* No such process */ -pub const EINTR: i32 = 4; /* Interrupted system call */ -pub const EIO: i32 = 5; /* I/O error */ -pub const ENXIO: i32 = 6; /* No such device or address */ -pub const E2BIG: i32 = 7; /* Argument list too long */ -pub const ENOEXEC: i32 = 8; /* Exec format error */ -pub const EBADF: i32 = 9; /* Bad file number */ -pub const ECHILD: i32 = 10; /* No child processes */ -pub const EAGAIN: i32 = 11; /* Try again */ -pub const ENOMEM: i32 = 12; /* Out of memory */ -pub const EACCES: i32 = 13; /* Permission denied */ -pub const EFAULT: i32 = 14; /* Bad address */ -pub const ENOTBLK: i32 = 15; /* Block device required */ -pub const EBUSY: i32 = 16; /* Device or resource busy */ -pub const EEXIST: i32 = 17; /* File exists */ -pub const EXDEV: i32 = 18; /* Cross-device link */ -pub const ENODEV: i32 = 19; /* No such device */ -pub const ENOTDIR: i32 = 20; /* Not a directory */ -pub const EISDIR: i32 = 21; /* Is a directory */ -pub const EINVAL: i32 = 22; /* Invalid argument */ -pub const ENFILE: i32 = 23; /* File table overflow */ -pub const EMFILE: i32 = 24; /* Too many open files */ -pub const ENOTTY: i32 = 25; /* Not a typewriter */ -pub const ETXTBSY: i32 = 26; /* Text file busy */ -pub const EFBIG: i32 = 27; /* File too large */ -pub const ENOSPC: i32 = 28; /* No space left on device */ -pub const ESPIPE: i32 = 29; /* Illegal seek */ -pub const EROFS: i32 = 30; /* Read-only file system */ -pub const EMLINK: i32 = 31; /* Too many links */ -pub const EPIPE: i32 = 32; /* Broken pipe */ -pub const EDOM: i32 = 33; /* Math argument out of domain of func */ -pub const ERANGE: i32 = 34; /* Math result not representable */ -pub const EDEADLK: i32 = 35; /* Resource deadlock would occur */ -pub const ENAMETOOLONG: i32 = 36; /* File name too long */ -pub const ENOLCK: i32 = 37; /* No record locks available */ -pub const ENOSYS: i32 = 38; /* Function not implemented */ -pub const ENOTEMPTY: i32 = 39; /* Directory not empty */ -pub const ELOOP: i32 = 40; /* Too many symbolic links encountered */ -pub const EWOULDBLOCK: i32 = 41; /* Operation would block */ -pub const ENOMSG: i32 = 42; /* No message of desired type */ -pub const EIDRM: i32 = 43; /* Identifier removed */ -pub const ECHRNG: i32 = 44; /* Channel number out of range */ -pub const EL2NSYNC: i32 = 45; /* Level 2 not synchronized */ -pub const EL3HLT: i32 = 46; /* Level 3 halted */ -pub const EL3RST: i32 = 47; /* Level 3 reset */ -pub const ELNRNG: i32 = 48; /* Link number out of range */ -pub const EUNATCH: i32 = 49; /* Protocol driver not attached */ -pub const ENOCSI: i32 = 50; /* No CSI structure available */ -pub const EL2HLT: i32 = 51; /* Level 2 halted */ -pub const EBADE: i32 = 52; /* Invalid exchange */ -pub const EBADR: i32 = 53; /* Invalid request descriptor */ -pub const EXFULL: i32 = 54; /* Exchange full */ -pub const ENOANO: i32 = 55; /* No anode */ -pub const EBADRQC: i32 = 56; /* Invalid request code */ -pub const EBADSLT: i32 = 57; /* Invalid slot */ +pub const EPERM: i32 = 1; /* Operation not permitted */ +pub const ENOENT: i32 = 2; /* No such file or directory */ +pub const ESRCH: i32 = 3; /* No such process */ +pub const EINTR: i32 = 4; /* Interrupted system call */ +pub const EIO: i32 = 5; /* I/O error */ +pub const ENXIO: i32 = 6; /* No such device or address */ +pub const E2BIG: i32 = 7; /* Argument list too long */ +pub const ENOEXEC: i32 = 8; /* Exec format error */ +pub const EBADF: i32 = 9; /* Bad file number */ +pub const ECHILD: i32 = 10; /* No child processes */ +pub const EAGAIN: i32 = 11; /* Try again */ +pub const ENOMEM: i32 = 12; /* Out of memory */ +pub const EACCES: i32 = 13; /* Permission denied */ +pub const EFAULT: i32 = 14; /* Bad address */ +pub const ENOTBLK: i32 = 15; /* Block device required */ +pub const EBUSY: i32 = 16; /* Device or resource busy */ +pub const EEXIST: i32 = 17; /* File exists */ +pub const EXDEV: i32 = 18; /* Cross-device link */ +pub const ENODEV: i32 = 19; /* No such device */ +pub const ENOTDIR: i32 = 20; /* Not a directory */ +pub const EISDIR: i32 = 21; /* Is a directory */ +pub const EINVAL: i32 = 22; /* Invalid argument */ +pub const ENFILE: i32 = 23; /* File table overflow */ +pub const EMFILE: i32 = 24; /* Too many open files */ +pub const ENOTTY: i32 = 25; /* Not a typewriter */ +pub const ETXTBSY: i32 = 26; /* Text file busy */ +pub const EFBIG: i32 = 27; /* File too large */ +pub const ENOSPC: i32 = 28; /* No space left on device */ +pub const ESPIPE: i32 = 29; /* Illegal seek */ +pub const EROFS: i32 = 30; /* Read-only file system */ +pub const EMLINK: i32 = 31; /* Too many links */ +pub const EPIPE: i32 = 32; /* Broken pipe */ +pub const EDOM: i32 = 33; /* Math argument out of domain of func */ +pub const ERANGE: i32 = 34; /* Math result not representable */ +pub const EDEADLK: i32 = 35; /* Resource deadlock would occur */ +pub const ENAMETOOLONG: i32 = 36; /* File name too long */ +pub const ENOLCK: i32 = 37; /* No record locks available */ +pub const ENOSYS: i32 = 38; /* Function not implemented */ +pub const ENOTEMPTY: i32 = 39; /* Directory not empty */ +pub const ELOOP: i32 = 40; /* Too many symbolic links encountered */ +pub const EWOULDBLOCK: i32 = 41; /* Operation would block */ +pub const ENOMSG: i32 = 42; /* No message of desired type */ +pub const EIDRM: i32 = 43; /* Identifier removed */ +pub const ECHRNG: i32 = 44; /* Channel number out of range */ +pub const EL2NSYNC: i32 = 45; /* Level 2 not synchronized */ +pub const EL3HLT: i32 = 46; /* Level 3 halted */ +pub const EL3RST: i32 = 47; /* Level 3 reset */ +pub const ELNRNG: i32 = 48; /* Link number out of range */ +pub const EUNATCH: i32 = 49; /* Protocol driver not attached */ +pub const ENOCSI: i32 = 50; /* No CSI structure available */ +pub const EL2HLT: i32 = 51; /* Level 2 halted */ +pub const EBADE: i32 = 52; /* Invalid exchange */ +pub const EBADR: i32 = 53; /* Invalid request descriptor */ +pub const EXFULL: i32 = 54; /* Exchange full */ +pub const ENOANO: i32 = 55; /* No anode */ +pub const EBADRQC: i32 = 56; /* Invalid request code */ +pub const EBADSLT: i32 = 57; /* Invalid slot */ pub const EDEADLOCK: i32 = 58; /* Resource deadlock would occur */ -pub const EBFONT: i32 = 59; /* Bad font file format */ -pub const ENOSTR: i32 = 60; /* Device not a stream */ -pub const ENODATA: i32 = 61; /* No data available */ -pub const ETIME: i32 = 62; /* Timer expired */ -pub const ENOSR: i32 = 63; /* Out of streams resources */ -pub const ENONET: i32 = 64; /* Machine is not on the network */ -pub const ENOPKG: i32 = 65; /* Package not installed */ -pub const EREMOTE: i32 = 66; /* Object is remote */ -pub const ENOLINK: i32 = 67; /* Link has been severed */ -pub const EADV: i32 = 68; /* Advertise error */ -pub const ESRMNT: i32 = 69; /* Srmount error */ -pub const ECOMM: i32 = 70; /* Communication error on send */ -pub const EPROTO: i32 = 71; /* Protocol error */ -pub const EMULTIHOP: i32 = 72; /* Multihop attempted */ -pub const EDOTDOT: i32 = 73; /* RFS specific error */ -pub const EBADMSG: i32 = 74; /* Not a data message */ -pub const EOVERFLOW: i32 = 75; /* Value too large for defined data type */ -pub const ENOTUNIQ: i32 = 76; /* Name not unique on network */ -pub const EBADFD: i32 = 77; /* File descriptor in bad state */ -pub const EREMCHG: i32 = 78; /* Remote address changed */ -pub const ELIBACC: i32 = 79; /* Can not access a needed shared library */ -pub const ELIBBAD: i32 = 80; /* Accessing a corrupted shared library */ -pub const ELIBSCN: i32 = 81; /* .lib section in a.out corrupted */ -pub const ELIBMAX: i32 = 82; /* Attempting to link in too many shared libraries */ -pub const ELIBEXEC: i32 = 83; /* Cannot exec a shared library directly */ -pub const EILSEQ: i32 = 84; /* Illegal byte sequence */ -pub const ERESTART: i32 = 85; /* Interrupted system call should be restarted */ -pub const ESTRPIPE: i32 = 86; /* Streams pipe error */ -pub const EUSERS: i32 = 87; /* Too many users */ -pub const ENOTSOCK: i32 = 88; /* Socket operation on non-socket */ -pub const EDESTADDRREQ: i32 = 89; /* Destination address required */ -pub const EMSGSIZE: i32 = 90; /* Message too long */ -pub const EPROTOTYPE: i32 = 91; /* Protocol wrong type for socket */ -pub const ENOPROTOOPT: i32 = 92; /* Protocol not available */ -pub const EPROTONOSUPPORT: i32 = 93; /* Protocol not supported */ -pub const ESOCKTNOSUPPORT: i32 = 94; /* Socket type not supported */ -pub const EOPNOTSUPP: i32 = 95; /* Operation not supported on transport endpoint */ -pub const EPFNOSUPPORT: i32 = 96; /* Protocol family not supported */ -pub const EAFNOSUPPORT: i32 = 97; /* Address family not supported by protocol */ -pub const EADDRINUSE: i32 = 98; /* Address already in use */ -pub const EADDRNOTAVAIL: i32 = 99; /* Cannot assign requested address */ +pub const EBFONT: i32 = 59; /* Bad font file format */ +pub const ENOSTR: i32 = 60; /* Device not a stream */ +pub const ENODATA: i32 = 61; /* No data available */ +pub const ETIME: i32 = 62; /* Timer expired */ +pub const ENOSR: i32 = 63; /* Out of streams resources */ +pub const ENONET: i32 = 64; /* Machine is not on the network */ +pub const ENOPKG: i32 = 65; /* Package not installed */ +pub const EREMOTE: i32 = 66; /* Object is remote */ +pub const ENOLINK: i32 = 67; /* Link has been severed */ +pub const EADV: i32 = 68; /* Advertise error */ +pub const ESRMNT: i32 = 69; /* Srmount error */ +pub const ECOMM: i32 = 70; /* Communication error on send */ +pub const EPROTO: i32 = 71; /* Protocol error */ +pub const EMULTIHOP: i32 = 72; /* Multihop attempted */ +pub const EDOTDOT: i32 = 73; /* RFS specific error */ +pub const EBADMSG: i32 = 74; /* Not a data message */ +pub const EOVERFLOW: i32 = 75; /* Value too large for defined data type */ +pub const ENOTUNIQ: i32 = 76; /* Name not unique on network */ +pub const EBADFD: i32 = 77; /* File descriptor in bad state */ +pub const EREMCHG: i32 = 78; /* Remote address changed */ +pub const ELIBACC: i32 = 79; /* Can not access a needed shared library */ +pub const ELIBBAD: i32 = 80; /* Accessing a corrupted shared library */ +pub const ELIBSCN: i32 = 81; /* .lib section in a.out corrupted */ +pub const ELIBMAX: i32 = 82; /* Attempting to link in too many shared libraries */ +pub const ELIBEXEC: i32 = 83; /* Cannot exec a shared library directly */ +pub const EILSEQ: i32 = 84; /* Illegal byte sequence */ +pub const ERESTART: i32 = 85; /* Interrupted system call should be restarted */ +pub const ESTRPIPE: i32 = 86; /* Streams pipe error */ +pub const EUSERS: i32 = 87; /* Too many users */ +pub const ENOTSOCK: i32 = 88; /* Socket operation on non-socket */ +pub const EDESTADDRREQ: i32 = 89; /* Destination address required */ +pub const EMSGSIZE: i32 = 90; /* Message too long */ +pub const EPROTOTYPE: i32 = 91; /* Protocol wrong type for socket */ +pub const ENOPROTOOPT: i32 = 92; /* Protocol not available */ +pub const EPROTONOSUPPORT: i32 = 93; /* Protocol not supported */ +pub const ESOCKTNOSUPPORT: i32 = 94; /* Socket type not supported */ +pub const EOPNOTSUPP: i32 = 95; /* Operation not supported on transport endpoint */ +pub const EPFNOSUPPORT: i32 = 96; /* Protocol family not supported */ +pub const EAFNOSUPPORT: i32 = 97; /* Address family not supported by protocol */ +pub const EADDRINUSE: i32 = 98; /* Address already in use */ +pub const EADDRNOTAVAIL: i32 = 99; /* Cannot assign requested address */ pub const ENETDOWN: i32 = 100; /* Network is down */ pub const ENETUNREACH: i32 = 101; /* Network is unreachable */ pub const ENETRESET: i32 = 102; /* Network dropped connection because of reset */ @@ -187,136 +190,138 @@ pub const EOWNERDEAD: i32 = 130; /* Owner died */ pub const ENOTRECOVERABLE: i32 = 131; /* State not recoverable */ pub const ESKMSG: i32 = 132; /* Scheme-kernel message code */ -pub static STR_ERROR: [&'static str; 133] = ["Success", - "Operation not permitted", - "No such file or directory", - "No such process", - "Interrupted system call", - "I/O error", - "No such device or address", - "Argument list too long", - "Exec format error", - "Bad file number", - "No child processes", - "Try again", - "Out of memory", - "Permission denied", - "Bad address", - "Block device required", - "Device or resource busy", - "File exists", - "Cross-device link", - "No such device", - "Not a directory", - "Is a directory", - "Invalid argument", - "File table overflow", - "Too many open files", - "Not a typewriter", - "Text file busy", - "File too large", - "No space left on device", - "Illegal seek", - "Read-only file system", - "Too many links", - "Broken pipe", - "Math argument out of domain of func", - "Math result not representable", - "Resource deadlock would occur", - "File name too long", - "No record locks available", - "Function not implemented", - "Directory not empty", - "Too many symbolic links encountered", - "Operation would block", - "No message of desired type", - "Identifier removed", - "Channel number out of range", - "Level 2 not synchronized", - "Level 3 halted", - "Level 3 reset", - "Link number out of range", - "Protocol driver not attached", - "No CSI structure available", - "Level 2 halted", - "Invalid exchange", - "Invalid request descriptor", - "Exchange full", - "No anode", - "Invalid request code", - "Invalid slot", - "Resource deadlock would occur", - "Bad font file format", - "Device not a stream", - "No data available", - "Timer expired", - "Out of streams resources", - "Machine is not on the network", - "Package not installed", - "Object is remote", - "Link has been severed", - "Advertise error", - "Srmount error", - "Communication error on send", - "Protocol error", - "Multihop attempted", - "RFS specific error", - "Not a data message", - "Value too large for defined data type", - "Name not unique on network", - "File descriptor in bad state", - "Remote address changed", - "Can not access a needed shared library", - "Accessing a corrupted shared library", - ".lib section in a.out corrupted", - "Attempting to link in too many shared libraries", - "Cannot exec a shared library directly", - "Illegal byte sequence", - "Interrupted system call should be restarted", - "Streams pipe error", - "Too many users", - "Socket operation on non-socket", - "Destination address required", - "Message too long", - "Protocol wrong type for socket", - "Protocol not available", - "Protocol not supported", - "Socket type not supported", - "Operation not supported on transport endpoint", - "Protocol family not supported", - "Address family not supported by protocol", - "Address already in use", - "Cannot assign requested address", - "Network is down", - "Network is unreachable", - "Network dropped connection because of reset", - "Software caused connection abort", - "Connection reset by peer", - "No buffer space available", - "Transport endpoint is already connected", - "Transport endpoint is not connected", - "Cannot send after transport endpoint shutdown", - "Too many references: cannot splice", - "Connection timed out", - "Connection refused", - "Host is down", - "No route to host", - "Operation already in progress", - "Operation now in progress", - "Stale NFS file handle", - "Structure needs cleaning", - "Not a XENIX named type file", - "No XENIX semaphores available", - "Is a named type file", - "Remote I/O error", - "Quota exceeded", - "No medium found", - "Wrong medium type", - "Operation Canceled", - "Required key not available", - "Key has expired", - "Key has been revoked", - "Key was rejected by service", - "Owner died", - "State not recoverable", - "Scheme-kernel message code"]; +pub static STR_ERROR: [&'static str; 133] = [ + "Success", + "Operation not permitted", + "No such file or directory", + "No such process", + "Interrupted system call", + "I/O error", + "No such device or address", + "Argument list too long", + "Exec format error", + "Bad file number", + "No child processes", + "Try again", + "Out of memory", + "Permission denied", + "Bad address", + "Block device required", + "Device or resource busy", + "File exists", + "Cross-device link", + "No such device", + "Not a directory", + "Is a directory", + "Invalid argument", + "File table overflow", + "Too many open files", + "Not a typewriter", + "Text file busy", + "File too large", + "No space left on device", + "Illegal seek", + "Read-only file system", + "Too many links", + "Broken pipe", + "Math argument out of domain of func", + "Math result not representable", + "Resource deadlock would occur", + "File name too long", + "No record locks available", + "Function not implemented", + "Directory not empty", + "Too many symbolic links encountered", + "Operation would block", + "No message of desired type", + "Identifier removed", + "Channel number out of range", + "Level 2 not synchronized", + "Level 3 halted", + "Level 3 reset", + "Link number out of range", + "Protocol driver not attached", + "No CSI structure available", + "Level 2 halted", + "Invalid exchange", + "Invalid request descriptor", + "Exchange full", + "No anode", + "Invalid request code", + "Invalid slot", + "Resource deadlock would occur", + "Bad font file format", + "Device not a stream", + "No data available", + "Timer expired", + "Out of streams resources", + "Machine is not on the network", + "Package not installed", + "Object is remote", + "Link has been severed", + "Advertise error", + "Srmount error", + "Communication error on send", + "Protocol error", + "Multihop attempted", + "RFS specific error", + "Not a data message", + "Value too large for defined data type", + "Name not unique on network", + "File descriptor in bad state", + "Remote address changed", + "Can not access a needed shared library", + "Accessing a corrupted shared library", + ".lib section in a.out corrupted", + "Attempting to link in too many shared libraries", + "Cannot exec a shared library directly", + "Illegal byte sequence", + "Interrupted system call should be restarted", + "Streams pipe error", + "Too many users", + "Socket operation on non-socket", + "Destination address required", + "Message too long", + "Protocol wrong type for socket", + "Protocol not available", + "Protocol not supported", + "Socket type not supported", + "Operation not supported on transport endpoint", + "Protocol family not supported", + "Address family not supported by protocol", + "Address already in use", + "Cannot assign requested address", + "Network is down", + "Network is unreachable", + "Network dropped connection because of reset", + "Software caused connection abort", + "Connection reset by peer", + "No buffer space available", + "Transport endpoint is already connected", + "Transport endpoint is not connected", + "Cannot send after transport endpoint shutdown", + "Too many references: cannot splice", + "Connection timed out", + "Connection refused", + "Host is down", + "No route to host", + "Operation already in progress", + "Operation now in progress", + "Stale NFS file handle", + "Structure needs cleaning", + "Not a XENIX named type file", + "No XENIX semaphores available", + "Is a named type file", + "Remote I/O error", + "Quota exceeded", + "No medium found", + "Wrong medium type", + "Operation Canceled", + "Required key not available", + "Key has expired", + "Key has been revoked", + "Key was rejected by service", + "Owner died", + "State not recoverable", + "Scheme-kernel message code", +]; diff --git a/src/flag.rs b/src/flag.rs index 13f62e2103..6f7a6a44d0 100644 --- a/src/flag.rs +++ b/src/flag.rs @@ -149,24 +149,24 @@ pub const MODE_PERM: u16 = 0x0FFF; pub const MODE_SETUID: u16 = 0o4000; pub const MODE_SETGID: u16 = 0o2000; -pub const O_RDONLY: usize = 0x0001_0000; -pub const O_WRONLY: usize = 0x0002_0000; -pub const O_RDWR: usize = 0x0003_0000; -pub const O_NONBLOCK: usize = 0x0004_0000; -pub const O_APPEND: usize = 0x0008_0000; -pub const O_SHLOCK: usize = 0x0010_0000; -pub const O_EXLOCK: usize = 0x0020_0000; -pub const O_ASYNC: usize = 0x0040_0000; -pub const O_FSYNC: usize = 0x0080_0000; -pub const O_CLOEXEC: usize = 0x0100_0000; -pub const O_CREAT: usize = 0x0200_0000; -pub const O_TRUNC: usize = 0x0400_0000; -pub const O_EXCL: usize = 0x0800_0000; -pub const O_DIRECTORY: usize = 0x1000_0000; -pub const O_STAT: usize = 0x2000_0000; -pub const O_SYMLINK: usize = 0x4000_0000; -pub const O_NOFOLLOW: usize = 0x8000_0000; -pub const O_ACCMODE: usize = O_RDONLY | O_WRONLY | O_RDWR; +pub const O_RDONLY: usize = 0x0001_0000; +pub const O_WRONLY: usize = 0x0002_0000; +pub const O_RDWR: usize = 0x0003_0000; +pub const O_NONBLOCK: usize = 0x0004_0000; +pub const O_APPEND: usize = 0x0008_0000; +pub const O_SHLOCK: usize = 0x0010_0000; +pub const O_EXLOCK: usize = 0x0020_0000; +pub const O_ASYNC: usize = 0x0040_0000; +pub const O_FSYNC: usize = 0x0080_0000; +pub const O_CLOEXEC: usize = 0x0100_0000; +pub const O_CREAT: usize = 0x0200_0000; +pub const O_TRUNC: usize = 0x0400_0000; +pub const O_EXCL: usize = 0x0800_0000; +pub const O_DIRECTORY: usize = 0x1000_0000; +pub const O_STAT: usize = 0x2000_0000; +pub const O_SYMLINK: usize = 0x4000_0000; +pub const O_NOFOLLOW: usize = 0x8000_0000; +pub const O_ACCMODE: usize = O_RDONLY | O_WRONLY | O_RDWR; // The top 48 bits of PTRACE_* are reserved, for now @@ -213,10 +213,7 @@ impl Deref for PtraceFlags { fn deref(&self) -> &Self::Target { // Same as to_ne_bytes but in-place unsafe { - slice::from_raw_parts( - &self.bits() as *const _ as *const u8, - mem::size_of::() - ) + slice::from_raw_parts(&self.bits() as *const _ as *const u8, mem::size_of::()) } } } @@ -225,37 +222,37 @@ pub const SEEK_SET: usize = 0; pub const SEEK_CUR: usize = 1; pub const SEEK_END: usize = 2; -pub const SIGHUP: usize = 1; -pub const SIGINT: usize = 2; -pub const SIGQUIT: usize = 3; -pub const SIGILL: usize = 4; -pub const SIGTRAP: usize = 5; -pub const SIGABRT: usize = 6; -pub const SIGBUS: usize = 7; -pub const SIGFPE: usize = 8; -pub const SIGKILL: usize = 9; -pub const SIGUSR1: usize = 10; -pub const SIGSEGV: usize = 11; -pub const SIGUSR2: usize = 12; -pub const SIGPIPE: usize = 13; -pub const SIGALRM: usize = 14; -pub const SIGTERM: usize = 15; -pub const SIGSTKFLT: usize= 16; -pub const SIGCHLD: usize = 17; -pub const SIGCONT: usize = 18; -pub const SIGSTOP: usize = 19; -pub const SIGTSTP: usize = 20; -pub const SIGTTIN: usize = 21; -pub const SIGTTOU: usize = 22; -pub const SIGURG: usize = 23; -pub const SIGXCPU: usize = 24; -pub const SIGXFSZ: usize = 25; -pub const SIGVTALRM: usize= 26; -pub const SIGPROF: usize = 27; +pub const SIGHUP: usize = 1; +pub const SIGINT: usize = 2; +pub const SIGQUIT: usize = 3; +pub const SIGILL: usize = 4; +pub const SIGTRAP: usize = 5; +pub const SIGABRT: usize = 6; +pub const SIGBUS: usize = 7; +pub const SIGFPE: usize = 8; +pub const SIGKILL: usize = 9; +pub const SIGUSR1: usize = 10; +pub const SIGSEGV: usize = 11; +pub const SIGUSR2: usize = 12; +pub const SIGPIPE: usize = 13; +pub const SIGALRM: usize = 14; +pub const SIGTERM: usize = 15; +pub const SIGSTKFLT: usize = 16; +pub const SIGCHLD: usize = 17; +pub const SIGCONT: usize = 18; +pub const SIGSTOP: usize = 19; +pub const SIGTSTP: usize = 20; +pub const SIGTTIN: usize = 21; +pub const SIGTTOU: usize = 22; +pub const SIGURG: usize = 23; +pub const SIGXCPU: usize = 24; +pub const SIGXFSZ: usize = 25; +pub const SIGVTALRM: usize = 26; +pub const SIGPROF: usize = 27; pub const SIGWINCH: usize = 28; -pub const SIGIO: usize = 29; -pub const SIGPWR: usize = 30; -pub const SIGSYS: usize = 31; +pub const SIGIO: usize = 29; +pub const SIGPWR: usize = 30; +pub const SIGSYS: usize = 31; bitflags! { pub struct WaitFlags: usize { diff --git a/src/io/io.rs b/src/io/io.rs index 2c4acd3883..977bd1caec 100644 --- a/src/io/io.rs +++ b/src/io/io.rs @@ -1,14 +1,20 @@ -use core::cmp::PartialEq; -use core::ops::{BitAnd, BitOr, Not}; +use core::{ + cmp::PartialEq, + ops::{BitAnd, BitOr, Not}, +}; pub trait Io { - type Value: Copy + PartialEq + BitAnd + BitOr + Not; + type Value: Copy + + PartialEq + + BitAnd + + BitOr + + Not; fn read(&self) -> Self::Value; fn write(&mut self, value: Self::Value); #[inline(always)] - fn readf(&self, flags: Self::Value) -> bool { + fn readf(&self, flags: Self::Value) -> bool { (self.read() & flags) as Self::Value == flags } @@ -23,14 +29,12 @@ pub trait Io { } pub struct ReadOnly { - inner: I + inner: I, } impl ReadOnly { pub const fn new(inner: I) -> ReadOnly { - ReadOnly { - inner: inner - } + ReadOnly { inner: inner } } } @@ -47,14 +51,12 @@ impl ReadOnly { } pub struct WriteOnly { - inner: I + inner: I, } impl WriteOnly { pub const fn new(inner: I) -> WriteOnly { - WriteOnly { - inner: inner - } + WriteOnly { inner: inner } } } diff --git a/src/io/mmio.rs b/src/io/mmio.rs index ef8f603911..1af643fa13 100644 --- a/src/io/mmio.rs +++ b/src/io/mmio.rs @@ -1,7 +1,6 @@ -use core::mem::MaybeUninit; -use core::ptr; #[cfg(not(any(target_arch = "x86", target_arch = "x86_64")))] use core::ops::{BitAnd, BitOr, Not}; +use core::{mem::MaybeUninit, ptr}; use super::io::Io; @@ -35,7 +34,10 @@ impl Mmio { // Generic implementation (WARNING: requires aligned pointers!) #[cfg(not(any(target_arch = "x86", target_arch = "x86_64")))] -impl Io for Mmio where T: Copy + PartialEq + BitAnd + BitOr + Not { +impl Io for Mmio +where + T: Copy + PartialEq + BitAnd + BitOr + Not, +{ type Value = T; fn read(&self) -> T { diff --git a/src/io/mod.rs b/src/io/mod.rs index 4661c5e26c..66ce6b7b5f 100644 --- a/src/io/mod.rs +++ b/src/io/mod.rs @@ -1,7 +1,6 @@ //! I/O functions -pub use self::io::*; -pub use self::mmio::*; +pub use self::{io::*, mmio::*}; #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] pub use self::pio::*; diff --git a/src/io/pio.rs b/src/io/pio.rs index 8b837bcdf1..76bd24c57e 100644 --- a/src/io/pio.rs +++ b/src/io/pio.rs @@ -1,5 +1,4 @@ -use core::arch::asm; -use core::marker::PhantomData; +use core::{arch::asm, marker::PhantomData}; use super::io::Io; diff --git a/src/lib.rs b/src/lib.rs index 4109c98c4a..aa1b2be97f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -4,36 +4,30 @@ #[cfg(test)] extern crate core; -pub use self::arch::*; -pub use self::call::*; -pub use self::data::*; -pub use self::error::*; -pub use self::flag::*; -pub use self::io::*; -pub use self::number::*; +pub use self::{arch::*, call::*, data::*, error::*, flag::*, io::*, number::*}; #[cfg(all(any(target_os = "none", target_os = "redox"), target_arch = "arm"))] -#[path="arch/nonredox.rs"] +#[path = "arch/nonredox.rs"] mod arch; #[cfg(all(any(target_os = "none", target_os = "redox"), target_arch = "aarch64"))] -#[path="arch/aarch64.rs"] +#[path = "arch/aarch64.rs"] mod arch; #[cfg(all(any(target_os = "none", target_os = "redox"), target_arch = "riscv64"))] -#[path="arch/riscv64.rs"] +#[path = "arch/riscv64.rs"] mod arch; #[cfg(all(any(target_os = "none", target_os = "redox"), target_arch = "x86"))] -#[path="arch/x86.rs"] +#[path = "arch/x86.rs"] mod arch; #[cfg(all(any(target_os = "none", target_os = "redox"), target_arch = "x86_64"))] -#[path="arch/x86_64.rs"] +#[path = "arch/x86_64.rs"] mod arch; #[cfg(not(any(target_os = "none", target_os = "redox")))] -#[path="arch/nonredox.rs"] +#[path = "arch/nonredox.rs"] mod arch; /// Function definitions diff --git a/src/number.rs b/src/number.rs index 136dcbe130..737cca61d3 100644 --- a/src/number.rs +++ b/src/number.rs @@ -1,51 +1,51 @@ -pub const SYS_CLASS: usize = 0xF000_0000; -pub const SYS_CLASS_PATH: usize=0x1000_0000; -pub const SYS_CLASS_FILE: usize=0x2000_0000; +pub const SYS_CLASS: usize = 0xF000_0000; +pub const SYS_CLASS_PATH: usize = 0x1000_0000; +pub const SYS_CLASS_FILE: usize = 0x2000_0000; -pub const SYS_ARG: usize = 0x0F00_0000; -pub const SYS_ARG_SLICE: usize =0x0100_0000; -pub const SYS_ARG_MSLICE: usize=0x0200_0000; +pub const SYS_ARG: usize = 0x0F00_0000; +pub const SYS_ARG_SLICE: usize = 0x0100_0000; +pub const SYS_ARG_MSLICE: usize = 0x0200_0000; pub const SYS_ARG_PATH: usize = 0x0300_0000; -pub const SYS_RET: usize = 0x00F0_0000; +pub const SYS_RET: usize = 0x00F0_0000; pub const SYS_RET_FILE: usize = 0x0010_0000; -pub const SYS_LINK: usize = SYS_CLASS_PATH | SYS_ARG_PATH | 9; -pub const SYS_OPEN: usize = SYS_CLASS_PATH | SYS_RET_FILE | 5; -pub const SYS_RMDIR: usize = SYS_CLASS_PATH | 84; -pub const SYS_UNLINK: usize = SYS_CLASS_PATH | 10; +pub const SYS_LINK: usize = SYS_CLASS_PATH | SYS_ARG_PATH | 9; +pub const SYS_OPEN: usize = SYS_CLASS_PATH | SYS_RET_FILE | 5; +pub const SYS_RMDIR: usize = SYS_CLASS_PATH | 84; +pub const SYS_UNLINK: usize = SYS_CLASS_PATH | 10; -pub const SYS_CLOSE: usize = SYS_CLASS_FILE | 6; -pub const SYS_DUP: usize = SYS_CLASS_FILE | SYS_RET_FILE | 41; -pub const SYS_DUP2: usize = SYS_CLASS_FILE | SYS_RET_FILE | 63; -pub const SYS_READ: usize = SYS_CLASS_FILE | SYS_ARG_MSLICE | 3; -pub const SYS_READ2: usize = SYS_CLASS_FILE | SYS_ARG_MSLICE | 35; -pub const SYS_WRITE: usize = SYS_CLASS_FILE | SYS_ARG_SLICE | 4; -pub const SYS_WRITE2: usize = SYS_CLASS_FILE | SYS_ARG_SLICE | 45; -pub const SYS_LSEEK: usize = SYS_CLASS_FILE | 19; -pub const SYS_FCHMOD: usize = SYS_CLASS_FILE | 94; -pub const SYS_FCHOWN: usize = SYS_CLASS_FILE | 207; -pub const SYS_FCNTL: usize = SYS_CLASS_FILE | 55; -pub const SYS_FEVENT: usize = SYS_CLASS_FILE | 927; +pub const SYS_CLOSE: usize = SYS_CLASS_FILE | 6; +pub const SYS_DUP: usize = SYS_CLASS_FILE | SYS_RET_FILE | 41; +pub const SYS_DUP2: usize = SYS_CLASS_FILE | SYS_RET_FILE | 63; +pub const SYS_READ: usize = SYS_CLASS_FILE | SYS_ARG_MSLICE | 3; +pub const SYS_READ2: usize = SYS_CLASS_FILE | SYS_ARG_MSLICE | 35; +pub const SYS_WRITE: usize = SYS_CLASS_FILE | SYS_ARG_SLICE | 4; +pub const SYS_WRITE2: usize = SYS_CLASS_FILE | SYS_ARG_SLICE | 45; +pub const SYS_LSEEK: usize = SYS_CLASS_FILE | 19; +pub const SYS_FCHMOD: usize = SYS_CLASS_FILE | 94; +pub const SYS_FCHOWN: usize = SYS_CLASS_FILE | 207; +pub const SYS_FCNTL: usize = SYS_CLASS_FILE | 55; +pub const SYS_FEVENT: usize = SYS_CLASS_FILE | 927; -pub const SYS_SENDFD: usize = SYS_CLASS_FILE | 34; +pub const SYS_SENDFD: usize = SYS_CLASS_FILE | 34; // TODO: Rename FMAP/FUNMAP to MMAP/MUNMAP -pub const SYS_FMAP_OLD: usize = SYS_CLASS_FILE | SYS_ARG_SLICE | 90; -pub const SYS_FMAP: usize = SYS_CLASS_FILE | SYS_ARG_SLICE | 900; +pub const SYS_FMAP_OLD: usize = SYS_CLASS_FILE | SYS_ARG_SLICE | 90; +pub const SYS_FMAP: usize = SYS_CLASS_FILE | SYS_ARG_SLICE | 900; // TODO: SYS_FUNMAP should be SYS_CLASS_FILE // TODO: Remove FMAP/FMAP_OLD pub const SYS_FUNMAP_OLD: usize = SYS_CLASS_FILE | 91; -pub const SYS_FUNMAP: usize = SYS_CLASS_FILE | 92; +pub const SYS_FUNMAP: usize = SYS_CLASS_FILE | 92; pub const SYS_MREMAP: usize = 155; -pub const SYS_FPATH: usize = SYS_CLASS_FILE | SYS_ARG_MSLICE | 928; -pub const SYS_FRENAME: usize = SYS_CLASS_FILE | SYS_ARG_PATH | 38; -pub const SYS_FSTAT: usize = SYS_CLASS_FILE | SYS_ARG_MSLICE | 28; -pub const SYS_FSTATVFS: usize = SYS_CLASS_FILE | SYS_ARG_MSLICE | 100; -pub const SYS_FSYNC: usize = SYS_CLASS_FILE | 118; -pub const SYS_FTRUNCATE: usize = SYS_CLASS_FILE | 93; -pub const SYS_FUTIMENS: usize = SYS_CLASS_FILE | SYS_ARG_SLICE | 320; +pub const SYS_FPATH: usize = SYS_CLASS_FILE | SYS_ARG_MSLICE | 928; +pub const SYS_FRENAME: usize = SYS_CLASS_FILE | SYS_ARG_PATH | 38; +pub const SYS_FSTAT: usize = SYS_CLASS_FILE | SYS_ARG_MSLICE | 28; +pub const SYS_FSTATVFS: usize = SYS_CLASS_FILE | SYS_ARG_MSLICE | 100; +pub const SYS_FSYNC: usize = SYS_CLASS_FILE | 118; +pub const SYS_FTRUNCATE: usize = SYS_CLASS_FILE | 93; +pub const SYS_FUTIMENS: usize = SYS_CLASS_FILE | SYS_ARG_SLICE | 320; // b = file, c = flags, d = required_page_count, uid:gid = offset pub const KSMSG_MMAP: usize = SYS_CLASS_FILE | 72; @@ -63,27 +63,27 @@ pub const KSMSG_MMAP_PREP: usize = SYS_CLASS_FILE | 75; pub const KSMSG_CANCEL: usize = SYS_CLASS_FILE | 76; pub const SYS_CLOCK_GETTIME: usize = 265; -pub const SYS_EXIT: usize = 1; -pub const SYS_FUTEX: usize = 240; -pub const SYS_GETEGID: usize = 202; -pub const SYS_GETENS: usize = 951; -pub const SYS_GETEUID: usize = 201; -pub const SYS_GETGID: usize = 200; -pub const SYS_GETNS: usize = 950; -pub const SYS_GETPID: usize = 20; -pub const SYS_GETPGID: usize = 132; -pub const SYS_GETPPID: usize = 64; -pub const SYS_GETUID: usize = 199; -pub const SYS_IOPL: usize = 110; -pub const SYS_KILL: usize = 37; +pub const SYS_EXIT: usize = 1; +pub const SYS_FUTEX: usize = 240; +pub const SYS_GETEGID: usize = 202; +pub const SYS_GETENS: usize = 951; +pub const SYS_GETEUID: usize = 201; +pub const SYS_GETGID: usize = 200; +pub const SYS_GETNS: usize = 950; +pub const SYS_GETPID: usize = 20; +pub const SYS_GETPGID: usize = 132; +pub const SYS_GETPPID: usize = 64; +pub const SYS_GETUID: usize = 199; +pub const SYS_IOPL: usize = 110; +pub const SYS_KILL: usize = 37; pub const SYS_MPROTECT: usize = 125; -pub const SYS_MKNS: usize = 984; -pub const SYS_NANOSLEEP: usize =162; -pub const SYS_VIRTTOPHYS: usize=949; -pub const SYS_SETPGID: usize = 57; +pub const SYS_MKNS: usize = 984; +pub const SYS_NANOSLEEP: usize = 162; +pub const SYS_VIRTTOPHYS: usize = 949; +pub const SYS_SETPGID: usize = 57; pub const SYS_SETREGID: usize = 204; -pub const SYS_SETRENS: usize = 952; +pub const SYS_SETRENS: usize = 952; pub const SYS_SETREUID: usize = 203; -pub const SYS_UMASK: usize = 60; -pub const SYS_WAITPID: usize = 7; -pub const SYS_YIELD: usize = 158; +pub const SYS_UMASK: usize = 60; +pub const SYS_WAITPID: usize = 7; +pub const SYS_YIELD: usize = 158; diff --git a/src/scheme/mod.rs b/src/scheme/mod.rs index 61655dabf3..721a2c0e87 100644 --- a/src/scheme/mod.rs +++ b/src/scheme/mod.rs @@ -1,12 +1,11 @@ use core::{slice, str}; -use crate::{Error, Result, EOPNOTSUPP, ESKMSG, Packet, SKMSG_FRETURNFD}; +use crate::{Error, Packet, Result, EOPNOTSUPP, ESKMSG, SKMSG_FRETURNFD}; -pub use self::scheme::Scheme; -pub use self::scheme_mut::SchemeMut; -pub use self::scheme_block::SchemeBlock; -pub use self::scheme_block_mut::SchemeBlockMut; -pub use self::seek::*; +pub use self::{ + scheme::Scheme, scheme_block::SchemeBlock, scheme_block_mut::SchemeBlockMut, + scheme_mut::SchemeMut, seek::*, +}; unsafe fn str_from_raw_parts(ptr: *const u8, len: usize) -> Option<&'static str> { let slice = slice::from_raw_parts(ptr, len); @@ -14,9 +13,9 @@ unsafe fn str_from_raw_parts(ptr: *const u8, len: usize) -> Option<&'static str> } mod scheme; -mod scheme_mut; mod scheme_block; mod scheme_block_mut; +mod scheme_mut; mod seek; pub struct CallerCtx { @@ -37,7 +36,10 @@ pub(crate) fn convert_to_this_scheme(r: Result) -> Result { pub(crate) fn convert_to_this_scheme_block(r: Result>) -> Result> { r.map(|o| o.map(|number| OpenResult::ThisScheme { number })) } -pub(crate) fn convert_in_scheme_handle_block(_: &Packet, result: Result>) -> Result> { +pub(crate) fn convert_in_scheme_handle_block( + _: &Packet, + result: Result>, +) -> Result> { match result { Ok(Some(OpenResult::ThisScheme { number })) => Ok(Some(number)), Ok(Some(OpenResult::OtherScheme { .. })) => Err(Error::new(EOPNOTSUPP)), @@ -45,7 +47,10 @@ pub(crate) fn convert_in_scheme_handle_block(_: &Packet, result: Result Err(err), } } -pub(crate) fn convert_in_scheme_handle(packet: &mut Packet, result: Result) -> Result { +pub(crate) fn convert_in_scheme_handle( + packet: &mut Packet, + result: Result, +) -> Result { match result { Ok(OpenResult::ThisScheme { number }) => Ok(number), Ok(OpenResult::OtherScheme { fd }) => { diff --git a/src/scheme/scheme.rs b/src/scheme/scheme.rs index ee09d697bf..2e77eccc00 100644 --- a/src/scheme/scheme.rs +++ b/src/scheme/scheme.rs @@ -1,70 +1,112 @@ use core::{mem, slice}; -use crate::CallerCtx; -use crate::OpenResult; -use crate::data::*; -use crate::error::*; -use crate::flag::*; -use crate::number::*; -use crate::scheme::*; +use crate::{data::*, error::*, flag::*, number::*, scheme::*, CallerCtx, OpenResult}; pub trait Scheme { fn handle(&self, packet: &mut Packet) { let res = match packet.a { - SYS_OPEN => if let Some(path) = unsafe { str_from_raw_parts(packet.b as *const u8, packet.c) } { - convert_in_scheme_handle(packet, self.xopen(path, packet.d, &CallerCtx::from_packet(&packet))) + SYS_OPEN => { + if let Some(path) = unsafe { str_from_raw_parts(packet.b as *const u8, packet.c) } { + convert_in_scheme_handle( + packet, + self.xopen(path, packet.d, &CallerCtx::from_packet(&packet)), + ) + } else { + Err(Error::new(EINVAL)) + } + } + SYS_RMDIR => { + if let Some(path) = unsafe { str_from_raw_parts(packet.b as *const u8, packet.c) } { + self.rmdir(path, packet.uid, packet.gid) + } else { + Err(Error::new(EINVAL)) + } + } + SYS_UNLINK => { + if let Some(path) = unsafe { str_from_raw_parts(packet.b as *const u8, packet.c) } { + self.unlink(path, packet.uid, packet.gid) + } else { + Err(Error::new(EINVAL)) + } } - else { - Err(Error::new(EINVAL)) - }, - SYS_RMDIR => if let Some(path) = unsafe { str_from_raw_parts(packet.b as *const u8, packet.c) } { - self.rmdir(path, packet.uid, packet.gid) - } else { - Err(Error::new(EINVAL)) - }, - SYS_UNLINK => if let Some(path) = unsafe { str_from_raw_parts(packet.b as *const u8, packet.c) } { - self.unlink(path, packet.uid, packet.gid) - } else { - Err(Error::new(EINVAL)) - }, - SYS_DUP => convert_in_scheme_handle(packet, self.xdup(packet.b, unsafe { slice::from_raw_parts(packet.c as *const u8, packet.d) }, &CallerCtx::from_packet(&packet))), - SYS_READ => self.read(packet.b, unsafe { slice::from_raw_parts_mut(packet.c as *mut u8, packet.d) }), - SYS_WRITE => self.write(packet.b, unsafe { slice::from_raw_parts(packet.c as *const u8, packet.d) }), - SYS_LSEEK => self.seek(packet.b, packet.c as isize, packet.d).map(|o| o as usize), + SYS_DUP => convert_in_scheme_handle( + packet, + self.xdup( + packet.b, + unsafe { slice::from_raw_parts(packet.c as *const u8, packet.d) }, + &CallerCtx::from_packet(&packet), + ), + ), + SYS_READ => self.read(packet.b, unsafe { + slice::from_raw_parts_mut(packet.c as *mut u8, packet.d) + }), + SYS_WRITE => self.write(packet.b, unsafe { + slice::from_raw_parts(packet.c as *const u8, packet.d) + }), + SYS_LSEEK => self + .seek(packet.b, packet.c as isize, packet.d) + .map(|o| o as usize), SYS_FCHMOD => self.fchmod(packet.b, packet.c as u16), SYS_FCHOWN => self.fchown(packet.b, packet.c as u32, packet.d as u32), SYS_FCNTL => self.fcntl(packet.b, packet.c, packet.d), - SYS_FEVENT => self.fevent(packet.b, EventFlags::from_bits_truncate(packet.c)).map(|f| f.bits()), - SYS_FPATH => self.fpath(packet.b, unsafe { slice::from_raw_parts_mut(packet.c as *mut u8, packet.d) }), - SYS_FRENAME => if let Some(path) = unsafe { str_from_raw_parts(packet.c as *const u8, packet.d) } { - self.frename(packet.b, path, packet.uid, packet.gid) - } else { - Err(Error::new(EINVAL)) - }, - SYS_FSTAT => if packet.d >= mem::size_of::() { - self.fstat(packet.b, unsafe { &mut *(packet.c as *mut Stat) }) - } else { - Err(Error::new(EFAULT)) - }, - SYS_FSTATVFS => if packet.d >= mem::size_of::() { - self.fstatvfs(packet.b, unsafe { &mut *(packet.c as *mut StatVfs) }) - } else { - Err(Error::new(EFAULT)) - }, + SYS_FEVENT => self + .fevent(packet.b, EventFlags::from_bits_truncate(packet.c)) + .map(|f| f.bits()), + SYS_FPATH => self.fpath(packet.b, unsafe { + slice::from_raw_parts_mut(packet.c as *mut u8, packet.d) + }), + SYS_FRENAME => { + if let Some(path) = unsafe { str_from_raw_parts(packet.c as *const u8, packet.d) } { + self.frename(packet.b, path, packet.uid, packet.gid) + } else { + Err(Error::new(EINVAL)) + } + } + SYS_FSTAT => { + if packet.d >= mem::size_of::() { + self.fstat(packet.b, unsafe { &mut *(packet.c as *mut Stat) }) + } else { + Err(Error::new(EFAULT)) + } + } + SYS_FSTATVFS => { + if packet.d >= mem::size_of::() { + self.fstatvfs(packet.b, unsafe { &mut *(packet.c as *mut StatVfs) }) + } else { + Err(Error::new(EFAULT)) + } + } SYS_FSYNC => self.fsync(packet.b), SYS_FTRUNCATE => self.ftruncate(packet.b, packet.c), - SYS_FUTIMENS => if packet.d >= mem::size_of::() { - self.futimens(packet.b, unsafe { slice::from_raw_parts(packet.c as *const TimeSpec, packet.d / mem::size_of::()) }) - } else { - Err(Error::new(EFAULT)) - }, + SYS_FUTIMENS => { + if packet.d >= mem::size_of::() { + self.futimens(packet.b, unsafe { + slice::from_raw_parts( + packet.c as *const TimeSpec, + packet.d / mem::size_of::(), + ) + }) + } else { + Err(Error::new(EFAULT)) + } + } SYS_CLOSE => self.close(packet.b), - KSMSG_MMAP_PREP => self.mmap_prep(packet.b, u64::from(packet.uid) | (u64::from(packet.gid) << 32), packet.c, MapFlags::from_bits_truncate(packet.d)), - KSMSG_MUNMAP => self.munmap(packet.b, u64::from(packet.uid) | (u64::from(packet.gid) << 32), packet.c, MunmapFlags::from_bits_truncate(packet.d)), + KSMSG_MMAP_PREP => self.mmap_prep( + packet.b, + u64::from(packet.uid) | (u64::from(packet.gid) << 32), + packet.c, + MapFlags::from_bits_truncate(packet.d), + ), + KSMSG_MUNMAP => self.munmap( + packet.b, + u64::from(packet.uid) | (u64::from(packet.gid) << 32), + packet.c, + MunmapFlags::from_bits_truncate(packet.d), + ), - _ => Err(Error::new(ENOSYS)) + _ => Err(Error::new(ENOSYS)), }; packet.a = Error::mux(res); diff --git a/src/scheme/scheme_block.rs b/src/scheme/scheme_block.rs index e74e3b7e2a..f5a66fa162 100644 --- a/src/scheme/scheme_block.rs +++ b/src/scheme/scheme_block.rs @@ -1,70 +1,112 @@ use core::{mem, slice}; -use crate::CallerCtx; -use crate::OpenResult; -use crate::data::*; -use crate::error::*; -use crate::flag::*; -use crate::number::*; -use crate::scheme::*; +use crate::{data::*, error::*, flag::*, number::*, scheme::*, CallerCtx, OpenResult}; pub trait SchemeBlock { fn handle(&self, packet: &Packet) -> Option { let res = match packet.a { - SYS_OPEN => if let Some(path) = unsafe { str_from_raw_parts(packet.b as *const u8, packet.c) } { - convert_in_scheme_handle_block(packet, self.xopen(path, packet.d, &CallerCtx::from_packet(&packet))) + SYS_OPEN => { + if let Some(path) = unsafe { str_from_raw_parts(packet.b as *const u8, packet.c) } { + convert_in_scheme_handle_block( + packet, + self.xopen(path, packet.d, &CallerCtx::from_packet(&packet)), + ) + } else { + Err(Error::new(EINVAL)) + } + } + SYS_RMDIR => { + if let Some(path) = unsafe { str_from_raw_parts(packet.b as *const u8, packet.c) } { + self.rmdir(path, packet.uid, packet.gid) + } else { + Err(Error::new(EINVAL)) + } + } + SYS_UNLINK => { + if let Some(path) = unsafe { str_from_raw_parts(packet.b as *const u8, packet.c) } { + self.unlink(path, packet.uid, packet.gid) + } else { + Err(Error::new(EINVAL)) + } } - else { - Err(Error::new(EINVAL)) - }, - SYS_RMDIR => if let Some(path) = unsafe { str_from_raw_parts(packet.b as *const u8, packet.c) } { - self.rmdir(path, packet.uid, packet.gid) - } else { - Err(Error::new(EINVAL)) - }, - SYS_UNLINK => if let Some(path) = unsafe { str_from_raw_parts(packet.b as *const u8, packet.c) } { - self.unlink(path, packet.uid, packet.gid) - } else { - Err(Error::new(EINVAL)) - }, - SYS_DUP => convert_in_scheme_handle_block(packet, self.xdup(packet.b, unsafe { slice::from_raw_parts(packet.c as *const u8, packet.d) }, &CallerCtx::from_packet(&packet))), - SYS_READ => self.read(packet.b, unsafe { slice::from_raw_parts_mut(packet.c as *mut u8, packet.d) }), - SYS_WRITE => self.write(packet.b, unsafe { slice::from_raw_parts(packet.c as *const u8, packet.d) }), - SYS_LSEEK => self.seek(packet.b, packet.c as isize, packet.d).map(|o| o.map(|o| o as usize)), + SYS_DUP => convert_in_scheme_handle_block( + packet, + self.xdup( + packet.b, + unsafe { slice::from_raw_parts(packet.c as *const u8, packet.d) }, + &CallerCtx::from_packet(&packet), + ), + ), + SYS_READ => self.read(packet.b, unsafe { + slice::from_raw_parts_mut(packet.c as *mut u8, packet.d) + }), + SYS_WRITE => self.write(packet.b, unsafe { + slice::from_raw_parts(packet.c as *const u8, packet.d) + }), + SYS_LSEEK => self + .seek(packet.b, packet.c as isize, packet.d) + .map(|o| o.map(|o| o as usize)), SYS_FCHMOD => self.fchmod(packet.b, packet.c as u16), SYS_FCHOWN => self.fchown(packet.b, packet.c as u32, packet.d as u32), SYS_FCNTL => self.fcntl(packet.b, packet.c, packet.d), - SYS_FEVENT => self.fevent(packet.b, EventFlags::from_bits_truncate(packet.c)).map(|f| f.map(|f| f.bits())), - SYS_FPATH => self.fpath(packet.b, unsafe { slice::from_raw_parts_mut(packet.c as *mut u8, packet.d) }), - SYS_FRENAME => if let Some(path) = unsafe { str_from_raw_parts(packet.c as *const u8, packet.d) } { - self.frename(packet.b, path, packet.uid, packet.gid) - } else { - Err(Error::new(EINVAL)) - }, - SYS_FSTAT => if packet.d >= mem::size_of::() { - self.fstat(packet.b, unsafe { &mut *(packet.c as *mut Stat) }) - } else { - Err(Error::new(EFAULT)) - }, - SYS_FSTATVFS => if packet.d >= mem::size_of::() { - self.fstatvfs(packet.b, unsafe { &mut *(packet.c as *mut StatVfs) }) - } else { - Err(Error::new(EFAULT)) - }, + SYS_FEVENT => self + .fevent(packet.b, EventFlags::from_bits_truncate(packet.c)) + .map(|f| f.map(|f| f.bits())), + SYS_FPATH => self.fpath(packet.b, unsafe { + slice::from_raw_parts_mut(packet.c as *mut u8, packet.d) + }), + SYS_FRENAME => { + if let Some(path) = unsafe { str_from_raw_parts(packet.c as *const u8, packet.d) } { + self.frename(packet.b, path, packet.uid, packet.gid) + } else { + Err(Error::new(EINVAL)) + } + } + SYS_FSTAT => { + if packet.d >= mem::size_of::() { + self.fstat(packet.b, unsafe { &mut *(packet.c as *mut Stat) }) + } else { + Err(Error::new(EFAULT)) + } + } + SYS_FSTATVFS => { + if packet.d >= mem::size_of::() { + self.fstatvfs(packet.b, unsafe { &mut *(packet.c as *mut StatVfs) }) + } else { + Err(Error::new(EFAULT)) + } + } SYS_FSYNC => self.fsync(packet.b), SYS_FTRUNCATE => self.ftruncate(packet.b, packet.c), - SYS_FUTIMENS => if packet.d >= mem::size_of::() { - self.futimens(packet.b, unsafe { slice::from_raw_parts(packet.c as *const TimeSpec, packet.d / mem::size_of::()) }) - } else { - Err(Error::new(EFAULT)) - }, + SYS_FUTIMENS => { + if packet.d >= mem::size_of::() { + self.futimens(packet.b, unsafe { + slice::from_raw_parts( + packet.c as *const TimeSpec, + packet.d / mem::size_of::(), + ) + }) + } else { + Err(Error::new(EFAULT)) + } + } SYS_CLOSE => self.close(packet.b), - KSMSG_MMAP_PREP => self.mmap_prep(packet.b, u64::from(packet.uid) | (u64::from(packet.gid) << 32), packet.c, MapFlags::from_bits_truncate(packet.d)), - KSMSG_MUNMAP => self.munmap(packet.b, u64::from(packet.uid) | (u64::from(packet.gid) << 32), packet.c, MunmapFlags::from_bits_truncate(packet.d)), + KSMSG_MMAP_PREP => self.mmap_prep( + packet.b, + u64::from(packet.uid) | (u64::from(packet.gid) << 32), + packet.c, + MapFlags::from_bits_truncate(packet.d), + ), + KSMSG_MUNMAP => self.munmap( + packet.b, + u64::from(packet.uid) | (u64::from(packet.gid) << 32), + packet.c, + MunmapFlags::from_bits_truncate(packet.d), + ), - _ => Err(Error::new(ENOSYS)) + _ => Err(Error::new(ENOSYS)), }; res.transpose().map(Error::mux) @@ -183,12 +225,24 @@ pub trait SchemeBlock { } #[allow(unused_variables)] - fn mmap_prep(&self, id: usize, offset: u64, size: usize, flags: MapFlags) -> Result> { + fn mmap_prep( + &self, + id: usize, + offset: u64, + size: usize, + flags: MapFlags, + ) -> Result> { Err(Error::new(EOPNOTSUPP)) } #[allow(unused_variables)] - fn munmap(&self, id: usize, offset: u64, size: usize, flags: MunmapFlags) -> Result> { + fn munmap( + &self, + id: usize, + offset: u64, + size: usize, + flags: MunmapFlags, + ) -> Result> { Err(Error::new(EOPNOTSUPP)) } } diff --git a/src/scheme/scheme_block_mut.rs b/src/scheme/scheme_block_mut.rs index fd2c59069b..1ed47c0ffc 100644 --- a/src/scheme/scheme_block_mut.rs +++ b/src/scheme/scheme_block_mut.rs @@ -1,70 +1,112 @@ use core::{mem, slice}; -use crate::CallerCtx; -use crate::OpenResult; -use crate::data::*; -use crate::error::*; -use crate::flag::*; -use crate::number::*; -use crate::scheme::*; +use crate::{data::*, error::*, flag::*, number::*, scheme::*, CallerCtx, OpenResult}; pub trait SchemeBlockMut { fn handle(&mut self, packet: &Packet) -> Option { let res = match packet.a { - SYS_OPEN => if let Some(path) = unsafe { str_from_raw_parts(packet.b as *const u8, packet.c) } { - convert_in_scheme_handle_block(packet, self.xopen(path, packet.d, &CallerCtx::from_packet(&packet))) + SYS_OPEN => { + if let Some(path) = unsafe { str_from_raw_parts(packet.b as *const u8, packet.c) } { + convert_in_scheme_handle_block( + packet, + self.xopen(path, packet.d, &CallerCtx::from_packet(&packet)), + ) + } else { + Err(Error::new(EINVAL)) + } + } + SYS_RMDIR => { + if let Some(path) = unsafe { str_from_raw_parts(packet.b as *const u8, packet.c) } { + self.rmdir(path, packet.uid, packet.gid) + } else { + Err(Error::new(EINVAL)) + } + } + SYS_UNLINK => { + if let Some(path) = unsafe { str_from_raw_parts(packet.b as *const u8, packet.c) } { + self.unlink(path, packet.uid, packet.gid) + } else { + Err(Error::new(EINVAL)) + } } - else { - Err(Error::new(EINVAL)) - }, - SYS_RMDIR => if let Some(path) = unsafe { str_from_raw_parts(packet.b as *const u8, packet.c) } { - self.rmdir(path, packet.uid, packet.gid) - } else { - Err(Error::new(EINVAL)) - }, - SYS_UNLINK => if let Some(path) = unsafe { str_from_raw_parts(packet.b as *const u8, packet.c) } { - self.unlink(path, packet.uid, packet.gid) - } else { - Err(Error::new(EINVAL)) - }, - SYS_DUP => convert_in_scheme_handle_block(packet, self.xdup(packet.b, unsafe { slice::from_raw_parts(packet.c as *const u8, packet.d) }, &CallerCtx::from_packet(&packet))), - SYS_READ => self.read(packet.b, unsafe { slice::from_raw_parts_mut(packet.c as *mut u8, packet.d) }), - SYS_WRITE => self.write(packet.b, unsafe { slice::from_raw_parts(packet.c as *const u8, packet.d) }), - SYS_LSEEK => self.seek(packet.b, packet.c as isize, packet.d).map(|o| o.map(|o| o as usize)), + SYS_DUP => convert_in_scheme_handle_block( + packet, + self.xdup( + packet.b, + unsafe { slice::from_raw_parts(packet.c as *const u8, packet.d) }, + &CallerCtx::from_packet(&packet), + ), + ), + SYS_READ => self.read(packet.b, unsafe { + slice::from_raw_parts_mut(packet.c as *mut u8, packet.d) + }), + SYS_WRITE => self.write(packet.b, unsafe { + slice::from_raw_parts(packet.c as *const u8, packet.d) + }), + SYS_LSEEK => self + .seek(packet.b, packet.c as isize, packet.d) + .map(|o| o.map(|o| o as usize)), SYS_FCHMOD => self.fchmod(packet.b, packet.c as u16), SYS_FCHOWN => self.fchown(packet.b, packet.c as u32, packet.d as u32), SYS_FCNTL => self.fcntl(packet.b, packet.c, packet.d), - SYS_FEVENT => self.fevent(packet.b, EventFlags::from_bits_truncate(packet.c)).map(|f| f.map(|f| f.bits())), - SYS_FPATH => self.fpath(packet.b, unsafe { slice::from_raw_parts_mut(packet.c as *mut u8, packet.d) }), - SYS_FRENAME => if let Some(path) = unsafe { str_from_raw_parts(packet.c as *const u8, packet.d) } { - self.frename(packet.b, path, packet.uid, packet.gid) - } else { - Err(Error::new(EINVAL)) - }, - SYS_FSTAT => if packet.d >= mem::size_of::() { - self.fstat(packet.b, unsafe { &mut *(packet.c as *mut Stat) }) - } else { - Err(Error::new(EFAULT)) - }, - SYS_FSTATVFS => if packet.d >= mem::size_of::() { - self.fstatvfs(packet.b, unsafe { &mut *(packet.c as *mut StatVfs) }) - } else { - Err(Error::new(EFAULT)) - }, + SYS_FEVENT => self + .fevent(packet.b, EventFlags::from_bits_truncate(packet.c)) + .map(|f| f.map(|f| f.bits())), + SYS_FPATH => self.fpath(packet.b, unsafe { + slice::from_raw_parts_mut(packet.c as *mut u8, packet.d) + }), + SYS_FRENAME => { + if let Some(path) = unsafe { str_from_raw_parts(packet.c as *const u8, packet.d) } { + self.frename(packet.b, path, packet.uid, packet.gid) + } else { + Err(Error::new(EINVAL)) + } + } + SYS_FSTAT => { + if packet.d >= mem::size_of::() { + self.fstat(packet.b, unsafe { &mut *(packet.c as *mut Stat) }) + } else { + Err(Error::new(EFAULT)) + } + } + SYS_FSTATVFS => { + if packet.d >= mem::size_of::() { + self.fstatvfs(packet.b, unsafe { &mut *(packet.c as *mut StatVfs) }) + } else { + Err(Error::new(EFAULT)) + } + } SYS_FSYNC => self.fsync(packet.b), SYS_FTRUNCATE => self.ftruncate(packet.b, packet.c), - SYS_FUTIMENS => if packet.d >= mem::size_of::() { - self.futimens(packet.b, unsafe { slice::from_raw_parts(packet.c as *const TimeSpec, packet.d / mem::size_of::()) }) - } else { - Err(Error::new(EFAULT)) - }, + SYS_FUTIMENS => { + if packet.d >= mem::size_of::() { + self.futimens(packet.b, unsafe { + slice::from_raw_parts( + packet.c as *const TimeSpec, + packet.d / mem::size_of::(), + ) + }) + } else { + Err(Error::new(EFAULT)) + } + } SYS_CLOSE => self.close(packet.b), - KSMSG_MMAP_PREP => self.mmap_prep(packet.b, u64::from(packet.uid) | (u64::from(packet.gid) << 32), packet.c, MapFlags::from_bits_truncate(packet.d)), - KSMSG_MUNMAP => self.munmap(packet.b, u64::from(packet.uid) | (u64::from(packet.gid) << 32), packet.c, MunmapFlags::from_bits_truncate(packet.d)), + KSMSG_MMAP_PREP => self.mmap_prep( + packet.b, + u64::from(packet.uid) | (u64::from(packet.gid) << 32), + packet.c, + MapFlags::from_bits_truncate(packet.d), + ), + KSMSG_MUNMAP => self.munmap( + packet.b, + u64::from(packet.uid) | (u64::from(packet.gid) << 32), + packet.c, + MunmapFlags::from_bits_truncate(packet.d), + ), - _ => Err(Error::new(ENOSYS)) + _ => Err(Error::new(ENOSYS)), }; res.transpose().map(Error::mux) @@ -183,12 +225,24 @@ pub trait SchemeBlockMut { } #[allow(unused_variables)] - fn mmap_prep(&mut self, id: usize, offset: u64, size: usize, flags: MapFlags) -> Result> { + fn mmap_prep( + &mut self, + id: usize, + offset: u64, + size: usize, + flags: MapFlags, + ) -> Result> { Err(Error::new(EOPNOTSUPP)) } #[allow(unused_variables)] - fn munmap(&mut self, id: usize, offset: u64, size: usize, flags: MunmapFlags) -> Result> { + fn munmap( + &mut self, + id: usize, + offset: u64, + size: usize, + flags: MunmapFlags, + ) -> Result> { Err(Error::new(EOPNOTSUPP)) } } diff --git a/src/scheme/scheme_mut.rs b/src/scheme/scheme_mut.rs index 2eea4dcbc8..24aaf75824 100644 --- a/src/scheme/scheme_mut.rs +++ b/src/scheme/scheme_mut.rs @@ -1,70 +1,112 @@ use core::{mem, slice}; -use crate::CallerCtx; -use crate::OpenResult; -use crate::data::*; -use crate::error::*; -use crate::flag::*; -use crate::number::*; -use crate::scheme::*; +use crate::{data::*, error::*, flag::*, number::*, scheme::*, CallerCtx, OpenResult}; pub trait SchemeMut { fn handle(&mut self, packet: &mut Packet) { let res = match packet.a { - SYS_OPEN => if let Some(path) = unsafe { str_from_raw_parts(packet.b as *const u8, packet.c) } { - convert_in_scheme_handle(packet, self.xopen(path, packet.d, &CallerCtx::from_packet(&packet))) + SYS_OPEN => { + if let Some(path) = unsafe { str_from_raw_parts(packet.b as *const u8, packet.c) } { + convert_in_scheme_handle( + packet, + self.xopen(path, packet.d, &CallerCtx::from_packet(&packet)), + ) + } else { + Err(Error::new(EINVAL)) + } + } + SYS_RMDIR => { + if let Some(path) = unsafe { str_from_raw_parts(packet.b as *const u8, packet.c) } { + self.rmdir(path, packet.uid, packet.gid) + } else { + Err(Error::new(EINVAL)) + } + } + SYS_UNLINK => { + if let Some(path) = unsafe { str_from_raw_parts(packet.b as *const u8, packet.c) } { + self.unlink(path, packet.uid, packet.gid) + } else { + Err(Error::new(EINVAL)) + } } - else { - Err(Error::new(EINVAL)) - }, - SYS_RMDIR => if let Some(path) = unsafe { str_from_raw_parts(packet.b as *const u8, packet.c) } { - self.rmdir(path, packet.uid, packet.gid) - } else { - Err(Error::new(EINVAL)) - }, - SYS_UNLINK => if let Some(path) = unsafe { str_from_raw_parts(packet.b as *const u8, packet.c) } { - self.unlink(path, packet.uid, packet.gid) - } else { - Err(Error::new(EINVAL)) - }, - SYS_DUP => convert_in_scheme_handle(packet, self.xdup(packet.b, unsafe { slice::from_raw_parts(packet.c as *const u8, packet.d) }, &CallerCtx::from_packet(&packet))), - SYS_READ => self.read(packet.b, unsafe { slice::from_raw_parts_mut(packet.c as *mut u8, packet.d) }), - SYS_WRITE => self.write(packet.b, unsafe { slice::from_raw_parts(packet.c as *const u8, packet.d) }), - SYS_LSEEK => self.seek(packet.b, packet.c as isize, packet.d).map(|o| o as usize), + SYS_DUP => convert_in_scheme_handle( + packet, + self.xdup( + packet.b, + unsafe { slice::from_raw_parts(packet.c as *const u8, packet.d) }, + &CallerCtx::from_packet(&packet), + ), + ), + SYS_READ => self.read(packet.b, unsafe { + slice::from_raw_parts_mut(packet.c as *mut u8, packet.d) + }), + SYS_WRITE => self.write(packet.b, unsafe { + slice::from_raw_parts(packet.c as *const u8, packet.d) + }), + SYS_LSEEK => self + .seek(packet.b, packet.c as isize, packet.d) + .map(|o| o as usize), SYS_FCHMOD => self.fchmod(packet.b, packet.c as u16), SYS_FCHOWN => self.fchown(packet.b, packet.c as u32, packet.d as u32), SYS_FCNTL => self.fcntl(packet.b, packet.c, packet.d), - SYS_FEVENT => self.fevent(packet.b, EventFlags::from_bits_truncate(packet.c)).map(|f| f.bits()), - SYS_FPATH => self.fpath(packet.b, unsafe { slice::from_raw_parts_mut(packet.c as *mut u8, packet.d) }), - SYS_FRENAME => if let Some(path) = unsafe { str_from_raw_parts(packet.c as *const u8, packet.d) } { - self.frename(packet.b, path, packet.uid, packet.gid) - } else { - Err(Error::new(EINVAL)) - }, - SYS_FSTAT => if packet.d >= mem::size_of::() { - self.fstat(packet.b, unsafe { &mut *(packet.c as *mut Stat) }) - } else { - Err(Error::new(EFAULT)) - }, - SYS_FSTATVFS => if packet.d >= mem::size_of::() { - self.fstatvfs(packet.b, unsafe { &mut *(packet.c as *mut StatVfs) }) - } else { - Err(Error::new(EFAULT)) - }, + SYS_FEVENT => self + .fevent(packet.b, EventFlags::from_bits_truncate(packet.c)) + .map(|f| f.bits()), + SYS_FPATH => self.fpath(packet.b, unsafe { + slice::from_raw_parts_mut(packet.c as *mut u8, packet.d) + }), + SYS_FRENAME => { + if let Some(path) = unsafe { str_from_raw_parts(packet.c as *const u8, packet.d) } { + self.frename(packet.b, path, packet.uid, packet.gid) + } else { + Err(Error::new(EINVAL)) + } + } + SYS_FSTAT => { + if packet.d >= mem::size_of::() { + self.fstat(packet.b, unsafe { &mut *(packet.c as *mut Stat) }) + } else { + Err(Error::new(EFAULT)) + } + } + SYS_FSTATVFS => { + if packet.d >= mem::size_of::() { + self.fstatvfs(packet.b, unsafe { &mut *(packet.c as *mut StatVfs) }) + } else { + Err(Error::new(EFAULT)) + } + } SYS_FSYNC => self.fsync(packet.b), SYS_FTRUNCATE => self.ftruncate(packet.b, packet.c), - SYS_FUTIMENS => if packet.d >= mem::size_of::() { - self.futimens(packet.b, unsafe { slice::from_raw_parts(packet.c as *const TimeSpec, packet.d / mem::size_of::()) }) - } else { - Err(Error::new(EFAULT)) - }, + SYS_FUTIMENS => { + if packet.d >= mem::size_of::() { + self.futimens(packet.b, unsafe { + slice::from_raw_parts( + packet.c as *const TimeSpec, + packet.d / mem::size_of::(), + ) + }) + } else { + Err(Error::new(EFAULT)) + } + } SYS_CLOSE => self.close(packet.b), - KSMSG_MMAP_PREP => self.mmap_prep(packet.b, u64::from(packet.uid) | (u64::from(packet.gid) << 32), packet.c, MapFlags::from_bits_truncate(packet.d)), - KSMSG_MUNMAP => self.munmap(packet.b, u64::from(packet.uid) | (u64::from(packet.gid) << 32), packet.c, MunmapFlags::from_bits_truncate(packet.d)), + KSMSG_MMAP_PREP => self.mmap_prep( + packet.b, + u64::from(packet.uid) | (u64::from(packet.gid) << 32), + packet.c, + MapFlags::from_bits_truncate(packet.d), + ), + KSMSG_MUNMAP => self.munmap( + packet.b, + u64::from(packet.uid) | (u64::from(packet.gid) << 32), + packet.c, + MunmapFlags::from_bits_truncate(packet.d), + ), - _ => Err(Error::new(ENOSYS)) + _ => Err(Error::new(ENOSYS)), }; packet.a = Error::mux(res); diff --git a/src/scheme/seek.rs b/src/scheme/seek.rs index 09a45186ac..0e145162c1 100644 --- a/src/scheme/seek.rs +++ b/src/scheme/seek.rs @@ -1,13 +1,16 @@ -use core::cmp; -use core::convert::TryFrom; -use crate::error::*; -use crate::flag::*; +use crate::{error::*, flag::*}; +use core::{cmp, convert::TryFrom}; /// Helper for seek calls /// In most cases it's easier to use a usize to track the offset and buffer size internally, /// but the seek interface uses isize. This wrapper ensures EOVERFLOW errors are returned /// as appropriate if the value in the usize can't fit in the isize. -pub fn calc_seek_offset_usize(cur_offset: usize, pos: isize, whence: usize, buf_len: usize) -> Result { +pub fn calc_seek_offset_usize( + cur_offset: usize, + pos: isize, + whence: usize, + buf_len: usize, +) -> Result { let cur_offset = isize::try_from(cur_offset).or_else(|_| Err(Error::new(EOVERFLOW)))?; let buf_len = isize::try_from(buf_len).or_else(|_| Err(Error::new(EOVERFLOW)))?; calc_seek_offset_isize(cur_offset, pos, whence, buf_len) @@ -17,7 +20,12 @@ pub fn calc_seek_offset_usize(cur_offset: usize, pos: isize, whence: usize, buf_ /// Result is guaranteed to be positive. /// EOVERFLOW returned if the arguments would cause an overflow. /// EINVAL returned if the new offset is out of bounds. -pub fn calc_seek_offset_isize(cur_offset: isize, pos: isize, whence: usize, buf_len: isize) -> Result { +pub fn calc_seek_offset_isize( + cur_offset: isize, + pos: isize, + whence: usize, + buf_len: isize, +) -> Result { let new_offset = match whence { SEEK_CUR => pos.checked_add(cur_offset), SEEK_END => pos.checked_add(buf_len), @@ -28,6 +36,6 @@ pub fn calc_seek_offset_isize(cur_offset: isize, pos: isize, whence: usize, buf_ match new_offset { Some(new_offset) if new_offset < 0 => Err(Error::new(EINVAL)), Some(new_offset) => Ok(cmp::min(new_offset, buf_len)), - None => Err(Error::new(EOVERFLOW)) + None => Err(Error::new(EOVERFLOW)), } -} \ No newline at end of file +} diff --git a/src/schemev2.rs b/src/schemev2.rs index 2ae9b46423..ac66efcbe2 100644 --- a/src/schemev2.rs +++ b/src/schemev2.rs @@ -1,5 +1,8 @@ -use core::ops::{Deref, DerefMut}; -use core::{mem, slice}; +use core::{ + mem, + ops::{Deref, DerefMut}, + slice, +}; use bitflags::bitflags; @@ -16,17 +19,13 @@ pub struct Sqe { impl Deref for Sqe { type Target = [u8]; fn deref(&self) -> &[u8] { - unsafe { - slice::from_raw_parts(self as *const Sqe as *const u8, mem::size_of::()) - } + unsafe { slice::from_raw_parts(self as *const Sqe as *const u8, mem::size_of::()) } } } impl DerefMut for Sqe { fn deref_mut(&mut self) -> &mut [u8] { - unsafe { - slice::from_raw_parts_mut(self as *mut Sqe as *mut u8, mem::size_of::()) - } + unsafe { slice::from_raw_parts_mut(self as *mut Sqe as *mut u8, mem::size_of::()) } } } @@ -50,17 +49,13 @@ pub struct Cqe { impl Deref for Cqe { type Target = [u8]; fn deref(&self) -> &[u8] { - unsafe { - slice::from_raw_parts(self as *const Cqe as *const u8, mem::size_of::()) - } + unsafe { slice::from_raw_parts(self as *const Cqe as *const u8, mem::size_of::()) } } } impl DerefMut for Cqe { fn deref_mut(&mut self) -> &mut [u8] { - unsafe { - slice::from_raw_parts_mut(self as *mut Cqe as *mut u8, mem::size_of::()) - } + unsafe { slice::from_raw_parts_mut(self as *mut Cqe as *mut u8, mem::size_of::()) } } } @@ -102,26 +97,26 @@ impl CqeOpcode { #[non_exhaustive] #[derive(Clone, Copy, Debug)] pub enum Opcode { - Open = 0, // path_ptr, path_len (utf8), flags - Rmdir = 1, // path_ptr, path_len (utf8) - Unlink = 2, // path_ptr, path_len (utf8) - Close = 3, // fd - Dup = 4, // old fd, buf_ptr, buf_len - Read = 5, // fd, buf_ptr, buf_len, TODO offset, TODO flags, _ - Write = 6, // fd, buf_ptr, buf_len, TODO offset, TODO flags) - Fsize = 7, // fd - Fchmod = 8, // fd, new mode - Fchown = 9, // fd, new uid, new gid - Fcntl = 10, // fd, cmd, arg + Open = 0, // path_ptr, path_len (utf8), flags + Rmdir = 1, // path_ptr, path_len (utf8) + Unlink = 2, // path_ptr, path_len (utf8) + Close = 3, // fd + Dup = 4, // old fd, buf_ptr, buf_len + Read = 5, // fd, buf_ptr, buf_len, TODO offset, TODO flags, _ + Write = 6, // fd, buf_ptr, buf_len, TODO offset, TODO flags) + Fsize = 7, // fd + Fchmod = 8, // fd, new mode + Fchown = 9, // fd, new uid, new gid + Fcntl = 10, // fd, cmd, arg Fevent = 11, // fd, requested mask Sendfd = 12, Fpath = 13, // fd, buf_ptr, buf_len Frename = 14, - Fstat = 15, // fd, buf_ptr, buf_len - Fstatvfs = 16, // fd, buf_ptr, buf_len - Fsync = 17, // fd + Fstat = 15, // fd, buf_ptr, buf_len + Fstatvfs = 16, // fd, buf_ptr, buf_len + Fsync = 17, // fd Ftruncate = 18, // fd, new len - Futimens = 19, // fd, times_buf, times_len + Futimens = 19, // fd, times_buf, times_len MmapPrep = 20, RequestMmap = 21,