Skip to content

Commit 5a83d71

Browse files
committed
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 <dxu@dxuuu.xyz>
1 parent f78d1af commit 5a83d71

File tree

3 files changed

+6
-10
lines changed

3 files changed

+6
-10
lines changed

drivers/android/process.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use core::{convert::TryFrom, mem::take, ops::Range};
44
use kernel::{
55
bindings,
66
cred::Credential,
7-
file::File,
7+
file::{File, FileFlags},
88
file_operations::{FileOperations, IoctlCommand, IoctlHandler, PollTable},
99
io_buffer::{IoBufferReader, IoBufferWriter},
1010
linked_list::List,
@@ -794,8 +794,9 @@ impl IoctlHandler for Process {
794794
data: UserSlicePtr,
795795
) -> Result<i32> {
796796
let thread = this.get_thread(Task::current().pid())?;
797+
let blocking = (file.flags() & FileFlags::O_NONBLOCK) == 0;
797798
match cmd {
798-
bindings::BINDER_WRITE_READ => thread.write_read(data, file.is_blocking())?,
799+
bindings::BINDER_WRITE_READ => thread.write_read(data, blocking)?,
799800
bindings::BINDER_GET_NODE_DEBUG_INFO => this.get_node_debug_info(data)?,
800801
bindings::BINDER_GET_NODE_INFO_FOR_REF => this.get_node_info_from_ref(data)?,
801802
bindings::BINDER_VERSION => this.version(data)?,

rust/kernel/file.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -127,12 +127,6 @@ impl File {
127127
unsafe { (*self.ptr).f_pos as u64 }
128128
}
129129

130-
/// Returns whether the file is in blocking mode.
131-
pub fn is_blocking(&self) -> bool {
132-
// SAFETY: `File::ptr` is guaranteed to be valid by the type invariants.
133-
unsafe { (*self.ptr).f_flags & bindings::O_NONBLOCK == 0 }
134-
}
135-
136130
/// Returns the credentials of the task that originally opened the file.
137131
pub fn cred(&self) -> CredentialRef<'_> {
138132
// SAFETY: `File::ptr` is guaranteed to be valid by the type invariants.

samples/rust/rust_random.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
//! <https://github.com/alex/just-use/blob/master/src/lib.rs>.
77
88
use kernel::{
9-
file::File,
9+
file::{File, FileFlags},
1010
file_operations::FileOperations,
1111
io_buffer::{IoBufferReader, IoBufferWriter},
1212
prelude::*,
@@ -28,8 +28,9 @@ impl FileOperations for RandomFile {
2828
while !buf.is_empty() {
2929
let len = chunkbuf.len().min(buf.len());
3030
let chunk = &mut chunkbuf[0..len];
31+
let blocking = (file.flags() & FileFlags::O_NONBLOCK) == 0;
3132

32-
if file.is_blocking() {
33+
if blocking {
3334
kernel::random::getrandom(chunk)?;
3435
} else {
3536
kernel::random::getrandom_nonblock(chunk)?;

0 commit comments

Comments
 (0)