Skip to content

Commit

Permalink
Amajd50/OS: updated is_terminal and set_blocking
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Amjad50 committed Jan 21, 2024
1 parent 5f7f6af commit d36fc6b
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 11 deletions.
8 changes: 4 additions & 4 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -83,19 +83,19 @@ checksum = "56fc6cf8dc8c4158eed8649f9b8b0ea1518eb62b544fe9490d66fa0b349eafe9"

[[package]]
name = "amjad_os_kernel_user_link"
version = "0.2.0"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e8d1291ea9cf6043bfa74865f170b13a220ae79c0d253d1b9ad57e90be137247"
checksum = "17549aafd3a6df6860b12329aff74941c7669483d0adaaf634f5e6aebff0639e"
dependencies = [
"compiler_builtins",
"rustc-std-workspace-core",
]

[[package]]
name = "amjad_os_user_std"
version = "0.2.0"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e0e98406c58607f4f54f9ec8e5ffbf7570daba78c343ac640b27f094d62fe3f7"
checksum = "d84fa958dc7be5b9c3a3f213869e53dd18bf8f4abee33f4bb620d94070226ba1"
dependencies = [
"amjad_os_kernel_user_link",
"compiler_builtins",
Expand Down
2 changes: 1 addition & 1 deletion library/std/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ r-efi-alloc = { version = "1.0.0", features = ['rustc-dep-of-std']}

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

[features]
backtrace = [
Expand Down
11 changes: 7 additions & 4 deletions library/std/src/sys/amjad_os/fd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use crate::{
os::amjad_os::io::{AsFd, AsRawFd, BorrowedFd, FromRawFd, IntoRawFd, OwnedFd, RawFd},
sys_common::{AsInner, FromInner, IntoInner},
};
// use crate::os::unix::io::{AsFd, AsRawFd, BorrowedFd, FromRawFd, IntoRawFd, OwnedFd, RawFd};
// use crate::sys_common::{AsInner, FromInner, IntoInner};

use user_std::io::FileMeta;

use super::syscall_to_io_error;

Expand Down Expand Up @@ -209,8 +209,11 @@ impl FileDesc {
};

unsafe {
user_std::io::syscall_blocking_mode(self.as_raw_fd(), blocking_mode)
.map_err(syscall_to_io_error)?
user_std::io::syscall_set_file_meta(
self.as_raw_fd(),
FileMeta::BlockingMode(blocking_mode),
)
.map_err(syscall_to_io_error)?
}

Ok(())
Expand Down
18 changes: 16 additions & 2 deletions library/std/src/sys/amjad_os/io.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
use crate::mem;

use crate::os::amjad_os::io::{AsFd, AsRawFd};
use crate::sys::amjad_os::syscall_to_io_error;
use user_std::io::FileMeta;

#[derive(Copy, Clone)]
pub struct IoSlice<'a>(&'a [u8]);

Expand Down Expand Up @@ -46,6 +50,16 @@ impl<'a> IoSliceMut<'a> {
}
}

pub fn is_terminal<T>(_: &T) -> bool {
false
pub fn is_terminal(file: &impl AsFd) -> bool {
let mut meta = FileMeta::IsTerminal(false);
unsafe {
user_std::io::syscall_get_file_meta(file.as_fd().as_raw_fd(), &mut meta)
.map_err(syscall_to_io_error)
.expect("syscall_get_file_meta failed");
}

match meta {
FileMeta::IsTerminal(is_terminal) => is_terminal,
_ => unreachable!(),
}
}

0 comments on commit d36fc6b

Please sign in to comment.