From f48cbf22f3cf85e73f2dd778c3764ad430cd30e8 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Mon, 14 Nov 2016 12:14:19 -0700 Subject: [PATCH] Add fcntl --- Cargo.toml | 2 +- src/call.rs | 5 +++++ src/flag.rs | 3 +++ src/number.rs | 3 ++- src/scheme.rs | 12 ++++++++++++ 5 files changed, 23 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index ba76a82..486aa59 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "redox_syscall" -version = "0.1.1" +version = "0.1.2" description = "A Rust library to access raw Redox system calls" license = "MIT" authors = ["Jeremy Soller "] diff --git a/src/call.rs b/src/call.rs index e412cbe..baa6737 100644 --- a/src/call.rs +++ b/src/call.rs @@ -67,6 +67,11 @@ pub fn exit(status: usize) -> Result { unsafe { syscall1(SYS_EXIT, status) } } +/// Register a file for event-based I/O +pub fn fcntl(fd: usize, cmd: usize, arg: usize) -> Result { + unsafe { syscall3(SYS_FCNTL, fd, cmd, arg) } +} + /// Register a file for event-based I/O pub fn fevent(fd: usize, flags: usize) -> Result { unsafe { syscall2(SYS_FEVENT, fd, flags) } diff --git a/src/flag.rs b/src/flag.rs index 6dd73f8..0d0f95a 100644 --- a/src/flag.rs +++ b/src/flag.rs @@ -19,6 +19,9 @@ pub const EVENT_NONE: usize = 0; pub const EVENT_READ: usize = 1; pub const EVENT_WRITE: usize = 2; +pub const F_GETFL: usize = 1; +pub const F_SETFL: usize = 2; + pub const FUTEX_WAIT: usize = 0; pub const FUTEX_WAKE: usize = 1; pub const FUTEX_REQUEUE: usize = 2; diff --git a/src/number.rs b/src/number.rs index 1d7da15..4768aa0 100644 --- a/src/number.rs +++ b/src/number.rs @@ -20,10 +20,11 @@ pub const SYS_CLOSE: usize = SYS_CLASS_FILE | 6; pub const SYS_DUP: usize = SYS_CLASS_FILE | SYS_RET_FILE | 41; pub const SYS_READ: usize = SYS_CLASS_FILE | SYS_ARG_MSLICE | 3; pub const SYS_WRITE: usize = SYS_CLASS_FILE | SYS_ARG_SLICE | 4; +pub const SYS_LSEEK: usize = SYS_CLASS_FILE | 19; +pub const SYS_FCNTL: usize = SYS_CLASS_FILE | 55; pub const SYS_FEVENT: usize = SYS_CLASS_FILE | 927; pub const SYS_FMAP: usize = SYS_CLASS_FILE | 90; pub const SYS_FUNMAP: usize = SYS_CLASS_FILE | 91; -pub const SYS_LSEEK: usize = SYS_CLASS_FILE | 19; pub const SYS_FPATH: usize = SYS_CLASS_FILE | SYS_ARG_MSLICE | 928; pub const SYS_FSTAT: usize = SYS_CLASS_FILE | SYS_ARG_MSLICE | 28; pub const SYS_FSYNC: usize = SYS_CLASS_FILE | 118; diff --git a/src/scheme.rs b/src/scheme.rs index 2ccf0d7..c3111fb 100644 --- a/src/scheme.rs +++ b/src/scheme.rs @@ -14,6 +14,7 @@ pub trait Scheme { 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, packet.d), + SYS_FCNTL => self.fcntl(packet.b, packet.c, packet.d), SYS_FEVENT => self.fevent(packet.b, packet.c), SYS_FMAP => self.fmap(packet.b, packet.c, packet.d), SYS_FPATH => self.fpath(packet.b, unsafe { slice::from_raw_parts_mut(packet.c as *mut u8, packet.d) }), @@ -69,6 +70,11 @@ pub trait Scheme { Err(Error::new(EBADF)) } + #[allow(unused_variables)] + fn fcntl(&self, id: usize, cmd: usize, arg: usize) -> Result { + Err(Error::new(EBADF)) + } + #[allow(unused_variables)] fn fevent(&self, id: usize, flags: usize) -> Result { Err(Error::new(EBADF)) @@ -117,6 +123,7 @@ pub trait SchemeMut { 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, packet.d), + SYS_FCNTL => self.fcntl(packet.b, packet.c, packet.d), SYS_FEVENT => self.fevent(packet.b, packet.c), SYS_FMAP => self.fmap(packet.b, packet.c, packet.d), SYS_FPATH => self.fpath(packet.b, unsafe { slice::from_raw_parts_mut(packet.c as *mut u8, packet.d) }), @@ -171,6 +178,11 @@ pub trait SchemeMut { Err(Error::new(EBADF)) } + #[allow(unused_variables)] + fn fcntl(&mut self, id: usize, cmd: usize, arg: usize) -> Result { + Err(Error::new(EBADF)) + } + #[allow(unused_variables)] fn fevent(&mut self, id: usize, flags: usize) -> Result { Err(Error::new(EBADF))