Skip to content

Commit

Permalink
rust: file: Remove is_blocking() method
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
danobi committed Feb 23, 2022
1 parent f78d1af commit 5a83d71
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 10 deletions.
5 changes: 3 additions & 2 deletions drivers/android/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -794,8 +794,9 @@ impl IoctlHandler for Process {
data: UserSlicePtr,
) -> Result<i32> {
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)?,
Expand Down
6 changes: 0 additions & 6 deletions rust/kernel/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 3 additions & 2 deletions samples/rust/rust_random.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
//! <https://github.com/alex/just-use/blob/master/src/lib.rs>.
use kernel::{
file::File,
file::{File, FileFlags},
file_operations::FileOperations,
io_buffer::{IoBufferReader, IoBufferWriter},
prelude::*,
Expand All @@ -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)?;
Expand Down

0 comments on commit 5a83d71

Please sign in to comment.