From 816d190f41e5ecf6819ba50be35c1b48f3b34ca4 Mon Sep 17 00:00:00 2001 From: 4lDO2 <4lDO2@protonmail.com> Date: Wed, 12 Jun 2024 15:57:02 +0200 Subject: [PATCH] READ2 and WRITE2 syscalls. --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/lib.rs | 12 ++++++------ src/scheme.rs | 23 ++++++++++++++--------- src/scheme_block.rs | 39 ++++++++++++++++----------------------- src/scheme_block_mut.rs | 39 ++++++++++++++++----------------------- src/scheme_mut.rs | 23 ++++++++++++++--------- 7 files changed, 68 insertions(+), 72 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ac15184..04bd17b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -36,7 +36,7 @@ dependencies = [ [[package]] name = "redox_syscall" version = "0.5.1" -source = "git+https://gitlab.redox-os.org/4lDO2/syscall.git?branch=schemev2#495a0adbd8333fd21fae2d97129b094607878ba7" +source = "git+https://gitlab.redox-os.org/4lDO2/syscall.git?branch=schemev2plus#35600d6c9c46a4d54ec17d80c9ff5d17ef79a052" dependencies = [ "bitflags", ] diff --git a/Cargo.toml b/Cargo.toml index fb1469e..38e3ade 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,4 +15,4 @@ redox_syscall = "0.5" libredox = { version = "0.1.3", default-features = false, features = ["redox_syscall", "call"] } [patch.crates-io] -redox_syscall = { git = "https://gitlab.redox-os.org/4lDO2/syscall.git", branch = "schemev2", features = ["std"] } +redox_syscall = { git = "https://gitlab.redox-os.org/4lDO2/syscall.git", branch = "schemev2plus", features = ["std"] } diff --git a/src/lib.rs b/src/lib.rs index 3d8ce19..5a71e12 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -314,11 +314,11 @@ impl CallRequest<V2> { result: fd as u64, }), } - Opcode::Read => scheme.read(a, slice::from_raw_parts_mut(b as *mut u8, c)), - Opcode::Write => scheme.write(a, slice::from_raw_parts(b as *const u8, c)), + Opcode::Read => scheme.read(a, slice::from_raw_parts_mut(b as *mut u8, c), args[3], args[4] as u32), + Opcode::Write => scheme.write(a, slice::from_raw_parts(b as *const u8, c), args[3], args[4] as u32), // TODO: 64-bit offset on 32-bit platforms - Opcode::Lseek => scheme.seek(a, b as isize, c).map(|o| o as usize), + Opcode::Fsize => scheme.fsize(a).map(|o| o as usize), Opcode::Fchmod => scheme.fchmod(a, b as u16), Opcode::Fchown => scheme.fchown(a, b as u32, c as u32), Opcode::Fcntl => scheme.fcntl(a, b, c), @@ -391,11 +391,11 @@ impl CallRequest<V2> { result: fd as u64, })), } - Opcode::Read => scheme.read(a, slice::from_raw_parts_mut(b as *mut u8, c)).transpose()?, - Opcode::Write => scheme.write(a, slice::from_raw_parts(b as *const u8, c)).transpose()?, + Opcode::Read => scheme.read(a, slice::from_raw_parts_mut(b as *mut u8, c), args[3], args[4] as u32).transpose()?, + Opcode::Write => scheme.write(a, slice::from_raw_parts(b as *const u8, c), args[3], args[4] as u32).transpose()?, // TODO: 64-bit offset on 32-bit platforms - Opcode::Lseek => scheme.seek(a, b as isize, c).transpose()?.map(|o| o as usize), + Opcode::Fsize => scheme.fsize(a).transpose()?.map(|o| o as usize), Opcode::Fchmod => scheme.fchmod(a, b as u16).transpose()?, Opcode::Fchown => scheme.fchown(a, b as u32, c as u32).transpose()?, Opcode::Fcntl => scheme.fcntl(a, b, c).transpose()?, diff --git a/src/scheme.rs b/src/scheme.rs index e039d43..fa0ccf3 100644 --- a/src/scheme.rs +++ b/src/scheme.rs @@ -42,15 +42,12 @@ pub trait Scheme { &CallerCtx::from_packet(&packet), ), ), - SYS_READ => self.read(packet.b, { + SYS_READ => self.read_old(packet.b, { slice::from_raw_parts_mut(packet.c as *mut u8, packet.d) }), - SYS_WRITE => self.write(packet.b, { + SYS_WRITE => self.write_old(packet.b, { 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), @@ -154,18 +151,26 @@ pub trait Scheme { } #[allow(unused_variables)] - fn read(&self, id: usize, buf: &mut [u8]) -> Result<usize> { + fn read_old(&self, id: usize, buf: &mut [u8]) -> Result<usize> { Err(Error::new(EBADF)) } + #[allow(unused_variables)] + fn read(&self, id: usize, buf: &mut [u8], offset: u64, fcntl_flags: u32) -> Result<usize> { + self.read_old(id, buf) + } #[allow(unused_variables)] - fn write(&self, id: usize, buf: &[u8]) -> Result<usize> { + fn write_old(&self, id: usize, buf: &[u8]) -> Result<usize> { Err(Error::new(EBADF)) } + #[allow(unused_variables)] + fn write(&self, id: usize, buf: &[u8], offset: u64, fcntl_flags: u32) -> Result<usize> { + self.write_old(id, buf) + } #[allow(unused_variables)] - fn seek(&self, id: usize, pos: isize, whence: usize) -> Result<isize> { - Err(Error::new(EBADF)) + fn fsize(&self, id: usize) -> Result<u64> { + Err(Error::new(ESPIPE)) } #[allow(unused_variables)] diff --git a/src/scheme_block.rs b/src/scheme_block.rs index 2be3e2f..8e274e8 100644 --- a/src/scheme_block.rs +++ b/src/scheme_block.rs @@ -42,15 +42,12 @@ pub trait SchemeBlock { &CallerCtx::from_packet(&packet), ), ), - SYS_READ => self.read(packet.b, { + SYS_READ => self.read_old(packet.b, { slice::from_raw_parts_mut(packet.c as *mut u8, packet.d) }), - SYS_WRITE => self.write(packet.b, { + SYS_WRITE => self.write_old(packet.b, { 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), @@ -154,18 +151,26 @@ pub trait SchemeBlock { } #[allow(unused_variables)] - fn read(&self, id: usize, buf: &mut [u8]) -> Result<Option<usize>> { + fn read_old(&self, id: usize, buf: &mut [u8]) -> Result<Option<usize>> { Err(Error::new(EBADF)) } + #[allow(unused_variables)] + fn read(&self, id: usize, buf: &mut [u8], offset: u64, fcntl_flags: u32) -> Result<Option<usize>> { + self.read_old(id, buf) + } #[allow(unused_variables)] - fn write(&self, id: usize, buf: &[u8]) -> Result<Option<usize>> { + fn write_old(&self, id: usize, buf: &[u8]) -> Result<Option<usize>> { Err(Error::new(EBADF)) } + #[allow(unused_variables)] + fn write(&self, id: usize, buf: &[u8], offset: u64, fcntl_flags: u32) -> Result<Option<usize>> { + self.write_old(id, buf) + } #[allow(unused_variables)] - fn seek(&self, id: usize, pos: isize, whence: usize) -> Result<Option<isize>> { - Err(Error::new(EBADF)) + fn fsize(&self, id: usize) -> Result<Option<u64>> { + Err(Error::new(ESPIPE)) } #[allow(unused_variables)] @@ -229,24 +234,12 @@ pub trait SchemeBlock { } #[allow(unused_variables)] - fn mmap_prep( - &self, - id: usize, - offset: u64, - size: usize, - flags: MapFlags, - ) -> Result<Option<usize>> { + fn mmap_prep(&self, id: usize, offset: u64, size: usize, flags: MapFlags) -> Result<Option<usize>> { Err(Error::new(EOPNOTSUPP)) } #[allow(unused_variables)] - fn munmap( - &self, - id: usize, - offset: u64, - size: usize, - flags: MunmapFlags, - ) -> Result<Option<usize>> { + fn munmap(&self, id: usize, offset: u64, size: usize, flags: MunmapFlags) -> Result<Option<usize>> { Err(Error::new(EOPNOTSUPP)) } } diff --git a/src/scheme_block_mut.rs b/src/scheme_block_mut.rs index eeca6cb..fa6a822 100644 --- a/src/scheme_block_mut.rs +++ b/src/scheme_block_mut.rs @@ -42,15 +42,12 @@ pub trait SchemeBlockMut { &CallerCtx::from_packet(&packet), ), ), - SYS_READ => self.read(packet.b, { + SYS_READ => self.read_old(packet.b, { slice::from_raw_parts_mut(packet.c as *mut u8, packet.d) }), - SYS_WRITE => self.write(packet.b, { + SYS_WRITE => self.write_old(packet.b, { 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), @@ -154,18 +151,26 @@ pub trait SchemeBlockMut { } #[allow(unused_variables)] - fn read(&mut self, id: usize, buf: &mut [u8]) -> Result<Option<usize>> { + fn read_old(&mut self, id: usize, buf: &mut [u8]) -> Result<Option<usize>> { Err(Error::new(EBADF)) } + #[allow(unused_variables)] + fn read(&mut self, id: usize, buf: &mut [u8], offset: u64, fcntl_flags: u32) -> Result<Option<usize>> { + self.read_old(id, buf) + } #[allow(unused_variables)] - fn write(&mut self, id: usize, buf: &[u8]) -> Result<Option<usize>> { + fn write_old(&mut self, id: usize, buf: &[u8]) -> Result<Option<usize>> { Err(Error::new(EBADF)) } + #[allow(unused_variables)] + fn write(&mut self, id: usize, buf: &[u8], offset: u64, fcntl_flags: u32) -> Result<Option<usize>> { + self.write_old(id, buf) + } #[allow(unused_variables)] - fn seek(&mut self, id: usize, pos: isize, whence: usize) -> Result<Option<isize>> { - Err(Error::new(EBADF)) + fn fsize(&mut self, id: usize) -> Result<Option<u64>> { + Err(Error::new(ESPIPE)) } #[allow(unused_variables)] @@ -229,24 +234,12 @@ pub trait SchemeBlockMut { } #[allow(unused_variables)] - fn mmap_prep( - &mut self, - id: usize, - offset: u64, - size: usize, - flags: MapFlags, - ) -> Result<Option<usize>> { + fn mmap_prep(&mut self, id: usize, offset: u64, size: usize, flags: MapFlags) -> Result<Option<usize>> { Err(Error::new(EOPNOTSUPP)) } #[allow(unused_variables)] - fn munmap( - &mut self, - id: usize, - offset: u64, - size: usize, - flags: MunmapFlags, - ) -> Result<Option<usize>> { + fn munmap(&mut self, id: usize, offset: u64, size: usize, flags: MunmapFlags) -> Result<Option<usize>> { Err(Error::new(EOPNOTSUPP)) } } diff --git a/src/scheme_mut.rs b/src/scheme_mut.rs index 05ead9e..4899dbb 100644 --- a/src/scheme_mut.rs +++ b/src/scheme_mut.rs @@ -42,15 +42,12 @@ pub trait SchemeMut { &CallerCtx::from_packet(&packet), ), ), - SYS_READ => self.read(packet.b, { + SYS_READ => self.read_old(packet.b, { slice::from_raw_parts_mut(packet.c as *mut u8, packet.d) }), - SYS_WRITE => self.write(packet.b, { + SYS_WRITE => self.write_old(packet.b, { 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), @@ -154,18 +151,26 @@ pub trait SchemeMut { } #[allow(unused_variables)] - fn read(&mut self, id: usize, buf: &mut [u8]) -> Result<usize> { + fn read_old(&mut self, id: usize, buf: &mut [u8]) -> Result<usize> { Err(Error::new(EBADF)) } + #[allow(unused_variables)] + fn read(&mut self, id: usize, buf: &mut [u8], offset: u64, fcntl_flags: u32) -> Result<usize> { + self.read_old(id, buf) + } #[allow(unused_variables)] - fn write(&mut self, id: usize, buf: &[u8]) -> Result<usize> { + fn write_old(&mut self, id: usize, buf: &[u8]) -> Result<usize> { Err(Error::new(EBADF)) } + #[allow(unused_variables)] + fn write(&mut self, id: usize, buf: &[u8], offset: u64, fcntl_flags: u32) -> Result<usize> { + self.write_old(id, buf) + } #[allow(unused_variables)] - fn seek(&mut self, id: usize, pos: isize, whence: usize) -> Result<isize> { - Err(Error::new(EBADF)) + fn fsize(&mut self, id: usize) -> Result<u64> { + Err(Error::new(ESPIPE)) } #[allow(unused_variables)] -- GitLab