From 5a83d71b8e7d9c4565e3147817c6250e76d4e81c Mon Sep 17 00:00:00 2001 From: Daniel Xu Date: Sun, 9 Jan 2022 13:43:58 -0800 Subject: [PATCH] rust: file: Remove `is_blocking()` method The previous commit adds a generic way to check file flags. Better not to have two ways to do the same thing, especially when the second way is highly specialized. Signed-off-by: Daniel Xu --- drivers/android/process.rs | 5 +++-- rust/kernel/file.rs | 6 ------ samples/rust/rust_random.rs | 5 +++-- 3 files changed, 6 insertions(+), 10 deletions(-) diff --git a/drivers/android/process.rs b/drivers/android/process.rs index 252ced2e5d9b0a..d6b25de79cb332 100644 --- a/drivers/android/process.rs +++ b/drivers/android/process.rs @@ -4,7 +4,7 @@ use core::{convert::TryFrom, mem::take, ops::Range}; use kernel::{ bindings, cred::Credential, - file::File, + file::{File, FileFlags}, file_operations::{FileOperations, IoctlCommand, IoctlHandler, PollTable}, io_buffer::{IoBufferReader, IoBufferWriter}, linked_list::List, @@ -794,8 +794,9 @@ impl IoctlHandler for Process { data: UserSlicePtr, ) -> Result { let thread = this.get_thread(Task::current().pid())?; + let blocking = (file.flags() & FileFlags::O_NONBLOCK) == 0; match cmd { - bindings::BINDER_WRITE_READ => thread.write_read(data, file.is_blocking())?, + bindings::BINDER_WRITE_READ => thread.write_read(data, blocking)?, bindings::BINDER_GET_NODE_DEBUG_INFO => this.get_node_debug_info(data)?, bindings::BINDER_GET_NODE_INFO_FOR_REF => this.get_node_info_from_ref(data)?, bindings::BINDER_VERSION => this.version(data)?, diff --git a/rust/kernel/file.rs b/rust/kernel/file.rs index 9e889e554f1b99..29784032fc71ab 100644 --- a/rust/kernel/file.rs +++ b/rust/kernel/file.rs @@ -127,12 +127,6 @@ impl File { unsafe { (*self.ptr).f_pos as u64 } } - /// Returns whether the file is in blocking mode. - pub fn is_blocking(&self) -> bool { - // SAFETY: `File::ptr` is guaranteed to be valid by the type invariants. - unsafe { (*self.ptr).f_flags & bindings::O_NONBLOCK == 0 } - } - /// Returns the credentials of the task that originally opened the file. pub fn cred(&self) -> CredentialRef<'_> { // SAFETY: `File::ptr` is guaranteed to be valid by the type invariants. diff --git a/samples/rust/rust_random.rs b/samples/rust/rust_random.rs index c1319513b170a1..96e7c81b9f27b6 100644 --- a/samples/rust/rust_random.rs +++ b/samples/rust/rust_random.rs @@ -6,7 +6,7 @@ //! . use kernel::{ - file::File, + file::{File, FileFlags}, file_operations::FileOperations, io_buffer::{IoBufferReader, IoBufferWriter}, prelude::*, @@ -28,8 +28,9 @@ impl FileOperations for RandomFile { while !buf.is_empty() { let len = chunkbuf.len().min(buf.len()); let chunk = &mut chunkbuf[0..len]; + let blocking = (file.flags() & FileFlags::O_NONBLOCK) == 0; - if file.is_blocking() { + if blocking { kernel::random::getrandom(chunk)?; } else { kernel::random::getrandom_nonblock(chunk)?;