Skip to content

Commit ca2b972

Browse files
committed
Merge remote-tracking branch 'origin/main' into Iommu
2 parents 8966897 + d417cd1 commit ca2b972

File tree

5 files changed

+83
-21
lines changed

5 files changed

+83
-21
lines changed

uefi/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
implements `Display`.
2020
- Added `Handle::component_name()` and `Handle::device_path()` to simplify the
2121
common use-case of querying more information about a handle.
22+
- Added `fs::path::Path::join()`.
2223

2324
## Changed
2425
- export all `text::{input, output}::*` types

uefi/src/fs/path/path.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,14 @@ impl Path {
8585
pub const fn is_empty(&self) -> bool {
8686
self.to_cstr16().is_empty()
8787
}
88+
89+
/// Creates an owned [`PathBuf`] with `path` adjoined to `self`.
90+
#[must_use]
91+
pub fn join<P: AsRef<Self>>(&self, path: P) -> PathBuf {
92+
let mut buf = self.to_path_buf();
93+
buf.push(path);
94+
buf
95+
}
8896
}
8997

9098
impl Display for Path {
@@ -294,4 +302,19 @@ mod tests {
294302
assert_ne!(path1, path3);
295303
assert_ne!(path3, path1);
296304
}
305+
306+
#[test]
307+
fn join() {
308+
let path1 = Path::new(cstr16!(r"a\b"));
309+
let path2 = Path::new(cstr16!(r"c\d"));
310+
let path3 = Path::new(cstr16!(r"a\b\c\d"));
311+
312+
assert_eq!(path1.join(path2), path3.to_path_buf());
313+
314+
let pathbuf1 = path1.to_path_buf();
315+
let pathbuf2 = path2.to_path_buf();
316+
let pathbuf3 = path3.to_path_buf();
317+
318+
assert_eq!(pathbuf1.join(pathbuf2), pathbuf3);
319+
}
297320
}

uefi/src/proto/console/serial.rs

Lines changed: 56 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
55
use crate::proto::unsafe_protocol;
66
use crate::{Error, Result, Status, StatusExt};
7-
use core::fmt::Write;
7+
use core::fmt;
88
use uefi_raw::protocol::console::serial::{
99
SerialIoProtocol, SerialIoProtocol_1_1, SerialIoProtocolRevision,
1010
};
@@ -131,28 +131,66 @@ impl Serial {
131131
unsafe { (self.0.set_control_bits)(&mut self.0, bits) }.to_result()
132132
}
133133

134-
/// Reads data from this device.
134+
/// Reads data from the device. This function has the raw semantics of the
135+
/// underlying UEFI protocol.
135136
///
136-
/// This operation will block until the buffer has been filled with data or
137-
/// an error occurs. In the latter case, the error will indicate how many
138-
/// bytes were actually read from the device.
139-
pub fn read(&mut self, data: &mut [u8]) -> Result<(), usize> {
140-
let mut buffer_size = data.len();
141-
unsafe { (self.0.read)(&mut self.0, &mut buffer_size, data.as_mut_ptr()) }.to_result_with(
142-
|| debug_assert_eq!(buffer_size, data.len()),
137+
/// The function will read bytes until either the buffer is full or a
138+
/// timeout or overrun error occurs.
139+
///
140+
/// # Arguments
141+
///
142+
/// - `buffer`: buffer to fill
143+
///
144+
/// # Tips
145+
///
146+
/// Consider setting non-default properties via [`Self::set_attributes`]
147+
/// and [`Self::set_control_bits`] matching your use-case. For more info,
148+
/// please read the general [documentation](Self) of the protocol.
149+
///
150+
/// # Errors
151+
///
152+
/// - [`Status::DEVICE_ERROR`]: serial device reported an error
153+
/// - [`Status::TIMEOUT`]: operation was stopped due to a timeout or overrun
154+
pub fn read(&mut self, buffer: &mut [u8]) -> Result<(), usize /* read bytes on timeout*/> {
155+
let mut buffer_size = buffer.len();
156+
unsafe { (self.0.read)(&mut self.0, &mut buffer_size, buffer.as_mut_ptr()) }.to_result_with(
157+
|| {
158+
// By spec: Either reads all requested bytes (and blocks) or
159+
// returns early with an error.
160+
assert_eq!(buffer_size, buffer.len())
161+
},
143162
|_| buffer_size,
144163
)
145164
}
146165

147-
/// Writes data to this device.
166+
/// Writes data to this device. This function has the raw semantics of the
167+
/// underlying UEFI protocol.
168+
///
169+
/// The function will try to write all provided bytes in the configured
170+
/// timeout.
171+
///
172+
/// # Arguments
173+
///
174+
/// - `data`: bytes to write
175+
///
176+
/// # Tips
177+
///
178+
/// Consider setting non-default properties via [`Self::set_attributes`]
179+
/// and [`Self::set_control_bits`] matching your use-case. For more info,
180+
/// please read the general [documentation](Self) of the protocol.
181+
///
182+
/// # Errors
148183
///
149-
/// This operation will block until the data has been fully written or an
150-
/// error occurs. In the latter case, the error will indicate how many bytes
151-
/// were actually written to the device.
152-
pub fn write(&mut self, data: &[u8]) -> Result<(), usize> {
184+
/// - [`Status::DEVICE_ERROR`]: serial device reported an error
185+
/// - [`Status::TIMEOUT`]: data write was stopped due to a timeout
186+
pub fn write(&mut self, data: &[u8]) -> Result<(), usize /* bytes written on timeout */> {
153187
let mut buffer_size = data.len();
154188
unsafe { (self.0.write)(&mut self.0, &mut buffer_size, data.as_ptr()) }.to_result_with(
155-
|| debug_assert_eq!(buffer_size, data.len()),
189+
|| {
190+
// By spec: Either reads all requested bytes (and blocks) or
191+
// returns early with an error.
192+
assert_eq!(buffer_size, data.len())
193+
},
156194
|_| buffer_size,
157195
)
158196
}
@@ -198,8 +236,8 @@ impl Serial {
198236
}
199237
}
200238

201-
impl Write for Serial {
202-
fn write_str(&mut self, s: &str) -> core::fmt::Result {
203-
self.write(s.as_bytes()).map_err(|_| core::fmt::Error)
239+
impl fmt::Write for Serial {
240+
fn write_str(&mut self, s: &str) -> fmt::Result {
241+
self.write(s.as_bytes()).map(|_| ()).map_err(|_| fmt::Error)
204242
}
205243
}

uefi/src/proto/device_path/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ use crate::proto::{ProtocolPointer, unsafe_protocol};
111111
use core::ffi::c_void;
112112
use core::fmt::{self, Debug, Display, Formatter};
113113
use core::ops::Deref;
114+
use core::ptr;
114115
use ptr_meta::Pointee;
115116
use uefi_raw::protocol::device_path::DevicePathProtocol;
116117
#[cfg(feature = "alloc")]
@@ -564,8 +565,7 @@ impl DevicePath {
564565
/// Cast to a [`FfiDevicePath`] pointer.
565566
#[must_use]
566567
pub const fn as_ffi_ptr(&self) -> *const FfiDevicePath {
567-
let p = self as *const Self;
568-
p.cast()
568+
ptr::from_ref(self).cast()
569569
}
570570

571571
/// Get an iterator over the [`DevicePathInstance`]s in this path.

uefi/src/proto/rng.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ impl Rng {
5252

5353
let algo = match algorithm.as_ref() {
5454
None => ptr::null(),
55-
Some(algo) => algo as *const RngAlgorithmType,
55+
Some(algo) => ptr::from_ref(algo),
5656
};
5757

5858
unsafe {

0 commit comments

Comments
 (0)