Skip to content

Commit 96c3de5

Browse files
committed
debug: add debug implementation for file-related structs
1 parent 22f6869 commit 96c3de5

File tree

4 files changed

+29
-2
lines changed

4 files changed

+29
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
- Added partial support for the TCG protocols for TPM devices under `uefi::proto::tcg`.
1818
- Added the `unsafe_protocol` macro to provide a slightly nicer way to
1919
implement protocols.
20+
- `FileType`, `FileHandle`, `RegularFile`, and `Directory` now implement `Debug`.
2021

2122
### Changed
2223

uefi/src/proto/media/file/dir.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use super::{File, FileHandle, FileInfo, FromUefi, RegularFile};
22
use crate::data_types::Align;
33
use crate::Result;
44
use core::ffi::c_void;
5+
use core::fmt::{Debug, Formatter};
56
#[cfg(feature = "alloc")]
67
use {crate::mem::make_boxed, alloc::boxed::Box};
78
#[cfg(all(feature = "unstable", feature = "alloc"))]
@@ -125,6 +126,12 @@ impl Directory {
125126
}
126127
}
127128

129+
impl Debug for Directory {
130+
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
131+
f.debug_tuple("Directory").field(&self.0).finish()
132+
}
133+
}
134+
128135
impl File for Directory {
129136
#[inline]
130137
fn handle(&mut self) -> &mut FileHandle {

uefi/src/proto/media/file/mod.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ mod regular;
1313
use crate::{CStr16, Char16, Guid, Result, Status};
1414
use bitflags::bitflags;
1515
use core::ffi::c_void;
16-
use core::fmt::Debug;
16+
use core::fmt::{Debug, Formatter};
1717
use core::mem;
1818
use core::ptr;
1919
#[cfg(all(feature = "unstable", feature = "alloc"))]
@@ -304,6 +304,17 @@ impl File for FileHandle {
304304
}
305305
}
306306

307+
impl Debug for FileHandle {
308+
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
309+
f.debug_struct("FileHandle")
310+
.field("is_regular_file", &self.is_regular_file().unwrap_or(false))
311+
.field("is_directory", &self.is_directory().unwrap_or(false))
312+
// We can't print the info, as fetching info requires &mut self.
313+
.field("info", &"<hidden>")
314+
.finish()
315+
}
316+
}
317+
307318
impl Drop for FileHandle {
308319
fn drop(&mut self) {
309320
let result: Result = (self.imp().close)(self.imp()).into();
@@ -365,7 +376,8 @@ pub(super) struct FileImpl {
365376
flush: extern "efiapi" fn(this: &mut FileImpl) -> Status,
366377
}
367378

368-
/// Disambiguates the file type. Returned by `File::into_type()`.
379+
/// Disambiguate the file type. Returned by `File::into_type()`.
380+
#[derive(Debug)]
369381
pub enum FileType {
370382
/// The file was a regular (data) file.
371383
Regular(RegularFile),

uefi/src/proto/media/file/regular.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use super::{File, FileHandle, FileInternal};
22
use crate::{Result, Status};
3+
use core::fmt::{Debug, Formatter};
34

45
/// A `FileHandle` that is also a regular (data) file.
56
///
@@ -115,6 +116,12 @@ impl RegularFile {
115116
}
116117
}
117118

119+
impl Debug for RegularFile {
120+
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
121+
f.debug_tuple("RegularFile").field(&self.0).finish()
122+
}
123+
}
124+
118125
impl File for RegularFile {
119126
#[inline]
120127
fn handle(&mut self) -> &mut FileHandle {

0 commit comments

Comments
 (0)