Skip to content

Commit 856eb0e

Browse files
authored
Merge pull request #828 from wedsonaf/flags-to-mod
rust: change `FileFlags` struct to `flags` module
2 parents 9c9d4b9 + 1b856c0 commit 856eb0e

File tree

3 files changed

+10
-15
lines changed

3 files changed

+10
-15
lines changed

drivers/android/process.rs

Lines changed: 2 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::{self, File, FileFlags, IoctlCommand, IoctlHandler, PollTable},
7+
file::{self, File, IoctlCommand, IoctlHandler, PollTable},
88
io_buffer::{IoBufferReader, IoBufferWriter},
99
linked_list::List,
1010
mm,
@@ -794,7 +794,7 @@ 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;
797+
let blocking = (file.flags() & file::flags::O_NONBLOCK) == 0;
798798
match cmd {
799799
bindings::BINDER_WRITE_READ => thread.write_read(data, blocking)?,
800800
bindings::BINDER_GET_NODE_DEBUG_INFO => this.get_node_debug_info(data)?,

rust/kernel/file.rs

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,7 @@ use core::{cell::UnsafeCell, marker, mem, ptr};
2222
use macros::vtable;
2323

2424
/// Flags associated with a [`File`].
25-
///
26-
/// It is tagged with `non_exhaustive` to prevent users from instantiating it.
27-
#[non_exhaustive]
28-
pub struct FileFlags;
29-
30-
impl FileFlags {
25+
pub mod flags {
3126
/// File is opened in append mode.
3227
pub const O_APPEND: u32 = bindings::O_APPEND;
3328

@@ -46,7 +41,7 @@ impl FileFlags {
4641
/// File must be a directory.
4742
pub const O_DIRECTORY: u32 = bindings::O_DIRECTORY;
4843

49-
/// Like `Self::O_SYNC` except metadata is not synced.
44+
/// Like [`O_SYNC`] except metadata is not synced.
5045
pub const O_DSYNC: u32 = bindings::O_DSYNC;
5146

5247
/// Ensure that this file is created with the `open(2)` call.
@@ -69,7 +64,7 @@ impl FileFlags {
6964

7065
/// Also known as `O_NDELAY`.
7166
///
72-
/// This is effectively the same flag as [`Self::O_NONBLOCK`] on all architectures
67+
/// This is effectively the same flag as [`O_NONBLOCK`] on all architectures
7368
/// except SPARC64.
7469
pub const O_NDELAY: u32 = bindings::O_NDELAY;
7570

@@ -90,10 +85,10 @@ impl FileFlags {
9085
/// # Examples
9186
///
9287
/// ```
93-
/// use kernel::file::FileFlags;
88+
/// use kernel::file;
9489
/// # fn do_something() {}
9590
/// # let flags = 0;
96-
/// if (flags & FileFlags::O_ACCMODE) == FileFlags::O_RDONLY {
91+
/// if (flags & file::flags::O_ACCMODE) == file::flags::O_RDONLY {
9792
/// do_something();
9893
/// }
9994
/// ```
@@ -163,7 +158,7 @@ impl File {
163158

164159
/// Returns the flags associated with the file.
165160
///
166-
/// The flags are a combination of the constants in [`FileFlags`].
161+
/// The flags are a combination of the constants in [`flags`].
167162
pub fn flags(&self) -> u32 {
168163
// SAFETY: The file is valid because the shared reference guarantees a nonzero refcount.
169164
unsafe { core::ptr::addr_of!((*self.0.get()).f_flags).read() }

samples/rust/rust_random.rs

Lines changed: 2 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::{self, File, FileFlags},
9+
file::{self, File},
1010
io_buffer::{IoBufferReader, IoBufferWriter},
1111
prelude::*,
1212
};
@@ -34,7 +34,7 @@ impl file::Operations for RandomFile {
3434
while !buf.is_empty() {
3535
let len = chunkbuf.len().min(buf.len());
3636
let chunk = &mut chunkbuf[0..len];
37-
let blocking = (file.flags() & FileFlags::O_NONBLOCK) == 0;
37+
let blocking = (file.flags() & file::flags::O_NONBLOCK) == 0;
3838

3939
if blocking {
4040
kernel::random::getrandom(chunk)?;

0 commit comments

Comments
 (0)