Skip to content

Commit d36fc6b

Browse files
committed
Amajd50/OS: updated is_terminal and set_blocking
Now we have some `FileMeta` which are metadata about the opened files. We are using these to set the blocking mode and check if the file is terminal.
1 parent 5f7f6af commit d36fc6b

File tree

4 files changed

+28
-11
lines changed

4 files changed

+28
-11
lines changed

Cargo.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,19 +83,19 @@ checksum = "56fc6cf8dc8c4158eed8649f9b8b0ea1518eb62b544fe9490d66fa0b349eafe9"
8383

8484
[[package]]
8585
name = "amjad_os_kernel_user_link"
86-
version = "0.2.0"
86+
version = "0.2.1"
8787
source = "registry+https://github.com/rust-lang/crates.io-index"
88-
checksum = "e8d1291ea9cf6043bfa74865f170b13a220ae79c0d253d1b9ad57e90be137247"
88+
checksum = "17549aafd3a6df6860b12329aff74941c7669483d0adaaf634f5e6aebff0639e"
8989
dependencies = [
9090
"compiler_builtins",
9191
"rustc-std-workspace-core",
9292
]
9393

9494
[[package]]
9595
name = "amjad_os_user_std"
96-
version = "0.2.0"
96+
version = "0.2.2"
9797
source = "registry+https://github.com/rust-lang/crates.io-index"
98-
checksum = "e0e98406c58607f4f54f9ec8e5ffbf7570daba78c343ac640b27f094d62fe3f7"
98+
checksum = "d84fa958dc7be5b9c3a3f213869e53dd18bf8f4abee33f4bb620d94070226ba1"
9999
dependencies = [
100100
"amjad_os_kernel_user_link",
101101
"compiler_builtins",

library/std/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ r-efi-alloc = { version = "1.0.0", features = ['rustc-dep-of-std']}
5959

6060
[target.'cfg(target_os = "amjad_os")'.dependencies]
6161
# This is from `https://github.com/Amjad50/OS`, i.e. it must be run from that context
62-
user_std = { version = "0.2.0", package = "amjad_os_user_std", features = ['rustc-dep-of-std'] }
62+
user_std = { version = "0.2.2", package = "amjad_os_user_std", features = ['rustc-dep-of-std'] }
6363

6464
[features]
6565
backtrace = [

library/std/src/sys/amjad_os/fd.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ use crate::{
77
os::amjad_os::io::{AsFd, AsRawFd, BorrowedFd, FromRawFd, IntoRawFd, OwnedFd, RawFd},
88
sys_common::{AsInner, FromInner, IntoInner},
99
};
10-
// use crate::os::unix::io::{AsFd, AsRawFd, BorrowedFd, FromRawFd, IntoRawFd, OwnedFd, RawFd};
11-
// use crate::sys_common::{AsInner, FromInner, IntoInner};
10+
11+
use user_std::io::FileMeta;
1212

1313
use super::syscall_to_io_error;
1414

@@ -209,8 +209,11 @@ impl FileDesc {
209209
};
210210

211211
unsafe {
212-
user_std::io::syscall_blocking_mode(self.as_raw_fd(), blocking_mode)
213-
.map_err(syscall_to_io_error)?
212+
user_std::io::syscall_set_file_meta(
213+
self.as_raw_fd(),
214+
FileMeta::BlockingMode(blocking_mode),
215+
)
216+
.map_err(syscall_to_io_error)?
214217
}
215218

216219
Ok(())

library/std/src/sys/amjad_os/io.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
use crate::mem;
22

3+
use crate::os::amjad_os::io::{AsFd, AsRawFd};
4+
use crate::sys::amjad_os::syscall_to_io_error;
5+
use user_std::io::FileMeta;
6+
37
#[derive(Copy, Clone)]
48
pub struct IoSlice<'a>(&'a [u8]);
59

@@ -46,6 +50,16 @@ impl<'a> IoSliceMut<'a> {
4650
}
4751
}
4852

49-
pub fn is_terminal<T>(_: &T) -> bool {
50-
false
53+
pub fn is_terminal(file: &impl AsFd) -> bool {
54+
let mut meta = FileMeta::IsTerminal(false);
55+
unsafe {
56+
user_std::io::syscall_get_file_meta(file.as_fd().as_raw_fd(), &mut meta)
57+
.map_err(syscall_to_io_error)
58+
.expect("syscall_get_file_meta failed");
59+
}
60+
61+
match meta {
62+
FileMeta::IsTerminal(is_terminal) => is_terminal,
63+
_ => unreachable!(),
64+
}
5165
}

0 commit comments

Comments
 (0)